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 
22 RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that
23 calculates the significance of a signal by comparing the likelihood of
24 a fit fit with a given parameter floating with a fit with that given
25 parameter fixed to a nominal value (usually zero). The difference in
26 the -log(L) of those two fits can be interpreted as the probability
27 that a statistical background fluctation may result in a signal as large
28 or larger than the signal observed. This interpretation is contingent
29 on underlying normal sampling distributions and a MC study is a good way
30 to test that assumption.
31 **/
32 
33 #include "Riostream.h"
34 
35 #include "RooDataSet.h"
36 #include "RooRealVar.h"
37 #include "TString.h"
38 #include "RooFit.h"
39 #include "RooFitResult.h"
41 #include "RooMsgService.h"
42 
43 
44 
45 using namespace std;
46 
48  ;
49 
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Constructor of module with parameter to be interpreted as nSignal and the value of the
54 /// null hypothesis for nSignal (usually zero)
55 
57  RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",param.GetName()),Form("RooDLLSignificanceMCSModule_%s",param.GetName())),
58  _parName(param.GetName()),
59  _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(nullHypoValue)
60 {
61 }
62 
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Constructor of module with parameter name to be interpreted as nSignal and the value of the
67 /// null hypothesis for nSignal (usually zero)
68 
70  RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",parName),Form("RooDLLSignificanceMCSModule_%s",parName)),
71  _parName(parName),
72  _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(nullHypoValue)
73 {
74 }
75 
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Copy constructor
80 
82  RooAbsMCStudyModule(other),
83  _parName(other._parName),
84  _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(other._nullValue)
85 {
86 }
87 
88 
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Destructor
92 
94 {
95  if (_nll0h) {
96  delete _nll0h ;
97  }
98  if (_dll0h) {
99  delete _dll0h ;
100  }
101  if (_sig0h) {
102  delete _sig0h ;
103  }
104  if (_data) {
105  delete _data ;
106  }
107 }
108 
109 
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Initialize module after attachment to RooMCStudy object
113 
115 {
116  // Check that parameter is also present in fit parameter list of RooMCStudy object
117  if (!fitParams()->find(_parName.c_str())) {
118  coutE(InputArguments) << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << endl ;
119  return kFALSE ;
120  }
121 
122  // Construct variable that holds -log(L) fit with null hypothesis for given parameter
123  TString nll0hName = Form("nll_nullhypo_%s",_parName.c_str()) ;
124  TString nll0hTitle = Form("-log(L) with null hypothesis for param %s",_parName.c_str()) ;
125  _nll0h = new RooRealVar(nll0hName.Data(),nll0hTitle.Data(),0) ;
126 
127  // Construct variable that holds -log(L) fit with null hypothesis for given parameter
128  TString dll0hName = Form("dll_nullhypo_%s",_parName.c_str()) ;
129  TString dll0hTitle = Form("-log(L) difference w.r.t null hypo for param %s",_parName.c_str()) ;
130  _dll0h = new RooRealVar(dll0hName.Data(),dll0hTitle.Data(),0) ;
131 
132  // Construct variable that holds significance corresponding to delta(-log(L)) w.r.t to null hypothesis for given parameter
133  TString sig0hName = Form("significance_nullhypo_%s",_parName.c_str()) ;
134  TString sig0hTitle = Form("Gaussian signficiance of Delta(-log(L)) w.r.t null hypo for param %s",_parName.c_str()) ;
135  _sig0h = new RooRealVar(sig0hName.Data(),sig0hTitle.Data(),-10,100) ;
136 
137  // Create new dataset to be merged with RooMCStudy::fitParDataSet
138  _data = new RooDataSet("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
139 
140  return kTRUE ;
141 }
142 
143 
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Initialize module at beginning of RooCMStudy run
147 
149 {
150  _data->reset() ;
151  return kTRUE ;
152 }
153 
154 
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Return auxiliary dataset with results of delta(-log(L))
158 /// calculations of this module so that it is merged with
159 /// RooMCStudy::fitParDataSet() by RooMCStudy
160 
162 {
163  return _data ;
164 }
165 
166 
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Save likelihood from nominal fit, fix chosen parameter to its
170 /// null hypothesis value and rerun fit Save difference in likelihood
171 /// and associated Gaussian significance in auxilary dataset
172 
174 {
175  RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
176  par->setVal(_nullValue) ;
177  par->setConstant(kTRUE) ;
178  RooFitResult* frnull = refit() ;
179  par->setConstant(kFALSE) ;
180 
181  _nll0h->setVal(frnull->minNll()) ;
182 
183  Double_t deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
184  Double_t signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
185  _sig0h->setVal(signif) ;
186  _dll0h->setVal(deltaLL) ;
187 
188 
190 
191  delete frnull ;
192 
193  return kTRUE ;
194 }
RooAbsMCStudyModule::nllVar
RooRealVar * nllVar()
Definition: RooAbsMCStudyModule.h:137
RooRealVar::setVal
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:226
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooDLLSignificanceMCSModule::initializeInstance
Bool_t initializeInstance()
Initialize module after attachment to RooMCStudy object.
Definition: RooDLLSignificanceMCSModule.cxx:114
RooDLLSignificanceMCSModule::~RooDLLSignificanceMCSModule
virtual ~RooDLLSignificanceMCSModule()
Destructor.
Definition: RooDLLSignificanceMCSModule.cxx:93
RooMsgService.h
RooDLLSignificanceMCSModule::_nullValue
Double_t _nullValue
Definition: RooDLLSignificanceMCSModule.h:59
RooDLLSignificanceMCSModule::_data
RooDataSet * _data
Definition: RooDLLSignificanceMCSModule.h:55
RooDLLSignificanceMCSModule::_parName
std::string _parName
Definition: RooDLLSignificanceMCSModule.h:54
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
TString::Data
const char * Data() const
Definition: TString.h:369
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
RooDLLSignificanceMCSModule::_nll0h
RooRealVar * _nll0h
Definition: RooDLLSignificanceMCSModule.h:56
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooDLLSignificanceMCSModule.h
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
RooDLLSignificanceMCSModule::initializeRun
Bool_t initializeRun(Int_t)
Initialize module at beginning of RooCMStudy run.
Definition: RooDLLSignificanceMCSModule.cxx:148
TString
Definition: TString.h:136
RooDLLSignificanceMCSModule::processAfterFit
Bool_t processAfterFit(Int_t)
Save likelihood from nominal fit, fix chosen parameter to its null hypothesis value and rerun fit Sav...
Definition: RooDLLSignificanceMCSModule.cxx:173
RooDataSet.h
TString.h
bool
RooFitResult
Definition: RooFitResult.h:40
RooDLLSignificanceMCSModule
Definition: RooDLLSignificanceMCSModule.h:23
RooAbsMCStudyModule
Definition: RooAbsMCStudyModule.h:30
RooDataSet::add
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
Definition: RooDataSet.cxx:1164
RooDLLSignificanceMCSModule::finalizeRun
RooDataSet * finalizeRun()
Return auxiliary dataset with results of delta(-log(L)) calculations of this module so that it is mer...
Definition: RooDLLSignificanceMCSModule.cxx:161
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
sqrt
double sqrt(double)
RooRealVar.h
RooFitResult.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooDLLSignificanceMCSModule::_sig0h
RooRealVar * _sig0h
Definition: RooDLLSignificanceMCSModule.h:58
RooDLLSignificanceMCSModule::_dll0h
RooRealVar * _dll0h
Definition: RooDLLSignificanceMCSModule.h:57
RooAbsRealLValue::setConstant
void setConstant(Bool_t value=kTRUE)
Definition: RooAbsRealLValue.h:109
RooAbsMCStudyModule::fitParams
RooArgSet * fitParams()
Definition: RooAbsMCStudyModule.h:133
RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule
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...
Definition: RooDLLSignificanceMCSModule.cxx:56
RooDataSet
Definition: RooDataSet.h:33
RooRealVar
Definition: RooRealVar.h:35
Riostream.h
RooFitResult::minNll
Double_t minNll() const
Definition: RooFitResult.h:98
RooArgSet
Definition: RooArgSet.h:28
RooAbsMCStudyModule::refit
RooFitResult * refit(RooAbsData *inGenSample=0)
Definition: RooAbsMCStudyModule.h:80
int
RooAbsData::reset
virtual void reset()
Definition: RooAbsData.cxx:314