Logo ROOT  
Reference Guide
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 
14 TestStatistic class that returns -log(L[null] / L[alt]) where
15 L is the likelihood.
16 It is often called as the LEP Test statistic.
17 
18 
19 */
20 
22 #include "RooStats/RooStatsUtils.h"
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 = *fNullParameters;
65  *attachedSet = 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 = *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 }
RooStats::SimpleLikelihoodRatioTestStat::fgAlwaysReuseNll
static Bool_t fgAlwaysReuseNll
transient copy of the alt NLL
Definition: SimpleLikelihoodRatioTestStat.h:177
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooAbsData
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:47
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
RooFit::MsgLevel
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Definition: RooGlobalFunc.h:65
bool
RooFit::GlobalObservables
RooCmdArg GlobalObservables(const RooArgSet &globs)
Definition: RooGlobalFunc.cxx:204
SimpleLikelihoodRatioTestStat.h
RooFit::FATAL
@ FATAL
Definition: RooGlobalFunc.h:65
RooFit::Constrain
RooCmdArg Constrain(const RooArgSet &params)
Definition: RooGlobalFunc.cxx:203
RooStats::SimpleLikelihoodRatioTestStat::Evaluate
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...
Definition: SimpleLikelihoodRatioTestStat.cxx:30
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooMsgService::setGlobalKillBelow
void setGlobalKillBelow(RooFit::MsgLevel level)
Definition: RooMsgService.h:160
RooStats::SimpleLikelihoodRatioTestStat::SetAlwaysReuseNLL
static void SetAlwaysReuseNLL(Bool_t flag)
Definition: SimpleLikelihoodRatioTestStat.cxx:28
oocoutW
#define oocoutW(o, a)
Definition: RooMsgService.h:47
RooFit::ConditionalObservables
RooCmdArg ConditionalObservables(const RooArgSet &set)
Definition: RooGlobalFunc.cxx:199
RooStatsUtils.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooFit::CloneData
RooCmdArg CloneData(Bool_t flag)
Definition: RooGlobalFunc.cxx:212
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooStats::MakeUnconstrainedPdf
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
Definition: RooStatsUtils.cxx:199
RooMsgService::instance
static RooMsgService & instance()
Return reference to singleton instance.
Definition: RooMsgService.cxx:366
RooMsgService::globalKillBelow
RooFit::MsgLevel globalKillBelow() const
Definition: RooMsgService.h:161
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29