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 reuse = (fReuseNll || fgAlwaysReuseNll) ;
50
51 bool created = false ;
52 if (!fNllNull) {
53 std::unique_ptr<RooArgSet> allParams{fNullPdf->getParameters(data)};
54 using namespace RooFit;
55 fNllNull = std::unique_ptr<RooAbsReal>{fNullPdf->createNLL(data, CloneData(false), Constrain(*allParams), GlobalObservables(fGlobalObs), ConditionalObservables(fConditionalObs))};
56 created = true ;
57 }
58 if (reuse && !created) {
59 fNllNull->setData(data, false) ;
60 }
61
62 // make sure we set the variables attached to this nll
63 std::unique_ptr<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 fNllNull.reset();
74 }
75
76 created = false ;
77 if (!fNllAlt) {
78 std::unique_ptr<RooArgSet> allParams{fAltPdf->getParameters(data)};
79 using namespace RooFit;
80 fNllAlt = std::unique_ptr<RooAbsReal>{fAltPdf->createNLL(data, CloneData(false), Constrain(*allParams), GlobalObservables(fGlobalObs), ConditionalObservables(fConditionalObs))};
81 created = true ;
82 }
83 if (reuse && !created) {
84 fNllAlt->setData(data, false) ;
85 }
86 // make sure we set the variables attached to this nll
87 attachedSet = std::unique_ptr<RooArgSet>{fNllAlt->getVariables()};
88 attachedSet->assign(*fAltParameters);
89 double altNLL = fNllAlt->getVal();
90
91 //std::cout << std::endl << "SLRTS: alt params:" << std::endl;
92 //attachedSet->Print("v");
93
94
95// std::cout << std::endl << "SLRTS null NLL: " << nullNLL << " alt NLL: " << altNLL << std::endl << std::endl;
96
97
98 if (!reuse) {
99 fNllAlt.reset();
100 }
101
102
103
104 // save this snapshot
105 if( fDetailedOutputEnabled ) {
106 if( !fDetailedOutput ) {
107 fDetailedOutput = new RooArgSet( *(new RooRealVar("nullNLL","null NLL",0)), "detailedOut_SLRTS" );
108 fDetailedOutput->add( *(new RooRealVar("altNLL","alternate NLL",0)) );
109 }
110 fDetailedOutput->setRealValue( "nullNLL", nullNLL );
111 fDetailedOutput->setRealValue( "altNLL", altNLL );
112
113// std::cout << std::endl << "STORING THIS AS DETAILED OUTPUT:" << std::endl;
114// fDetailedOutput->Print("v");
115// std::cout << std::endl;
116 }
117
118
120 return nullNLL - altNLL;
121}
#define oocoutW(o, a)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:59
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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:40
double Evaluate(RooAbsData &data, RooArgSet &nullPOI) override
Main interface to evaluate the test statistic on a dataset given the values for the Null Parameters O...
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition Common.h:18
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=nullptr)
remove constraints from pdf and return the unconstrained pdf