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
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 = (RooArgSet*) set->snapshot() ;
118 setCopy->setName(set->GetName()) ;
119 _configSets.Add(setCopy);
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 ;
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)) {
149 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
150 setCopy->setName(set->GetName()) ;
151 _configSets.Add(setCopy);
152 }
153
154 return *this ;
155}
156
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Add a configuration section for a particular integrator. Integrator name and capabilities are
161/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
162/// as the default configuration for the integrator.
163
165{
166 std::string name = proto->ClassName() ;
167
168 // Register integrator for appropriate dimensionalities
169 if (proto->canIntegrate1D()) {
171 if (proto->canIntegrateOpenEnded()) {
173 }
174 }
175
176 if (proto->canIntegrate2D()) {
178 if (proto->canIntegrateOpenEnded()) {
180 }
181 }
182
183 if (proto->canIntegrateND()) {
185 if (proto->canIntegrateOpenEnded()) {
187 }
188 }
189
190 // Store default configuration parameters
191 RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
192 config->setName(name.c_str());
193 _configSets.Add(config) ;
194
195 return false ;
196}
197
198
199
200////////////////////////////////////////////////////////////////////////////////
201/// Return section with configuration parameters for integrator with given (class) name
202
204{
205 return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
206}
207
208
209////////////////////////////////////////////////////////////////////////////////
210/// Retrieve configuration information specific to integrator with given name
211
213{
214 static RooArgSet dummy ;
216 if (!config) {
217 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::getConfigSection: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
218 return dummy ;
219 }
220 return *config ;
221}
222
223
224
225////////////////////////////////////////////////////////////////////////////////
226/// Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
227
228void RooNumIntConfig::setEpsAbs(double newEpsAbs)
229{
230 if (newEpsAbs<0) {
231 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater or equal than zero" << endl ;
232 return ;
233 }
234 _epsAbs = newEpsAbs ;
235}
236
237
239{
240 if (!opt) {
241 return kStandard ;
242 }
243
244 TString o(opt) ;
245 o.ToLower() ;
246
247 if (o.Contains("v")) {
248 return kVerbose ;
249 }
250 return kStandard ;
251}
252
253
254
255////////////////////////////////////////////////////////////////////////////////
256/// Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
257
258void RooNumIntConfig::setEpsRel(double newEpsRel)
259{
260 if (newEpsRel<0) {
261 oocoutE(nullptr,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater or equal than zero" << endl ;
262 return ;
263 }
264 _epsRel = newEpsRel ;
265}
266
267
268
269////////////////////////////////////////////////////////////////////////////////
270/// Detailed printing interface
271
272void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, bool verbose, TString indent) const
273{
274 os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << endl << endl ;
275 if (_printEvalCounter) {
276 os << indent << "Printing of function evaluation counter for each integration enabled" << endl << endl ;
277 }
278
279 os << indent << "1-D integration method: " << _method1D.getCurrentLabel() ;
281 os << " (" << _method1DOpen.getCurrentLabel() << " if open-ended)" << endl ;
282 } else {
283 os << endl ;
284 }
285 os << indent << "2-D integration method: " << _method2D.getCurrentLabel() ;
287 os << " (" << _method2DOpen.getCurrentLabel() << " if open-ended)" << endl ;
288 } else {
289 os << endl ;
290 }
291 os << indent << "N-D integration method: " << _methodND.getCurrentLabel() ;
293 os << " (" << _methodNDOpen.getCurrentLabel() << " if open-ended)" << endl ;
294 } else {
295 os << endl ;
296 }
297
298 if (verbose) {
299
300 os << endl << "Available integration methods:" << endl << endl ;
301 for(auto * configSet : static_range_cast<RooArgSet*>(_configSets)) {
302
303 os << indent << "*** " << configSet->GetName() << " ***" << endl ;
304 os << indent << "Capabilities: " ;
306 if (proto->canIntegrate1D()) os << "[1-D] " ;
307 if (proto->canIntegrate2D()) os << "[2-D] " ;
308 if (proto->canIntegrateND()) os << "[N-D] " ;
309 if (proto->canIntegrateOpenEnded()) os << "[OpenEnded] " ;
310 os << endl ;
311
312 os << "Configuration: " << endl ;
313 configSet->printMultiline(os,kName|kValue) ;
314 //configSet->writeToStream(os,false) ;
315
316 const char* depName = RooNumIntFactory::instance().getDepIntegratorName(configSet->GetName()) ;
317 if (strlen(depName)>0) {
318 os << indent << "(Depends on '" << depName << "')" << endl ;
319 }
320 os << endl ;
321
322 }
323 }
324}
#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:17502
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:56
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:179
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)
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:41
Basic string class.
Definition: TString.h:136
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1159
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
@ InputArguments
Definition: RooGlobalFunc.h:62