ROOT  6.06/09
Reference Guide
RooNumIntFactory.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 // RooNumIntFactory is a factory to instantiate numeric integrators
21 // from a given function binding and a given configuration. The factory
22 // searches for a numeric integrator registered with the factory that
23 // has the ability to perform the numeric integration. The choice of
24 // method may depend on the number of dimensions integrated,
25 // the nature of the integration limits (closed or open ended) and
26 // the preference of the caller as encoded in the configuration object.
27 // END_HTML
28 //
29 
30 #include "TClass.h"
31 #include "Riostream.h"
32 
33 #include "RooFit.h"
34 
35 #include "RooNumIntFactory.h"
36 #include "RooArgSet.h"
37 #include "RooAbsFunc.h"
38 #include "RooNumIntConfig.h"
39 #include "RooNumber.h"
40 
41 #include "RooIntegrator1D.h"
42 #include "RooBinIntegrator.h"
43 #include "RooIntegrator2D.h"
47 #include "RooMCIntegrator.h"
51 #include "RooSentinel.h"
52 
53 #include "RooMsgService.h"
54 
55 using namespace std ;
56 
58 ;
59 
60 RooNumIntFactory* RooNumIntFactory::_instance = 0 ;
61 
62 
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Constructor. Register all known integrators by calling
66 /// their static registration functions
67 
69 {
70  _instance = this ;
71 
82 
83  RooNumIntConfig::defaultConfig().method1D().setLabel("RooIntegrator1D") ;
84  RooNumIntConfig::defaultConfig().method1DOpen().setLabel("RooImproperIntegrator1D") ;
85  RooNumIntConfig::defaultConfig().method2D().setLabel("RooAdaptiveIntegratorND") ;
86  RooNumIntConfig::defaultConfig().methodND().setLabel("RooAdaptiveIntegratorND") ;
87 
88 }
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Destructor
94 
96 {
97  std::map<std::string,pair<RooAbsIntegrator*,std::string> >::iterator iter = _map.begin() ;
98  while (iter != _map.end()) {
99  delete iter->second.first ;
100  ++iter ;
101  }
102 }
103 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Copy constructor
107 
109 {
110 }
111 
112 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Static method returning reference to singleton instance of factory
116 
118 {
119  if (_instance==0) {
120  new RooNumIntFactory ;
122  }
123  return *_instance ;
124 }
125 
126 
127 ////////////////////////////////////////////////////////////////////////////////
128 /// Cleanup routine called by atexit() handler installed by RooSentinel
129 
131 {
132  if (_instance) {
133  delete _instance ;
134  _instance = 0 ;
135  }
136 }
137 
138 
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Method accepting registration of a prototype numeric integrator along with a RooArgSet of its
142 /// default configuration options and an optional list of names of other numeric integrators
143 /// on which this integrator depends. Returns true if integrator was previously registered
144 
145 Bool_t RooNumIntFactory::storeProtoIntegrator(RooAbsIntegrator* proto, const RooArgSet& defConfig, const char* depName)
146 {
147  TString name = proto->IsA()->GetName() ;
148 
149  if (getProtoIntegrator(name)) {
150  //cout << "RooNumIntFactory::storeIntegrator() ERROR: integrator '" << name << "' already registered" << endl ;
151  return kTRUE ;
152  }
153 
154  // Add to factory
155  _map[name.Data()] = std::pair<RooAbsIntegrator*,std::string>(proto,depName) ;
156 
157  // Add default config to master config
159 
160  return kFALSE ;
161 }
162 
163 
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Return prototype integrator with given (class) name
167 
169 {
170  if (_map.count(name)==0) {
171  return 0 ;
172  }
173 
174  return _map[name].first ;
175 }
176 
177 
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Get list of class names of integrators needed by integrator named 'name'
181 
183 {
184  if (_map.count(name)==0) {
185  return 0 ;
186  }
187 
188  return _map[name].second.c_str() ;
189 }
190 
191 
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Construct a numeric integrator instance that operates on function 'func' and is configured
195 /// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
196 /// of the integration, otherwise it is queried from 'func'. This function iterators over list
197 /// of available prototype integrators and returns an clone attached to the given function of
198 /// the first class that matches the specifications of the requested integration considering
199 /// the number of dimensions, the nature of the limits (open ended vs closed) and the user
200 /// preference stated in 'config'
201 
203 {
204  // First determine dimensionality and domain of integrand
205  Int_t ndim = ndimPreset>0 ? ndimPreset : ((Int_t)func.getDimension()) ;
206 
207  Bool_t openEnded = kFALSE ;
208  Int_t i ;
209  for (i=0 ; i<ndim ; i++) {
210  if(RooNumber::isInfinite(func.getMinLimit(i)) ||
212  openEnded = kTRUE ;
213  }
214  }
215 
216  // Find method defined configuration
217  TString method ;
218  switch(ndim) {
219  case 1:
220  method = openEnded ? config.method1DOpen().getLabel() : config.method1D().getLabel() ;
221  break ;
222 
223  case 2:
224  method = openEnded ? config.method2DOpen().getLabel() : config.method2D().getLabel() ;
225  break ;
226 
227  default:
228  method = openEnded ? config.methodNDOpen().getLabel() : config.methodND().getLabel() ;
229  break ;
230  }
231 
232  // If distribution is binned and not open-ended override with bin integrator
233  if (isBinned & !openEnded) {
234  method = "RooBinIntegrator" ;
235  }
236 
237  // Check that a method was defined for this case
238  if (!method.CompareTo("N/A")) {
239  oocoutE((TObject*)0,Integration) << "RooNumIntFactory::createIntegrator: No integration method has been defined for "
240  << (openEnded?"an open ended ":"a ") << ndim << "-dimensional integral" << endl ;
241  return 0 ;
242  }
243 
244  // Retrieve proto integrator and return clone configured for the requested integration task
245  const RooAbsIntegrator* proto = getProtoIntegrator(method) ;
246  RooAbsIntegrator* engine = proto->clone(func,config) ;
247  if (config.printEvalCounter()) {
248  engine->setPrintEvalCounter(kTRUE) ;
249  }
250  return engine ;
251 }
static RooNumIntConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
static RooNumIntFactory * _instance
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
virtual RooAbsIntegrator * clone(const RooAbsFunc &function, const RooNumIntConfig &config) const =0
RooCategory & methodND()
std::map< std::string, std::pair< RooAbsIntegrator *, std::string > > _map
RooCategory & method2D()
static void registerIntegrator(RooNumIntFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
void setPrintEvalCounter(Bool_t value)
Basic string class.
Definition: TString.h:137
RooCategory & method2DOpen()
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
static Int_t isInfinite(Double_t x)
Return true if x is infinite by RooNumBer internal specification.
Definition: RooNumber.cxx:57
static void registerIntegrator(RooNumIntFactory &fact)
Register RooImproperIntegrator1D, its parameters and capabilities with RooNumIntFactory.
STL namespace.
UInt_t getDimension() const
Definition: RooAbsFunc.h:29
const RooAbsIntegrator * getProtoIntegrator(const char *name)
Return prototype integrator with given (class) name.
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
const char * Data() const
Definition: TString.h:349
RooCategory & method1D()
RooAbsIntegrator * createIntegrator(RooAbsFunc &func, const RooNumIntConfig &config, Int_t ndim=0, Bool_t isBinned=kFALSE)
Construct a numeric integrator instance that operates on function 'func' and is configured with 'conf...
#define oocoutE(o, a)
Definition: RooMsgService.h:48
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactor...
RooCategory & methodNDOpen()
RooNumIntFactory()
Constructor.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooIntegrator2D, is parameters and capabilities with RooNumIntFactory.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooGaussKronrodIntegrator1D, its parameters and capabilities with RooNumIntConfig.
virtual ~RooNumIntFactory()
Destructor.
static void registerIntegrator(RooNumIntFactory &fact)
This function registers class RooMCIntegrator, its configuration options and its capabilities with Ro...
virtual Double_t getMinLimit(UInt_t dimension) const =0
ClassImp(RooNumIntFactory)
static void cleanup()
Cleanup routine called by atexit() handler installed by RooSentinel.
std::map< Int_t, const RooCatType * > _map
static void registerIntegrator(RooNumIntFactory &fact)
Register RooBinIntegrator, is parameters and capabilities with RooNumIntFactory.
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
Definition: RooSentinel.cxx:70
virtual Double_t getMaxLimit(UInt_t dimension) const =0
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
RooCategory & method1DOpen()
const char * getDepIntegratorName(const char *name)
Get list of class names of integrators needed by integrator named 'name'.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory...
double func(double *x, double *p)
Definition: stressTF1.cxx:213
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator2D, its parameters, dependencies and capabilities with RooNumIntFactor...
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
static void registerIntegrator(RooNumIntFactory &fact)
Register this class with RooNumIntConfig as a possible choice of numeric integrator for one-dimension...
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t addConfigSection(const RooAbsIntegrator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
Bool_t printEvalCounter() const
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:385
virtual const char * getLabel() const
Return label string of current state.
Definition: RooCategory.h:40
Bool_t storeProtoIntegrator(RooAbsIntegrator *proto, const RooArgSet &defConfig, const char *depName="")
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...