ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // RooGenFitStudy is an abstract base class for RooStudyManager modules
21 //
22 // END_HTML
23 //
24 
25 
26 
27 #include "RooFit.h"
28 #include "Riostream.h"
29 
30 #include "RooGenFitStudy.h"
31 #include "RooWorkspace.h"
32 #include "RooMsgService.h"
33 #include "RooDataSet.h"
34 #include "RooAbsPdf.h"
35 #include "RooRealVar.h"
36 #include "RooGlobalFunc.h"
37 #include "RooFitResult.h"
38 
39 
40 using namespace std ;
41 
43  ;
44 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Constructor
48 
49 RooGenFitStudy::RooGenFitStudy(const char* name, const char* title) :
50  RooAbsStudy(name?name:"RooGenFitStudy",title?title:"RooGenFitStudy"),
51  _genPdf(0),
52  _fitPdf(0),
53  _genSpec(0),
54  _nllVar(0),
55  _ngenVar(0),
56  _params(0),
57  _initParams(0)
58 {
59 }
60 
61 
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Copy constructor
65 
67  RooAbsStudy(other),
68  _genPdfName(other._genPdfName),
69  _genObsName(other._genObsName),
70  _fitPdfName(other._fitPdfName),
71  _fitObsName(other._fitObsName),
72  _genPdf(0),
73  _fitPdf(0),
74  _genSpec(0),
75  _nllVar(0),
76  _ngenVar(0),
77  _params(0),
78  _initParams(0)
79 {
80  TIterator* giter = other._genOpts.MakeIterator() ;
81  TObject* o ;
82  while((o=giter->Next())) {
83  _genOpts.Add(o->Clone()) ;
84  }
85  delete giter ;
86 
87  TIterator* fiter = other._fitOpts.MakeIterator() ;
88  while((o=fiter->Next())) {
89  _fitOpts.Add(o->Clone()) ;
90  }
91  delete fiter ;
92 
93 }
94 
95 
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 
100 {
101  if (_params) delete _params ;
102 }
103 
104 
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Function called after insertion into workspace
108 
110 {
111  Bool_t ret = kFALSE ;
112 
113  RooAbsPdf* pdf = w.pdf(_genPdfName.c_str()) ;
114  if (pdf) {
115  _genPdf = pdf ;
116  } else {
117  coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: generator p.d.f named " << _genPdfName << " not found in workspace " << w.GetName() << endl ;
118  ret = kTRUE ;
119  }
120 
121  _genObs.add(w.argSet(_genObsName.c_str())) ;
122  if (_genObs.getSize()==0) {
123  coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no generator observables defined" << endl ;
124  ret = kTRUE ;
125  }
126 
127  pdf = w.pdf(_fitPdfName.c_str()) ;
128  if (pdf) {
129  _fitPdf = pdf ;
130  } else {
131  coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: fitting p.d.f named " << _fitPdfName << " not found in workspace " << w.GetName() << endl ;
132  ret = kTRUE ;
133  }
134 
135  _fitObs.add(w.argSet(_fitObsName.c_str())) ;
136  if (_fitObs.getSize()==0) {
137  coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no fitting observables defined" << endl ;
138  ret = kTRUE ;
139  }
140 
141  return ret ;
142 }
143 
144 
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 
148 void RooGenFitStudy::setGenConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
149 {
150  _genPdfName = pdfName ;
151  _genObsName = obsName ;
152  _genOpts.Add(arg1.Clone()) ;
153  _genOpts.Add(arg2.Clone()) ;
154  _genOpts.Add(arg3.Clone()) ;
155 }
156 
157 
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 
161 void RooGenFitStudy::setFitConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
162 {
163  _fitPdfName = pdfName ;
164  _fitObsName = obsName ;
165  _fitOpts.Add(arg1.Clone()) ;
166  _fitOpts.Add(arg2.Clone()) ;
167  _fitOpts.Add(arg3.Clone()) ;
168 }
169 
170 
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// One-time initialization of study
174 
176 {
177  _nllVar = new RooRealVar("NLL","-log(Likelihood)",0) ;
178  _ngenVar = new RooRealVar("ngen","number of generated events",0) ;
179 
181  RooArgSet modelParams(*_params) ;
183  _params->add(*_nllVar) ;
184  _params->add(*_ngenVar) ;
185 
187 
188  registerSummaryOutput(*_params,modelParams) ;
189  return kFALSE ;
190 }
191 
192 
193 
194 ////////////////////////////////////////////////////////////////////////////////
195 /// Execute one study iteration
196 
198 {
199  *_params = *_initParams ;
200  RooDataSet* data = _genPdf->generate(*_genSpec) ;
202 
203  if (fr->status()==0) {
204  _ngenVar->setVal(data->sumEntries()) ;
205  _nllVar->setVal(fr->minNll()) ;
207  storeDetailedOutput(*fr) ;
208  }
209 
210  delete data ;
211  return kFALSE ;
212 }
213 
214 
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Finalization of study
218 
220 {
221  delete _params ;
222  delete _nllVar ;
223  delete _ngenVar ;
224  delete _initParams ;
225  delete _genSpec ;
226  _params = 0 ;
227  _nllVar = 0 ;
228  _ngenVar = 0 ;
229  _initParams = 0 ;
230  _genSpec = 0 ;
231 
232 
233  return kFALSE ;
234 }
235 
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 
239 void RooGenFitStudy::Print(Option_t* /*options*/) const
240 {
241 }
242 
243 
void setFitConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
#define coutE(a)
Definition: RooMsgService.h:35
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
RooArgSet argSet(const char *nameList) const
Return set of RooAbsArgs matching to given list of names.
virtual Bool_t initialize()
One-time initialization of study.
virtual Bool_t finalize()
Finalization of study.
std::string _genPdfName
const char Option_t
Definition: RtypesCore.h:62
void storeSummaryOutput(const RooArgSet &vars)
Definition: RooAbsStudy.cxx:93
RooAbsPdf * _fitPdf
RooRealVar * _nllVar
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:51
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
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 idetical spec...
Definition: RooAbsPdf.cxx:1855
STL namespace.
Iterator abstract base class.
Definition: TIterator.h:32
RooLinkedList _genOpts
RooLinkedList _fitOpts
virtual Bool_t execute()
Execute one study iteration.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:203
RooAbsPdf * _genPdf
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
void setGenConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
std::string _fitPdfName
RooArgSet _genObs
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:559
std::string _fitObsName
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:202
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
void Print(Option_t *options=0) const
Print TNamed name and title.
RooArgSet _fitObs
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
ClassImp(RooGenFitStudy)
std::string _genObsName
virtual Double_t sumEntries() const
RooRealVar * _ngenVar
Int_t status() const
Definition: RooFitResult.h:76
Double_t minNll() const
Definition: RooFitResult.h:97
void registerSummaryOutput(const RooArgSet &allVars, const RooArgSet &varsWithError=RooArgSet(), const RooArgSet &varsWithAsymError=RooArgSet())
Definition: RooAbsStudy.cxx:78
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
RooGenFitStudy(const char *name=0, const char *title=0)
Constructor.
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
RooCmdArg Save(Bool_t flag=kTRUE)
virtual ~RooGenFitStudy()
virtual Bool_t attach(RooWorkspace &w)
Function called after insertion into workspace.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
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())
Generate a new dataset containing the specified variables with events sampled from our distribution...
Definition: RooAbsPdf.cxx:1702
virtual TObject * Next()=0
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:1056
RooAbsPdf::GenSpec * _genSpec
Int_t getSize() const
RooArgSet * _params
RooArgSet * _initParams
const Bool_t kTRUE
Definition: Rtypes.h:91
void storeDetailedOutput(Bool_t flag)
Definition: RooAbsStudy.h:47
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448