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