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 
22 RooNumIntConfig holds the configuration parameters of the various
23 numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
24 use this class in the (normalization) integral configuration interface
25 **/
26 
27 #include "RooFit.h"
28 #include "Riostream.h"
29 
30 #include "RooNumIntConfig.h"
31 #include "RooArgSet.h"
32 #include "RooAbsIntegrator.h"
33 #include "RooNumIntFactory.h"
34 #include "RooMsgService.h"
35 
36 #include "TClass.h"
37 
38 
39 
40 using namespace std;
41 
43 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Return reference to instance of default numeric integrator configuration object
47 
48 RooNumIntConfig& RooNumIntConfig::defaultConfig()
49 {
50  static RooNumIntConfig theConfig;
51  static bool initStarted = false;
52 
53  if (!initStarted) {
54  // This is needed to break a deadlock. We need the RooNumIntFactory constructor
55  // to initialise us, but this constructor will call back to us again.
56  // Here, we ensure that we can return the instance to the factory constructor by
57  // flipping the bool, but we only return to the outside world when the factory
58  // is done constructing (i.e. we leave this block).
59  initStarted = true;
61  }
62 
63  return theConfig;
64 }
65 
66 
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Constructor
70 
72  _epsAbs(1e-7),
73  _epsRel(1e-7),
74  _printEvalCounter(kFALSE),
75  _method1D("method1D","1D integration method"),
76  _method2D("method2D","2D integration method"),
77  _methodND("methodND","ND integration method"),
78  _method1DOpen("method1DOpen","1D integration method in open domain"),
79  _method2DOpen("method2DOpen","2D integration method in open domain"),
80  _methodNDOpen("methodNDOpen","ND integration method in open domain")
81 {
82  // Set all methods to undefined
83  // Defined methods will be registered by static initialization routines
84  // of the various numeric integrator engines
85  _method1D.defineType("N/A",0) ;
86  _method2D.defineType("N/A",0) ;
87  _methodND.defineType("N/A",0) ;
88  _method1DOpen.defineType("N/A",0) ;
89  _method2DOpen.defineType("N/A",0) ;
90  _methodNDOpen.defineType("N/A",0) ;
91 }
92 
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Destructor
96 
98 {
99  // Delete all configuration data
100  _configSets.Delete() ;
101 }
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Copy constructor
106 
108  TObject(other), RooPrintable(other),
109  _epsAbs(other._epsAbs),
110  _epsRel(other._epsRel),
111  _printEvalCounter(other._printEvalCounter),
112  _method1D(other._method1D),
113  _method2D(other._method2D),
114  _methodND(other._methodND),
115  _method1DOpen(other._method1DOpen),
116  _method2DOpen(other._method2DOpen),
117  _methodNDOpen(other._methodNDOpen)
118 {
119  // Clone all configuration dat
120  TIterator* iter = other._configSets.MakeIterator() ;
121  RooArgSet* set ;
122  while((set=(RooArgSet*)iter->Next())) {
123  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
124  setCopy->setName(set->GetName()) ;
125  _configSets.Add(setCopy);
126  }
127  delete iter ;
128 }
129 
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Assignment operator from other RooNumIntConfig
133 
135 {
136  // Prevent self-assignment
137  if (&other==this) {
138  return *this ;
139  }
140 
141  // Copy common properties
142  _epsAbs = other._epsAbs ;
143  _epsRel = other._epsRel ;
150 
151  // Delete old integrator-specific configuration data
152  _configSets.Delete() ;
153 
154  // Copy new integrator-specific data
155  TIterator* iter = other._configSets.MakeIterator() ;
156  RooArgSet* set ;
157  while((set=(RooArgSet*)iter->Next())) {
158  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
159  setCopy->setName(set->GetName()) ;
160  _configSets.Add(setCopy);
161  }
162  delete iter ;
163 
164  return *this ;
165 }
166 
167 
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// Add a configuration section for a particular integrator. Integrator name and capabilities are
171 /// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
172 /// as the default configuration for the integrator.
173 
175 {
176  std::string name = proto->IsA()->GetName() ;
177 
178  // Register integrator for appropriate dimensionalities
179  if (proto->canIntegrate1D()) {
181  if (proto->canIntegrateOpenEnded()) {
183  }
184  }
185 
186  if (proto->canIntegrate2D()) {
188  if (proto->canIntegrateOpenEnded()) {
190  }
191  }
192 
193  if (proto->canIntegrateND()) {
195  if (proto->canIntegrateOpenEnded()) {
197  }
198  }
199 
200  // Store default configuration parameters
201  RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
202  config->setName(name.c_str());
203  _configSets.Add(config) ;
204 
205  return kFALSE ;
206 }
207 
208 
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Return section with configuration parameters for integrator with given (class) name
212 
214 {
215  return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
216 }
217 
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Retrieve configuration information specific to integrator with given name
221 
223 {
224  static RooArgSet dummy ;
226  if (!config) {
227  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::getConfigSection: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
228  return dummy ;
229  }
230  return *config ;
231 }
232 
233 
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
237 
239 {
240  if (newEpsAbs<0) {
241  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater or equal than zero" << endl ;
242  return ;
243  }
244  _epsAbs = newEpsAbs ;
245 }
246 
247 
249 {
250  if (!opt) {
251  return kStandard ;
252  }
253 
254  TString o(opt) ;
255  o.ToLower() ;
256 
257  if (o.Contains("v")) {
258  return kVerbose ;
259  }
260  return kStandard ;
261 }
262 
263 
264 
265 ////////////////////////////////////////////////////////////////////////////////
266 /// Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
267 
269 {
270  if (newEpsRel<0) {
271  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater or equal than zero" << endl ;
272  return ;
273  }
274  _epsRel = newEpsRel ;
275 }
276 
277 
278 
279 ////////////////////////////////////////////////////////////////////////////////
280 /// Detailed printing interface
281 
282 void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
283 {
284  os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << endl << endl ;
285  if (_printEvalCounter) {
286  os << indent << "Printing of function evaluation counter for each integration enabled" << endl << endl ;
287  }
288 
289  os << indent << "1-D integration method: " << _method1D.getCurrentLabel() ;
291  os << " (" << _method1DOpen.getCurrentLabel() << " if open-ended)" << endl ;
292  } else {
293  os << endl ;
294  }
295  os << indent << "2-D integration method: " << _method2D.getCurrentLabel() ;
297  os << " (" << _method2DOpen.getCurrentLabel() << " if open-ended)" << endl ;
298  } else {
299  os << endl ;
300  }
301  os << indent << "N-D integration method: " << _methodND.getCurrentLabel() ;
303  os << " (" << _methodNDOpen.getCurrentLabel() << " if open-ended)" << endl ;
304  } else {
305  os << endl ;
306  }
307 
308  if (verbose) {
309 
310  os << endl << "Available integration methods:" << endl << endl ;
311  TIterator* cIter = _configSets.MakeIterator() ;
312  RooArgSet* configSet ;
313  while ((configSet=(RooArgSet*)cIter->Next())) {
314 
315  os << indent << "*** " << configSet->GetName() << " ***" << endl ;
316  os << indent << "Capabilities: " ;
318  if (proto->canIntegrate1D()) os << "[1-D] " ;
319  if (proto->canIntegrate2D()) os << "[2-D] " ;
320  if (proto->canIntegrateND()) os << "[N-D] " ;
321  if (proto->canIntegrateOpenEnded()) os << "[OpenEnded] " ;
322  os << endl ;
323 
324  os << "Configuration: " << endl ;
325  configSet->printMultiline(os,kName|kValue) ;
326  //configSet->writeToStream(os,kFALSE) ;
327 
328  const char* depName = RooNumIntFactory::instance().getDepIntegratorName(configSet->GetName()) ;
329  if (strlen(depName)>0) {
330  os << indent << "(Depends on '" << depName << "')" << endl ;
331  }
332  os << endl ;
333 
334  }
335 
336  delete cIter ;
337  }
338 }
RooLinkedList::MakeIterator
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
Definition: RooLinkedList.cxx:731
RooNumIntConfig::getConfigSection
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Definition: RooNumIntConfig.cxx:222
RooPrintable::kVerbose
@ kVerbose
Definition: RooPrintable.h:34
e
#define e(i)
Definition: RSha256.hxx:103
RooNumIntConfig::_method2D
RooCategory _method2D
Definition: RooNumIntConfig.h:79
RooMsgService.h
RooNumIntConfig::~RooNumIntConfig
virtual ~RooNumIntConfig()
Destructor.
Definition: RooNumIntConfig.cxx:97
RooNumIntConfig::operator=
RooNumIntConfig & operator=(const RooNumIntConfig &other)
Assignment operator from other RooNumIntConfig.
Definition: RooNumIntConfig.cxx:134
Option_t
const char Option_t
Definition: RtypesCore.h:66
RooNumIntConfig.h
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:61
RooArgSet.h
RooPrintable::kStandard
@ kStandard
Definition: RooPrintable.h:34
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooPrintable::StyleOption
StyleOption
Definition: RooPrintable.h:34
RooNumIntConfig::_methodND
RooCategory _methodND
Definition: RooNumIntConfig.h:80
RooNumIntConfig::_epsRel
Double_t _epsRel
Definition: RooNumIntConfig.h:75
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
RooCategory::setIndex
virtual Bool_t setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
Definition: RooCategory.cxx:163
TClass.h
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooAbsCollection::printMultiline
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Implement multiline printing of collection, one line for each contained object showing the requested ...
Definition: RooAbsCollection.cxx:1118
RooNumIntConfig::_configSets
RooLinkedList _configSets
Definition: RooNumIntConfig.h:84
RooNumIntFactory::getProtoIntegrator
const RooAbsIntegrator * getProtoIntegrator(const char *name) const
Return prototype integrator with given (class) name.
Definition: RooNumIntFactory.cxx:142
oocoutE
#define oocoutE(o, a)
Definition: RooMsgService.h:48
TString
Basic string class.
Definition: TString.h:136
RooLinkedList::FindObject
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
Definition: RooLinkedList.cxx:531
RooAbsCollection::GetName
const char * GetName() const
Returns name of object.
Definition: RooAbsCollection.h:286
RooPrintable
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
RooNumIntConfig::_method2DOpen
RooCategory _method2DOpen
Definition: RooNumIntConfig.h:82
RooAbsCategory::getCurrentLabel
virtual const char * getCurrentLabel() const
Return label string of current state.
Definition: RooAbsCategory.cxx:130
RooCategory::defineType
bool defineType(const std::string &label)
Define a state with given name.
Definition: RooCategory.cxx:208
RooNumIntConfig::RooNumIntConfig
RooNumIntConfig()
Constructor.
Definition: RooNumIntConfig.cxx:71
bool
TIterator
Iterator abstract base class.
Definition: TIterator.h:30
RooNumIntConfig::printMultiline
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose, TString indent="") const
Detailed printing interface.
Definition: RooNumIntConfig.cxx:282
RooNumIntConfig::_epsAbs
Double_t _epsAbs
Definition: RooNumIntConfig.h:74
RooAbsCollection::setName
void setName(const char *name)
Definition: RooAbsCollection.h:282
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:115
RooNumIntConfig::defaultPrintStyle
virtual StyleOption defaultPrintStyle(Option_t *opt) const
Definition: RooNumIntConfig.cxx:248
RooPrintable::kName
@ kName
Definition: RooPrintable.h:33
RooNumIntConfig::addConfigSection
Bool_t addConfigSection(const RooAbsIntegrator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
Definition: RooNumIntConfig.cxx:174
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooNumIntConfig::setEpsRel
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
Definition: RooNumIntConfig.cxx:268
RooAbsIntegrator.h
RooLinkedList::Add
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:64
RooPrintable::kValue
@ kValue
Definition: RooPrintable.h:33
TIterator::Next
virtual TObject * Next()=0
proto
const char * proto
Definition: civetweb.c:16604
Double_t
double Double_t
Definition: RtypesCore.h:59
RooNumIntConfig::setEpsAbs
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
Definition: RooNumIntConfig.cxx:238
RooNumIntFactory::getDepIntegratorName
const char * getDepIntegratorName(const char *name) const
Get list of class names of integrators needed by integrator named 'name'.
Definition: RooNumIntFactory.cxx:154
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
name
char name[80]
Definition: TGX11.cxx:110
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooNumIntConfig
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
Definition: RooNumIntConfig.h:25
RooAbsIntegrator
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
Definition: RooAbsIntegrator.h:22
RooNumIntFactory::instance
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
Definition: RooNumIntFactory.cxx:96
RooNumIntConfig::_method1DOpen
RooCategory _method1DOpen
Definition: RooNumIntConfig.h:81
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1147
RooCategory::getCurrentIndex
virtual value_type getCurrentIndex() const override final
Return current index.
Definition: RooCategory.h:39
RooNumIntConfig::_methodNDOpen
RooCategory _methodNDOpen
Definition: RooNumIntConfig.h:83
Riostream.h
RooNumIntConfig::_method1D
RooCategory _method1D
Definition: RooNumIntConfig.h:78
RooNumIntConfig::_printEvalCounter
Bool_t _printEvalCounter
Definition: RooNumIntConfig.h:76
RooLinkedList::Delete
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
Definition: RooLinkedList.cxx:575
RooNumIntFactory.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33
int