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 namespace std;
37
39
40
41////////////////////////////////////////////////////////////////////////////////
42/// Return reference to instance of default numeric integrator configuration object
43
45{
46 static RooNumIntConfig theConfig;
47 static bool initStarted = false;
48
49 if (!initStarted) {
50 // This is needed to break a deadlock. We need the RooNumIntFactory constructor
51 // to initialise us, but this constructor will call back to us again.
52 // Here, we ensure that we can return the instance to the factory constructor by
53 // flipping the bool, but we only return to the outside world when the factory
54 // is done constructing (i.e. we leave this block).
55 initStarted = true;
57 }
58
59 return theConfig;
60}
61
62
63
64////////////////////////////////////////////////////////////////////////////////
65/// Constructor
66
68 _epsAbs(1e-7),
69 _epsRel(1e-7),
70 _printEvalCounter(false),
71 _method1D("method1D","1D integration method"),
72 _method2D("method2D","2D integration method"),
73 _methodND("methodND","ND integration method"),
74 _method1DOpen("method1DOpen","1D integration method in open domain"),
75 _method2DOpen("method2DOpen","2D integration method in open domain"),
76 _methodNDOpen("methodNDOpen","ND integration method in open domain")
77{
78 // Set all methods to undefined
79 // Defined methods will be registered by static initialization routines
80 // of the various numeric integrator engines
81 _method1D.defineType("N/A",0) ;
82 _method2D.defineType("N/A",0) ;
83 _methodND.defineType("N/A",0) ;
84 _method1DOpen.defineType("N/A",0) ;
85 _method2DOpen.defineType("N/A",0) ;
86 _methodNDOpen.defineType("N/A",0) ;
87}
88
89
90////////////////////////////////////////////////////////////////////////////////
91/// Destructor
92
94{
95 // Delete all configuration data
97}
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Copy constructor
102
104 TObject(other), RooPrintable(other),
105 _epsAbs(other._epsAbs),
106 _epsRel(other._epsRel),
107 _printEvalCounter(other._printEvalCounter),
108 _method1D(other._method1D),
109 _method2D(other._method2D),
110 _methodND(other._methodND),
111 _method1DOpen(other._method1DOpen),
112 _method2DOpen(other._method2DOpen),
113 _methodNDOpen(other._methodNDOpen)
114{
115 // Clone all configuration dat
116 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
117 RooArgSet* setCopy = new RooArgSet;
118 set->snapshot(*setCopy);
119 setCopy->setName(set->GetName()) ;
120 _configSets.Add(setCopy);
121 }
122}
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// Assignment operator from other RooNumIntConfig
127
129{
130 // Prevent self-assignment
131 if (&other==this) {
132 return *this ;
133 }
134
135 // Copy common properties
136 _epsAbs = other._epsAbs ;
137 _epsRel = other._epsRel ;
144
145 // Delete old integrator-specific configuration data
147
148 // Copy new integrator-specific data
149 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
150 RooArgSet* setCopy = new RooArgSet;
151 set->snapshot(*setCopy);
152 setCopy->setName(set->GetName()) ;
153 _configSets.Add(setCopy);
154 }
155
156 return *this ;
157}
158
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Add a configuration section for a particular integrator. Integrator name and capabilities are
163/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
164/// as the default configuration for the integrator.
165
166bool RooNumIntConfig::addConfigSection(std::string const &name, const RooArgSet &inDefaultConfig, bool canIntegrate1D,
167 bool canIntegrate2D, bool canIntegrateND, bool canIntegrateOpenEnded)
168{
169 // Register integrator for appropriate dimensionalities
170 if (canIntegrate1D) {
172 if (canIntegrateOpenEnded) {
174 }
175 }
176
177 if (canIntegrate2D) {
179 if (canIntegrateOpenEnded) {
181 }
182 }
183
184 if (canIntegrateND) {
186 if (canIntegrateOpenEnded) {
188 }
189 }
190
191 // Store default configuration parameters
192 RooArgSet* config = new RooArgSet;
193 inDefaultConfig.snapshot(*config);
194 config->setName(name.c_str());
195 _configSets.Add(config) ;
196
197 return false ;
198}
199
200
201
202////////////////////////////////////////////////////////////////////////////////
203/// Return section with configuration parameters for integrator with given (class) name
204
206{
207 return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
208}
209
210
211////////////////////////////////////////////////////////////////////////////////
212/// Retrieve configuration information specific to integrator with given name
213
215{
216 static RooArgSet dummy ;
217 RooArgSet* config = static_cast<RooArgSet*>(_configSets.FindObject(name)) ;
218 if (!config) {
219 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::getConfigSection: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
220 return dummy ;
221 }
222 return *config ;
223}
224
225
226
227////////////////////////////////////////////////////////////////////////////////
228/// Set absolute convergence criteria (convergence if std::abs(Err)<newEpsAbs)
229
230void RooNumIntConfig::setEpsAbs(double newEpsAbs)
231{
232 if (newEpsAbs<0) {
233 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater or equal than zero" << endl ;
234 return ;
235 }
236 _epsAbs = newEpsAbs ;
237}
238
239
241{
242 if (!opt) {
243 return kStandard ;
244 }
245
246 TString o(opt) ;
247 o.ToLower() ;
248
249 if (o.Contains("v")) {
250 return kVerbose ;
251 }
252 return kStandard ;
253}
254
255
256
257////////////////////////////////////////////////////////////////////////////////
258/// Set relative convergence criteria (convergence if std::abs(Err)/abs(Int)<newEpsRel)
259
260void RooNumIntConfig::setEpsRel(double newEpsRel)
261{
262 if (newEpsRel<0) {
263 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater or equal than zero" << endl ;
264 return ;
265 }
266 _epsRel = newEpsRel ;
267}
268
269
270
271////////////////////////////////////////////////////////////////////////////////
272/// Detailed printing interface
273
274void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, bool verbose, TString indent) const
275{
276 os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << endl << endl ;
277 if (_printEvalCounter) {
278 os << indent << "Printing of function evaluation counter for each integration enabled" << endl << endl ;
279 }
280
281 os << indent << "1-D integration method: " << _method1D.getCurrentLabel() ;
283 os << " (" << _method1DOpen.getCurrentLabel() << " if open-ended)" << endl ;
284 } else {
285 os << endl ;
286 }
287 os << indent << "2-D integration method: " << _method2D.getCurrentLabel() ;
289 os << " (" << _method2DOpen.getCurrentLabel() << " if open-ended)" << endl ;
290 } else {
291 os << endl ;
292 }
293 os << indent << "N-D integration method: " << _methodND.getCurrentLabel() ;
295 os << " (" << _methodNDOpen.getCurrentLabel() << " if open-ended)" << endl ;
296 } else {
297 os << endl ;
298 }
299
300 if (verbose) {
301
302 os << endl << "Available integration methods:" << endl << endl ;
303 for(auto * configSet : static_range_cast<RooArgSet*>(_configSets)) {
304
305 auto const& info = *RooNumIntFactory::instance().getPluginInfo(configSet->GetName());
306
307 os << indent << "*** " << configSet->GetName() << " ***" << endl ;
308 os << indent << "Capabilities: " ;
309 if (info.canIntegrate1D) os << "[1-D] " ;
310 if (info.canIntegrate2D) os << "[2-D] " ;
311 if (info.canIntegrateND) os << "[N-D] " ;
312 if (info.canIntegrateOpenEnded) os << "[OpenEnded] " ;
313 os << endl ;
314
315 os << "Configuration: " << endl ;
316 configSet->printMultiline(os,kName|kValue) ;
317 //configSet->writeToStream(os,false) ;
318
319 if (!info.depName.empty()) {
320 os << indent << "(Depends on '" << info.depName << "')" << endl ;
321 }
322 os << endl ;
323
324 }
325 }
326}
#define e(i)
Definition RSha256.hxx:103
#define oocoutE(o, a)
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
static void indent(ostringstream &buf, int indent_level)
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:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
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.
void setEpsAbs(double newEpsAbs)
Set absolute convergence criteria (convergence if std::abs(Err)<newEpsAbs)
PluginInfo const * getPluginInfo(std::string const &name) const
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:1170
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:634