Logo ROOT   6.14/05
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 
46 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Function called by atexit() handler installed by RooSentinel to
50 /// cleanup global objects at end of job
51 
53 {
54  if (_default) {
55  delete _default ;
56  _default = 0 ;
57  }
58 }
59 
60 
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Return reference to instance of default numeric integrator configuration object
64 
66 {
67  // Instantiate object if it doesn't exist yet
68  if (_default==0) {
69  _default = new RooNumIntConfig ;
71  }
72  return *_default ;
73 }
74 
75 
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Constructor
79 
81  _epsAbs(1e-7),
82  _epsRel(1e-7),
83  _printEvalCounter(kFALSE),
84  _method1D("method1D","1D integration method"),
85  _method2D("method2D","2D integration method"),
86  _methodND("methodND","ND integration method"),
87  _method1DOpen("method1DOpen","1D integration method in open domain"),
88  _method2DOpen("method2DOpen","2D integration method in open domain"),
89  _methodNDOpen("methodNDOpen","ND integration method in open domain")
90 {
91  // Set all methods to undefined
92  // Defined methods will be registered by static initialization routines
93  // of the various numeric integrator engines
94  _method1D.defineType("N/A",0) ;
95  _method2D.defineType("N/A",0) ;
96  _methodND.defineType("N/A",0) ;
97  _method1DOpen.defineType("N/A",0) ;
98  _method2DOpen.defineType("N/A",0) ;
99  _methodNDOpen.defineType("N/A",0) ;
100 }
101 
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Destructor
105 
107 {
108  // Delete all configuration data
109  _configSets.Delete() ;
110 }
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Copy constructor
115 
117  TObject(other), RooPrintable(other),
118  _epsAbs(other._epsAbs),
119  _epsRel(other._epsRel),
121  _method1D(other._method1D),
122  _method2D(other._method2D),
123  _methodND(other._methodND),
127 {
128  // Clone all configuration dat
129  TIterator* iter = other._configSets.MakeIterator() ;
130  RooArgSet* set ;
131  while((set=(RooArgSet*)iter->Next())) {
132  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
133  setCopy->setName(set->GetName()) ;
134  _configSets.Add(setCopy);
135  }
136  delete iter ;
137 }
138 
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Assignment operator from other RooNumIntConfig
142 
144 {
145  // Prevent self-assignment
146  if (&other==this) {
147  return *this ;
148  }
149 
150  // Copy common properties
151  _epsAbs = other._epsAbs ;
152  _epsRel = other._epsRel ;
159 
160  // Delete old integrator-specific configuration data
161  _configSets.Delete() ;
162 
163  // Copy new integrator-specific data
164  TIterator* iter = other._configSets.MakeIterator() ;
165  RooArgSet* set ;
166  while((set=(RooArgSet*)iter->Next())) {
167  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
168  setCopy->setName(set->GetName()) ;
169  _configSets.Add(setCopy);
170  }
171  delete iter ;
172 
173  return *this ;
174 }
175 
176 
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Add a configuration section for a particular integrator. Integrator name and capabilities are
180 /// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
181 /// as the default configuration for the integrator.
182 
184 {
185  TString name = proto->IsA()->GetName() ;
186 
187  // Register integrator for appropriate dimensionalities
188  if (proto->canIntegrate1D()) {
189  _method1D.defineType(name) ;
190  if (proto->canIntegrateOpenEnded()) {
191  _method1DOpen.defineType(name) ;
192  }
193  }
194 
195  if (proto->canIntegrate2D()) {
196  _method2D.defineType(name) ;
197  if (proto->canIntegrateOpenEnded()) {
198  _method2DOpen.defineType(name) ;
199  }
200  }
201 
202  if (proto->canIntegrateND()) {
203  _methodND.defineType(name) ;
204  if (proto->canIntegrateOpenEnded()) {
205  _methodNDOpen.defineType(name) ;
206  }
207  }
208 
209  // Store default configuration parameters
210  RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
211  config->setName(name) ;
212  _configSets.Add(config) ;
213 
214  return kFALSE ;
215 }
216 
217 
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Return section with configuration parameters for integrator with given (class) name
221 
223 {
224  return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
225 }
226 
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// Retrieve configuration information specific to integrator with given name
230 
232 {
233  static RooArgSet dummy ;
234  RooArgSet* config = (RooArgSet*) _configSets.FindObject(name) ;
235  if (!config) {
236  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
237  return dummy ;
238  }
239  return *config ;
240 }
241 
242 
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 /// Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
246 
248 {
249  if (newEpsAbs<0) {
250  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater or equal than zero" << endl ;
251  return ;
252  }
253  _epsAbs = newEpsAbs ;
254 }
255 
256 
258 {
259  if (!opt) {
260  return kStandard ;
261  }
262 
263  TString o(opt) ;
264  o.ToLower() ;
265 
266  if (o.Contains("v")) {
267  return kVerbose ;
268  }
269  return kStandard ;
270 }
271 
272 
273 
274 ////////////////////////////////////////////////////////////////////////////////
275 /// Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
276 
278 {
279  if (newEpsRel<0) {
280  oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater or equal than zero" << endl ;
281  return ;
282  }
283  _epsRel = newEpsRel ;
284 }
285 
286 
287 
288 ////////////////////////////////////////////////////////////////////////////////
289 /// Detailed printing interface
290 
291 void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
292 {
293  os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << endl << endl ;
294  if (_printEvalCounter) {
295  os << indent << "Printing of function evaluation counter for each integration enabled" << endl << endl ;
296  }
297 
298  os << indent << "1-D integration method: " << _method1D.getLabel() ;
300  os << " (" << _method1DOpen.getLabel() << " if open-ended)" << endl ;
301  } else {
302  os << endl ;
303  }
304  os << indent << "2-D integration method: " << _method2D.getLabel() ;
306  os << " (" << _method2DOpen.getLabel() << " if open-ended)" << endl ;
307  } else {
308  os << endl ;
309  }
310  os << indent << "N-D integration method: " << _methodND.getLabel() ;
312  os << " (" << _methodNDOpen.getLabel() << " if open-ended)" << endl ;
313  } else {
314  os << endl ;
315  }
316 
317  if (verbose) {
318 
319  os << endl << "Available integration methods:" << endl << endl ;
320  TIterator* cIter = _configSets.MakeIterator() ;
321  RooArgSet* configSet ;
322  while ((configSet=(RooArgSet*)cIter->Next())) {
323 
324  os << indent << "*** " << configSet->GetName() << " ***" << endl ;
325  os << indent << "Capabilities: " ;
327  if (proto->canIntegrate1D()) os << "[1-D] " ;
328  if (proto->canIntegrate2D()) os << "[2-D] " ;
329  if (proto->canIntegrateND()) os << "[N-D] " ;
330  if (proto->canIntegrateOpenEnded()) os << "[OpenEnded] " ;
331  os << endl ;
332 
333  os << "Configuration: " << endl ;
334  configSet->printMultiline(os,kName|kValue) ;
335  //configSet->writeToStream(os,kFALSE) ;
336 
337  const char* depName = RooNumIntFactory::instance().getDepIntegratorName(configSet->GetName()) ;
338  if (strlen(depName)>0) {
339  os << indent << "(Depends on '" << depName << "')" << endl ;
340  }
341  os << endl ;
342 
343  }
344 
345  delete cIter ;
346  }
347 }
static RooNumIntConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
RooCategory _method1DOpen
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
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
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
STL namespace.
const RooAbsIntegrator * getProtoIntegrator(const char *name)
Return prototype integrator with given (class) name.
Iterator abstract base class.
Definition: TIterator.h:30
RooPlotable is a &#39;mix-in&#39; base class that define the standard RooFit plotting and printing methods...
Definition: RooPrintable.h:25
#define oocoutE(o, a)
Definition: RooMsgService.h:47
RooCategory _methodND
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
RooNumIntConfig()
Constructor.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
RooCategory _method1D
Bool_t _printEvalCounter
static RooNumIntConfig * _default
virtual Int_t getIndex() const
Return index number of current state.
Definition: RooCategory.h:34
const Bool_t kFALSE
Definition: RtypesCore.h:88
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...
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
const char * getDepIntegratorName(const char *name)
Get list of class names of integrators needed by integrator named &#39;name&#39;.
RooCategory _method2DOpen
static RooMathCoreReg dummy
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...
RooCategory _methodNDOpen
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual const char * getLabel() const
Return label string of current state.
Definition: RooCategory.h:39
const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
Definition: TObject.h:37
static void cleanup()
Function called by atexit() handler installed by RooSentinel to cleanup global objects at end of job...
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
virtual TObject * Next()=0
virtual Bool_t canIntegrate1D() const =0
void setName(const char *name)
const char * proto
Definition: civetweb.c:15049
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.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
Bool_t addConfigSection(const RooAbsIntegrator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
virtual Bool_t canIntegrateOpenEnded() const =0
char name[80]
Definition: TGX11.cxx:109
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose, TString indent="") const
Detailed printing interface.