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