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#include "Riostream.h"
27
28#include "RooGenFitStudy.h"
29#include "RooWorkspace.h"
30#include "RooMsgService.h"
31#include "RooDataSet.h"
32#include "RooAbsPdf.h"
33#include "RooRealVar.h"
34#include "RooGlobalFunc.h"
35#include "RooFitResult.h"
36
37
38using namespace std ;
39
41 ;
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Constructor
46
47RooGenFitStudy::RooGenFitStudy(const char* name, const char* title) :
48 RooAbsStudy(name?name:"RooGenFitStudy",title?title:"RooGenFitStudy"),
49 _genPdf(0),
50 _fitPdf(0),
51 _genSpec(0),
52 _nllVar(0),
53 _ngenVar(0),
54 _params(0),
55 _initParams(0)
56{
57}
58
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// Copy constructor
63
65 RooAbsStudy(other),
66 _genPdfName(other._genPdfName),
67 _genObsName(other._genObsName),
68 _fitPdfName(other._fitPdfName),
69 _fitObsName(other._fitObsName),
70 _genPdf(0),
71 _fitPdf(0),
72 _genSpec(0),
73 _nllVar(0),
74 _ngenVar(0),
75 _params(0),
76 _initParams(0)
77{
78 for(TObject * o : other._genOpts) _genOpts.Add(o->Clone());
79 for(TObject * o : other._fitOpts) _fitOpts.Add(o->Clone());
80}
81
82
83
84////////////////////////////////////////////////////////////////////////////////
85
87{
88 if (_params) delete _params ;
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Function called after insertion into workspace
95
97{
98 Bool_t ret = kFALSE ;
99
100 RooAbsPdf* pdf = w.pdf(_genPdfName.c_str()) ;
101 if (pdf) {
102 _genPdf = pdf ;
103 } else {
104 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: generator p.d.f named " << _genPdfName << " not found in workspace " << w.GetName() << endl ;
105 ret = kTRUE ;
106 }
107
108 _genObs.add(w.argSet(_genObsName)) ;
109 if (_genObs.getSize()==0) {
110 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no generator observables defined" << endl ;
111 ret = kTRUE ;
112 }
113
114 pdf = w.pdf(_fitPdfName.c_str()) ;
115 if (pdf) {
116 _fitPdf = pdf ;
117 } else {
118 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: fitting p.d.f named " << _fitPdfName << " not found in workspace " << w.GetName() << endl ;
119 ret = kTRUE ;
120 }
121
122 _fitObs.add(w.argSet(_fitObsName)) ;
123 if (_fitObs.getSize()==0) {
124 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no fitting observables defined" << endl ;
125 ret = kTRUE ;
126 }
127
128 return ret ;
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134
135void RooGenFitStudy::setGenConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
136{
137 _genPdfName = pdfName ;
138 _genObsName = obsName ;
139 _genOpts.Add(arg1.Clone()) ;
140 _genOpts.Add(arg2.Clone()) ;
141 _genOpts.Add(arg3.Clone()) ;
142}
143
144
145
146////////////////////////////////////////////////////////////////////////////////
147
148void RooGenFitStudy::setFitConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
149{
150 _fitPdfName = pdfName ;
151 _fitObsName = obsName ;
152 _fitOpts.Add(arg1.Clone()) ;
153 _fitOpts.Add(arg2.Clone()) ;
154 _fitOpts.Add(arg3.Clone()) ;
155}
156
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// One-time initialization of study
161
163{
164 _nllVar = new RooRealVar("NLL","-log(Likelihood)",0) ;
165 _ngenVar = new RooRealVar("ngen","number of generated events",0) ;
166
168 RooArgSet modelParams(*_params) ;
170 _params->add(*_nllVar) ;
171 _params->add(*_ngenVar) ;
172
174
175 registerSummaryOutput(*_params,modelParams) ;
176 return kFALSE ;
177}
178
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Execute one study iteration
183
185{
189
190 if (fr->status()==0) {
191 _ngenVar->setVal(data->sumEntries()) ;
192 _nllVar->setVal(fr->minNll()) ;
195 }
196
197 delete data ;
198 return kFALSE ;
199}
200
201
202
203////////////////////////////////////////////////////////////////////////////////
204/// Finalization of study
205
207{
208 delete _params ;
209 delete _nllVar ;
210 delete _ngenVar ;
211 delete _initParams ;
212 delete _genSpec ;
213 _params = 0 ;
214 _nllVar = 0 ;
215 _ngenVar = 0 ;
216 _initParams = 0 ;
217 _genSpec = 0 ;
218
219
220 return kFALSE ;
221}
222
223
224////////////////////////////////////////////////////////////////////////////////
225
226void RooGenFitStudy::Print(Option_t* /*options*/) const
227{
228}
229
230
#define coutE(a)
Definition: RooMsgService.h:33
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:375
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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...
Definition: RooAbsArg.cxx:569
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Int_t getSize() const
Return the number of elements in the collection.
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...
Definition: RooAbsPdf.cxx:2075
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:1474
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:60
RooAbsStudy is an abstract base class for RooStudyManager modules.
Definition: RooAbsStudy.h:33
void storeSummaryOutput(const RooArgSet &vars)
Definition: RooAbsStudy.cxx:91
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:76
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:180
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
TObject * Clone(const char *newName=0) const override
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:57
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
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
Return minimized -log(L) value.
Definition: RooFitResult.h:99
Int_t status() const
Return MINUIT status code.
Definition: RooFitResult.h:78
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())
RooArgSet * _initParams
!
RooAbsPdf * _fitPdf
!
RooArgSet _fitObs
!
std::string _fitPdfName
std::string _genPdfName
Bool_t attach(RooWorkspace &w) override
Function called after insertion into workspace.
RooArgSet * _params
!
std::string _fitObsName
~RooGenFitStudy() override
RooLinkedList _genOpts
RooAbsPdf::GenSpec * _genSpec
!
RooRealVar * _nllVar
!
RooGenFitStudy(const char *name=0, const char *title=0)
Constructor.
Bool_t finalize() override
Finalization of study.
Bool_t initialize() override
One-time initialization of study.
void Print(Option_t *options=0) const override
Print TNamed name and title.
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
!
Bool_t execute() override
Execute one study iteration.
RooAbsPdf * _genPdf
!
std::string _genObsName
TObject * At(int index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:67
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
void setVal(Double_t value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:281
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
const char * GetName() const override
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:146
RooCmdArg Save(Bool_t flag=kTRUE)
@ InputArguments
Definition: RooGlobalFunc.h:64