ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
15 
16 
17 #ifndef ROOT_Rtypes
18 #include "Rtypes.h"
19 #endif
20 
21 #ifndef ROO_NLL_VAR
22 #include "RooNLLVar.h"
23 #endif
24 
25 #ifndef ROO_REAL_VAR
26 #include "RooRealVar.h"
27 #endif
28 
29 #ifndef ROOSTATS_TestStatistic
30 #include "RooStats/TestStatistic.h"
31 #endif
32 
33 
34 namespace RooStats {
35 
36  /**
37 
38  TestStatistic class that returns -log(L[null] / L[alt]) where
39  L is the likelihood.
40  It is often called as the LEP Test statistic.
41 
42  \ingroup Roostats
43 
44  */
45 
46 
48 
49  public:
50 
51  //__________________________________
54  {
55  // Constructor for proof. Do not use.
56  fFirstEval = true;
57  fDetailedOutputEnabled = false;
62  fNllNull=NULL ;
63  fNllAlt=NULL ;
64  }
65 
66  //__________________________________
68  RooAbsPdf& nullPdf,
69  RooAbsPdf& altPdf
70  ) :
71  fFirstEval(true)
72  {
73  // Takes null and alternate parameters from PDF. Can be overridden.
74 
75  fNullPdf = &nullPdf;
76  fAltPdf = &altPdf;
77 
78  RooArgSet * allNullVars = fNullPdf->getVariables();
79  fNullParameters = (RooArgSet*) allNullVars->snapshot();
80  delete allNullVars;
81 
82  RooArgSet * allAltVars = fAltPdf->getVariables();
83  fAltParameters = (RooArgSet*) allAltVars->snapshot();
84  delete allAltVars;
85 
86  fDetailedOutputEnabled = false;
88 
90  fNllNull=NULL ;
91  fNllAlt=NULL ;
92  }
93  //__________________________________
95  RooAbsPdf& nullPdf,
96  RooAbsPdf& altPdf,
97  const RooArgSet& nullParameters,
98  const RooArgSet& altParameters
99  ) :
100  fFirstEval(true)
101  {
102  // Takes null and alternate parameters from values in nullParameters
103  // and altParameters. Can be overridden.
104  fNullPdf = &nullPdf;
105  fAltPdf = &altPdf;
106 
107  fNullParameters = (RooArgSet*) nullParameters.snapshot();
108  fAltParameters = (RooArgSet*) altParameters.snapshot();
109 
110  fDetailedOutputEnabled = false;
112 
113  fReuseNll=kFALSE ;
114  fNllNull=NULL ;
115  fNllAlt=NULL ;
116  }
117 
118  //______________________________
120  if (fNullParameters) delete fNullParameters;
121  if (fAltParameters) delete fAltParameters;
122  if (fNllNull) delete fNllNull ;
123  if (fNllAlt) delete fNllAlt ;
124  if (fDetailedOutput) delete fDetailedOutput;
125  }
126 
127  static void SetAlwaysReuseNLL(Bool_t flag);
128 
129  void SetReuseNLL(Bool_t flag) { fReuseNll = flag ; }
130 
131  //_________________________________________
132  void SetNullParameters(const RooArgSet& nullParameters) {
133  if (fNullParameters) delete fNullParameters;
134  fFirstEval = true;
135  // if(fNullParameters) delete fNullParameters;
136  fNullParameters = (RooArgSet*) nullParameters.snapshot();
137  }
138 
139  //_________________________________________
140  void SetAltParameters(const RooArgSet& altParameters) {
141  if (fAltParameters) delete fAltParameters;
142  fFirstEval = true;
143  // if(fAltParameters) delete fAltParameters;
144  fAltParameters = (RooArgSet*) altParameters.snapshot();
145  }
146 
147  //______________________________
148  bool ParamsAreEqual() {
149  // this should be possible with RooAbsCollection
150  if (!fNullParameters->equals(*fAltParameters)) return false;
151 
152  RooAbsReal* null;
153  RooAbsReal* alt;
154 
157  bool ret = true;
158  while ((null = (RooAbsReal*) nullIt->Next()) && (alt = (RooAbsReal*) altIt->Next())) {
159  if (null->getVal() != alt->getVal()) ret = false;
160  }
161  delete nullIt;
162  delete altIt;
163  return ret;
164  }
165 
166 
167  // set the conditional observables which will be used when creating the NLL
168  // so the pdf's will not be normalized on the conditional observables when computing the NLL
170 
171  //______________________________
172  virtual Double_t Evaluate(RooAbsData& data, RooArgSet& nullPOI);
173 
174  virtual void EnableDetailedOutput( bool e=true ) { fDetailedOutputEnabled = e; fDetailedOutput = NULL; }
175  virtual const RooArgSet* GetDetailedOutput(void) const { return fDetailedOutput; }
176 
177  virtual const TString GetVarName() const {
178  return "log(L(#mu_{1}) / L(#mu_{0}))";
179  }
180 
181  private:
182 
189 
192 
193  RooAbsReal* fNllNull ; //! transient copy of the null NLL
194  RooAbsReal* fNllAlt ; //! transient copy of the alt NLL
197 
198 
199  protected:
201 };
202 
203 }
204 
205 #endif
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
SimpleLikelihoodRatioTestStat(RooAbsPdf &nullPdf, RooAbsPdf &altPdf)
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically named contents.
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
RooAbsReal * fNllAlt
transient copy of the null NLL
void SetAltParameters(const RooArgSet &altParameters)
Iterator abstract base class.
Definition: TIterator.h:32
null_t< F > null()
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2082
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...
TIterator * createIterator(Bool_t dir=kIterForward) const
virtual void SetConditionalObservables(const RooArgSet &set)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual const RooArgSet * GetDetailedOutput(void) const
return detailed output: for fits this can be pulls, processing time, ... The returned pointer will no...
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)
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
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
#define NULL
Definition: Rtypes.h:82
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:33
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448