Logo ROOT  
Reference Guide
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 TIterator* giter = other._genOpts.MakeIterator() ;
82 TObject* o ;
83 while((o=giter->Next())) {
84 _genOpts.Add(o->Clone()) ;
85 }
86 delete giter ;
87
88 TIterator* fiter = other._fitOpts.MakeIterator() ;
89 while((o=fiter->Next())) {
90 _fitOpts.Add(o->Clone()) ;
91 }
92 delete fiter ;
93
94}
95
96
97
98////////////////////////////////////////////////////////////////////////////////
99
101{
102 if (_params) delete _params ;
103}
104
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Function called after insertion into workspace
109
111{
112 Bool_t ret = kFALSE ;
113
114 RooAbsPdf* pdf = w.pdf(_genPdfName.c_str()) ;
115 if (pdf) {
116 _genPdf = pdf ;
117 } else {
118 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: generator p.d.f named " << _genPdfName << " not found in workspace " << w.GetName() << endl ;
119 ret = kTRUE ;
120 }
121
122 _genObs.add(w.argSet(_genObsName.c_str())) ;
123 if (_genObs.getSize()==0) {
124 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no generator observables defined" << endl ;
125 ret = kTRUE ;
126 }
127
128 pdf = w.pdf(_fitPdfName.c_str()) ;
129 if (pdf) {
130 _fitPdf = pdf ;
131 } else {
132 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: fitting p.d.f named " << _fitPdfName << " not found in workspace " << w.GetName() << endl ;
133 ret = kTRUE ;
134 }
135
136 _fitObs.add(w.argSet(_fitObsName.c_str())) ;
137 if (_fitObs.getSize()==0) {
138 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no fitting observables defined" << endl ;
139 ret = kTRUE ;
140 }
141
142 return ret ;
143}
144
145
146
147////////////////////////////////////////////////////////////////////////////////
148
149void RooGenFitStudy::setGenConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
150{
151 _genPdfName = pdfName ;
152 _genObsName = obsName ;
153 _genOpts.Add(arg1.Clone()) ;
154 _genOpts.Add(arg2.Clone()) ;
155 _genOpts.Add(arg3.Clone()) ;
156}
157
158
159
160////////////////////////////////////////////////////////////////////////////////
161
162void RooGenFitStudy::setFitConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
163{
164 _fitPdfName = pdfName ;
165 _fitObsName = obsName ;
166 _fitOpts.Add(arg1.Clone()) ;
167 _fitOpts.Add(arg2.Clone()) ;
168 _fitOpts.Add(arg3.Clone()) ;
169}
170
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// One-time initialization of study
175
177{
178 _nllVar = new RooRealVar("NLL","-log(Likelihood)",0) ;
179 _ngenVar = new RooRealVar("ngen","number of generated events",0) ;
180
182 RooArgSet modelParams(*_params) ;
184 _params->add(*_nllVar) ;
185 _params->add(*_ngenVar) ;
186
188
189 registerSummaryOutput(*_params,modelParams) ;
190 return kFALSE ;
191}
192
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Execute one study iteration
197
199{
200 *_params = *_initParams ;
203
204 if (fr->status()==0) {
205 _ngenVar->setVal(data->sumEntries()) ;
206 _nllVar->setVal(fr->minNll()) ;
209 }
210
211 delete data ;
212 return kFALSE ;
213}
214
215
216
217////////////////////////////////////////////////////////////////////////////////
218/// Finalization of study
219
221{
222 delete _params ;
223 delete _nllVar ;
224 delete _ngenVar ;
225 delete _initParams ;
226 delete _genSpec ;
227 _params = 0 ;
228 _nllVar = 0 ;
229 _ngenVar = 0 ;
230 _initParams = 0 ;
231 _genSpec = 0 ;
232
233
234 return kFALSE ;
235}
236
237
238////////////////////////////////////////////////////////////////////////////////
239
240void RooGenFitStudy::Print(Option_t* /*options*/) const
241{
242}
243
244
#define coutE(a)
Definition: RooMsgService.h:34
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:548
Int_t getSize() const
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...
Definition: RooAbsPdf.cxx:2195
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:55
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.
Definition: RooAbsPdf.cxx:1286
RooAbsStudy is an abstract base class for RooStudyManager modules.
Definition: RooAbsStudy.h:33
void storeSummaryOutput(const RooArgSet &vars)
Definition: RooAbsStudy.cxx:94
void storeDetailedOutput(Bool_t flag)
Definition: RooAbsStudy.h:47
void registerSummaryOutput(const RooArgSet &allVars, const RooArgSet &varsWithError=RooArgSet(), const RooArgSet &varsWithAsymError=RooArgSet())
Definition: RooAbsStudy.cxx:79
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:134
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:28
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:52
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
virtual Double_t sumEntries() const override
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
Double_t minNll() const
Definition: RooFitResult.h:98
Int_t status() const
Definition: RooFitResult.h:77
RooGenFitStudy is an abstract base class for RooStudyManager modules.
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
RooArgSet _genObs
virtual Bool_t execute()
Execute one study iteration.
void setFitConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
RooAbsPdf * _genPdf
std::string _genObsName
void setGenConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
void Print(Option_t *options=0) const
Print TNamed name and title.
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:63
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:278
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
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.
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * Next()=0
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
@ InputArguments
Definition: RooGlobalFunc.h:68
RooCmdArg Save(Bool_t flag=kTRUE)