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 
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 ;
201  RooDataSet* data = _genPdf->generate(*_genSpec) ;
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 
RooGenFitStudy::setGenConfig
void setGenConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
Definition: RooGenFitStudy.cxx:149
RooLinkedList::MakeIterator
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
Definition: RooLinkedList.cxx:747
RooWorkspace.h
RooCmdArg
Definition: RooCmdArg.h:27
RooGenFitStudy::_genObsName
std::string _genObsName
Definition: RooGenFitStudy.h:57
RooRealVar::setVal
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:226
RooGenFitStudy::_genObs
RooArgSet _genObs
Definition: RooGenFitStudy.h:64
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooMsgService.h
RooGenFitStudy::_initParams
RooArgSet * _initParams
Definition: RooGenFitStudy.h:72
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
RooGenFitStudy::_fitObs
RooArgSet _fitObs
Definition: RooGenFitStudy.h:66
RooGenFitStudy::execute
virtual Bool_t execute()
Execute one study iteration.
Definition: RooGenFitStudy.cxx:198
RooGenFitStudy::_ngenVar
RooRealVar * _ngenVar
Definition: RooGenFitStudy.h:70
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooAbsStudy::storeSummaryOutput
void storeSummaryOutput(const RooArgSet &vars)
Definition: RooAbsStudy.cxx:94
RooGenFitStudy::_genPdfName
std::string _genPdfName
Definition: RooGenFitStudy.h:56
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooLinkedList::At
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
Definition: RooLinkedList.cxx:496
RooGenFitStudy::RooGenFitStudy
RooGenFitStudy(const char *name=0, const char *title=0)
Constructor.
Definition: RooGenFitStudy.cxx:50
RooGenFitStudy::_nllVar
RooRealVar * _nllVar
Definition: RooGenFitStudy.h:69
RooArgSet::add
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
RooGenFitStudy::initialize
virtual Bool_t initialize()
One-time initialization of study.
Definition: RooGenFitStudy.cxx:176
RooDataSet.h
bool
TIterator
Definition: TIterator.h:30
RooFitResult
Definition: RooFitResult.h:40
RooGenFitStudy::attach
virtual Bool_t attach(RooWorkspace &w)
Function called after insertion into workspace.
Definition: RooGenFitStudy.cxx:110
RooAbsArg::getParameters
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:546
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:134
RooGenFitStudy.h
RooGenFitStudy::setFitConfig
void setFitConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg())
Definition: RooGenFitStudy.cxx:162
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
RooAbsPdf.h
RooGenFitStudy::_params
RooArgSet * _params
Definition: RooGenFitStudy.h:71
RooGenFitStudy::~RooGenFitStudy
virtual ~RooGenFitStudy()
Definition: RooGenFitStudy.cxx:100
RooFitResult::status
Int_t status() const
Definition: RooFitResult.h:77
RooAbsPdf::prepareMultiGen
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:2177
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooAbsStudy::registerSummaryOutput
void registerSummaryOutput(const RooArgSet &allVars, const RooArgSet &varsWithError=RooArgSet(), const RooArgSet &varsWithAsymError=RooArgSet())
Definition: RooAbsStudy.cxx:79
RooGenFitStudy::finalize
virtual Bool_t finalize()
Finalization of study.
Definition: RooGenFitStudy.cxx:220
TObject::Clone
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:146
RooGenFitStudy::_genPdf
RooAbsPdf * _genPdf
Definition: RooGenFitStudy.h:63
RooWorkspace::pdf
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1277
RooLinkedList::Add
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
RooGenFitStudy::_genOpts
RooLinkedList _genOpts
Definition: RooGenFitStudy.h:60
RooRealVar.h
RooDataSet::sumEntries
virtual Double_t sumEntries() const override
Definition: RooDataSet.cxx:1047
RooFitResult.h
TIterator::Next
virtual TObject * Next()=0
RooCmdArg::Clone
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:51
RooGlobalFunc.h
RooWorkspace
Definition: RooWorkspace.h:43
RooGenFitStudy
Definition: RooGenFitStudy.h:35
RooWorkspace::argSet
RooArgSet argSet(const char *nameList) const
Return set of RooAbsArgs matching to given list of names.
Definition: RooWorkspace.cxx:1333
RooAbsPdf::generate
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
RooGenFitStudy::_fitOpts
RooLinkedList _fitOpts
Definition: RooGenFitStudy.h:61
TObject
Definition: TObject.h:37
RooAbsStudy::storeDetailedOutput
void storeDetailedOutput(Bool_t flag)
Definition: RooAbsStudy.h:47
name
char name[80]
Definition: TGX11.cxx:110
RooGenFitStudy::_genSpec
RooAbsPdf::GenSpec * _genSpec
Definition: RooGenFitStudy.h:68
RooGenFitStudy::_fitPdfName
std::string _fitPdfName
Definition: RooGenFitStudy.h:58
RooDataSet
Definition: RooDataSet.h:33
RooAbsPdf
Definition: RooAbsPdf.h:40
RooGenFitStudy::_fitPdf
RooAbsPdf * _fitPdf
Definition: RooGenFitStudy.h:65
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooRealVar
Definition: RooRealVar.h:35
RooFit::Save
RooCmdArg Save(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:187
Riostream.h
RooGenFitStudy::_fitObsName
std::string _fitObsName
Definition: RooGenFitStudy.h:59
RooGenFitStudy::Print
void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooGenFitStudy.cxx:240
RooFitResult::minNll
Double_t minNll() const
Definition: RooFitResult.h:98
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooAbsStudy
Definition: RooAbsStudy.h:33
RooArgSet
Definition: RooArgSet.h:28
RooAbsPdf::fitTo
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:1261