Logo ROOT  
Reference Guide
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
51////////////////////////////////////////////////////////////////////////////////
52/// Constructor of module with parameter to be interpreted as nSignal and the value of the
53/// null hypothesis for nSignal (usually zero)
54
56 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",param.GetName()),Form("RooDLLSignificanceMCSModule_%s",param.GetName())),
57 _parName(param.GetName()),
58 _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(nullHypoValue)
59{
60}
61
62
63
64////////////////////////////////////////////////////////////////////////////////
65/// Constructor of module with parameter name to be interpreted as nSignal and the value of the
66/// null hypothesis for nSignal (usually zero)
67
69 RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",parName),Form("RooDLLSignificanceMCSModule_%s",parName)),
70 _parName(parName),
71 _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(nullHypoValue)
72{
73}
74
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// Copy constructor
79
82 _parName(other._parName),
83 _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(other._nullValue)
84{
85}
86
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Destructor
91
93{
94 if (_nll0h) {
95 delete _nll0h ;
96 }
97 if (_dll0h) {
98 delete _dll0h ;
99 }
100 if (_sig0h) {
101 delete _sig0h ;
102 }
103 if (_data) {
104 delete _data ;
105 }
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Initialize module after attachment to RooMCStudy object
112
114{
115 // Check that parameter is also present in fit parameter list of RooMCStudy object
116 if (!fitParams()->find(_parName.c_str())) {
117 coutE(InputArguments) << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << endl ;
118 return kFALSE ;
119 }
120
121 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
122 TString nll0hName = Form("nll_nullhypo_%s",_parName.c_str()) ;
123 TString nll0hTitle = Form("-log(L) with null hypothesis for param %s",_parName.c_str()) ;
124 _nll0h = new RooRealVar(nll0hName.Data(),nll0hTitle.Data(),0) ;
125
126 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
127 TString dll0hName = Form("dll_nullhypo_%s",_parName.c_str()) ;
128 TString dll0hTitle = Form("-log(L) difference w.r.t null hypo for param %s",_parName.c_str()) ;
129 _dll0h = new RooRealVar(dll0hName.Data(),dll0hTitle.Data(),0) ;
130
131 // Construct variable that holds significance corresponding to delta(-log(L)) w.r.t to null hypothesis for given parameter
132 TString sig0hName = Form("significance_nullhypo_%s",_parName.c_str()) ;
133 TString sig0hTitle = Form("Gaussian signficiance of Delta(-log(L)) w.r.t null hypo for param %s",_parName.c_str()) ;
134 _sig0h = new RooRealVar(sig0hName.Data(),sig0hTitle.Data(),-10,100) ;
135
136 // Create new dataset to be merged with RooMCStudy::fitParDataSet
137 _data = new RooDataSet("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
138
139 return kTRUE ;
140}
141
142
143
144////////////////////////////////////////////////////////////////////////////////
145/// Initialize module at beginning of RooCMStudy run
146
148{
149 _data->reset() ;
150 return kTRUE ;
151}
152
153
154
155////////////////////////////////////////////////////////////////////////////////
156/// Return auxiliary dataset with results of delta(-log(L))
157/// calculations of this module so that it is merged with
158/// RooMCStudy::fitParDataSet() by RooMCStudy
159
161{
162 return _data ;
163}
164
165
166
167////////////////////////////////////////////////////////////////////////////////
168/// Save likelihood from nominal fit, fix chosen parameter to its
169/// null hypothesis value and rerun fit Save difference in likelihood
170/// and associated Gaussian significance in auxilary dataset
171
173{
174 RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
175 par->setVal(_nullValue) ;
176 par->setConstant(kTRUE) ;
177 RooFitResult* frnull = refit() ;
178 par->setConstant(kFALSE) ;
179
180 _nll0h->setVal(frnull->minNll()) ;
181
182 Double_t deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
183 Double_t signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
184 _sig0h->setVal(signif) ;
185 _dll0h->setVal(deltaLL) ;
186
187
189
190 delete frnull ;
191
192 return kTRUE ;
193}
#define coutE(a)
Definition: RooMsgService.h:33
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:375
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual void reset()
Definition: RooAbsData.cxx:388
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.
RooArgSet * fitParams()
Return current value of parameters of fit model.
RooFitResult * refit(RooAbsData *inGenSample=0)
Refit model using orignal or specified data sample.
void setConstant(Bool_t value=kTRUE)
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:93
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that calculates the significance of a ...
~RooDLLSignificanceMCSModule() override
Destructor.
RooDataSet * _data
Summary dataset to store results.
Bool_t processAfterFit(Int_t) override
Save likelihood from nominal fit, fix chosen parameter to its null hypothesis value and rerun fit Sav...
Bool_t initializeInstance() override
Initialize module after attachment to RooMCStudy object.
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.
RooDLLSignificanceMCSModule(const RooRealVar &param, Double_t nullHypoValue=0)
Constructor of module with parameter to be interpreted as nSignal and the value of the null hypothesi...
Bool_t initializeRun(Int_t) override
Initialize module at beginning of RooCMStudy run.
Double_t _nullValue
Numeric value of Nsignal parameter representing the null hypothesis.
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:55
void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add one ore more rows of data.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
Double_t minNll() const
Return minimized -log(L) value.
Definition: RooFitResult.h:99
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
void setVal(Double_t value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:281
Basic string class.
Definition: TString.h:136
const char * Data() const
Definition: TString.h:369
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
@ InputArguments
Definition: RooGlobalFunc.h:64