Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooGenFitStudy.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 RooGenFitStudy.cxx
19\class RooGenFitStudy
20\ingroup Roofitcore
21
22RooGenFitStudy is an abstract base class for RooStudyManager modules
23
24**/
25
26
27
28#include "RooFit.h"
29#include "Riostream.h"
30
31#include "RooGenFitStudy.h"
32#include "RooWorkspace.h"
33#include "RooMsgService.h"
34#include "RooDataSet.h"
35#include "RooAbsPdf.h"
36#include "RooRealVar.h"
37#include "RooGlobalFunc.h"
38#include "RooFitResult.h"
39
40
41using namespace std ;
42
44 ;
45
46
47////////////////////////////////////////////////////////////////////////////////
48/// Constructor
49
50RooGenFitStudy::RooGenFitStudy(const char* name, const char* title) :
51 RooAbsStudy(name?name:"RooGenFitStudy",title?title:"RooGenFitStudy"),
52 _genPdf(0),
53 _fitPdf(0),
54 _genSpec(0),
55 _nllVar(0),
56 _ngenVar(0),
57 _params(0),
58 _initParams(0)
59{
60}
61
62
63
64////////////////////////////////////////////////////////////////////////////////
65/// Copy constructor
66
68 RooAbsStudy(other),
69 _genPdfName(other._genPdfName),
70 _genObsName(other._genObsName),
71 _fitPdfName(other._fitPdfName),
72 _fitObsName(other._fitObsName),
73 _genPdf(0),
74 _fitPdf(0),
75 _genSpec(0),
76 _nllVar(0),
77 _ngenVar(0),
78 _params(0),
79 _initParams(0)
80{
81 for(TObject * o : other._genOpts) _genOpts.Add(o->Clone());
82 for(TObject * o : other._fitOpts) _fitOpts.Add(o->Clone());
83}
84
85
86
87////////////////////////////////////////////////////////////////////////////////
88
90{
91 if (_params) delete _params ;
92}
93
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Function called after insertion into workspace
98
100{
101 Bool_t ret = kFALSE ;
102
103 RooAbsPdf* pdf = w.pdf(_genPdfName.c_str()) ;
104 if (pdf) {
105 _genPdf = pdf ;
106 } else {
107 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: generator p.d.f named " << _genPdfName << " not found in workspace " << w.GetName() << endl ;
108 ret = kTRUE ;
109 }
110
111 _genObs.add(w.argSet(_genObsName.c_str())) ;
112 if (_genObs.getSize()==0) {
113 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no generator observables defined" << endl ;
114 ret = kTRUE ;
115 }
116
117 pdf = w.pdf(_fitPdfName.c_str()) ;
118 if (pdf) {
119 _fitPdf = pdf ;
120 } else {
121 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: fitting p.d.f named " << _fitPdfName << " not found in workspace " << w.GetName() << endl ;
122 ret = kTRUE ;
123 }
124
125 _fitObs.add(w.argSet(_fitObsName.c_str())) ;
126 if (_fitObs.getSize()==0) {
127 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no fitting observables defined" << endl ;
128 ret = kTRUE ;
129 }
130
131 return ret ;
132}
133
134
135
136////////////////////////////////////////////////////////////////////////////////
137
138void RooGenFitStudy::setGenConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
139{
140 _genPdfName = pdfName ;
141 _genObsName = obsName ;
142 _genOpts.Add(arg1.Clone()) ;
143 _genOpts.Add(arg2.Clone()) ;
144 _genOpts.Add(arg3.Clone()) ;
145}
146
147
148
149////////////////////////////////////////////////////////////////////////////////
150
151void RooGenFitStudy::setFitConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
152{
153 _fitPdfName = pdfName ;
154 _fitObsName = obsName ;
155 _fitOpts.Add(arg1.Clone()) ;
156 _fitOpts.Add(arg2.Clone()) ;
157 _fitOpts.Add(arg3.Clone()) ;
158}
159
160
161
162////////////////////////////////////////////////////////////////////////////////
163/// One-time initialization of study
164
166{
167 _nllVar = new RooRealVar("NLL","-log(Likelihood)",0) ;
168 _ngenVar = new RooRealVar("ngen","number of generated events",0) ;
169
171 RooArgSet modelParams(*_params) ;
173 _params->add(*_nllVar) ;
174 _params->add(*_ngenVar) ;
175
177
178 registerSummaryOutput(*_params,modelParams) ;
179 return kFALSE ;
180}
181
182
183
184////////////////////////////////////////////////////////////////////////////////
185/// Execute one study iteration
186
188{
192
193 if (fr->status()==0) {
194 _ngenVar->setVal(data->sumEntries()) ;
195 _nllVar->setVal(fr->minNll()) ;
198 }
199
200 delete data ;
201 return kFALSE ;
202}
203
204
205
206////////////////////////////////////////////////////////////////////////////////
207/// Finalization of study
208
210{
211 delete _params ;
212 delete _nllVar ;
213 delete _ngenVar ;
214 delete _initParams ;
215 delete _genSpec ;
216 _params = 0 ;
217 _nllVar = 0 ;
218 _ngenVar = 0 ;
219 _initParams = 0 ;
220 _genSpec = 0 ;
221
222
223 return kFALSE ;
224}
225
226
227////////////////////////////////////////////////////////////////////////////////
228
229void RooGenFitStudy::Print(Option_t* /*options*/) const
230{
231}
232
233
#define coutE(a)
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
GenSpec * prepareMultiGen(const RooArgSet &whatVars, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none())
Prepare GenSpec configuration object for efficient generation of multiple datasets from identical spe...
virtual RooFitResult * fitTo(RooAbsData &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
RooDataSet * generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition RooAbsPdf.h:58
RooAbsStudy is an abstract base class for RooStudyManager modules.
Definition RooAbsStudy.h:33
void storeSummaryOutput(const RooArgSet &vars)
void storeDetailedOutput(Bool_t flag)
Definition RooAbsStudy.h:47
void registerSummaryOutput(const RooArgSet &allVars, const RooArgSet &varsWithError=RooArgSet(), const RooArgSet &varsWithAsymError=RooArgSet())
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:158
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:27
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
Definition RooCmdArg.h:51
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:36
virtual Double_t sumEntries() const override
Return effective number of entries in dataset, i.e., sum all weights.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Double_t minNll() const
Return minimized -log(L) value.
Int_t status() const
Return MINUIT status code.
RooGenFitStudy is an abstract base class for RooStudyManager modules.
void setGenConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
virtual Bool_t initialize()
One-time initialization of study.
RooArgSet * _initParams
RooAbsPdf * _fitPdf
virtual Bool_t attach(RooWorkspace &w)
Function called after insertion into workspace.
RooArgSet _fitObs
std::string _fitPdfName
virtual Bool_t finalize()
Finalization of study.
std::string _genPdfName
RooArgSet * _params
std::string _fitObsName
RooLinkedList _genOpts
virtual ~RooGenFitStudy()
RooAbsPdf::GenSpec * _genSpec
RooRealVar * _nllVar
RooGenFitStudy(const char *name=0, const char *title=0)
Constructor.
RooLinkedList _fitOpts
RooRealVar * _ngenVar
void setFitConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
RooArgSet _genObs
virtual Bool_t execute()
Execute one study iteration.
RooAbsPdf * _genPdf
std::string _genObsName
void Print(Option_t *options=0) const
Print TNamed name and title.
TObject * At(int index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
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'.
The RooWorkspace is a persistable container for RooFit projects.
RooArgSet argSet(const char *nameList) const
Return set of RooAbsArgs matching to given list of names.
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
RooCmdArg Save(Bool_t flag=kTRUE)