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 "RooAbsPdf.h"
17#include "RooRealVar.h"
18
20
21namespace RooStats {
22
24
25 public:
26
27 /// Constructor for proof. Do not use.
29 fNullPdf(nullptr), fAltPdf(nullptr)
30 {
31 fFirstEval = true;
33 fDetailedOutput = nullptr;
34 fNullParameters = nullptr;
35 fAltParameters = nullptr;
36 fReuseNll=false ;
37 }
38
39 /// Takes null and alternate parameters from PDF. Can be overridden.
41 RooAbsPdf& nullPdf,
42 RooAbsPdf& altPdf
43 ) :
44 fFirstEval(true)
45 {
46 fNullPdf = &nullPdf;
47 fAltPdf = &altPdf;
48
49 std::unique_ptr<RooArgSet> allNullVars{fNullPdf->getVariables()};
50 fNullParameters = (RooArgSet*) allNullVars->snapshot();
51
52 std::unique_ptr<RooArgSet> allAltVars{fAltPdf->getVariables()};
53 fAltParameters = (RooArgSet*) allAltVars->snapshot();
54
56 fDetailedOutput = nullptr;
57
58 fReuseNll=false ;
59 }
60
61 /// Takes null and alternate parameters from values in nullParameters
62 /// and altParameters. Can be overridden.
64 RooAbsPdf& nullPdf,
65 RooAbsPdf& altPdf,
66 const RooArgSet& nullParameters,
67 const RooArgSet& altParameters
68 ) :
69 fFirstEval(true)
70 {
71 fNullPdf = &nullPdf;
72 fAltPdf = &altPdf;
73
74 fNullParameters = (RooArgSet*) nullParameters.snapshot();
75 fAltParameters = (RooArgSet*) altParameters.snapshot();
76
78 fDetailedOutput = nullptr;
79
80 fReuseNll=false ;
81 }
82
87 }
88
89 static void SetAlwaysReuseNLL(bool flag);
90
91 void SetReuseNLL(bool flag) { fReuseNll = flag ; }
92
93 void SetNullParameters(const RooArgSet& nullParameters) {
95 fFirstEval = true;
96 fNullParameters = (RooArgSet*) nullParameters.snapshot();
97 }
98
99 void SetAltParameters(const RooArgSet& altParameters) {
100 if (fAltParameters) delete fAltParameters;
101 fFirstEval = true;
102 fAltParameters = (RooArgSet*) altParameters.snapshot();
103 }
104
105 /// this should be possible with RooAbsCollection
107 if (!fNullParameters->equals(*fAltParameters)) return false;
108
109 bool ret = true;
110
111 for (auto nullIt = fNullParameters->begin(), altIt = fAltParameters->begin();
112 nullIt != fNullParameters->end() && altIt != fAltParameters->end(); ++nullIt, ++altIt) {
113 RooAbsReal *null = static_cast<RooAbsReal *>(*nullIt);
114 RooAbsReal *alt = static_cast<RooAbsReal *>(*altIt);
115 if (null->getVal() != alt->getVal())
116 ret = false;
117 }
118
119 return ret;
120 }
121
122
123 /// set the conditional observables which will be used when creating the NLL
124 /// so the pdf's will not be normalized on the conditional observables when computing the NLL
126
127 /// set the global observables which will be used when creating the NLL
128 /// so the constraint pdf's will be normalized correctly on the global observables when computing the NLL
130
131 double Evaluate(RooAbsData& data, RooArgSet& nullPOI) override;
132
133 virtual void EnableDetailedOutput( bool e=true ) { fDetailedOutputEnabled = e; fDetailedOutput = nullptr; }
134 const RooArgSet* GetDetailedOutput(void) const override { return fDetailedOutput; }
135
136 const TString GetVarName() const override {
137 return "log(L(#mu_{1}) / L(#mu_{0}))";
138 }
139
140 private:
141
149
152
153 std::unique_ptr<RooAbsReal> fNllNull; ///<! transient copy of the null NLL
154 std::unique_ptr<RooAbsReal> fNllAlt; ///<! transient copy of the alt NLL
155 static bool fgAlwaysReuseNll ;
157
158
159 protected:
161};
162
163}
164
165#endif
#define e(i)
Definition RSha256.hxx:103
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
bool equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
const_iterator end() const
const_iterator begin() const
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:59
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
TestStatistic class that returns -log(L[null] / L[alt]) where L is the likelihood.
double Evaluate(RooAbsData &data, RooArgSet &nullPOI) override
Main interface to evaluate the test statistic on a dataset given the values for the Null Parameters O...
SimpleLikelihoodRatioTestStat(RooAbsPdf &nullPdf, RooAbsPdf &altPdf, const RooArgSet &nullParameters, const RooArgSet &altParameters)
Takes null and alternate parameters from values in nullParameters and altParameters.
void SetConditionalObservables(const RooArgSet &set) override
set the conditional observables which will be used when creating the NLL so the pdf's will not be nor...
SimpleLikelihoodRatioTestStat()
Constructor for proof. Do not use.
std::unique_ptr< RooAbsReal > fNllAlt
! transient copy of the alt NLL
std::unique_ptr< RooAbsReal > fNllNull
! transient copy of the null NLL
void SetNullParameters(const RooArgSet &nullParameters)
SimpleLikelihoodRatioTestStat(RooAbsPdf &nullPdf, RooAbsPdf &altPdf)
Takes null and alternate parameters from PDF. Can be overridden.
bool ParamsAreEqual()
this should be possible with RooAbsCollection
void SetGlobalObservables(const RooArgSet &set) override
set the global observables which will be used when creating the NLL so the constraint pdf's will be n...
void SetAltParameters(const RooArgSet &altParameters)
const RooArgSet * GetDetailedOutput(void) const override
return detailed output: for fits this can be pulls, processing time, ... The returned pointer will no...
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
Basic string class.
Definition TString.h:139
Namespace for the RooStats classes.
Definition Asimov.h:19