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
22Holds 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 "Riostream.h"
28
29#include "RooNumIntConfig.h"
30#include "RooArgSet.h"
31#include "RooAbsIntegrator.h"
32#include "RooNumIntFactory.h"
33#include "RooMsgService.h"
34
35
36using std::endl, std::ostream;
37
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// Return reference to instance of default numeric integrator configuration object
42
44{
46 static bool initStarted = false;
47
48 if (!initStarted) {
49 // This is needed to break a deadlock. We need the RooNumIntFactory constructor
50 // to initialise us, but this constructor will call back to us again.
51 // Here, we ensure that we can return the instance to the factory constructor by
52 // flipping the bool, but we only return to the outside world when the factory
53 // is done constructing (i.e. we leave this block).
54 initStarted = true;
56 }
57
58 return theConfig;
59}
60
61
62
63////////////////////////////////////////////////////////////////////////////////
64/// Constructor
65
67 _epsAbs(1e-7),
68 _epsRel(1e-7),
69 _printEvalCounter(false),
70 _method1D("method1D","1D integration method"),
71 _method2D("method2D","2D integration method"),
72 _methodND("methodND","ND integration method"),
73 _method1DOpen("method1DOpen","1D integration method in open domain"),
74 _method2DOpen("method2DOpen","2D integration method in open domain"),
75 _methodNDOpen("methodNDOpen","ND integration method in open domain")
76{
77 // Set all methods to undefined
78 // Defined methods will be registered by static initialization routines
79 // of the various numeric integrator engines
80 _method1D.defineType("N/A",0) ;
81 _method2D.defineType("N/A",0) ;
82 _methodND.defineType("N/A",0) ;
83 _method1DOpen.defineType("N/A",0) ;
84 _method2DOpen.defineType("N/A",0) ;
85 _methodNDOpen.defineType("N/A",0) ;
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Destructor
91
93{
94 // Delete all configuration data
96}
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// Copy constructor
101
104 _epsAbs(other._epsAbs),
105 _epsRel(other._epsRel),
106 _printEvalCounter(other._printEvalCounter),
107 _method1D(other._method1D),
108 _method2D(other._method2D),
109 _methodND(other._methodND),
110 _method1DOpen(other._method1DOpen),
111 _method2DOpen(other._method2DOpen),
112 _methodNDOpen(other._methodNDOpen)
113{
114 // Clone all configuration dat
115 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
117 set->snapshot(*setCopy);
118 setCopy->setName(set->GetName()) ;
120 }
121}
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Assignment operator from other RooNumIntConfig
126
128{
129 // Prevent self-assignment
130 if (&other==this) {
131 return *this ;
132 }
133
134 // Copy common properties
135 _epsAbs = other._epsAbs ;
136 _epsRel = other._epsRel ;
137 _method1D.setIndex(other._method1D.getCurrentIndex()) ;
138 _method2D.setIndex(other._method2D.getCurrentIndex()) ;
139 _methodND.setIndex(other._methodND.getCurrentIndex()) ;
140 _method1DOpen.setIndex(other._method1DOpen.getCurrentIndex()) ;
141 _method2DOpen.setIndex(other._method2DOpen.getCurrentIndex()) ;
142 _methodNDOpen.setIndex(other._methodNDOpen.getCurrentIndex()) ;
143
144 // Delete old integrator-specific configuration data
146
147 // Copy new integrator-specific data
148 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
150 set->snapshot(*setCopy);
151 setCopy->setName(set->GetName()) ;
153 }
154
155 return *this ;
156}
157
158
159
160////////////////////////////////////////////////////////////////////////////////
161/// Add a configuration section for a particular integrator. Integrator name and capabilities are
162/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
163/// as the default configuration for the integrator.
164
165bool RooNumIntConfig::addConfigSection(std::string const &name, const RooArgSet &inDefaultConfig, bool canIntegrate1D,
166 bool canIntegrate2D, bool canIntegrateND, bool canIntegrateOpenEnded)
167{
168 // Register integrator for appropriate dimensionalities
169 if (canIntegrate1D) {
171 if (canIntegrateOpenEnded) {
173 }
174 }
175
176 if (canIntegrate2D) {
178 if (canIntegrateOpenEnded) {
180 }
181 }
182
183 if (canIntegrateND) {
185 if (canIntegrateOpenEnded) {
187 }
188 }
189
190 // Store default configuration parameters
191 RooArgSet* config = new RooArgSet;
192 inDefaultConfig.snapshot(*config);
193 config->setName(name.c_str());
194 _configSets.Add(config) ;
195
196 return false ;
197}
198
199
200
201////////////////////////////////////////////////////////////////////////////////
202/// Return section with configuration parameters for integrator with given (class) name
203
205{
206 return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
207}
208
209
210////////////////////////////////////////////////////////////////////////////////
211/// Retrieve configuration information specific to integrator with given name
212
214{
215 static RooArgSet dummy ;
216 RooArgSet* config = static_cast<RooArgSet*>(_configSets.FindObject(name)) ;
217 if (!config) {
218 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::getConfigSection: ERROR: no configuration stored for integrator '" << name << "'" << std::endl ;
219 return dummy ;
220 }
221 return *config ;
222}
223
224
225
226////////////////////////////////////////////////////////////////////////////////
227/// Set absolute convergence criteria (convergence if std::abs(Err)<newEpsAbs)
228
230{
231 if (newEpsAbs<0) {
232 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater or equal than zero" << std::endl ;
233 return ;
234 }
236}
237
238
240{
241 if (!opt) {
242 return kStandard ;
243 }
244
245 TString o(opt) ;
246 o.ToLower() ;
247
248 if (o.Contains("v")) {
249 return kVerbose ;
250 }
251 return kStandard ;
252}
253
254
255
256////////////////////////////////////////////////////////////////////////////////
257/// Set relative convergence criteria (convergence if std::abs(Err)/abs(Int)<newEpsRel)
258
260{
261 if (newEpsRel<0) {
262 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater or equal than zero" << std::endl ;
263 return ;
264 }
266}
267
268
269
270////////////////////////////////////////////////////////////////////////////////
271/// Detailed printing interface
272
273void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, bool verbose, TString indent) const
274{
275 os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << std::endl << std::endl ;
276 if (_printEvalCounter) {
277 os << indent << "Printing of function evaluation counter for each integration enabled" << std::endl << std::endl ;
278 }
279
280 os << indent << "1-D integration method: " << _method1D.getCurrentLabel() ;
282 os << " (" << _method1DOpen.getCurrentLabel() << " if open-ended)" << std::endl ;
283 } else {
284 os << std::endl ;
285 }
286 os << indent << "2-D integration method: " << _method2D.getCurrentLabel() ;
288 os << " (" << _method2DOpen.getCurrentLabel() << " if open-ended)" << std::endl ;
289 } else {
290 os << std::endl ;
291 }
292 os << indent << "N-D integration method: " << _methodND.getCurrentLabel() ;
294 os << " (" << _methodNDOpen.getCurrentLabel() << " if open-ended)" << std::endl ;
295 } else {
296 os << std::endl ;
297 }
298
299 if (verbose) {
300
301 os << std::endl << "Available integration methods:" << std::endl << std::endl ;
303
304 auto const& info = *RooNumIntFactory::instance().getPluginInfo(configSet->GetName());
305
306 os << indent << "*** " << configSet->GetName() << " ***" << std::endl ;
307 os << indent << "Capabilities: " ;
308 if (info.canIntegrate1D) os << "[1-D] " ;
309 if (info.canIntegrate2D) os << "[2-D] " ;
310 if (info.canIntegrateND) os << "[N-D] " ;
311 if (info.canIntegrateOpenEnded) os << "[OpenEnded] " ;
312 os << std::endl ;
313
314 os << "Configuration: " << std::endl ;
315 configSet->printMultiline(os,kName|kValue) ;
316 //configSet->writeToStream(os,false) ;
317
318 if (!info.depName.empty()) {
319 os << indent << "(Depends on '" << info.depName << "')" << std::endl ;
320 }
321 os << std::endl ;
322
323 }
324 }
325}
#define e(i)
Definition RSha256.hxx:103
#define oocoutE(o, a)
const char Option_t
Definition RtypesCore.h:66
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
virtual const char * getCurrentLabel() const
Return label string of current state.
void setName(const char *name)
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:159
bool setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
bool defineType(const std::string &label)
Define a state with given name.
value_type getCurrentIndex() const final
Return current index.
Definition RooCategory.h:40
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
TObject * FindObject(const char *name) const override
Return pointer to object with given name.
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
RooCategory _method1D
Selects integration method for 1D integrals.
RooCategory _method1DOpen
Selects integration method for open ended 1D integrals.
void printMultiline(std::ostream &os, Int_t content, bool verbose, TString indent="") const override
Detailed printing interface.
RooNumIntConfig()
Constructor.
RooLinkedList _configSets
List of configuration sets for individual integration methods.
void setEpsRel(double newEpsRel)
Set relative convergence criteria (convergence if std::abs(Err)/abs(Int)<newEpsRel)
RooCategory _methodND
Selects integration method for ND integrals.
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
double _epsAbs
Absolute precision.
RooCategory _methodNDOpen
Selects integration method for open ended ND integrals.
bool _printEvalCounter
Flag to control printing of function evaluation counter.
double _epsRel
Relative precision.
~RooNumIntConfig() override
Destructor.
StyleOption defaultPrintStyle(Option_t *opt) const override
bool addConfigSection(std::string const &name, const RooArgSet &inDefaultConfig, bool canIntegrate1D, bool canIntegrate2D, bool canIntegrateND, bool canIntegrateOpenEnded)
Add a configuration section for a particular integrator.
RooCategory _method2D
Selects integration method for 2D integrals.
RooCategory _method2DOpen
Selects integration method for open ended 2D integrals.
RooNumIntConfig & operator=(const RooNumIntConfig &other)
Assignment operator from other RooNumIntConfig.
static RooNumIntConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
void setEpsAbs(double newEpsAbs)
Set absolute convergence criteria (convergence if std::abs(Err)<newEpsAbs)
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
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:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632