Logo ROOT  
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
22RooNumIntFactory is a factory to instantiate numeric integrators
23from a given function binding and a given configuration. The factory
24searches for a numeric integrator registered with the factory that
25has the ability to perform the numeric integration. The choice of
26method may depend on the number of dimensions integrated,
27the nature of the integration limits (closed or open ended) and
28the preference of the caller as encoded in the configuration object.
29**/
30
31#include "TClass.h"
32#include "TSystem.h"
33#include "Riostream.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"
49
50#include "RooMsgService.h"
51
52using namespace std ;
53
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Register all known integrators by calling
60/// their static registration functions
69 // GSL integrator is now in RooFitMore and it register itself
70 //RooAdaptiveGaussKronrodIntegrator1D::registerIntegrator(*this) ;
71 //RooGaussKronrodIntegrator1D::registerIntegrator(*this) ;
73
74 RooNumIntConfig::defaultConfig().method1D().setLabel("RooIntegrator1D") ;
75 RooNumIntConfig::defaultConfig().method1DOpen().setLabel("RooImproperIntegrator1D") ;
76 RooNumIntConfig::defaultConfig().method2D().setLabel("RooAdaptiveIntegratorND") ;
77 RooNumIntConfig::defaultConfig().methodND().setLabel("RooAdaptiveIntegratorND") ;
78
79 //if GSL is available load (and register GSL integrator)
80#ifdef R__HAS_MATHMORE
81 int iret = gSystem->Load("libRooFitMore");
82 if (iret < 0) {
83 oocoutE(nullptr, Integration) << " RooNumIntFactory::Init : libRooFitMore cannot be loaded. GSL integrators will not beavailable ! " << std::endl;
84 }
85#endif
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Static method returning reference to singleton instance of factory
91
93{
94 static unique_ptr<RooNumIntFactory> instance;
95
96 if (!instance) {
97 // This is needed to break a deadlock. During init(),
98 // other functions may call back to this one here. So we need to construct first,
99 // and ensure that we can return an instance while we are waiting for init()
100 // to finish.
101 instance.reset(new RooNumIntFactory);
102 instance->init();
103 }
104
105 return *instance;
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Method accepting registration of a prototype numeric integrator along with a RooArgSet of its
112/// default configuration options and an optional list of names of other numeric integrators
113/// on which this integrator depends. Returns true if integrator was previously registered
114
115bool RooNumIntFactory::storeProtoIntegrator(RooAbsIntegrator* proto, const RooArgSet& defConfig, const char* depName)
116{
117 TString name = proto->IsA()->GetName() ;
118
120 //cout << "RooNumIntFactory::storeIntegrator() ERROR: integrator '" << name << "' already registered" << endl ;
121 return true ;
122 }
123
124 // Add to factory
125 _map[name.Data()] = std::make_pair(unique_ptr<RooAbsIntegrator>(proto), std::string(depName));
126
127 // Add default config to master config
129
130 return false ;
131}
132
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// Return prototype integrator with given (class) name
137
139{
140 auto item = _map.find(name);
141
142 return item == _map.end() ? nullptr : item->second.first.get();
143}
144
145
146
147////////////////////////////////////////////////////////////////////////////////
148/// Get list of class names of integrators needed by integrator named 'name'
149
150const char* RooNumIntFactory::getDepIntegratorName(const char* name) const
151{
152 auto item = _map.find(name);
153
154 return item == _map.end() ? nullptr : item->second.second.c_str();
155}
156
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Construct a numeric integrator instance that operates on function 'func' and is configured
161/// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
162/// of the integration, otherwise it is queried from 'func'. This function iterators over list
163/// of available prototype integrators and returns an clone attached to the given function of
164/// the first class that matches the specifications of the requested integration considering
165/// the number of dimensions, the nature of the limits (open ended vs closed) and the user
166/// preference stated in 'config'
167
168RooAbsIntegrator* RooNumIntFactory::createIntegrator(RooAbsFunc& func, const RooNumIntConfig& config, Int_t ndimPreset, bool isBinned) const
169{
170 // First determine dimensionality and domain of integrand
171 Int_t ndim = ndimPreset>0 ? ndimPreset : ((Int_t)func.getDimension()) ;
172
173 bool openEnded = false ;
174 Int_t i ;
175 for (i=0 ; i<ndim ; i++) {
178 openEnded = true ;
179 }
180 }
181
182 // Find method defined configuration
183 TString method ;
184 switch(ndim) {
185 case 1:
186 method = openEnded ? config.method1DOpen().getCurrentLabel() : config.method1D().getCurrentLabel() ;
187 break ;
188
189 case 2:
190 method = openEnded ? config.method2DOpen().getCurrentLabel() : config.method2D().getCurrentLabel() ;
191 break ;
192
193 default:
194 method = openEnded ? config.methodNDOpen().getCurrentLabel() : config.methodND().getCurrentLabel() ;
195 break ;
196 }
197
198 // If distribution is binned and not open-ended override with bin integrator
199 if (isBinned & !openEnded) {
200 method = "RooBinIntegrator" ;
201 }
202
203 // Check that a method was defined for this case
204 if (!method.CompareTo("N/A")) {
205 oocoutE(nullptr,Integration) << "RooNumIntFactory::createIntegrator: No integration method has been defined for "
206 << (openEnded?"an open ended ":"a ") << ndim << "-dimensional integral" << endl ;
207 return 0 ;
208 }
209
210 // Retrieve proto integrator and return clone configured for the requested integration task
211 const RooAbsIntegrator* proto = getProtoIntegrator(method) ;
212 RooAbsIntegrator* engine = proto->clone(func,config) ;
213 if (config.printEvalCounter()) {
214 engine->setPrintEvalCounter(true) ;
215 }
216 return engine ;
217}
#define oocoutE(o, a)
Definition: RooMsgService.h:52
int Int_t
Definition: RtypesCore.h:45
#define ClassImp(name)
Definition: Rtypes.h:375
char name[80]
Definition: TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
const char * proto
Definition: civetweb.c:17493
virtual const char * getCurrentLabel() const
Return label string of current state.
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
Definition: RooAbsFunc.h:27
virtual double getMaxLimit(UInt_t dimension) const =0
virtual double getMinLimit(UInt_t dimension) const =0
UInt_t getDimension() const
Definition: RooAbsFunc.h:33
RooAbsIntegrator is the abstract interface for integrators of real-valued functions that implement th...
void setPrintEvalCounter(bool value)
static void registerIntegrator(RooNumIntFactory &fact)
Register RooAdaptiveIntegratorND, its parameters, dependencies and capabilities with RooNumIntFactory...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
static void registerIntegrator(RooNumIntFactory &fact)
Register RooBinIntegrator, is parameters and capabilities with RooNumIntFactory.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooImproperIntegrator1D, its parameters and capabilities with RooNumIntFactory.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
static void registerIntegrator(RooNumIntFactory &fact)
Register RooIntegrator2D, is parameters and capabilities with RooNumIntFactory.
static void registerIntegrator(RooNumIntFactory &fact)
This function registers class RooMCIntegrator, its configuration options and its capabilities with Ro...
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
RooCategory & method2DOpen()
RooCategory & method2D()
RooCategory & methodND()
RooCategory & methodNDOpen()
bool addConfigSection(const RooAbsIntegrator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
RooCategory & method1D()
RooCategory & method1DOpen()
bool printEvalCounter() const
static RooNumIntConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
RooNumIntFactory is a factory to instantiate numeric integrators from a given function binding and a ...
std::map< std::string, std::pair< std::unique_ptr< RooAbsIntegrator >, std::string > > _map
void init()
Register all known integrators by calling their static registration functions.
RooAbsIntegrator * createIntegrator(RooAbsFunc &func, const RooNumIntConfig &config, Int_t ndim=0, bool isBinned=false) const
Construct a numeric integrator instance that operates on function 'func' and is configured with 'conf...
const RooAbsIntegrator * getProtoIntegrator(const char *name) const
Return prototype integrator with given (class) name.
const char * getDepIntegratorName(const char *name) const
Get list of class names of integrators needed by integrator named 'name'.
bool storeProtoIntegrator(RooAbsIntegrator *proto, const RooArgSet &defConfig, const char *depName="")
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
static Int_t isInfinite(double x)
Return true if x is infinite by RooNumBer internal specification.
Definition: RooNumber.cxx:57
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator1D, its parameters, dependencies and capabilities with RooNumIntFactor...
static void registerIntegrator(RooNumIntFactory &fact)
Register RooSegmentedIntegrator2D, its parameters, dependencies and capabilities with RooNumIntFactor...
Basic string class.
Definition: TString.h:136
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:442
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1855
void(off) SmallVectorTemplateBase< T
void init()
Inspect hardware capabilities, and load the optimal library for RooFit computations.
@ Integration
Definition: RooGlobalFunc.h:63