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
22RooDLLSignificanceMCSModule is an add-on modules 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 namespace std;
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
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Destructor
89
91{
92 if (_nll0h) {
93 delete _nll0h ;
94 }
95 if (_dll0h) {
96 delete _dll0h ;
97 }
98 if (_sig0h) {
99 delete _sig0h ;
100 }
101 if (_data) {
102 delete _data ;
103 }
104}
105
106
107
108////////////////////////////////////////////////////////////////////////////////
109/// Initialize module after attachment to RooMCStudy object
110
112{
113 // Check that parameter is also present in fit parameter list of RooMCStudy object
114 if (!fitParams()->find(_parName.c_str())) {
115 coutE(InputArguments) << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << endl ;
116 return false ;
117 }
118
119 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
120 TString nll0hName = Form("nll_nullhypo_%s",_parName.c_str()) ;
121 TString nll0hTitle = Form("-log(L) with null hypothesis for param %s",_parName.c_str()) ;
122 _nll0h = new RooRealVar(nll0hName.Data(),nll0hTitle.Data(),0) ;
123
124 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
125 TString dll0hName = Form("dll_nullhypo_%s",_parName.c_str()) ;
126 TString dll0hTitle = Form("-log(L) difference w.r.t null hypo for param %s",_parName.c_str()) ;
127 _dll0h = new RooRealVar(dll0hName.Data(),dll0hTitle.Data(),0) ;
128
129 // Construct variable that holds significance corresponding to delta(-log(L)) w.r.t to null hypothesis for given parameter
130 TString sig0hName = Form("significance_nullhypo_%s",_parName.c_str()) ;
131 TString sig0hTitle = Form("Gaussian signficiance of Delta(-log(L)) w.r.t null hypo for param %s",_parName.c_str()) ;
132 _sig0h = new RooRealVar(sig0hName.Data(),sig0hTitle.Data(),-10,100) ;
133
134 // Create new dataset to be merged with RooMCStudy::fitParDataSet
135 _data = new RooDataSet("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
136
137 return true ;
138}
139
140
141
142////////////////////////////////////////////////////////////////////////////////
143/// Initialize module at beginning of RooCMStudy run
144
146{
147 _data->reset() ;
148 return true ;
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Return auxiliary dataset with results of delta(-log(L))
155/// calculations of this module so that it is merged with
156/// RooMCStudy::fitParDataSet() by RooMCStudy
157
159{
160 return _data ;
161}
162
163
164
165////////////////////////////////////////////////////////////////////////////////
166/// Save likelihood from nominal fit, fix chosen parameter to its
167/// null hypothesis value and rerun fit Save difference in likelihood
168/// and associated Gaussian significance in auxiliary dataset
169
171{
172 RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
173 par->setVal(_nullValue) ;
174 par->setConstant(true) ;
175 std::unique_ptr<RooFitResult> frnull{refit()};
176 par->setConstant(false) ;
177
178 _nll0h->setVal(frnull->minNll()) ;
179
180 double deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
181 double signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
182 _sig0h->setVal(signif) ;
183 _dll0h->setVal(deltaLL) ;
184
185
187
188 return true ;
189}
#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:2467
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual void reset()
RooAbsMCStudyModule is a base class for add-on modules to RooMCStudy that can perform additional calc...
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
RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that calculates the significance of a ...
double _nullValue
Numeric value of Nsignal parameter representing the null hypothesis.
~RooDLLSignificanceMCSModule() override
Destructor.
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...
RooDataSet * _data
Summary dataset to store results.
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.
RooRealVar * _sig0h
Container variable for NLL result with signal.
bool initializeInstance() override
Initialize module after attachment to RooMCStudy object.
bool initializeRun(Int_t) override
Initialize module at beginning of RooCMStudy run.
bool processAfterFit(Int_t) override
Save likelihood from nominal fit, fix chosen parameter to its null hypothesis value and rerun fit Sav...
RooRealVar * _nll0h
Container variable for NLL result on null hypothesis.
RooRealVar * _dll0h
Container variable for delta NLL.
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
void add(const RooArgSet &row, double weight, double weightError)
Add one ore more rows of data.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:380