Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooNumIntConfig.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 RooNumIntConfig.cxx
19\class RooNumIntConfig
20\ingroup Roofitcore
21
22RooNumIntConfig holds the configuration parameters of the various
23numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
24use this class in the (normalization) integral configuration interface
25**/
26
27#include "RooFit.h"
28#include "Riostream.h"
29
30#include "RooNumIntConfig.h"
31#include "RooArgSet.h"
32#include "RooAbsIntegrator.h"
33#include "RooNumIntFactory.h"
34#include "RooMsgService.h"
35
36#include "TClass.h"
37
38
39
40using namespace std;
41
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Return reference to instance of default numeric integrator configuration object
47
49{
50 static RooNumIntConfig theConfig;
51 static bool initStarted = false;
52
53 if (!initStarted) {
54 // This is needed to break a deadlock. We need the RooNumIntFactory constructor
55 // to initialise us, but this constructor will call back to us again.
56 // Here, we ensure that we can return the instance to the factory constructor by
57 // flipping the bool, but we only return to the outside world when the factory
58 // is done constructing (i.e. we leave this block).
59 initStarted = true;
61 }
62
63 return theConfig;
64}
65
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Constructor
70
72 _epsAbs(1e-7),
73 _epsRel(1e-7),
74 _printEvalCounter(kFALSE),
75 _method1D("method1D","1D integration method"),
76 _method2D("method2D","2D integration method"),
77 _methodND("methodND","ND integration method"),
78 _method1DOpen("method1DOpen","1D integration method in open domain"),
79 _method2DOpen("method2DOpen","2D integration method in open domain"),
80 _methodNDOpen("methodNDOpen","ND integration method in open domain")
81{
82 // Set all methods to undefined
83 // Defined methods will be registered by static initialization routines
84 // of the various numeric integrator engines
85 _method1D.defineType("N/A",0) ;
86 _method2D.defineType("N/A",0) ;
87 _methodND.defineType("N/A",0) ;
88 _method1DOpen.defineType("N/A",0) ;
89 _method2DOpen.defineType("N/A",0) ;
90 _methodNDOpen.defineType("N/A",0) ;
91}
92
93
94////////////////////////////////////////////////////////////////////////////////
95/// Destructor
96
98{
99 // Delete all configuration data
101}
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// Copy constructor
106
108 TObject(other), RooPrintable(other),
109 _epsAbs(other._epsAbs),
110 _epsRel(other._epsRel),
111 _printEvalCounter(other._printEvalCounter),
112 _method1D(other._method1D),
113 _method2D(other._method2D),
114 _methodND(other._methodND),
115 _method1DOpen(other._method1DOpen),
116 _method2DOpen(other._method2DOpen),
117 _methodNDOpen(other._methodNDOpen)
118{
119 // Clone all configuration dat
120 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
121 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
122 setCopy->setName(set->GetName()) ;
123 _configSets.Add(setCopy);
124 }
125}
126
127
128////////////////////////////////////////////////////////////////////////////////
129/// Assignment operator from other RooNumIntConfig
130
132{
133 // Prevent self-assignment
134 if (&other==this) {
135 return *this ;
136 }
137
138 // Copy common properties
139 _epsAbs = other._epsAbs ;
140 _epsRel = other._epsRel ;
147
148 // Delete old integrator-specific configuration data
150
151 // Copy new integrator-specific data
152 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
153 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
154 setCopy->setName(set->GetName()) ;
155 _configSets.Add(setCopy);
156 }
157
158 return *this ;
159}
160
161
162
163////////////////////////////////////////////////////////////////////////////////
164/// Add a configuration section for a particular integrator. Integrator name and capabilities are
165/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
166/// as the default configuration for the integrator.
167
169{
170 std::string name = proto->IsA()->GetName() ;
171
172 // Register integrator for appropriate dimensionalities
173 if (proto->canIntegrate1D()) {
175 if (proto->canIntegrateOpenEnded()) {
177 }
178 }
179
180 if (proto->canIntegrate2D()) {
182 if (proto->canIntegrateOpenEnded()) {
184 }
185 }
186
187 if (proto->canIntegrateND()) {
189 if (proto->canIntegrateOpenEnded()) {
191 }
192 }
193
194 // Store default configuration parameters
195 RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
196 config->setName(name.c_str());
197 _configSets.Add(config) ;
198
199 return kFALSE ;
200}
201
202
203
204////////////////////////////////////////////////////////////////////////////////
205/// Return section with configuration parameters for integrator with given (class) name
206
208{
209 return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
210}
211
212
213////////////////////////////////////////////////////////////////////////////////
214/// Retrieve configuration information specific to integrator with given name
215
217{
218 static RooArgSet dummy ;
220 if (!config) {
221 oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::getConfigSection: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
222 return dummy ;
223 }
224 return *config ;
225}
226
227
228
229////////////////////////////////////////////////////////////////////////////////
230/// Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
231
233{
234 if (newEpsAbs<0) {
235 oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater or equal than zero" << endl ;
236 return ;
237 }
238 _epsAbs = newEpsAbs ;
239}
240
241
243{
244 if (!opt) {
245 return kStandard ;
246 }
247
248 TString o(opt) ;
249 o.ToLower() ;
250
251 if (o.Contains("v")) {
252 return kVerbose ;
253 }
254 return kStandard ;
255}
256
257
258
259////////////////////////////////////////////////////////////////////////////////
260/// Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
261
263{
264 if (newEpsRel<0) {
265 oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater or equal than zero" << endl ;
266 return ;
267 }
268 _epsRel = newEpsRel ;
269}
270
271
272
273////////////////////////////////////////////////////////////////////////////////
274/// Detailed printing interface
275
276void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
277{
278 os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << endl << endl ;
279 if (_printEvalCounter) {
280 os << indent << "Printing of function evaluation counter for each integration enabled" << endl << endl ;
281 }
282
283 os << indent << "1-D integration method: " << _method1D.getCurrentLabel() ;
285 os << " (" << _method1DOpen.getCurrentLabel() << " if open-ended)" << endl ;
286 } else {
287 os << endl ;
288 }
289 os << indent << "2-D integration method: " << _method2D.getCurrentLabel() ;
291 os << " (" << _method2DOpen.getCurrentLabel() << " if open-ended)" << endl ;
292 } else {
293 os << endl ;
294 }
295 os << indent << "N-D integration method: " << _methodND.getCurrentLabel() ;
297 os << " (" << _methodNDOpen.getCurrentLabel() << " if open-ended)" << endl ;
298 } else {
299 os << endl ;
300 }
301
302 if (verbose) {
303
304 os << endl << "Available integration methods:" << endl << endl ;
305 for(auto * configSet : static_range_cast<RooArgSet*>(_configSets)) {
306
307 os << indent << "*** " << configSet->GetName() << " ***" << endl ;
308 os << indent << "Capabilities: " ;
310 if (proto->canIntegrate1D()) os << "[1-D] " ;
311 if (proto->canIntegrate2D()) os << "[2-D] " ;
312 if (proto->canIntegrateND()) os << "[N-D] " ;
313 if (proto->canIntegrateOpenEnded()) os << "[OpenEnded] " ;
314 os << endl ;
315
316 os << "Configuration: " << endl ;
317 configSet->printMultiline(os,kName|kValue) ;
318 //configSet->writeToStream(os,kFALSE) ;
319
320 const char* depName = RooNumIntFactory::instance().getDepIntegratorName(configSet->GetName()) ;
321 if (strlen(depName)>0) {
322 os << indent << "(Depends on '" << depName << "')" << endl ;
323 }
324 os << endl ;
325
326 }
327 }
328}
#define e(i)
Definition RSha256.hxx:103
#define oocoutE(o, a)
const Bool_t kFALSE
Definition RtypesCore.h:101
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:16613
virtual const char * getCurrentLabel() const
Return label string of current state.
void setName(const char *name)
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:158
bool defineType(const std::string &label)
Define a state with given name.
virtual value_type getCurrentIndex() const override final
Return current index.
Definition RooCategory.h:39
virtual Bool_t setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
RooCategory _method1D
RooCategory _method1DOpen
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose, TString indent="") const
Detailed printing interface.
RooNumIntConfig()
Constructor.
RooLinkedList _configSets
virtual StyleOption defaultPrintStyle(Option_t *opt) const
RooCategory _methodND
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
RooCategory _methodNDOpen
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
RooCategory _method2D
Bool_t addConfigSection(const RooAbsIntegrator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
RooCategory _method2DOpen
RooNumIntConfig & operator=(const RooNumIntConfig &other)
Assignment operator from other RooNumIntConfig.
virtual ~RooNumIntConfig()
Destructor.
const RooAbsIntegrator * getProtoIntegrator(const char *name) const
Return prototype integrator with given (class) name.
const char * getDepIntegratorName(const char *name) const
Get list of class names of integrators needed by integrator named 'name'.
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:136
void ToLower()
Change string to lower-case.
Definition TString.cxx:1150
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624