Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22Abstract base class for RooStudyManager modules
23**/
24
25#include "Riostream.h"
26
27#include "RooGenFitStudy.h"
28#include "RooWorkspace.h"
29#include "RooMsgService.h"
30#include "RooDataSet.h"
31#include "RooAbsPdf.h"
32#include "RooRealVar.h"
33#include "RooGlobalFunc.h"
34#include "RooFitResult.h"
35
36
38
39////////////////////////////////////////////////////////////////////////////////
40/// Constructor
41
42RooGenFitStudy::RooGenFitStudy(const char* name, const char* title) :
43 RooAbsStudy(name?name:"RooGenFitStudy",title?title:"RooGenFitStudy")
44{
45}
46
47
48
49////////////////////////////////////////////////////////////////////////////////
50/// Copy constructor
51
53 RooAbsStudy(other),
54 _genPdfName(other._genPdfName),
55 _genObsName(other._genObsName),
56 _fitPdfName(other._fitPdfName),
57 _fitObsName(other._fitObsName)
58{
59 for(TObject * o : other._genOpts) _genOpts.Add(o->Clone());
60 for(TObject * o : other._fitOpts) _fitOpts.Add(o->Clone());
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Function called after insertion into workspace
65
67{
68 bool ret = false ;
69
70 RooAbsPdf* pdf = w.pdf(_genPdfName) ;
71 if (pdf) {
72 _genPdf = pdf ;
73 } else {
74 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: generator p.d.f named " << _genPdfName << " not found in workspace " << w.GetName() << std::endl ;
75 ret = true ;
76 }
77
78 _genObs.add(w.argSet(_genObsName)) ;
79 if (_genObs.empty()) {
80 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no generator observables defined" << std::endl ;
81 ret = true ;
82 }
83
84 pdf = w.pdf(_fitPdfName) ;
85 if (pdf) {
86 _fitPdf = pdf ;
87 } else {
88 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: fitting p.d.f named " << _fitPdfName << " not found in workspace " << w.GetName() << std::endl ;
89 ret = true ;
90 }
91
92 _fitObs.add(w.argSet(_fitObsName)) ;
93 if (_fitObs.empty()) {
94 coutE(InputArguments) << "RooGenFitStudy(" << GetName() << ") ERROR: no fitting observables defined" << std::endl ;
95 ret = true ;
96 }
97
98 return ret ;
99}
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104
105void RooGenFitStudy::setGenConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
106{
107 _genPdfName = pdfName ;
108 _genObsName = obsName ;
109 _genOpts.Add(arg1.Clone()) ;
110 _genOpts.Add(arg2.Clone()) ;
111 _genOpts.Add(arg3.Clone()) ;
112}
113
114
115
116////////////////////////////////////////////////////////////////////////////////
117
118void RooGenFitStudy::setFitConfig(const char* pdfName, const char* obsName, const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3)
119{
120 _fitPdfName = pdfName ;
121 _fitObsName = obsName ;
122 _fitOpts.Add(arg1.Clone()) ;
123 _fitOpts.Add(arg2.Clone()) ;
124 _fitOpts.Add(arg3.Clone()) ;
125}
126
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// One-time initialization of study
131
133{
134 _nllVar = new RooRealVar("NLL","-log(Likelihood)",0) ;
135 _ngenVar = new RooRealVar("ngen","number of generated events",0) ;
136
137 _params = std::unique_ptr<RooArgSet>{_fitPdf->getParameters(_genObs)};
138 RooArgSet modelParams(*_params) ;
141 _params->add(*_nllVar) ;
142 _params->add(*_ngenVar) ;
143
144 _genSpec = _genPdf->prepareMultiGen(_genObs,static_cast<RooCmdArg&>(*_genOpts.At(0)),static_cast<RooCmdArg&>(*_genOpts.At(1)),static_cast<RooCmdArg&>(*_genOpts.At(2))) ;
145
146 registerSummaryOutput(*_params,modelParams) ;
147 return false ;
148}
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Execute one study iteration
154
156{
157 _params->assign(*_initParams) ;
158 std::unique_ptr<RooDataSet> data{_genPdf->generate(*_genSpec)};
159 std::unique_ptr<RooFitResult> fr{_fitPdf->fitTo(*data,RooFit::Save(true),static_cast<RooCmdArg&>(*_fitOpts.At(0)),static_cast<RooCmdArg&>(*_fitOpts.At(1)),static_cast<RooCmdArg&>(*_fitOpts.At(2)))};
160
161 if (fr->status()==0) {
162 _ngenVar->setVal(data->sumEntries()) ;
163 _nllVar->setVal(fr->minNll()) ;
165 storeDetailedOutput(std::move(fr)) ;
166 }
167
168 return false ;
169}
170
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Finalization of study
175
177{
178 delete _nllVar ;
179 delete _ngenVar ;
180 delete _initParams ;
181 delete _genSpec ;
182 _params.reset();
183 _nllVar = nullptr ;
184 _ngenVar = nullptr ;
185 _initParams = nullptr ;
186 _genSpec = nullptr ;
187
188
189 return false ;
190}
191
192
193////////////////////////////////////////////////////////////////////////////////
194
195void RooGenFitStudy::Print(Option_t* /*options*/) const
196{
197}
198
199
#define coutE(a)
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
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
RooFit::OwningPtr< 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...
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
GenSpec * prepareMultiGen(const RooArgSet &whatVars, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={})
Prepare GenSpec configuration object for efficient generation of multiple datasets from identical spe...
RooFit::OwningPtr< RooFitResult > fitTo(RooAbsData &data, CmdArgs_t const &... cmdArgs)
Fit PDF to given dataset.
Definition RooAbsPdf.h:157
RooFit::OwningPtr< RooDataSet > generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={})
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition RooAbsPdf.h:57
Abstract base class for RooStudyManager modules.
Definition RooAbsStudy.h:33
void storeDetailedOutput(bool flag)
Definition RooAbsStudy.h:47
void storeSummaryOutput(const RooArgSet &vars)
void registerSummaryOutput(const RooArgSet &allVars, const RooArgSet &varsWithError=RooArgSet(), const RooArgSet &varsWithAsymError=RooArgSet())
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:191
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
TObject * Clone(const char *newName=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooCmdArg.h:57
Abstract base class for RooStudyManager modules.
bool initialize() override
One-time initialization of study.
RooArgSet * _initParams
!
RooAbsPdf * _fitPdf
!
RooArgSet _fitObs
!
std::string _fitPdfName
void setFitConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={})
std::string _genPdfName
std::string _fitObsName
RooLinkedList _genOpts
RooGenFitStudy(const char *name=nullptr, const char *title=nullptr)
Constructor.
RooAbsPdf::GenSpec * _genSpec
!
RooRealVar * _nllVar
!
std::unique_ptr< RooArgSet > _params
!
bool execute() override
Execute one study iteration.
RooLinkedList _fitOpts
RooRealVar * _ngenVar
!
RooArgSet _genObs
!
void setGenConfig(const char *pdfName, const char *obsName, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={})
bool finalize() override
Finalization of study.
RooAbsPdf * _genPdf
!
std::string _genObsName
bool attach(RooWorkspace &w) override
Function called after insertion into workspace.
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
TObject * At(int index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
Variable that can be changed from the outside.
Definition RooRealVar.h:37
void setVal(double value) override
Set value of variable to 'value'.
Persistable container for RooFit projects.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
RooCmdArg Save(bool flag=true)