CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VerticalInterpHistPdf.h
Go to the documentation of this file.
1 #ifndef ROO_VERTICA_INTERP_HIST
2 #define ROO_VERTICA_INTERP_HIST
3 
7 #include "RooAbsPdf.h"
8 #include "RooRealProxy.h"
9 #include "RooListProxy.h"
10 #include "TH1.h"
11 #include "../interface/SimpleCacheSentry.h"
12 #include "../interface/FastTemplate.h"
13 #include <cmath>
14 
15 #define FastVerticalInterpHistPdf_CopyConstructor
16 #define FastVerticalInterpHistPdf_Serializable
17 
19 
20 class VerticalInterpHistPdf : public RooAbsPdf {
21 public:
22 
24  VerticalInterpHistPdf(const char *name, const char *title, const RooRealVar &x, const RooArgList& funcList, const RooArgList& coefList, Double_t smoothRegion=1., Int_t smoothAlgo=1) ;
25  VerticalInterpHistPdf(const VerticalInterpHistPdf& other, const char* name=0) ;
26  virtual TObject* clone(const char* newname) const { return new VerticalInterpHistPdf(*this,newname) ; }
27  virtual ~VerticalInterpHistPdf() ;
28 
29  Bool_t selfNormalized() const { return kTRUE; }
30 
31  Double_t evaluate() const ;
32 
33  const RooArgList& funcList() const { return _funcList ; }
34  const RooArgList& coefList() const { return _coefList ; }
35 
36  const RooRealProxy &x() const { return _x; }
38 protected:
39  RooRealProxy _x;
40  RooListProxy _funcList ; // List of component FUNCs
41  RooListProxy _coefList ; // List of coefficients
42  Double_t _smoothRegion;
43  Int_t _smoothAlgo;
44  TIterator* _funcIter ;
45  TIterator* _coefIter ;
46 
47  // TH1 containing the histogram of this pdf
48  mutable SimpleCacheSentry _sentry; // !not to be serialized
49  mutable TH1 *_cacheTotal;
50  // For additive morphing, histograms of fNominal, fUp and fDown
51  // For multiplicative morphing, histograms of fNominal, log(fUp/fNominal), -log(fDown/fNominal);
52  mutable TH1 **_cacheSingle;
53  mutable int *_cacheSingleGood;
54 private:
55 
56  ClassDef(VerticalInterpHistPdf,1) //
57 
58 protected:
59  void setupCaches() const ;
60  void syncTotal() const ;
61  void syncComponent(int which) const ;
62  // return a smooth function that is equal to +/-1 for |x| >= smoothRegion_ and it's null in zero
63  inline double smoothStepFunc(double x) const {
64  if (fabs(x) >= _smoothRegion) return x > 0 ? +1 : -1;
65  double xnorm = x/_smoothRegion, xnorm2 = xnorm*xnorm;
66  return 0.125 * xnorm * (xnorm2 * (3.*xnorm2 - 10.) + 15);
67  }
68 };
69 
70 class FastVerticalInterpHistPdfBase : public RooAbsPdf {
71 public:
72 
74  FastVerticalInterpHistPdfBase(const char *name, const char *title, const RooArgSet &obs, const RooArgList& funcList, const RooArgList& coefList, Double_t smoothRegion=1., Int_t smoothAlgo=1) ;
75  FastVerticalInterpHistPdfBase(const FastVerticalInterpHistPdfBase& other, const char* name=0) ;
76  virtual TObject* clone(const char* newname) const = 0;
78 
79  Bool_t selfNormalized() const { return kTRUE; }
80 
81  Double_t evaluate() const = 0;
82 
83  const RooArgList& funcList() const { return _funcList ; }
84  const RooArgList& coefList() const { return _coefList ; }
85 
88 protected:
89  RooRealProxy _x;
90  RooListProxy _funcList ; // List of component FUNCs
91  RooListProxy _coefList ; // List of coefficients
92  Double_t _smoothRegion;
93  Int_t _smoothAlgo;
94  TIterator* _funcIter ;
95  TIterator* _coefIter ;
96 
97  // TH1 containing the histogram of this pdf
98  mutable bool _init;
100 
101  // For additive morphing, histograms of (fUp-f0)+(fDown-f0) and (fUp-f0)-(fDown-f0)
102  // For multiplicative morphing, log(fUp/f0)+log(fDown/f0), log(fUp/f0)-log(fDown/f0)
103  mutable std::vector<Morph> _morphs;
104  mutable std::vector<RooAbsReal *> _morphParams;
105 
106  // Prepare morphing data for a triplet of templates
107  void syncMorph(Morph &out, const FastTemplate &nominal, FastTemplate &lo, FastTemplate &hi) const;
108 
109  // Do the vertical morphing from nominal value and morphs into cache.
110  // Do not normalize yet, as that depends on the dimension of the template
111  void syncTotal(FastTemplate &cache, const FastTemplate &cacheNominal, const FastTemplate &cacheNominalLog) const ;
112 
113  // return a smooth function that is equal to +/-1 for |x| >= smoothRegion_ and it's null in zero
114  inline double smoothStepFunc(double x) const {
115  if (fabs(x) >= _smoothRegion) return x > 0 ? +1 : -1;
116  double xnorm = x/_smoothRegion, xnorm2 = xnorm*xnorm;
117  return 0.125 * xnorm * (xnorm2 * (3.*xnorm2 - 10.) + 15);
118  }
119 
120 private:
121  ClassDef(FastVerticalInterpHistPdfBase,2) //
122 };
123 
124 
126 public:
127 
129  FastVerticalInterpHistPdf(const char *name, const char *title, const RooRealVar &x, const RooArgList& funcList, const RooArgList& coefList, Double_t smoothRegion=1., Int_t smoothAlgo=1) :
130  FastVerticalInterpHistPdfBase(name,title,RooArgSet(x),funcList,coefList,smoothRegion,smoothAlgo),
131  _x("x","Independent variable",this,const_cast<RooRealVar&>(x)),
135  _x("x",this,other._x),
138 #else
140 #endif
141  virtual TObject* clone(const char* newname) const { return new FastVerticalInterpHistPdf(*this,newname) ; }
143 
144  Double_t evaluate() const ;
145 
146  Bool_t hasCache() const { return _cache.size() > 0; }
147  Bool_t isCacheReady() const { return _cache.size() > 0 && _init; }
148 protected:
149  RooRealProxy _x;
150 
152  mutable FastHisto _cache;
153  mutable FastHisto _cacheNominal;
156 
157  void setupCaches() const ;
158  void syncTotal() const ;
159  void syncComponent(int which) const ;
160  void syncNominal() const ;
161  void syncComponents(int dimension) const ;
162 
163 private:
164  ClassDef(FastVerticalInterpHistPdf,1) //
165 };
166 
168 public:
169 
173  FastVerticalInterpHistPdf2D(const char *name, const char *title, const RooRealVar &x, const RooRealVar &y, bool conditional, const RooArgList& funcList, const RooArgList& coefList, Double_t smoothRegion=1., Int_t smoothAlgo=1) :
174  FastVerticalInterpHistPdfBase(name,title,RooArgSet(x,y),funcList,coefList,smoothRegion,smoothAlgo),
175  _x("x","Independent variable",this,const_cast<RooRealVar&>(x)),
176  _y("y","Independent variable",this,const_cast<RooRealVar&>(y)),
177  _conditional(conditional),
181  _x("x",this,other._x), _y("y",this,other._y), _conditional(other._conditional),
184 #else
186 #endif
187  virtual TObject* clone(const char* newname) const { return new FastVerticalInterpHistPdf2D(*this,newname) ; }
189 
190  Double_t evaluate() const ;
191 
192  Bool_t selfNormalized() const { return kTRUE; }
193  Bool_t conditional() const { return _conditional; }
194 
195  Bool_t hasCache() const { return _cache.size() > 0; }
196  Bool_t isCacheReady() const { return _cache.size() > 0 && _init; }
197 protected:
198  RooRealProxy _x, _y;
200 
202  mutable FastHisto2D _cache;
203  mutable FastHisto2D _cacheNominal;
206 
207  void setupCaches() const ;
208  void syncTotal() const ;
209  void syncComponent(int which) const ;
210  void syncNominal() const ;
211  void syncComponents(int dimension) const ;
212 
213 private:
214  ClassDef(FastVerticalInterpHistPdf2D,1) //
215 };
216 
217 
218 
219 
220 
221 #endif
void syncComponent(int which) const
virtual TObject * clone(const char *newname) const
const unsigned int size() const
Definition: FastTemplate.h:42
FastHisto _cache
Cache of the result.
FastHisto2D _cacheNominal
Cache of nominal pdf (additive morphing) and its bin-by-bin logarithm (multiplicative) ...
#define FastVerticalInterpHistPdf_CopyConstructor
FastVerticalInterpHistPdf2D(const char *name, const char *title, const RooRealVar &x, const RooRealVar &y, bool conditional, const RooArgList &funcList, const RooArgList &coefList, Double_t smoothRegion=1., Int_t smoothAlgo=1)
FastVerticalInterpHistPdf2D(const FastVerticalInterpHistPdf2D &other, const char *name=0)
ClassDef(VerticalInterpHistPdf, 1) protected void syncTotal() const
not to be serialized
void setupCaches() const
not to be serialized
virtual TObject * clone(const char *newname) const
void syncTotal(FastTemplate &cache, const FastTemplate &cacheNominal, const FastTemplate &cacheNominalLog) const
const RooArgList & coefList() const
void syncComponent(int which) const
const RooRealProxy & x() const
TIterator * _coefIter
Iterator over FUNC list.
int * _cacheSingleGood
not to be serialized
void syncComponents(int dimension) const
bool _init
Iterator over coefficient list.
FastHisto _cacheNominal
Cache of nominal pdf (additive morphing) and its bin-by-bin logarithm (multiplicative) ...
const RooArgList & funcList() const
Must be public, for serialization.
Bool_t selfNormalized() const
TIterator * _coefIter
Iterator over FUNC list.
void setupCaches() const
not to be serialized
double smoothStepFunc(double x) const
void syncComponent(int which) const
SimpleCacheSentry _sentry
Iterator over coefficient list.
virtual TObject * clone(const char *newname) const =0
virtual TObject * clone(const char *newname) const
tuple out
Definition: dbtoconf.py:99
std::vector< RooAbsReal * > _morphParams
not to be serialized
const RooArgList & funcList() const
std::vector< Morph > _morphs
not to be serialized
void syncComponents(int dimension) const
FastVerticalInterpHistPdf(const FastVerticalInterpHistPdf &other, const char *name=0)
FastVerticalInterpHistPdf(const char *name, const char *title, const RooRealVar &x, const RooArgList &funcList, const RooArgList &coefList, Double_t smoothRegion=1., Int_t smoothAlgo=1)
string const
Definition: compareJSON.py:14
double smoothStepFunc(double x) const
SimpleCacheSentry _sentry
not to be serialized
TH1 ** _cacheSingle
not to be serialized
FastHisto2D _cacheNominalLog
not to be serialized
#define protected
Definition: FWEveView.cc:36
const RooArgList & coefList() const
x
Definition: VDTMath.h:216
void syncMorph(Morph &out, const FastTemplate &nominal, FastTemplate &lo, FastTemplate &hi) const
not to be serialized
FastHisto2D _cache
Cache of the result.
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
FastHisto _cacheNominalLog
not to be serialized
Double_t evaluate() const =0