ROOT  6.06/09
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()) {
22  oocoutW(fNullParameters,InputArguments)
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) {
29  fNullPdf = RooStats::MakeUnconstrainedPdf(*fNullPdf, *fNullPdf->getObservables(data));
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);
43  fNllNull = fNullPdf->createNLL(data, RooFit::CloneData(kFALSE),RooFit::Constrain(*allParams),RooFit::ConditionalObservables(fConditionalObs));
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);
69  fNllAlt = fAltPdf->createNLL(data, RooFit::CloneData(kFALSE),RooFit::Constrain(*allParams),RooFit::ConditionalObservables(fConditionalObs));
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
96  if( fDetailedOutputEnabled ) {
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 }
RooCmdArg CloneData(Bool_t flag)
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
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...
RooFit::MsgLevel globalKillBelow() const
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=NULL)
void setGlobalKillBelow(RooFit::MsgLevel level)
double Double_t
Definition: RtypesCore.h:55
#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)