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 "RooDataSet.h"
34#include "RooRealVar.h"
35#include "TString.h"
36#include "RooFitResult.h"
38#include "RooMsgService.h"
39
40#include <ostream>
41
42using std::endl;
43
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// Constructor of module with parameter to be interpreted as nSignal and the value of the
48/// null hypothesis for nSignal (usually zero)
49
51 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",param.GetName()),Form("RooDLLSignificanceMCSModule_%s",param.GetName())),
52 _parName(param.GetName()),
53 _nullValue(nullHypoValue)
54{
55}
56
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Constructor of module with parameter name to be interpreted as nSignal and the value of the
61/// null hypothesis for nSignal (usually zero)
62
64 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",parName),Form("RooDLLSignificanceMCSModule_%s",parName)),
65 _parName(parName),
66 _nullValue(nullHypoValue)
67{
68}
69
70
71
72////////////////////////////////////////////////////////////////////////////////
73/// Copy constructor
74
81
83
84////////////////////////////////////////////////////////////////////////////////
85/// Initialize module after attachment to RooMCStudy object
86
88{
89 // Check that parameter is also present in fit parameter list of RooMCStudy object
90 if (!fitParams()->find(_parName.c_str())) {
91 coutE(InputArguments) << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << std::endl ;
92 return false ;
93 }
94
95 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
96 std::string nll0hName = "nll_nullhypo_" + _parName;
97 std::string nll0hTitle = "-log(L) with null hypothesis for param " + _parName;
98 _nll0h = std::make_unique<RooRealVar>(nll0hName.c_str(),nll0hTitle.c_str(),0) ;
99
100 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
101 std::string dll0hName = "dll_nullhypo_" + _parName;
102 std::string dll0hTitle = "-log(L) difference w.r.t null hypo for param " + _parName;
103 _dll0h = std::make_unique<RooRealVar>(dll0hName.c_str(),dll0hTitle.c_str(),0) ;
104
105 // Construct variable that holds significance corresponding to delta(-log(L)) w.r.t to null hypothesis for given parameter
106 std::string sig0hName = "significance_nullhypo_" + _parName;
107 std::string sig0hTitle = "Gaussian signficiance of Delta(-log(L)) w.r.t null hypo for param " + _parName;
108 _sig0h = std::make_unique<RooRealVar>(sig0hName.c_str(),sig0hTitle.c_str(),-10,100) ;
109
110 // Create new dataset to be merged with RooMCStudy::fitParDataSet
111 _data = std::make_unique<RooDataSet>("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
112
113 return true ;
114}
115
116
117
118////////////////////////////////////////////////////////////////////////////////
119/// Initialize module at beginning of RooCMStudy run
120
122{
123 _data->reset() ;
124 return true ;
125}
126
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Return auxiliary dataset with results of delta(-log(L))
131/// calculations of this module so that it is merged with
132/// RooMCStudy::fitParDataSet() by RooMCStudy
133
138
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Save likelihood from nominal fit, fix chosen parameter to its
143/// null hypothesis value and rerun fit Save difference in likelihood
144/// and associated Gaussian significance in auxiliary dataset
145
147{
148 if(!fitOk)
149 return true;
150
151 RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
152 par->setVal(_nullValue) ;
153 par->setConstant(true) ;
154 std::unique_ptr<RooFitResult> frnull{refit()};
155 par->setConstant(false) ;
156
157 _nll0h->setVal(frnull->minNll()) ;
158
159 double deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
160 double signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
161 _sig0h->setVal(signif) ;
162 _dll0h->setVal(deltaLL) ;
163
164
166
167 return true ;
168}
#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:2571
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:107
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
bool initializeRun(Int_t numSamples) override
Initialize module at beginning of RooCMStudy run.
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 processAfterFit(bool fitOk) override
Save likelihood from nominal fit, fix chosen parameter to its null hypothesis value and rerun fit Sav...
bool initializeInstance() override
Initialize module after attachment to RooMCStudy object.
std::unique_ptr< RooDataSet > _data
Summary dataset to store results.
Container class to hold unbinned data.
Definition RooDataSet.h:32
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.