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 std::unique_ptr<RooArgSet> nullObs{fNullPdf->getObservables(data)};
41 fNullPdf = RooStats::MakeUnconstrainedPdf(*fNullPdf, *nullObs);
42 std::unique_ptr<RooArgSet> altObs{fAltPdf->getObservables(data)};
43 fAltPdf = RooStats::MakeUnconstrainedPdf(*fAltPdf, *altObs);
44 }
45
46 fFirstEval = false;
47
49 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
50
51 bool reuse = (fReuseNll || fgAlwaysReuseNll) ;
52
53 bool created = false ;
54 if (!fNllNull) {
55 std::unique_ptr<RooArgSet> allParams{fNullPdf->getParameters(data)};
56 using namespace RooFit;
57 fNllNull = std::unique_ptr<RooAbsReal>{fNullPdf->createNLL(data, CloneData(false), Constrain(*allParams), GlobalObservables(fGlobalObs), ConditionalObservables(fConditionalObs))};
58 created = true ;
59 }
60 if (reuse && !created) {
61 fNllNull->setData(data, false) ;
62 }
63
64 // make sure we set the variables attached to this nll
65 std::unique_ptr<RooArgSet> attachedSet{fNllNull->getVariables()};
66 attachedSet->assign(*fNullParameters);
67 attachedSet->assign(nullPOI);
68 double nullNLL = fNllNull->getVal();
69
70 //std::cout << std::endl << "SLRTS: null params:" << std::endl;
71 //attachedSet->Print("v");
72
73
74 if (!reuse) {
75 fNllNull.reset();
76 }
77
78 created = false ;
79 if (!fNllAlt) {
80 std::unique_ptr<RooArgSet> allParams{fAltPdf->getParameters(data)};
81 using namespace RooFit;
82 fNllAlt = std::unique_ptr<RooAbsReal>{fAltPdf->createNLL(data, CloneData(false), Constrain(*allParams), GlobalObservables(fGlobalObs), ConditionalObservables(fConditionalObs))};
83 created = true ;
84 }
85 if (reuse && !created) {
86 fNllAlt->setData(data, false) ;
87 }
88 // make sure we set the variables attached to this nll
89 attachedSet = std::unique_ptr<RooArgSet>{fNllAlt->getVariables()};
90 attachedSet->assign(*fAltParameters);
91 double altNLL = fNllAlt->getVal();
92
93 //std::cout << std::endl << "SLRTS: alt params:" << std::endl;
94 //attachedSet->Print("v");
95
96
97// std::cout << std::endl << "SLRTS null NLL: " << nullNLL << " alt NLL: " << altNLL << std::endl << std::endl;
98
99
100 if (!reuse) {
101 fNllAlt.reset();
102 }
103
104
105
106 // save this snapshot
107 if( fDetailedOutputEnabled ) {
108 if( !fDetailedOutput ) {
109 fDetailedOutput = std::make_unique<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
116
117 RooMsgService::instance().setGlobalKillBelow(msglevel);
118 return nullNLL - altNLL;
119}
#define oocoutW(o, a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:56
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
static RooMsgService & instance()
Return reference to singleton instance.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
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 CodegenImpl.h:72
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