ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // RooNumIntConfig holds the configuration parameters of the various
21 // numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
22 // use this class in the (normalization) integral configuration interface
23 // END_HTML
24 //
25 
26 #include "RooFit.h"
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 
39 using namespace std;
40 
42 ;
43 
44 RooNumIntConfig* RooNumIntConfig::_default = 0 ;
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Function called by atexit() handler installed by RooSentinel to
49 /// cleanup global objects at end of job
50 
52 {
53  if (_default) {
54  delete _default ;
55  _default = 0 ;
56  }
57 }
58 
59 
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Return reference to instance of default numeric integrator configuration object
63 
65 {
66  // Instantiate object if it doesn't exist yet
67  if (_default==0) {
68  _default = new RooNumIntConfig ;
70  }
71  return *_default ;
72 }
73 
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Constructor
78 
80  _epsAbs(1e-7),
81  _epsRel(1e-7),
82  _printEvalCounter(kFALSE),
83  _method1D("method1D","1D integration method"),
84  _method2D("method2D","2D integration method"),
85  _methodND("methodND","ND integration method"),
86  _method1DOpen("method1DOpen","1D integration method in open domain"),
87  _method2DOpen("method2DOpen","2D integration method in open domain"),
88  _methodNDOpen("methodNDOpen","ND integration method in open domain")
89 {
90  // Set all methods to undefined
91  // Defined methods will be registered by static initialization routines
92  // of the various numeric integrator engines
93  _method1D.defineType("N/A",0) ;
94  _method2D.defineType("N/A",0) ;
95  _methodND.defineType("N/A",0) ;
96  _method1DOpen.defineType("N/A",0) ;
97  _method2DOpen.defineType("N/A",0) ;
98  _methodNDOpen.defineType("N/A",0) ;
99 }
100 
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Destructor
104 
106 {
107  // Delete all configuration data
108  _configSets.Delete() ;
109 }
110 
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Copy constructor
114 
116  TObject(other), RooPrintable(other),
117  _epsAbs(other._epsAbs),
118  _epsRel(other._epsRel),
119  _printEvalCounter(other._printEvalCounter),
120  _method1D(other._method1D),
121  _method2D(other._method2D),
122  _methodND(other._methodND),
123  _method1DOpen(other._method1DOpen),
124  _method2DOpen(other._method2DOpen),
125  _methodNDOpen(other._methodNDOpen)
126 {
127  // Clone all configuration dat
129  RooArgSet* set ;
130  while((set=(RooArgSet*)iter->Next())) {
131  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
132  setCopy->setName(set->GetName()) ;
133  _configSets.Add(setCopy);
134  }
135  delete iter ;
136 }
137 
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Assignment operator from other RooNumIntConfig
141 
143 {
144  // Prevent self-assignment
145  if (&other==this) {
146  return *this ;
147  }
148 
149  // Copy common properties
150  _epsAbs = other._epsAbs ;
151  _epsRel = other._epsRel ;
158 
159  // Delete old integrator-specific configuration data
160  _configSets.Delete() ;
161 
162  // Copy new integrator-specific data
164  RooArgSet* set ;
165  while((set=(RooArgSet*)iter->Next())) {
166  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
167  setCopy->setName(set->GetName()) ;
168  _configSets.Add(setCopy);
169  }
170  delete iter ;
171 
172  return *this ;
173 }
174 
175 
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Add a configuration section for a particular integrator. Integrator name and capabilities are
179 /// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
180 /// as the default configuration for the integrator.
181 
183 {
184  TString name = proto->IsA()->GetName() ;
185 
186  // Register integrator for appropriate dimensionalities
187  if (proto->canIntegrate1D()) {
188  _method1D.defineType(name) ;
189  if (proto->canIntegrateOpenEnded()) {
190  _method1DOpen.defineType(name) ;
191  }
192  }
193 
194  if (proto->canIntegrate2D()) {
195  _method2D.defineType(name) ;
196  if (proto->canIntegrateOpenEnded()) {
197  _method2DOpen.defineType(name) ;
198  }
199  }
200 
201  if (proto->canIntegrateND()) {
202  _methodND.defineType(name) ;
203  if (proto->canIntegrateOpenEnded()) {
204  _methodNDOpen.defineType(name) ;
205  }
206  }
207 
208  // Store default configuration parameters
209  RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
210  config->setName(name) ;
211  _configSets.Add(config) ;
212 
213  return kFALSE ;
214 }
215 
216 
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Return section with configuration parameters for integrator with given (class) name
220 
222 {
223  return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
224 }
225 
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Retrieve configuration information specific to integrator with given name
229 
231 {
232  static RooArgSet dummy ;
233  RooArgSet* config = (RooArgSet*) _configSets.FindObject(name) ;
234  if (!config) {
235  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
236  return dummy ;
237  }
238  return *config ;
239 }
240 
241 
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 /// Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
245 
247 {
248  if (newEpsAbs<0) {
249  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater or equal than zero" << endl ;
250  return ;
251  }
252  _epsAbs = newEpsAbs ;
253 }
254 
255 
257 {
258  if (!opt) {
259  return kStandard ;
260  }
261 
262  TString o(opt) ;
263  o.ToLower() ;
264 
265  if (o.Contains("v")) {
266  return kVerbose ;
267  }
268  return kStandard ;
269 }
270 
271 
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
275 
277 {
278  if (newEpsRel<0) {
279  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater or equal than zero" << endl ;
280  return ;
281  }
282  _epsRel = newEpsRel ;
283 }
284 
285 
286 
287 ////////////////////////////////////////////////////////////////////////////////
288 /// Detailed printing interface
289 
290 void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
291 {
292  os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << endl << endl ;
293  if (_printEvalCounter) {
294  os << indent << "Printing of function evaluation counter for each integration enabled" << endl << endl ;
295  }
296 
297  os << indent << "1-D integration method: " << _method1D.getLabel() ;
299  os << " (" << _method1DOpen.getLabel() << " if open-ended)" << endl ;
300  } else {
301  os << endl ;
302  }
303  os << indent << "2-D integration method: " << _method2D.getLabel() ;
305  os << " (" << _method2DOpen.getLabel() << " if open-ended)" << endl ;
306  } else {
307  os << endl ;
308  }
309  os << indent << "N-D integration method: " << _methodND.getLabel() ;
311  os << " (" << _methodNDOpen.getLabel() << " if open-ended)" << endl ;
312  } else {
313  os << endl ;
314  }
315 
316  if (verbose) {
317 
318  os << endl << "Available integration methods:" << endl << endl ;
319  TIterator* cIter = _configSets.MakeIterator() ;
320  RooArgSet* configSet ;
321  while ((configSet=(RooArgSet*)cIter->Next())) {
322 
323  os << indent << "*** " << configSet->GetName() << " ***" << endl ;
324  os << indent << "Capabilities: " ;
326  if (proto->canIntegrate1D()) os << "[1-D] " ;
327  if (proto->canIntegrate2D()) os << "[2-D] " ;
328  if (proto->canIntegrateND()) os << "[N-D] " ;
329  if (proto->canIntegrateOpenEnded()) os << "[OpenEnded] " ;
330  os << endl ;
331 
332  os << "Configuration: " << endl ;
333  configSet->printMultiline(os,kName|kValue) ;
334  //configSet->writeToStream(os,kFALSE) ;
335 
336  const char* depName = RooNumIntFactory::instance().getDepIntegratorName(configSet->GetName()) ;
337  if (strlen(depName)>0) {
338  os << indent << "(Depends on '" << depName << "')" << endl ;
339  }
340  os << endl ;
341 
342  }
343 
344  delete cIter ;
345  }
346 }
static RooNumIntConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
virtual Int_t getIndex() const
Return index number of current state.
Definition: RooCategory.h:35
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
RooCategory _method1DOpen
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
virtual Bool_t canIntegrateND() const =0
const char Option_t
Definition: RtypesCore.h:62
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)
Set value by specifying the index code of the desired state.
virtual Bool_t canIntegrate2D() const =0
Basic string class.
Definition: TString.h:137
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1088
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
const RooAbsIntegrator * getProtoIntegrator(const char *name)
Return prototype integrator with given (class) name.
Iterator abstract base class.
Definition: TIterator.h:32
#define oocoutE(o, a)
Definition: RooMsgService.h:48
RooCategory _methodND
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
RooNumIntConfig()
Constructor.
RooCategory _method1D
Bool_t _printEvalCounter
return
Definition: TBase64.cxx:62
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose, TString indent="") const
Detailed printing interface.
bool verbose
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
static void indent(ostringstream &buf, int indent_level)
RooNumIntConfig & operator=(const RooNumIntConfig &other)
Assignment operator from other RooNumIntConfig.
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements...
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
double Double_t
Definition: RtypesCore.h:55
const char * getDepIntegratorName(const char *name)
Get list of class names of integrators needed by integrator named 'name'.
ClassImp(RooNumIntConfig)
RooCategory _method2DOpen
static RooMathCoreReg dummy
RooCategory _methodNDOpen
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
static void cleanup()
Function called by atexit() handler installed by RooSentinel to cleanup global objects at end of job...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
virtual TObject * Next()=0
virtual Bool_t canIntegrate1D() const =0
void setName(const char *name)
Bool_t defineType(const char *label)
Define a state with given name, the lowest available positive integer is assigned as index...
RooLinkedList _configSets
RooCategory _method2D
virtual ~RooNumIntConfig()
Destructor.
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)
Bool_t addConfigSection(const RooAbsIntegrator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
virtual Bool_t canIntegrateOpenEnded() const =0
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Implement multiline printin of collection, one line for each ontained object showing the requested co...
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)
const char * GetName() const
Returns name of object.
virtual const char * getLabel() const
Return label string of current state.
Definition: RooCategory.h:40