Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 "Riostream.h"
20
21#include "RooDataSet.h"
22#include "RooFitResult.h"
24#include "RooMsgService.h"
30#include "RooRealVar.h"
31
32
33using namespace RooStats ;
34
35////////////////////////////////////////////////////////////////////////////////
36
38 RooAbsMCStudyModule(Form("UpperLimitMCSModule_%s",poi->first()->GetName()),Form("UpperLimitMCSModule_%s",poi->first()->GetName())),
39 _parName(poi->first()->GetName()),
40 _plc(nullptr),_ul(nullptr),_poi(nullptr), _data(nullptr),_cl(CL), _model(nullptr)
41{
42 std::cout<<"RooUpperLimitConstructor ParName:"<<_parName<<std::endl;
43 std::cout<<"RooUpperLimitConstructor CL:"<<_cl<<std::endl;
44 // Constructor of module with parameter to be interpreted as nSignal and the value of the
45 // null hypothesis for nSignal (usually zero)
46}
47
48
49
50////////////////////////////////////////////////////////////////////////////////
51/// Copy constructor
52
55 _parName(other._poi->first()->GetName()),
56 _plc(nullptr),_ul(nullptr),_poi(other._poi), _data(nullptr), _cl(other._cl), _model(other._model)
57{
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Destructor
62
64{
65
66 if (_plc) {
67 delete _plc ;
68 }
69 if (_data) {
70 delete _data ;
71 }
72 if(_ul){
73 delete _ul;
74 }
75 if(_poi){
76 delete _poi;
77 }
78 if (_model){
79 delete _model;
80 }
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Initialize module after attachment to RooMCStudy object
85
87{
88 // Check that parameter is also present in fit parameter list of RooMCStudy object
89 if (!fitParams()->find(_parName.c_str())) {
90 coutE(InputArguments) << "UpperLimitMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << std::endl ;
91 return false ;
92 }
93
94 //Construct the ProfileLikelihoodCalculator
95 _poi=new RooArgSet(*(fitParams()->find(_parName.c_str())));
96 std::cout<<"RooUpperLimit Initialize Instance: POI Set:"<<std::endl;
97 _poi->Print("v");
98 std::cout<<"RooUpperLimit Initialize Instance: End:"<<std::endl;
99
100
101
102 std::string ulName = "ul_" + _parName;
103 std::string ulTitle = "UL for parameter " + _parName;
104 _ul = new RooRealVar(ulName.c_str(),ulTitle.c_str(),0) ;
105
106
107 // Create new dataset to be merged with RooMCStudy::fitParDataSet
108 _data = new RooDataSet("ULSigData","Additional data for UL study",RooArgSet(*_ul)) ;
109
110 return true ;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Initialize module at beginning of RooCMStudy run
115
117{
118 _data->reset() ;
119 return true ;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Return auxiliary dataset with results of delta(-log(L))
124/// calculations of this module so that it is merged with
125/// RooMCStudy::fitParDataSet() by RooMCStudy
126
131
132////////////////////////////////////////////////////////////////////////////////
133
134// bool UpperLimitMCSModule::processAfterFit(Int_t /*sampleNum*/)
135// {
136// // Save likelihood from nominal fit, fix chosen parameter to its
137// // null hypothesis value and rerun fit Save difference in likelihood
138// // and associated Gaussian significance in auxiliary dataset
139
140// RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
141// par->setVal(_nullValue) ;
142// par->setConstant(true) ;
143// RooFitResult* frnull = refit() ;
144// par->setConstant(false) ;
145
146// _nll0h->setVal(frnull->minNll()) ;
147
148// double deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
149// double signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
150// _sig0h->setVal(signif) ;
151// _dll0h->setVal(deltaLL) ;
152
153
154// _data->add(RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
155
156// delete frnull ;
157// return true ;
158
159// }
160
161////////////////////////////////////////////////////////////////////////////////
162
164 std::cout<<"after generation Test"<<std::endl;
165
166 if (!fitInitParams() || !genSample() || !fitParams() || !fitModel() ) return false;
167
168 static_cast<RooRealVar*>(_poi->first())->setVal(static_cast<RooRealVar*>(fitInitParams()->find(_parName.c_str()))->getVal());
169
170 //_poi->first()->Print();
171 static_cast<RooRealVar*>(_poi->first())->setBins(1000);
172 //fitModel()->Print("v");
173
174 std::cout<<"generated Entries:"<<genSample()->numEntries()<<std::endl;
175
177
178 //PLC calculates intervals. for one sided ul multiply testsize by two
179 plc.SetTestSize(2*(1-_cl));
180 RooStats::ConfInterval* pllint=plc.GetInterval();
181
182 if (!pllint) return false;
183
184 std::cout<<"poi value: "<<(static_cast<RooRealVar*>(_poi->first()))->getVal()<<std::endl;
185 std::cout<<(static_cast<RooRealVar*>((fitParams()->find(_parName.c_str()))))->getVal()<<std::endl;
186 std::cout<<(static_cast<RooStats::LikelihoodInterval*>(pllint))->UpperLimit(static_cast<RooRealVar&>(*(_poi->first())))<<std::endl;
187
188
189 //Go to the fit Value for zour POI to make sure upper limit works correct.
190 //fitModel()->fitTo(*genSample());
191
192
193
194 _ul->setVal((static_cast<RooStats::LikelihoodInterval*>(pllint))->UpperLimit(static_cast<RooRealVar&>(*(fitParams()->find(_parName.c_str())))));
195
197 std::cout<<"UL:"<<_ul->getVal()<<std::endl;
198// if (_ul->getVal()<1){
199
200// RooStats::LikelihoodIntervalPlot plotpll((RooStats::LikelihoodInterval*) pllint);
201// TCanvas c1;
202// plotpll.Draw();
203// c1.Print("test.ps");
204// std::cout<<" UL<1 whats going on here?"<<std::endl;
205// abort();
206// }
207
208 delete pllint;
209
210
211 return true;
212}
#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:2489
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:103
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Container class to hold unbinned data.
Definition RooDataSet.h:34
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...
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...
~UpperLimitMCSModule() override
Destructor.
bool processBetweenGenAndFit(Int_t) override
Method called after generation of toy data sample and resetting of fit parameters to initial values a...
RooStats::ProfileLikelihoodCalculator * _plc
bool initializeRun(Int_t) override
Initialize module at beginning of RooCMStudy run.
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:58