Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
UpperLimitMCSModule.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke, Nils Ruthmann
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11/** \class RooStats::UpperLimitMCSModule
12 \ingroup Roostats
13
14This class allow to compute in the ToyMcStudy framework the ProfileLikelihood
15upper limit for each toy-MC sample generated
16
17*/
18
19#include "RooDataSet.h"
20#include "RooFitResult.h"
22#include "RooMsgService.h"
26#include "RooRealVar.h"
27
28#include <ostream>
29
30using namespace RooStats ;
31
32////////////////////////////////////////////////////////////////////////////////
33
35 RooAbsMCStudyModule(Form("UpperLimitMCSModule_%s",poi->first()->GetName()),Form("UpperLimitMCSModule_%s",poi->first()->GetName())),
36 _parName(poi->first()->GetName()),
37 _plc(nullptr),_ul(nullptr),_poi(nullptr), _data(nullptr),_cl(CL), _model(nullptr)
38{
39 coutI(InputArguments)<<"RooUpperLimitConstructor ParName:"<<_parName<<std::endl;
40 coutI(InputArguments)<<"RooUpperLimitConstructor CL:"<<_cl<<std::endl;
41 // Constructor of module with parameter to be interpreted as nSignal and the value of the
42 // null hypothesis for nSignal (usually zero)
43}
44
45
46
47////////////////////////////////////////////////////////////////////////////////
48/// Copy constructor
49
52 _parName(other._poi->first()->GetName()),
53 _plc(nullptr),_ul(nullptr),_poi(other._poi), _data(nullptr), _cl(other._cl), _model(other._model)
54{
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Destructor
59
61{
62
63 if (_plc) {
64 delete _plc ;
65 }
66 if (_data) {
67 delete _data ;
68 }
69 if(_ul){
70 delete _ul;
71 }
72 if(_poi){
73 delete _poi;
74 }
75 if (_model){
76 delete _model;
77 }
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Initialize module after attachment to RooMCStudy object
82
84{
85 // Check that parameter is also present in fit parameter list of RooMCStudy object
86 if (!fitParams()->find(_parName.c_str())) {
87 coutE(InputArguments) << "UpperLimitMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << std::endl ;
88 return false ;
89 }
90
91 //Construct the ProfileLikelihoodCalculator
92 _poi=new RooArgSet(*(fitParams()->find(_parName.c_str())));
93 coutI(Eval)<<"RooUpperLimit Initialize Instance: POI Set:"<<std::endl;
94 _poi->Print("v");
95 coutI(Eval)<<"RooUpperLimit Initialize Instance: End:"<<std::endl;
96
97
98
99 std::string ulName = "ul_" + _parName;
100 std::string ulTitle = "UL for parameter " + _parName;
101 _ul = new RooRealVar(ulName.c_str(),ulTitle.c_str(),0) ;
102
103
104 // Create new dataset to be merged with RooMCStudy::fitParDataSet
105 _data = new RooDataSet("ULSigData","Additional data for UL study",RooArgSet(*_ul)) ;
106
107 return true ;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Initialize module at beginning of RooCMStudy run
112
114{
115 _data->reset() ;
116 return true ;
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Return auxiliary dataset with results of delta(-log(L))
121/// calculations of this module so that it is merged with
122/// RooMCStudy::fitParDataSet() by RooMCStudy
123
128
129////////////////////////////////////////////////////////////////////////////////
130
132{
133 if (!fitOk)
134 return true;
136 coutI(Eval)<<"UL:"<<_ul->getVal()<<std::endl;
137// if (_ul->getVal()<1){
138
139// RooStats::LikelihoodIntervalPlot plotpll((RooStats::LikelihoodInterval*) pllint);
140// TCanvas c1;
141// plotpll.Draw();
142// c1.Print("test.ps");
143// std::cout<<" UL<1 whats going on here?"<<std::endl;
144// abort();
145// }
146
147
148// // Save likelihood from nominal fit, fix chosen parameter to its
149// // null hypothesis value and rerun fit Save difference in likelihood
150// // and associated Gaussian significance in auxiliary dataset
151
152// RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
153// par->setVal(_nullValue) ;
154// par->setConstant(true) ;
155// RooFitResult* frnull = refit() ;
156// par->setConstant(false) ;
157
158// _nll0h->setVal(frnull->minNll()) ;
159
160// double deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
161// double signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
162// _sig0h->setVal(signif) ;
163// _dll0h->setVal(deltaLL) ;
164
165
166// _data->add(RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
167
168// delete frnull ;
169 return true ;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173
175 coutI(Eval)<<"after generation Test"<<std::endl;
176
177 if (!fitInitParams() || !genSample() || !fitParams() || !fitModel() ) return false;
178
179 static_cast<RooRealVar*>(_poi->first())->setVal(static_cast<RooRealVar*>(fitInitParams()->find(_parName.c_str()))->getVal());
180
181 //_poi->first()->Print();
182 static_cast<RooRealVar*>(_poi->first())->setBins(1000);
183 //fitModel()->Print("v");
184
185 coutI(Eval)<<"generated Entries:"<<genSample()->numEntries()<<std::endl;
186
188
189 //PLC calculates intervals. for one sided ul multiply testsize by two
190 plc.SetTestSize(2*(1-_cl));
191 RooStats::ConfInterval* pllint=plc.GetInterval();
192
193 if (!pllint) return false;
194
195 coutI(Eval)<<"poi value: "<<(static_cast<RooRealVar*>(_poi->first()))->getVal()<<std::endl;
196 coutI(Eval)<<(static_cast<RooRealVar*>((fitParams()->find(_parName.c_str()))))->getVal()<<std::endl;
197 coutI(Eval)<<(static_cast<RooStats::LikelihoodInterval*>(pllint))->UpperLimit(static_cast<RooRealVar&>(*(_poi->first())))<<std::endl;
198
199
200 //Go to the fit Value for zour POI to make sure upper limit works correct.
201 //fitModel()->fitTo(*genSample());
202
203
204
205 _ul->setVal((static_cast<RooStats::LikelihoodInterval*>(pllint))->UpperLimit(static_cast<RooRealVar&>(*(fitParams()->find(_parName.c_str())))));
206
207 delete pllint;
208
209
210 return true;
211}
#define coutI(a)
#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:2570
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual void reset()
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Base class for add-on modules to RooMCStudy that can perform additional calculations on each generate...
RooAbsData * genSample()
Return generate sample.
RooAbsPdf * fitModel()
Return fit model.
RooArgSet * fitParams()
Return current value of parameters of fit model.
RooArgSet * fitInitParams()
Return initial value of parameters of fit model.
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
Container class to hold unbinned data.
Definition RooDataSet.h:32
void add(const RooArgSet &row, double weight, double weightError)
Add one ore more rows of data.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.
ConfInterval is an interface class for a generic interval in the RooStats framework.
LikelihoodInterval is a concrete implementation of the RooStats::ConfInterval interface.
The ProfileLikelihoodCalculator is a concrete implementation of CombinedCalculator (the interface cla...
This class allow to compute in the ToyMcStudy framework the ProfileLikelihood upper limit for each to...
bool processBetweenGenAndFit(Int_t sampleNum) override
Method called after generation of toy data sample and resetting of fit parameters to initial values a...
const RooArgSet * _poi
parameters of interest
UpperLimitMCSModule(const RooArgSet *poi, double CL=0.95)
RooDataSet * finalizeRun() override
Return auxiliary dataset with results of delta(-log(L)) calculations of this module so that it is mer...
bool processAfterFit(bool fitOk) override
Method called after fit has been performed.
~UpperLimitMCSModule() override
Destructor.
bool initializeRun(Int_t numSamples) override
Initialize module at beginning of RooCMStudy run.
RooStats::ProfileLikelihoodCalculator * _plc
std::string _parName
Name of Nsignal parameter.
RooDataSet * _data
Summary dataset to store results.
bool initializeInstance() override
Initialize module after attachment to RooMCStudy object.
Namespace for the RooStats classes.
Definition CodegenImpl.h:67