Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Roo2DKeysPdf.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitModels *
4  * File: $Id: Roo2DKeysPdf.h,v 1.12 2007/05/11 09:13:07 verkerke Exp $
5  * Authors: *
6  * AB, Adrian Bevan, Liverpool University, bevan@slac.stanford.edu *
7  * *
8  * Copyright (c) 2000-2005, Regents of the University of California, *
9  * Liverpool University, *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_2DKEYS
17 #define ROO_2DKEYS
18 
19 #include "RooAbsPdf.h"
20 #include "RooRealProxy.h"
21 #include "RooAbsReal.h"
22 #include "RooDataSet.h"
23 
24 ////////////////////////////////////////////////////////////////////////////////////
25 class Roo2DKeysPdf : public RooAbsPdf
26 {
27 public:
28  Roo2DKeysPdf(const char *name, const char *title,
29  RooAbsReal& xx, RooAbsReal &yy, RooDataSet& data, TString options = "a", Double_t widthScaleFactor = 1.0);
30  Roo2DKeysPdf(const Roo2DKeysPdf& other, const char* name=0);
31  virtual TObject* clone(const char* newname) const { return new Roo2DKeysPdf(*this,newname); }
32 
33  virtual ~Roo2DKeysPdf();
34 
35 //load in a new dataset and re-calculate the PDF
36 //return 0 if successful
37  Int_t loadDataSet(RooDataSet& data, TString options);
38 
39 // The Roo2DKeys options available are:
40 // a = select an adaptive bandwidth [default]
41 // n = select a normal bandwidth
42 // m = mirror kernel contributions at edges [fold gaussians back into the x,y plane]
43 // d = print debug statements [useful for development only; default is off]
44 // v = print verbose debug statements [useful for development only; default is off]
45 // vv = print ludicrously verbose debug statements [useful for development only; default is off]
46  void setOptions(TString options);
47  void getOptions(void) const;
48 
49 // Set the value of a scale factor to modify the bandwidth by. The default value for this is unity.
50 // Modification of 'normal' bandwidths is useful when the data are not 'normally distributed',
51 // otherwise one expects little departure from that behavior. Note that both the normal and adaptive
52 // bandwidth selections are modified by this factor. Useful for systematic studies.
53 // ***********
54 // *IMPORTANT* The kernel is proportional to 1/widthScaleFactor.
55 // ***********
56  inline void setWidthScaleFactor(Double_t widthScaleFactor);
57 
58 // choose the kernel bandwith to use. The default is 0
59 // 0 = use adaptive kernel estimator (uses local population to vary with of kernels)
60 // 1 = use trivial kernel estimator (uses all data and sigma to estimate uniform kernel bandwidth)
61  Int_t calculateBandWidth(Int_t kernel = -999);
62 
63  Int_t getBandWidthType() const;
64  Double_t getMean(const char * axis) const;
65  Double_t getSigma(const char * axis) const;
66 
67 // print content and basic information about the data
68  void PrintInfo(std::ostream &) const;
69 
70 // save PDF to a file as a TH2F *, TTree * or both
71 // this is so that you only need to compute the PDF once and
72 // are free to use the much faster Roo2DHistPdf class in order
73 // to perform fits/do toy studies etc.
74  void writeToFile(char * outputFile, const char * name) const;
75  void writeHistToFile(char * outputFile, const char * histName) const;
76  void writeNTupleToFile(char * outputFile, const char * name) const;
77 
78  RooRealProxy x;
79  RooRealProxy y;
80 
81  Double_t evaluate() const;
82 
83 protected:
84 
85 private:
86  // these are used in calculating bandwidths for x and y
87  Double_t evaluateFull(Double_t thisX, Double_t thisY) const;
88  Double_t g(Double_t var1, Double_t * _var1, Double_t sigma1, Double_t var2,
89  Double_t * _var2, Double_t sigma2) const;
90 
91  //mirror corrections for the boundaries
92  Double_t highBoundaryCorrection(Double_t thisVar, Double_t thisH, Double_t high, Double_t tVar) const;
93  Double_t lowBoundaryCorrection(Double_t thisVar, Double_t thisH, Double_t low, Double_t tVar) const;
94 
95  Double_t * _x;
96  Double_t * _hx;
97  Double_t * _y;
98  Double_t * _hy;
99  Double_t _norm;
100  Double_t _xMean; // the (x,y) mean and sigma are properties of the data, not of the PDF
101  Double_t _xSigma;
102  Double_t _yMean;
103  Double_t _ySigma;
104  Double_t _n; //coefficient of the kernel estimation sum
105  Double_t _n16; //pow(_nEvents, -1/6)
106  Double_t _sqrt2pi;
107  Double_t _2pi; // = M_PI*2
108  Double_t _lox,_hix;
109  Double_t _loy,_hiy;
110  Double_t _xoffset;
111  Double_t _yoffset;
112  Double_t _widthScaleFactor; //allow manipulation of the bandwidth by a scale factor
113 
114  Int_t _nEvents;
115  Int_t _BandWidthType;
116  Int_t _MirrorAtBoundary;
117  Int_t _debug;
118  Int_t _verbosedebug;
119  Int_t _vverbosedebug;
120 
121  ClassDef(Roo2DKeysPdf,0) // Two-dimensional kernel estimation p.d.f.
122 };
123 
124 inline void Roo2DKeysPdf::setWidthScaleFactor(Double_t widthScaleFactor) { _widthScaleFactor = widthScaleFactor; }
125 
126 #endif