Logo ROOT   6.12/07
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 
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) {
118  if (fAltParameters) delete fAltParameters;
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
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2078
TIterator * createIterator(Bool_t dir=kIterForward) const
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:86
SimpleLikelihoodRatioTestStat(RooAbsPdf &nullPdf, RooAbsPdf &altPdf)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
Basic string class.
Definition: TString.h:125
bool Bool_t
Definition: RtypesCore.h:59
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically named contents.
RooAbsReal * fNllAlt
transient copy of the null NLL
void SetAltParameters(const RooArgSet &altParameters)
Iterator abstract base class.
Definition: TIterator.h:30
null_t< F > null()
virtual const RooArgSet * GetDetailedOutput(void) const
return detailed output: for fits this can be pulls, processing time, ... The returned pointer will no...
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
void SetNullParameters(const RooArgSet &nullParameters)
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...
virtual void SetConditionalObservables(const RooArgSet &set)
interface to set conditional observables. If a test statistics needs them it will re-implement this f...
virtual void SetGlobalObservables(const RooArgSet &set)
interface to set global observables. If a test statistics needs them it will re-implement this functi...
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
SimpleLikelihoodRatioTestStat(RooAbsPdf &nullPdf, RooAbsPdf &altPdf, const RooArgSet &nullParameters, const RooArgSet &altParameters)
const Bool_t kFALSE
Definition: RtypesCore.h:88
Namespace for the RooStats classes.
Definition: Asimov.h:20
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
TestStatistic class that returns -log(L[null] / L[alt]) where L is the likelihood.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
virtual TObject * Next()=0
static Bool_t fgAlwaysReuseNll
transient copy of the alt NLL
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
Definition: TestStatistic.h:31