Logo ROOT   6.14/05
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 
22 RooGenFitStudy 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 
41 using namespace std ;
42 
44  ;
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Constructor
49 
50 RooGenFitStudy::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 
149 void 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 
162 void 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()) ;
208  storeDetailedOutput(*fr) ;
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 
240 void RooGenFitStudy::Print(Option_t* /*options*/) const
241 {
242 }
243 
244 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
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:34
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:86
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:94
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:51
RooAbsPdf * _fitPdf
RooRealVar * _nllVar
bool Bool_t
Definition: RtypesCore.h:59
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:1878
STL namespace.
RooArgSet argSet(const char *nameList) const
Return set of RooAbsArgs matching to given list of names.
Iterator abstract base class.
Definition: TIterator.h:30
RooGenFitStudy is an abstract base class for RooStudyManager modules.
RooLinkedList _genOpts
RooLinkedList _fitOpts
virtual Bool_t execute()
Execute one study iteration.
RooAbsPdf * _genPdf
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
std::string _fitObsName
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooAbsStudy is an abstract base class for RooStudyManager modules.
Definition: RooAbsStudy.h:33
virtual void setVal(Double_t value)
Set value of variable to &#39;value&#39;.
Definition: RooRealVar.cxx:204
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
Int_t getSize() const
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
Double_t minNll() const
Definition: RooFitResult.h:98
RooArgSet _fitObs
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
std::string _genObsName
const Bool_t kFALSE
Definition: RtypesCore.h:88
RooRealVar * _ngenVar
virtual Double_t sumEntries() const
#define ClassImp(name)
Definition: Rtypes.h:359
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
void registerSummaryOutput(const RooArgSet &allVars, const RooArgSet &varsWithError=RooArgSet(), const RooArgSet &varsWithAsymError=RooArgSet())
Definition: RooAbsStudy.cxx:79
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&#39;t match any of...
Definition: RooAbsArg.cxx:532
RooGenFitStudy(const char *name=0, const char *title=0)
Constructor.
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
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
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
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:1725
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:1079
void Print(Option_t *options=0) const
Print TNamed name and title.
RooAbsPdf::GenSpec * _genSpec
RooArgSet * _params
RooArgSet * _initParams
const Bool_t kTRUE
Definition: RtypesCore.h:87
void storeDetailedOutput(Bool_t flag)
Definition: RooAbsStudy.h:47
char name[80]
Definition: TGX11.cxx:109
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
Int_t status() const
Definition: RooFitResult.h:77