Logo ROOT   6.14/05
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()) {
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) {
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);
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);
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 }
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:778
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2073
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:86
Bool_t setRealValue(const char *name, Double_t newVal=0, Bool_t verbose=kFALSE)
Set value of a RooAbsRealLValye stored in set with given name to newVal No error messages are printed...
Definition: RooArgSet.cxx:547
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Definition: RooAbsArg.h:194
RooCmdArg CloneData(Bool_t flag)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
RooFit::MsgLevel globalKillBelow() const
bool Bool_t
Definition: RtypesCore.h:59
RooAbsReal * fNllAlt
transient copy of the null NLL
static RooMsgService & instance()
Return reference to singleton instance.
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...
virtual Bool_t setData(RooAbsData &, Bool_t=kTRUE)
Definition: RooAbsReal.h:305
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooCmdArg GlobalObservables(const RooArgSet &globs)
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
void setGlobalKillBelow(RooFit::MsgLevel level)
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
const Bool_t kFALSE
Definition: RtypesCore.h:88
double Double_t
Definition: RtypesCore.h:55
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don&#39;t match any of...
Definition: RooAbsArg.cxx:532
#define oocoutW(o, a)
Definition: RooMsgService.h:46
static Bool_t fgAlwaysReuseNll
transient copy of the alt NLL
RooCmdArg ConditionalObservables(const RooArgSet &set)
const Bool_t kTRUE
Definition: RtypesCore.h:87
RooCmdArg Constrain(const RooArgSet &params)