Logo ROOT   6.08/07
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 
12 #include "RooStats/RooStatsUtils.h"
13 
14 
16 
18 
20 
21  if (fFirstEval && ParamsAreEqual()) {
23  << "Same RooArgSet used for null and alternate, so you must explicitly SetNullParameters and SetAlternateParameters or the likelihood ratio will always be 1."
24  << std::endl;
25  }
26 
27  // strip pdfs of constraints (which cancel out in the ratio) to avoid unnecessary computations and computational errors
28  if (fFirstEval) {
30  fAltPdf = RooStats::MakeUnconstrainedPdf(*fAltPdf , *fAltPdf->getObservables(data) );
31  }
32 
33  fFirstEval = false;
34 
37 
38  Bool_t reuse = (fReuseNll || fgAlwaysReuseNll) ;
39 
40  Bool_t created = kFALSE ;
41  if (!fNllNull) {
42  RooArgSet* allParams = fNullPdf->getParameters(data);
44  delete allParams;
45  created = kTRUE ;
46  }
47  if (reuse && !created) {
48  fNllNull->setData(data, kFALSE) ;
49  }
50 
51  // make sure we set the variables attached to this nll
52  RooArgSet* attachedSet = fNllNull->getVariables();
53  *attachedSet = *fNullParameters;
54  *attachedSet = nullPOI;
55  double nullNLL = fNllNull->getVal();
56 
57  //std::cout << std::endl << "SLRTS: null params:" << std::endl;
58  //attachedSet->Print("v");
59 
60 
61  if (!reuse) {
62  delete fNllNull ; fNllNull = NULL ;
63  }
64  delete attachedSet;
65 
66  created = kFALSE ;
67  if (!fNllAlt) {
68  RooArgSet* allParams = fAltPdf->getParameters(data);
70  delete allParams;
71  created = kTRUE ;
72  }
73  if (reuse && !created) {
74  fNllAlt->setData(data, kFALSE) ;
75  }
76  // make sure we set the variables attached to this nll
77  attachedSet = fNllAlt->getVariables();
78  *attachedSet = *fAltParameters;
79  double altNLL = fNllAlt->getVal();
80 
81  //std::cout << std::endl << "SLRTS: alt params:" << std::endl;
82  //attachedSet->Print("v");
83 
84 
85 // std::cout << std::endl << "SLRTS null NLL: " << nullNLL << " alt NLL: " << altNLL << std::endl << std::endl;
86 
87 
88  if (!reuse) {
89  delete fNllAlt ; fNllAlt = NULL ;
90  }
91  delete attachedSet;
92 
93 
94 
95  // save this snapshot
97  if( !fDetailedOutput ) {
98  fDetailedOutput = new RooArgSet( *(new RooRealVar("nullNLL","null NLL",0)), "detailedOut_SLRTS" );
99  fDetailedOutput->add( *(new RooRealVar("altNLL","alternate NLL",0)) );
100  }
101  fDetailedOutput->setRealValue( "nullNLL", nullNLL );
102  fDetailedOutput->setRealValue( "altNLL", altNLL );
103 
104 // std::cout << std::endl << "STORING THIS AS DETAILED OUTPUT:" << std::endl;
105 // fDetailedOutput->Print("v");
106 // std::cout << std::endl;
107  }
108 
109 
111  return nullNLL - altNLL;
112 }
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:777
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2082
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:548
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
const Bool_t kFALSE
Definition: Rtypes.h:92
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:37
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
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:560
#define oocoutW(o, a)
Definition: RooMsgService.h:47
#define NULL
Definition: Rtypes.h:82
static Bool_t fgAlwaysReuseNll
transient copy of the alt NLL
RooCmdArg ConditionalObservables(const RooArgSet &set)
const Bool_t kTRUE
Definition: Rtypes.h:91
RooCmdArg Constrain(const RooArgSet &params)