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