ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitModels                                                     *
 *    File: $Id: Roo2DKeysPdf.h,v 1.12 2007/05/11 09:13:07 verkerke Exp $
 * Authors:                                                                  *
 *   AB, Adrian Bevan, Liverpool University, bevan@slac.stanford.edu         *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California,         *
 *                          Liverpool University,                            *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_2DKEYS
#define ROO_2DKEYS

#include "RooAbsPdf.h"
#include "RooRealProxy.h"
#include "RooAbsReal.h"
#include "RooDataSet.h"

////////////////////////////////////////////////////////////////////////////////////
class Roo2DKeysPdf : public RooAbsPdf 
{
public:
  Roo2DKeysPdf(const char *name, const char *title,
             RooAbsReal& xx, RooAbsReal &yy, RooDataSet& data, TString options = "a", Double_t widthScaleFactor = 1.0);
  Roo2DKeysPdf(const Roo2DKeysPdf& other, const char* name=0);
  virtual TObject* clone(const char* newname) const { return new Roo2DKeysPdf(*this,newname); }

  virtual ~Roo2DKeysPdf();

//load in a new dataset and re-calculate the PDF
//return 0 if sucessful
  Int_t    loadDataSet(RooDataSet& data, TString options);

// The Roo2DKeys options available are:
//      a = select an adaptove bandwidth [default]
//      n = select a normal bandwidth
//      m = mirror kernal contributions at edges [fold gaussians back into the x,y plane]
//      d = print debug statements [useful for development only; default is off]
//      v  = print verbose debug statements [useful for development only; default is off]
//      vv = print ludicrously verbose debug statements [useful for development only; default is off]
  void     setOptions(TString options);
  void     getOptions(void) const;

// Set the value of a scale factor to modify the bandwidth by. The default value for this is unity.
// Modification of 'normal' bandwidths is useful when the data are not 'normally distributed', 
// otherwise one expects little departure from that behavior.  Note that both the normal and adaptive
// bandwidth selections are modified by this factor.  Useful for systematic studies.
//           ***********
//           *IMPORTANT* The kernel is proportional to 1/widthScaleFactor.
//           ***********
  inline void     setWidthScaleFactor(Double_t widthScaleFactor);

// choose the kernel bandwith to use.  The default is 0                                               
//    0 = use adaptive kernel estimator (uses local population to vary with of kernels)               
//    1 = use trivial kernel estimator (uses all data and sigma to estimate uniform kernel bandwidth)
  Int_t    calculateBandWidth(Int_t kernel = -999);

  Int_t    getBandWidthType() const;
  Double_t getMean(const char * axis) const;
  Double_t getSigma(const char * axis) const;

// print content and basic information about the data
  void     PrintInfo(ostream &) const;

// save PDF to a file as a TH2F *, TTree * or both
// this is so that you only need to compute the PDF once and 
// are free to use the much faster Roo2DHistPdf class in order 
// to perform fits/do toy studies etc.  
  void     writeToFile(char * outputFile, const char * name) const;
  void     writeHistToFile(char * outputFile, const char * histName) const;
  void     writeNTupleToFile(char * outputFile, const char * name) const;

  RooRealProxy x;
  RooRealProxy y;

  Double_t evaluate() const;

protected:

private:
  // these are used in calculating bandwidths for x and y
  Double_t evaluateFull(Double_t thisX, Double_t thisY) const;
  Double_t g(Double_t var1, Double_t * _var1, Double_t sigma1, Double_t var2, 
	     Double_t * _var2, Double_t sigma2) const; 

  //mirror corrections for the boundaries
  Double_t highBoundaryCorrection(Double_t thisVar, Double_t thisH, Double_t high, Double_t tVar) const;
  Double_t lowBoundaryCorrection(Double_t thisVar, Double_t thisH, Double_t low, Double_t tVar) const;

  Double_t * _x;
  Double_t * _hx;
  Double_t * _y;
  Double_t * _hy;
  Double_t   _norm;
  Double_t   _xMean;    // the (x,y) mean and sigma are properties of the data, not of the PDF
  Double_t   _xSigma;
  Double_t   _yMean;
  Double_t   _ySigma;
  Double_t   _n;         //coefficient of the kernel estimation sum
  Double_t   _n16;       //pow(_nEvents, -1/6)
  Double_t   _sqrt2pi;
  Double_t   _2pi;       // = M_PI*2
  Double_t   _lox,_hix;
  Double_t   _loy,_hiy;
  Double_t   _xoffset;
  Double_t   _yoffset;
  Double_t   _widthScaleFactor; //allow manipulation of the bandwidth by a scale factor

  Int_t      _nEvents;
  Int_t      _BandWidthType;
  Int_t      _MirrorAtBoundary;
  Int_t      _debug;
  Int_t      _verbosedebug;
  Int_t      _vverbosedebug;

  ClassDef(Roo2DKeysPdf,0) // Two-dimensional kernel estimation p.d.f.
};

inline void  Roo2DKeysPdf::setWidthScaleFactor(Double_t widthScaleFactor) { _widthScaleFactor = widthScaleFactor; }

#endif



 Roo2DKeysPdf.h:1
 Roo2DKeysPdf.h:2
 Roo2DKeysPdf.h:3
 Roo2DKeysPdf.h:4
 Roo2DKeysPdf.h:5
 Roo2DKeysPdf.h:6
 Roo2DKeysPdf.h:7
 Roo2DKeysPdf.h:8
 Roo2DKeysPdf.h:9
 Roo2DKeysPdf.h:10
 Roo2DKeysPdf.h:11
 Roo2DKeysPdf.h:12
 Roo2DKeysPdf.h:13
 Roo2DKeysPdf.h:14
 Roo2DKeysPdf.h:15
 Roo2DKeysPdf.h:16
 Roo2DKeysPdf.h:17
 Roo2DKeysPdf.h:18
 Roo2DKeysPdf.h:19
 Roo2DKeysPdf.h:20
 Roo2DKeysPdf.h:21
 Roo2DKeysPdf.h:22
 Roo2DKeysPdf.h:23
 Roo2DKeysPdf.h:24
 Roo2DKeysPdf.h:25
 Roo2DKeysPdf.h:26
 Roo2DKeysPdf.h:27
 Roo2DKeysPdf.h:28
 Roo2DKeysPdf.h:29
 Roo2DKeysPdf.h:30
 Roo2DKeysPdf.h:31
 Roo2DKeysPdf.h:32
 Roo2DKeysPdf.h:33
 Roo2DKeysPdf.h:34
 Roo2DKeysPdf.h:35
 Roo2DKeysPdf.h:36
 Roo2DKeysPdf.h:37
 Roo2DKeysPdf.h:38
 Roo2DKeysPdf.h:39
 Roo2DKeysPdf.h:40
 Roo2DKeysPdf.h:41
 Roo2DKeysPdf.h:42
 Roo2DKeysPdf.h:43
 Roo2DKeysPdf.h:44
 Roo2DKeysPdf.h:45
 Roo2DKeysPdf.h:46
 Roo2DKeysPdf.h:47
 Roo2DKeysPdf.h:48
 Roo2DKeysPdf.h:49
 Roo2DKeysPdf.h:50
 Roo2DKeysPdf.h:51
 Roo2DKeysPdf.h:52
 Roo2DKeysPdf.h:53
 Roo2DKeysPdf.h:54
 Roo2DKeysPdf.h:55
 Roo2DKeysPdf.h:56
 Roo2DKeysPdf.h:57
 Roo2DKeysPdf.h:58
 Roo2DKeysPdf.h:59
 Roo2DKeysPdf.h:60
 Roo2DKeysPdf.h:61
 Roo2DKeysPdf.h:62
 Roo2DKeysPdf.h:63
 Roo2DKeysPdf.h:64
 Roo2DKeysPdf.h:65
 Roo2DKeysPdf.h:66
 Roo2DKeysPdf.h:67
 Roo2DKeysPdf.h:68
 Roo2DKeysPdf.h:69
 Roo2DKeysPdf.h:70
 Roo2DKeysPdf.h:71
 Roo2DKeysPdf.h:72
 Roo2DKeysPdf.h:73
 Roo2DKeysPdf.h:74
 Roo2DKeysPdf.h:75
 Roo2DKeysPdf.h:76
 Roo2DKeysPdf.h:77
 Roo2DKeysPdf.h:78
 Roo2DKeysPdf.h:79
 Roo2DKeysPdf.h:80
 Roo2DKeysPdf.h:81
 Roo2DKeysPdf.h:82
 Roo2DKeysPdf.h:83
 Roo2DKeysPdf.h:84
 Roo2DKeysPdf.h:85
 Roo2DKeysPdf.h:86
 Roo2DKeysPdf.h:87
 Roo2DKeysPdf.h:88
 Roo2DKeysPdf.h:89
 Roo2DKeysPdf.h:90
 Roo2DKeysPdf.h:91
 Roo2DKeysPdf.h:92
 Roo2DKeysPdf.h:93
 Roo2DKeysPdf.h:94
 Roo2DKeysPdf.h:95
 Roo2DKeysPdf.h:96
 Roo2DKeysPdf.h:97
 Roo2DKeysPdf.h:98
 Roo2DKeysPdf.h:99
 Roo2DKeysPdf.h:100
 Roo2DKeysPdf.h:101
 Roo2DKeysPdf.h:102
 Roo2DKeysPdf.h:103
 Roo2DKeysPdf.h:104
 Roo2DKeysPdf.h:105
 Roo2DKeysPdf.h:106
 Roo2DKeysPdf.h:107
 Roo2DKeysPdf.h:108
 Roo2DKeysPdf.h:109
 Roo2DKeysPdf.h:110
 Roo2DKeysPdf.h:111
 Roo2DKeysPdf.h:112
 Roo2DKeysPdf.h:113
 Roo2DKeysPdf.h:114
 Roo2DKeysPdf.h:115
 Roo2DKeysPdf.h:116
 Roo2DKeysPdf.h:117
 Roo2DKeysPdf.h:118
 Roo2DKeysPdf.h:119
 Roo2DKeysPdf.h:120
 Roo2DKeysPdf.h:121
 Roo2DKeysPdf.h:122
 Roo2DKeysPdf.h:123
 Roo2DKeysPdf.h:124
 Roo2DKeysPdf.h:125
 Roo2DKeysPdf.h:126
 Roo2DKeysPdf.h:127
 Roo2DKeysPdf.h:128
 Roo2DKeysPdf.h:129