Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooDLLSignificanceMCSModule.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooDLLSignificanceMCSModule.cxx
19\class RooDLLSignificanceMCSModule
20\ingroup Roofitcore
21
22Add-on module to RooMCStudy that
23calculates the significance of a signal by comparing the likelihood of
24a fit fit with a given parameter floating with a fit with that given
25parameter fixed to a nominal value (usually zero). The difference in
26the -log(L) of those two fits can be interpreted as the probability
27that a statistical background fluctation may result in a signal as large
28or larger than the signal observed. This interpretation is contingent
29on underlying normal sampling distributions and a MC study is a good way
30to test that assumption.
31**/
32
33#include "Riostream.h"
34
35#include "RooDataSet.h"
36#include "RooRealVar.h"
37#include "TString.h"
38#include "RooFitResult.h"
40#include "RooMsgService.h"
41
42
43
44using std::endl;
45
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Constructor of module with parameter to be interpreted as nSignal and the value of the
50/// null hypothesis for nSignal (usually zero)
51
53 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",param.GetName()),Form("RooDLLSignificanceMCSModule_%s",param.GetName())),
54 _parName(param.GetName()),
55 _nullValue(nullHypoValue)
56{
57}
58
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// Constructor of module with parameter name to be interpreted as nSignal and the value of the
63/// null hypothesis for nSignal (usually zero)
64
66 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",parName),Form("RooDLLSignificanceMCSModule_%s",parName)),
67 _parName(parName),
68 _nullValue(nullHypoValue)
69{
70}
71
72
73
74////////////////////////////////////////////////////////////////////////////////
75/// Copy constructor
76
83
85
86////////////////////////////////////////////////////////////////////////////////
87/// Initialize module after attachment to RooMCStudy object
88
90{
91 // Check that parameter is also present in fit parameter list of RooMCStudy object
92 if (!fitParams()->find(_parName.c_str())) {
93 coutE(InputArguments) << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << std::endl ;
94 return false ;
95 }
96
97 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
98 std::string nll0hName = "nll_nullhypo_" + _parName;
99 std::string nll0hTitle = "-log(L) with null hypothesis for param " + _parName;
100 _nll0h = std::make_unique<RooRealVar>(nll0hName.c_str(),nll0hTitle.c_str(),0) ;
101
102 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
103 std::string dll0hName = "dll_nullhypo_" + _parName;
104 std::string dll0hTitle = "-log(L) difference w.r.t null hypo for param " + _parName;
105 _dll0h = std::make_unique<RooRealVar>(dll0hName.c_str(),dll0hTitle.c_str(),0) ;
106
107 // Construct variable that holds significance corresponding to delta(-log(L)) w.r.t to null hypothesis for given parameter
108 std::string sig0hName = "significance_nullhypo_" + _parName;
109 std::string sig0hTitle = "Gaussian signficiance of Delta(-log(L)) w.r.t null hypo for param " + _parName;
110 _sig0h = std::make_unique<RooRealVar>(sig0hName.c_str(),sig0hTitle.c_str(),-10,100) ;
111
112 // Create new dataset to be merged with RooMCStudy::fitParDataSet
113 _data = std::make_unique<RooDataSet>("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
114
115 return true ;
116}
117
118
119
120////////////////////////////////////////////////////////////////////////////////
121/// Initialize module at beginning of RooCMStudy run
122
124{
125 _data->reset() ;
126 return true ;
127}
128
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Return auxiliary dataset with results of delta(-log(L))
133/// calculations of this module so that it is merged with
134/// RooMCStudy::fitParDataSet() by RooMCStudy
135
140
141
142
143////////////////////////////////////////////////////////////////////////////////
144/// Save likelihood from nominal fit, fix chosen parameter to its
145/// null hypothesis value and rerun fit Save difference in likelihood
146/// and associated Gaussian significance in auxiliary dataset
147
149{
150 RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
151 par->setVal(_nullValue) ;
152 par->setConstant(true) ;
153 std::unique_ptr<RooFitResult> frnull{refit()};
154 par->setConstant(false) ;
155
156 _nll0h->setVal(frnull->minNll()) ;
157
158 double deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
159 double signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
160 _sig0h->setVal(signif) ;
161 _dll0h->setVal(deltaLL) ;
162
163
165
166 return true ;
167}
#define coutE(a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
RooAbsArg * find(const char *name) const
Find object with given name in list.
Base class for add-on modules to RooMCStudy that can perform additional calculations on each generate...
RooRealVar * nllVar()
Return pointer to RooRealVar holding minimized -log(L) value.
RooFit::OwningPtr< RooFitResult > refit(RooAbsData *inGenSample=nullptr)
Refit model using original or specified data sample.
RooArgSet * fitParams()
Return current value of parameters of fit model.
void setConstant(bool value=true)
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Add-on module to RooMCStudy that calculates the significance of a signal by comparing the likelihood ...
std::unique_ptr< RooRealVar > _nll0h
Container variable for NLL result on null hypothesis.
std::unique_ptr< RooRealVar > _sig0h
Container variable for NLL result with signal.
double _nullValue
Numeric value of Nsignal parameter representing the null hypothesis.
~RooDLLSignificanceMCSModule() override
RooDLLSignificanceMCSModule(const RooRealVar &param, double nullHypoValue=0.0)
Constructor of module with parameter to be interpreted as nSignal and the value of the null hypothesi...
std::unique_ptr< RooRealVar > _dll0h
Container variable for delta NLL.
RooDataSet * finalizeRun() override
Return auxiliary dataset with results of delta(-log(L)) calculations of this module so that it is mer...
std::string _parName
Name of Nsignal parameter.
bool initializeInstance() override
Initialize module after attachment to RooMCStudy object.
bool initializeRun(Int_t) override
Initialize module at beginning of RooCMStudy run.
std::unique_ptr< RooDataSet > _data
Summary dataset to store results.
bool processAfterFit(Int_t) override
Save likelihood from nominal fit, fix chosen parameter to its null hypothesis value and rerun fit Sav...
Container class to hold unbinned data.
Definition RooDataSet.h:34
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.