Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
SimpleLikelihoodRatioTestStat.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
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/** \class RooStats::SimpleLikelihoodRatioTestStat
12 \ingroup Roostats
13
14TestStatistic class that returns -log(L[null] / L[alt]) where
15L is the likelihood.
16It is often called as the LEP Test statistic.
17
18
19*/
20
23
25
26////////////////////////////////////////////////////////////////////////////////
27
29
31
32 if (fFirstEval && ParamsAreEqual()) {
33 oocoutW(fNullParameters,InputArguments)
34 << "Same RooArgSet used for null and alternate, so you must explicitly SetNullParameters and SetAlternateParameters or the likelihood ratio will always be 1."
35 << std::endl;
36 }
37
38 // strip pdfs of constraints (which cancel out in the ratio) to avoid unnecessary computations and computational errors
39 if (fFirstEval) {
40 fNullPdf = RooStats::MakeUnconstrainedPdf(*fNullPdf, *fNullPdf->getObservables(data));
41 fAltPdf = RooStats::MakeUnconstrainedPdf(*fAltPdf , *fAltPdf->getObservables(data) );
42 }
43
44 fFirstEval = false;
45
48
49 Bool_t reuse = (fReuseNll || fgAlwaysReuseNll) ;
50
51 Bool_t created = kFALSE ;
52 if (!fNllNull) {
53 RooArgSet* allParams = fNullPdf->getParameters(data);
54 fNllNull = fNullPdf->createNLL(data, RooFit::CloneData(kFALSE),RooFit::Constrain(*allParams),RooFit::GlobalObservables(fGlobalObs),RooFit::ConditionalObservables(fConditionalObs));
55 delete allParams;
56 created = kTRUE ;
57 }
58 if (reuse && !created) {
59 fNllNull->setData(data, kFALSE) ;
60 }
61
62 // make sure we set the variables attached to this nll
63 RooArgSet* attachedSet = fNllNull->getVariables();
64 attachedSet->assign(*fNullParameters);
65 attachedSet->assign(nullPOI);
66 double nullNLL = fNllNull->getVal();
67
68 //std::cout << std::endl << "SLRTS: null params:" << std::endl;
69 //attachedSet->Print("v");
70
71
72 if (!reuse) {
73 delete fNllNull ; fNllNull = NULL ;
74 }
75 delete attachedSet;
76
77 created = kFALSE ;
78 if (!fNllAlt) {
79 RooArgSet* allParams = fAltPdf->getParameters(data);
80 fNllAlt = fAltPdf->createNLL(data, RooFit::CloneData(kFALSE),RooFit::Constrain(*allParams),RooFit::GlobalObservables(fGlobalObs),RooFit::ConditionalObservables(fConditionalObs));
81 delete allParams;
82 created = kTRUE ;
83 }
84 if (reuse && !created) {
85 fNllAlt->setData(data, kFALSE) ;
86 }
87 // make sure we set the variables attached to this nll
88 attachedSet = fNllAlt->getVariables();
89 attachedSet->assign(*fAltParameters);
90 double altNLL = fNllAlt->getVal();
91
92 //std::cout << std::endl << "SLRTS: alt params:" << std::endl;
93 //attachedSet->Print("v");
94
95
96// std::cout << std::endl << "SLRTS null NLL: " << nullNLL << " alt NLL: " << altNLL << std::endl << std::endl;
97
98
99 if (!reuse) {
100 delete fNllAlt ; fNllAlt = NULL ;
101 }
102 delete attachedSet;
103
104
105
106 // save this snapshot
107 if( fDetailedOutputEnabled ) {
108 if( !fDetailedOutput ) {
109 fDetailedOutput = new RooArgSet( *(new RooRealVar("nullNLL","null NLL",0)), "detailedOut_SLRTS" );
110 fDetailedOutput->add( *(new RooRealVar("altNLL","alternate NLL",0)) );
111 }
112 fDetailedOutput->setRealValue( "nullNLL", nullNLL );
113 fDetailedOutput->setRealValue( "altNLL", altNLL );
114
115// std::cout << std::endl << "STORING THIS AS DETAILED OUTPUT:" << std::endl;
116// fDetailedOutput->Print("v");
117// std::cout << std::endl;
118 }
119
120
122 return nullNLL - altNLL;
123}
#define oocoutW(o, a)
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:100
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:82
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
static Bool_t fgAlwaysReuseNll
transient copy of the alt NLL
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...
RooCmdArg Constrain(const RooArgSet &params)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg CloneData(Bool_t flag)
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)