CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CachingNLL.h
Go to the documentation of this file.
1 #ifndef HiggsAnalysis_CombinedLimit_CachingNLL_h
2 #define HiggsAnalysis_CombinedLimit_CachingNLL_h
3 
4 #include <memory>
5 #include <map>
6 #include <RooAbsPdf.h>
7 #include <RooAddPdf.h>
8 #include <RooRealSumPdf.h>
9 #include <RooProdPdf.h>
10 #include <RooAbsData.h>
11 #include <RooArgSet.h>
12 #include <RooSetProxy.h>
13 #include <RooRealVar.h>
14 #include <RooSimultaneous.h>
15 #include <RooGaussian.h>
16 
17 // Part zero: ArgSet checker
18 namespace cacheutils {
19  class ArgSetChecker {
20  public:
22  ArgSetChecker(const RooAbsCollection &set) ;
23  bool changed(bool updateIfChanged=false) ;
24  private:
25  std::vector<RooRealVar *> vars_;
26  std::vector<double> vals_;
27  };
28 
29 // Part zero point five: Cache of pdf values for different parameters
30  class ValuesCache {
31  public:
32  ValuesCache(const RooAbsReal &pdf, const RooArgSet &obs, int size=MaxItems_);
33  ValuesCache(const RooAbsCollection &params, int size=MaxItems_);
34  ~ValuesCache();
35  // search for the item corresponding to the current values of the parameters.
36  // if available, return (&values, true)
37  // if not available, return (&room, false)
38  // and it will be up to the caller code to fill the room the new item
39  std::pair<std::vector<Double_t> *, bool> get();
40  void clear();
41  private:
42  struct Item {
43  Item(const RooAbsCollection &set) : checker(set), good(false) {}
44  Item(const ArgSetChecker &check) : checker(check), good(false) {}
45  std::vector<Double_t> values;
47  bool good;
48  };
50  enum { MaxItems_ = 3 };
52  };
53 // Part one: cache all values of a pdf
54 class CachingPdf {
55  public:
56  CachingPdf(RooAbsReal *pdf, const RooArgSet *obs) ;
57  CachingPdf(const CachingPdf &other) ;
58  ~CachingPdf() ;
59  const std::vector<Double_t> & eval(const RooAbsData &data) ;
60  const RooAbsReal *pdf() const { return pdf_; }
61  void setDataDirty() { lastData_ = 0; }
62  private:
63  const RooArgSet *obs_;
64  RooAbsReal *pdfOriginal_;
65  RooArgSet pdfPieces_;
66  RooAbsReal *pdf_;
67  const RooAbsData *lastData_;
69  void realFill_(const RooAbsData &data, std::vector<Double_t> &values) ;
70 };
71 
72 class CachingAddNLL : public RooAbsReal {
73  public:
74  CachingAddNLL(const char *name, const char *title, RooAbsPdf *pdf, RooAbsData *data) ;
75  CachingAddNLL(const CachingAddNLL &other, const char *name = 0) ;
76  virtual ~CachingAddNLL() ;
77  virtual CachingAddNLL *clone(const char *name = 0) const ;
78  virtual Double_t evaluate() const ;
79  virtual Bool_t isDerived() const { return kTRUE; }
80  virtual Double_t defaultErrorLevel() const { return 0.5; }
81  void setData(const RooAbsData &data) ;
82  virtual RooArgSet* getObservables(const RooArgSet* depList, Bool_t valueOnly = kTRUE) const ;
83  virtual RooArgSet* getParameters(const RooArgSet* depList, Bool_t stripDisconnected = kTRUE) const ;
84  double sumWeights() const { return sumWeights_; }
85  const RooAbsPdf *pdf() const { return pdf_; }
86  void setZeroPoint() { zeroPoint_ = -this->getVal(); setValueDirty(); }
87  void clearZeroPoint() { zeroPoint_ = 0.0; setValueDirty(); }
88  RooSetProxy & params() { return params_; }
89  private:
90  void setup_();
91  RooAbsPdf *pdf_;
92  RooSetProxy params_;
93  const RooAbsData *data_;
94  std::vector<Double_t> weights_;
95  double sumWeights_;
96  mutable std::vector<RooAbsReal*> coeffs_;
97  mutable std::vector<CachingPdf> pdfs_;
98  mutable std::vector<RooAbsReal*> integrals_;
99  mutable std::vector<Double_t> partialSum_;
100  mutable bool isRooRealSum_;
101  double zeroPoint_;
102 };
103 
104 class CachingSimNLL : public RooAbsReal {
105  public:
106  CachingSimNLL(RooSimultaneous *pdf, RooAbsData *data, const RooArgSet *nuis=0) ;
107  CachingSimNLL(const CachingSimNLL &other, const char *name = 0) ;
108  ~CachingSimNLL() ;
109  virtual CachingSimNLL *clone(const char *name = 0) const ;
110  virtual Double_t evaluate() const ;
111  virtual Bool_t isDerived() const { return kTRUE; }
112  virtual Double_t defaultErrorLevel() const { return 0.5; }
113  void setData(const RooAbsData &data) ;
114  virtual RooArgSet* getObservables(const RooArgSet* depList, Bool_t valueOnly = kTRUE) const ;
115  virtual RooArgSet* getParameters(const RooArgSet* depList, Bool_t stripDisconnected = kTRUE) const ;
116  void splitWithWeights(const RooAbsData &data, const RooAbsCategory& splitCat, Bool_t createEmptyDataSets) ;
117  static void setNoDeepLogEvalError(bool noDeep) { noDeepLEE_ = noDeep; }
118  void setZeroPoint() ;
119  void clearZeroPoint() ;
120  friend class CachingAddNLL;
121  private:
122  class SimpleGaussianConstraint : public RooGaussian {
123  public:
124  SimpleGaussianConstraint(const RooGaussian &g) : RooGaussian(g, "") {}
125  double getLogValFast() const {
126  Double_t arg = x - mean;
127  Double_t sig = sigma ;
128  return -0.5*arg*arg/(sig*sig);
129  }
130  };
131 
132  void setup_();
133  RooSimultaneous *pdfOriginal_;
134  const RooAbsData *dataOriginal_;
135  const RooArgSet *nuis_;
136  RooSetProxy params_;
137  RooArgSet piecesForCloning_;
138  std::auto_ptr<RooSimultaneous> factorizedPdf_;
139  std::vector<RooAbsPdf *> constrainPdfs_;
140  std::vector<SimpleGaussianConstraint *> constrainPdfsFast_;
141  std::vector<CachingAddNLL*> pdfs_;
142  std::auto_ptr<TList> dataSets_;
143  std::vector<RooDataSet *> datasets_;
144  static bool noDeepLEE_;
145  static bool hasError_;
146  std::vector<double> constrainZeroPoints_;
147  std::vector<double> constrainZeroPointsFast_;
148 };
149 
150 }
151 #endif
virtual CachingSimNLL * clone(const char *name=0) const
Definition: CachingNLL.cc:483
const RooAbsData * lastData_
Definition: CachingNLL.h:67
double sumWeights() const
Definition: CachingNLL.h:84
virtual CachingAddNLL * clone(const char *name=0) const
Definition: CachingNLL.cc:266
std::vector< RooAbsPdf * > constrainPdfs_
Definition: CachingNLL.h:139
virtual RooArgSet * getObservables(const RooArgSet *depList, Bool_t valueOnly=kTRUE) const
Definition: CachingNLL.cc:677
void setData(const RooAbsData &data)
Definition: CachingNLL.cc:415
void splitWithWeights(const RooAbsData &data, const RooAbsCategory &splitCat, Bool_t createEmptyDataSets)
Definition: CachingNLL.cc:629
virtual Double_t defaultErrorLevel() const
Definition: CachingNLL.h:112
std::vector< CachingPdf > pdfs_
Definition: CachingNLL.h:97
Item(const ArgSetChecker &check)
Definition: CachingNLL.h:44
virtual Bool_t isDerived() const
Definition: CachingNLL.h:79
std::vector< SimpleGaussianConstraint * > constrainPdfsFast_
Definition: CachingNLL.h:140
std::auto_ptr< RooSimultaneous > factorizedPdf_
Definition: CachingNLL.h:138
std::vector< double > constrainZeroPointsFast_
Definition: CachingNLL.h:147
const RooAbsData * data_
Definition: CachingNLL.h:93
RooSimultaneous * pdfOriginal_
Definition: CachingNLL.h:133
std::vector< Double_t > values
Definition: CachingNLL.h:45
virtual RooArgSet * getParameters(const RooArgSet *depList, Bool_t stripDisconnected=kTRUE) const
Definition: CachingNLL.cc:458
A arg
Definition: Factorize.h:36
virtual Double_t defaultErrorLevel() const
Definition: CachingNLL.h:80
const RooAbsData * dataOriginal_
Definition: CachingNLL.h:134
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
const RooAbsReal * pdf() const
Definition: CachingNLL.h:60
CachingAddNLL(const char *name, const char *title, RooAbsPdf *pdf, RooAbsData *data)
Definition: CachingNLL.cc:238
std::vector< RooDataSet * > datasets_
Definition: CachingNLL.h:143
virtual Double_t evaluate() const
Definition: CachingNLL.cc:568
Item * items[MaxItems_]
Definition: CachingNLL.h:51
RooAbsReal * pdfOriginal_
Definition: CachingNLL.h:64
ValuesCache(const RooAbsReal &pdf, const RooArgSet &obs, int size=MaxItems_)
Definition: CachingNLL.cc:101
CachingSimNLL(RooSimultaneous *pdf, RooAbsData *data, const RooArgSet *nuis=0)
Definition: CachingNLL.cc:464
void setData(const RooAbsData &data)
Definition: CachingNLL.cc:610
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
bool changed(bool updateIfChanged=false)
Definition: CachingNLL.cc:77
ValuesCache cache_
Definition: CachingNLL.h:68
std::vector< CachingAddNLL * > pdfs_
Definition: CachingNLL.h:141
CachingPdf(RooAbsReal *pdf, const RooArgSet *obs)
Definition: CachingNLL.cc:173
const std::vector< Double_t > & eval(const RooAbsData &data)
Definition: CachingNLL.cc:198
RooAbsReal * pdf_
Definition: CachingNLL.h:66
virtual Bool_t isDerived() const
Definition: CachingNLL.h:111
const RooAbsPdf * pdf() const
Definition: CachingNLL.h:85
std::vector< double > vals_
Definition: CachingNLL.h:26
std::vector< double > constrainZeroPoints_
Definition: CachingNLL.h:146
std::auto_ptr< TList > dataSets_
Definition: CachingNLL.h:142
const RooArgSet * obs_
Definition: CachingNLL.h:63
std::vector< RooRealVar * > vars_
Definition: CachingNLL.h:25
Item(const RooAbsCollection &set)
Definition: CachingNLL.h:43
const RooArgSet * nuis_
Definition: CachingNLL.h:135
void realFill_(const RooAbsData &data, std::vector< Double_t > &values)
Definition: CachingNLL.cc:219
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual RooArgSet * getObservables(const RooArgSet *depList, Bool_t valueOnly=kTRUE) const
Definition: CachingNLL.cc:452
virtual Double_t evaluate() const
Definition: CachingNLL.cc:343
std::vector< Double_t > weights_
Definition: CachingNLL.h:94
RooSetProxy & params()
Definition: CachingNLL.h:88
std::vector< RooAbsReal * > integrals_
Definition: CachingNLL.h:98
Definition: DDAxes.h:10
std::vector< RooAbsReal * > coeffs_
Definition: CachingNLL.h:96
tuple size
Write out results.
virtual RooArgSet * getParameters(const RooArgSet *depList, Bool_t stripDisconnected=kTRUE) const
Definition: CachingNLL.cc:683
static void setNoDeepLogEvalError(bool noDeep)
Definition: CachingNLL.h:117
std::vector< Double_t > partialSum_
Definition: CachingNLL.h:99
void set(const std::string &name, int value)
set the flag, with a run-time name