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
47
48
49////////////////////////////////////////////////////////////////////////////////
50/// Constructor of module with parameter to be interpreted as nSignal and the value of the
51/// null hypothesis for nSignal (usually zero)
52
54 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",param.GetName()),Form("RooDLLSignificanceMCSModule_%s",param.GetName())),
55 _parName(param.GetName()),
56 _nullValue(nullHypoValue)
57{
58}
59
60
61
62////////////////////////////////////////////////////////////////////////////////
63/// Constructor of module with parameter name to be interpreted as nSignal and the value of the
64/// null hypothesis for nSignal (usually zero)
65
66RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule(const char* parName, double nullHypoValue) :
67 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",parName),Form("RooDLLSignificanceMCSModule_%s",parName)),
68 _parName(parName),
69 _nullValue(nullHypoValue)
70{
71}
72
73
74
75////////////////////////////////////////////////////////////////////////////////
76/// Copy constructor
77
80 _parName(other._parName),
81 _nullValue(other._nullValue)
82{
83}
84
86
87////////////////////////////////////////////////////////////////////////////////
88/// Initialize module after attachment to RooMCStudy object
89
91{
92 // Check that parameter is also present in fit parameter list of RooMCStudy object
93 if (!fitParams()->find(_parName.c_str())) {
94 coutE(InputArguments) << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << endl ;
95 return false ;
96 }
97
98 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
99 std::string nll0hName = "nll_nullhypo_" + _parName;
100 std::string nll0hTitle = "-log(L) with null hypothesis for param " + _parName;
101 _nll0h = std::make_unique<RooRealVar>(nll0hName.c_str(),nll0hTitle.c_str(),0) ;
102
103 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
104 std::string dll0hName = "dll_nullhypo_" + _parName;
105 std::string dll0hTitle = "-log(L) difference w.r.t null hypo for param " + _parName;
106 _dll0h = std::make_unique<RooRealVar>(dll0hName.c_str(),dll0hTitle.c_str(),0) ;
107
108 // Construct variable that holds significance corresponding to delta(-log(L)) w.r.t to null hypothesis for given parameter
109 std::string sig0hName = "significance_nullhypo_" + _parName;
110 std::string sig0hTitle = "Gaussian signficiance of Delta(-log(L)) w.r.t null hypo for param " + _parName;
111 _sig0h = std::make_unique<RooRealVar>(sig0hName.c_str(),sig0hTitle.c_str(),-10,100) ;
112
113 // Create new dataset to be merged with RooMCStudy::fitParDataSet
114 _data = std::make_unique<RooDataSet>("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
115
116 return true ;
117}
118
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Initialize module at beginning of RooCMStudy run
123
125{
126 _data->reset() ;
127 return true ;
128}
129
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Return auxiliary dataset with results of delta(-log(L))
134/// calculations of this module so that it is merged with
135/// RooMCStudy::fitParDataSet() by RooMCStudy
136
138{
139 return _data.get();
140}
141
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Save likelihood from nominal fit, fix chosen parameter to its
146/// null hypothesis value and rerun fit Save difference in likelihood
147/// and associated Gaussian significance in auxiliary dataset
148
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)
#define ClassImp(name)
Definition Rtypes.h:377
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:55
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:57
const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.