Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
21
22namespace RooStats {
23
25
26 public:
27
28 //__________________________________
30 fNullPdf(NULL), fAltPdf(NULL)
31 {
32 // Constructor for proof. Do not use.
33 fFirstEval = true;
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
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
88 fDetailedOutput = NULL;
89
91 fNllNull=NULL ;
92 fNllAlt=NULL ;
93 }
94
95 //______________________________
99 if (fNllNull) delete fNllNull ;
100 if (fNllAlt) delete fNllAlt ;
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) {
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 //______________________________
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
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
#define e(i)
Definition RSha256.hxx:103
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
#define ClassDef(name, id)
Definition Rtypes.h:325
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:82
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:94
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:158
TestStatistic class that returns -log(L[null] / L[alt]) where L is the likelihood.
virtual void SetConditionalObservables(const RooArgSet &set)
interface to set conditional observables. If a test statistics needs them it will re-implement this f...
SimpleLikelihoodRatioTestStat(RooAbsPdf &nullPdf, RooAbsPdf &altPdf, const RooArgSet &nullParameters, const RooArgSet &altParameters)
virtual const RooArgSet * GetDetailedOutput(void) const
return detailed output: for fits this can be pulls, processing time, ... The returned pointer will no...
void SetNullParameters(const RooArgSet &nullParameters)
SimpleLikelihoodRatioTestStat(RooAbsPdf &nullPdf, RooAbsPdf &altPdf)
virtual void SetGlobalObservables(const RooArgSet &set)
interface to set global observables. If a test statistics needs them it will re-implement this functi...
RooAbsReal * fNllAlt
transient copy of the null NLL
static Bool_t fgAlwaysReuseNll
transient copy of the alt NLL
void SetAltParameters(const RooArgSet &altParameters)
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...
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
Iterator abstract base class.
Definition TIterator.h:30
virtual TObject * Next()=0
Basic string class.
Definition TString.h:136
Namespace for the RooStats classes.
Definition Asimov.h:19