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 "Riostream.h"
20
21#include "RooDataSet.h"
22#include "TString.h"
23#include "RooFitResult.h"
25#include "RooMsgService.h"
31#include "TCanvas.h"
32#include "RooNLLVar.h"
33#include "RooCmdArg.h"
34#include "RooRealVar.h"
35
36using namespace std;
37
39
40
41using namespace RooStats ;
42
43////////////////////////////////////////////////////////////////////////////////
44
46 RooAbsMCStudyModule(Form("UpperLimitMCSModule_%s",poi->first()->GetName()),Form("UpperLimitMCSModule_%s",poi->first()->GetName())),
47 _parName(poi->first()->GetName()),
48 _plc(0),_ul(0),_poi(0), _data(0),_cl(CL), _model(0)
49{
50 std::cout<<"RooUpperLimitConstructor ParName:"<<_parName<<std::endl;
51 std::cout<<"RooUpperLimitConstructor CL:"<<_cl<<std::endl;
52 // Constructor of module with parameter to be interpreted as nSignal and the value of the
53 // null hypothesis for nSignal (usually zero)
54}
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Copy constructor
60
63 _parName(other._poi->first()->GetName()),
64 _plc(0),_ul(0),_poi(other._poi), _data(0), _cl(other._cl), _model(other._model)
65{
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Destructor
70
72{
73
74 if (_plc) {
75 delete _plc ;
76 }
77 if (_data) {
78 delete _data ;
79 }
80 if(_ul){
81 delete _ul;
82 }
83 if(_poi){
84 delete _poi;
85 }
86 if (_model){
87 delete _model;
88 }
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Initialize module after attachment to RooMCStudy object
93
95{
96 // Check that parameter is also present in fit parameter list of RooMCStudy object
97 if (!fitParams()->find(_parName.c_str())) {
98 coutE(InputArguments) << "UpperLimitMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << endl ;
99 return kFALSE ;
100 }
101
102 //Construct the ProfileLikelihoodCalculator
103 _poi=new RooArgSet(*(fitParams()->find(_parName.c_str())));
104 std::cout<<"RooUpperLimit Initialize Instance: POI Set:"<<std::endl;
105 _poi->Print("v");
106 std::cout<<"RooUpperLimit Initialize Instance: End:"<<std::endl;
107
108
109
110 TString ulName = Form("ul_%s",_parName.c_str()) ;
111 TString ulTitle = Form("UL for parameter %s",_parName.c_str()) ;
112 _ul = new RooRealVar(ulName.Data(),ulTitle.Data(),0) ;
113
114
115 // Create new dataset to be merged with RooMCStudy::fitParDataSet
116 _data = new RooDataSet("ULSigData","Additional data for UL study",RooArgSet(*_ul)) ;
117
118 return kTRUE ;
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Initialize module at beginning of RooCMStudy run
123
125{
126 _data->reset() ;
127 return kTRUE ;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Return auxiliary dataset with results of delta(-log(L))
132/// calculations of this module so that it is merged with
133/// RooMCStudy::fitParDataSet() by RooMCStudy
134
136{
137 return _data ;
138}
139
140////////////////////////////////////////////////////////////////////////////////
141
142// Bool_t UpperLimitMCSModule::processAfterFit(Int_t /*sampleNum*/)
143// {
144// // Save likelihood from nominal fit, fix chosen parameter to its
145// // null hypothesis value and rerun fit Save difference in likelihood
146// // and associated Gaussian significance in auxiliary dataset
147
148// RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
149// par->setVal(_nullValue) ;
150// par->setConstant(kTRUE) ;
151// RooFitResult* frnull = refit() ;
152// par->setConstant(kFALSE) ;
153
154// _nll0h->setVal(frnull->minNll()) ;
155
156// Double_t deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
157// Double_t signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
158// _sig0h->setVal(signif) ;
159// _dll0h->setVal(deltaLL) ;
160
161
162// _data->add(RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
163
164// delete frnull ;
165// return kTRUE ;
166
167// }
168
169////////////////////////////////////////////////////////////////////////////////
170
172 std::cout<<"after generation Test"<<std::endl;
173
174 if (!fitInitParams() || !genSample() || !fitParams() || !fitModel() ) return kFALSE;
175
176 static_cast<RooRealVar*>(_poi->first())->setVal(static_cast<RooRealVar*>(fitInitParams()->find(_parName.c_str()))->getVal());
177
178 //_poi->first()->Print();
179 static_cast<RooRealVar*>(_poi->first())->setBins(1000);
180 //fitModel()->Print("v");
181
182 std::cout<<"generated Entries:"<<genSample()->numEntries()<<std::endl;
183
185
186 //PLC calculates intervals. for one sided ul multiply testsize by two
187 plc.SetTestSize(2*(1-_cl));
189
190 if (!pllint) return kFALSE;
191
192 std::cout<<"poi value: "<<((RooRealVar*)( _poi->first()))->getVal()<<std::endl;
193 std::cout<<(static_cast<RooRealVar*>((fitParams()->find(_parName.c_str()))))->getVal()<<std::endl;
194 std::cout<<((RooStats::LikelihoodInterval*)pllint)->UpperLimit((RooRealVar&)*(_poi->first()))<<std::endl;
195
196
197 //Go to the fit Value for zour POI to make sure upper limit works correct.
198 //fitModel()->fitTo(*genSample());
199
200
201
202 _ul->setVal(((RooStats::LikelihoodInterval*)pllint)->UpperLimit(static_cast<RooRealVar&>(*(fitParams()->find(_parName.c_str())))));
203
205 std::cout<<"UL:"<<_ul->getVal()<<std::endl;
206// if (_ul->getVal()<1){
207
208// RooStats::LikelihoodIntervalPlot plotpll((RooStats::LikelihoodInterval*) pllint);
209// TCanvas c1;
210// plotpll.Draw();
211// c1.Print("test.ps");
212// std::cout<<" UL<1 whats going on here?"<<std::endl;
213// abort();
214// }
215
216 delete pllint;
217
218
219 return kTRUE;
220}
#define coutE(a)
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
char * Form(const char *fmt,...)
RooAbsArg * first() const
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
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.
RooAbsMCStudyModule is a base class for add-on modules to RooMCStudy that can perform additional calc...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:94
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:36
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.
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
virtual void setVal(Double_t value)
Set value of variable to 'value'.
virtual void SetTestSize(Double_t size)
set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
ConfInterval is an interface class for a generic interval in the RooStats framework.
LikelihoodInterval is a concrete implementation of the RooStats::ConfInterval interface.
Double_t UpperLimit(const RooRealVar &param)
return the upper bound of the interval on a given parameter
The ProfileLikelihoodCalculator is a concrete implementation of CombinedCalculator (the interface cla...
virtual LikelihoodInterval * GetInterval() const
Return a likelihood interval.
This class allow to compute in the ToyMcStudy framework the ProfileLikelihood upper limit for each to...
Bool_t initializeRun(Int_t)
Initialize module at beginning of RooCMStudy run.
Bool_t initializeInstance()
Initialize module after attachment to RooMCStudy object.
UpperLimitMCSModule(const RooArgSet *poi, Double_t CL=0.95)
virtual ~UpperLimitMCSModule()
Destructor.
RooStats::ProfileLikelihoodCalculator * _plc
RooDataSet * finalizeRun()
Return auxiliary dataset with results of delta(-log(L)) calculations of this module so that it is mer...
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
Namespace for the RooStats classes.
Definition Asimov.h:19
Definition first.py:1