Logo ROOT  
Reference Guide
SimpleLikelihoodRatioTestStat.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: Kyle Cranmer and Sven Kreiss June 2010
3 /*************************************************************************
4  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 #ifndef ROOSTATS_SimpleLikelihoodRatioTestStat
12 #define ROOSTATS_SimpleLikelihoodRatioTestStat
13 
14 #include "Rtypes.h"
15 
16 #include "RooNLLVar.h"
17 
18 #include "RooRealVar.h"
19 
20 #include "RooStats/TestStatistic.h"
21 
22 namespace RooStats {
23 
24  class SimpleLikelihoodRatioTestStat : public TestStatistic {
25 
26  public:
27 
28  //__________________________________
30  fNullPdf(NULL), fAltPdf(NULL)
31  {
32  // Constructor for proof. Do not use.
33  fFirstEval = true;
34  fDetailedOutputEnabled = false;
35  fDetailedOutput = NULL;
36  fNullParameters = NULL;
37  fAltParameters = NULL;
39  fNllNull=NULL ;
40  fNllAlt=NULL ;
41  }
42 
43  //__________________________________
45  RooAbsPdf& nullPdf,
46  RooAbsPdf& altPdf
47  ) :
48  fFirstEval(true)
49  {
50  // Takes null and alternate parameters from PDF. Can be overridden.
51 
52  fNullPdf = &nullPdf;
53  fAltPdf = &altPdf;
54 
55  RooArgSet * allNullVars = fNullPdf->getVariables();
56  fNullParameters = (RooArgSet*) allNullVars->snapshot();
57  delete allNullVars;
58 
59  RooArgSet * allAltVars = fAltPdf->getVariables();
60  fAltParameters = (RooArgSet*) allAltVars->snapshot();
61  delete allAltVars;
62 
63  fDetailedOutputEnabled = false;
64  fDetailedOutput = NULL;
65 
67  fNllNull=NULL ;
68  fNllAlt=NULL ;
69  }
70  //__________________________________
72  RooAbsPdf& nullPdf,
73  RooAbsPdf& altPdf,
74  const RooArgSet& nullParameters,
75  const RooArgSet& altParameters
76  ) :
77  fFirstEval(true)
78  {
79  // Takes null and alternate parameters from values in nullParameters
80  // and altParameters. Can be overridden.
81  fNullPdf = &nullPdf;
82  fAltPdf = &altPdf;
83 
84  fNullParameters = (RooArgSet*) nullParameters.snapshot();
85  fAltParameters = (RooArgSet*) altParameters.snapshot();
86 
87  fDetailedOutputEnabled = false;
88  fDetailedOutput = NULL;
89 
91  fNllNull=NULL ;
92  fNllAlt=NULL ;
93  }
94 
95  //______________________________
97  if (fNullParameters) delete fNullParameters;
98  if (fAltParameters) delete fAltParameters;
99  if (fNllNull) delete fNllNull ;
100  if (fNllAlt) delete fNllAlt ;
101  if (fDetailedOutput) delete fDetailedOutput;
102  }
103 
104  static void SetAlwaysReuseNLL(Bool_t flag);
105 
106  void SetReuseNLL(Bool_t flag) { fReuseNll = flag ; }
107 
108  //_________________________________________
109  void SetNullParameters(const RooArgSet& nullParameters) {
110  if (fNullParameters) delete fNullParameters;
111  fFirstEval = true;
112  // if(fNullParameters) delete fNullParameters;
113  fNullParameters = (RooArgSet*) nullParameters.snapshot();
114  }
115 
116  //_________________________________________
117  void SetAltParameters(const RooArgSet& altParameters) {
119  fFirstEval = true;
120  // if(fAltParameters) delete fAltParameters;
121  fAltParameters = (RooArgSet*) altParameters.snapshot();
122  }
123 
124  //______________________________
125  bool ParamsAreEqual() {
126  // this should be possible with RooAbsCollection
127  if (!fNullParameters->equals(*fAltParameters)) return false;
128 
129  RooAbsReal* null;
130  RooAbsReal* alt;
131 
134  bool ret = true;
135  while ((null = (RooAbsReal*) nullIt->Next()) && (alt = (RooAbsReal*) altIt->Next())) {
136  if (null->getVal() != alt->getVal()) ret = false;
137  }
138  delete nullIt;
139  delete altIt;
140  return ret;
141  }
142 
143 
144  // set the conditional observables which will be used when creating the NLL
145  // so the pdf's will not be normalized on the conditional observables when computing the NLL
147 
148  // set the global observables which will be used when creating the NLL
149  // so the constraint pdf's will be normalized correctly on the global observables when computing the NLL
150  virtual void SetGlobalObservables(const RooArgSet& set) {fGlobalObs.removeAll(); fGlobalObs.add(set);}
151 
152  //______________________________
153  virtual Double_t Evaluate(RooAbsData& data, RooArgSet& nullPOI);
154 
155  virtual void EnableDetailedOutput( bool e=true ) { fDetailedOutputEnabled = e; fDetailedOutput = NULL; }
156  virtual const RooArgSet* GetDetailedOutput(void) const { return fDetailedOutput; }
157 
158  virtual const TString GetVarName() const {
159  return "log(L(#mu_{1}) / L(#mu_{0}))";
160  }
161 
162  private:
163 
171 
174 
175  RooAbsReal* fNllNull ; //! transient copy of the null NLL
176  RooAbsReal* fNllAlt ; //! transient copy of the alt NLL
179 
180 
181  protected:
183 };
184 
185 }
186 
187 #endif
RooStats::SimpleLikelihoodRatioTestStat::fFirstEval
bool fFirstEval
Definition: SimpleLikelihoodRatioTestStat.h:182
RooStats::SimpleLikelihoodRatioTestStat::EnableDetailedOutput
virtual void EnableDetailedOutput(bool e=true)
Definition: SimpleLikelihoodRatioTestStat.h:167
RooStats::SimpleLikelihoodRatioTestStat::fgAlwaysReuseNll
static Bool_t fgAlwaysReuseNll
transient copy of the alt NLL
Definition: SimpleLikelihoodRatioTestStat.h:189
e
#define e(i)
Definition: RSha256.hxx:121
RooAbsData
Definition: RooAbsData.h:46
RooStats::SimpleLikelihoodRatioTestStat::fConditionalObs
RooArgSet fConditionalObs
Definition: SimpleLikelihoodRatioTestStat.h:180
RooStats::SimpleLikelihoodRatioTestStat::SimpleLikelihoodRatioTestStat
SimpleLikelihoodRatioTestStat()
Definition: SimpleLikelihoodRatioTestStat.h:41
RooStats::SimpleLikelihoodRatioTestStat::fDetailedOutput
RooArgSet * fDetailedOutput
Definition: SimpleLikelihoodRatioTestStat.h:185
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooStats::SimpleLikelihoodRatioTestStat::SetNullParameters
void SetNullParameters(const RooArgSet &nullParameters)
Definition: SimpleLikelihoodRatioTestStat.h:121
RooArgSet::add
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooAbsReal
Definition: RooAbsReal.h:61
RooStats::SimpleLikelihoodRatioTestStat::fNllAlt
RooAbsReal * fNllAlt
transient copy of the null NLL
Definition: SimpleLikelihoodRatioTestStat.h:188
TString
Definition: TString.h:136
RooStats::SimpleLikelihoodRatioTestStat::SetAltParameters
void SetAltParameters(const RooArgSet &altParameters)
Definition: SimpleLikelihoodRatioTestStat.h:129
RooNLLVar.h
bool
TIterator
Definition: TIterator.h:30
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:134
RooStats::SimpleLikelihoodRatioTestStat::GetDetailedOutput
virtual const RooArgSet * GetDetailedOutput(void) const
return detailed output: for fits this can be pulls, processing time, ... The returned pointer will no...
Definition: SimpleLikelihoodRatioTestStat.h:168
RooStats::SimpleLikelihoodRatioTestStat::fDetailedOutputEnabled
bool fDetailedOutputEnabled
Definition: SimpleLikelihoodRatioTestStat.h:184
RooStats::SimpleLikelihoodRatioTestStat::SetConditionalObservables
virtual void SetConditionalObservables(const RooArgSet &set)
interface to set conditional observables. If a test statistics needs them it will re-implement this f...
Definition: SimpleLikelihoodRatioTestStat.h:158
RooStats::SimpleLikelihoodRatioTestStat::fNullPdf
RooAbsPdf * fNullPdf
Definition: SimpleLikelihoodRatioTestStat.h:176
RooStats::SimpleLikelihoodRatioTestStat::Evaluate
virtual Double_t Evaluate(RooAbsData &data, RooArgSet &nullPOI)
Main interface to evaluate the test statistic on a dataset given the values for the Null Parameters O...
Definition: SimpleLikelihoodRatioTestStat.cxx:30
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooStats::SimpleLikelihoodRatioTestStat::SetGlobalObservables
virtual void SetGlobalObservables(const RooArgSet &set)
interface to set global observables. If a test statistics needs them it will re-implement this functi...
Definition: SimpleLikelihoodRatioTestStat.h:162
RooStats::SimpleLikelihoodRatioTestStat::SetReuseNLL
void SetReuseNLL(Bool_t flag)
Definition: SimpleLikelihoodRatioTestStat.h:118
RooAbsCollection::createIterator
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Definition: RooAbsCollection.h:118
TestStatistic.h
RooStats::SimpleLikelihoodRatioTestStat::fAltParameters
RooArgSet * fAltParameters
Definition: SimpleLikelihoodRatioTestStat.h:179
RooStats::SimpleLikelihoodRatioTestStat::SetAlwaysReuseNLL
static void SetAlwaysReuseNLL(Bool_t flag)
Definition: SimpleLikelihoodRatioTestStat.cxx:28
RooStats::SimpleLikelihoodRatioTestStat
Definition: SimpleLikelihoodRatioTestStat.h:30
RooStats::SimpleLikelihoodRatioTestStat::~SimpleLikelihoodRatioTestStat
virtual ~SimpleLikelihoodRatioTestStat()
Definition: SimpleLikelihoodRatioTestStat.h:108
RooRealVar.h
RooStats::SimpleLikelihoodRatioTestStat::fAltPdf
RooAbsPdf * fAltPdf
Definition: SimpleLikelihoodRatioTestStat.h:177
TIterator::Next
virtual TObject * Next()=0
RooStats::SimpleLikelihoodRatioTestStat::fNullParameters
RooArgSet * fNullParameters
Definition: SimpleLikelihoodRatioTestStat.h:178
Double_t
double Double_t
Definition: RtypesCore.h:59
RooStats::SimpleLikelihoodRatioTestStat::GetVarName
virtual const TString GetVarName() const
Definition: SimpleLikelihoodRatioTestStat.h:170
RooAbsCollection::equals
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
Definition: RooAbsCollection.cxx:763
RooStats
Definition: Asimov.h:19
RooStats::SimpleLikelihoodRatioTestStat::fNllNull
RooAbsReal * fNllNull
Definition: SimpleLikelihoodRatioTestStat.h:187
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
RooStats::SimpleLikelihoodRatioTestStat::fReuseNll
Bool_t fReuseNll
Definition: SimpleLikelihoodRatioTestStat.h:190
RooStats::SimpleLikelihoodRatioTestStat::ParamsAreEqual
bool ParamsAreEqual()
Definition: SimpleLikelihoodRatioTestStat.h:137
RooStats::SimpleLikelihoodRatioTestStat::fGlobalObs
RooArgSet fGlobalObs
Definition: SimpleLikelihoodRatioTestStat.h:181
RooAbsPdf
Definition: RooAbsPdf.h:40
RooAbsArg::getVariables
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:1911
TMVA::null
null_t< F > null()
Definition: DataSetFactory.h:133
RooAbsCollection::removeAll
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Definition: RooAbsCollection.cxx:643
Rtypes.h
RooArgSet
Definition: RooArgSet.h:28