Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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%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 "TSystem.h"
32
33#include "RooNumIntFactory.h"
34#include "RooArgSet.h"
35#include "RooAbsFunc.h"
36#include "RooNumIntConfig.h"
37#include "RooNumber.h"
39#include "RooBinIntegrator.h"
41#include "RooMCIntegrator.h"
43#include "RooMsgService.h"
44
45#include <ostream>
46
47////////////////////////////////////////////////////////////////////////////////
48/// Register all known integrators by calling
49/// their static registration functions
51 RooBinIntegrator::registerIntegrator(*this) ;
52 RooRombergIntegrator::registerIntegrator(*this) ;
53 RooImproperIntegrator1D::registerIntegrator(*this) ;
54 RooMCIntegrator::registerIntegrator(*this) ;
55 // GSL integrator is now in RooFitMore and it register itself
56 //RooAdaptiveGaussKronrodIntegrator1D::registerIntegrator(*this) ;
57 //RooGaussKronrodIntegrator1D::registerIntegrator(*this) ;
58 RooAdaptiveIntegratorND::registerIntegrator(*this) ;
59
60 RooNumIntConfig::defaultConfig().method1D().setLabel("RooIntegrator1D") ;
61 RooNumIntConfig::defaultConfig().method1DOpen().setLabel("RooImproperIntegrator1D") ;
62 RooNumIntConfig::defaultConfig().method2D().setLabel("RooAdaptiveIntegratorND") ;
63 RooNumIntConfig::defaultConfig().methodND().setLabel("RooAdaptiveIntegratorND") ;
64
65 //if GSL is available load (and register GSL integrator)
66#ifdef R__HAS_MATHMORE
67 int iret = gSystem->Load("libRooFitMore");
68 if (iret < 0) {
69 oocoutE(nullptr, Integration) << " RooNumIntFactory::Init : libRooFitMore cannot be loaded. GSL integrators will not be available ! " << std::endl;
70 }
71#endif
72}
73
74
75////////////////////////////////////////////////////////////////////////////////
76/// Static method returning reference to singleton instance of factory
77
79{
80 static std::unique_ptr<RooNumIntFactory> instance;
81
82 if (!instance) {
83 // This is needed to break a deadlock. During init(),
84 // other functions may call back to this one here. So we need to construct first,
85 // and ensure that we can return an instance while we are waiting for init()
86 // to finish.
87 instance.reset(new RooNumIntFactory);
88 instance->init();
89 }
90
91 return *instance;
92}
93
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Method accepting registration of a prototype numeric integrator along with a RooArgSet of its
98/// default configuration options and an optional list of names of other numeric integrators
99/// on which this integrator depends. Returns true if integrator was previously registered
100
101bool RooNumIntFactory::registerPlugin(std::string const &name, Creator const &creator, const RooArgSet &defConfig,
102 bool canIntegrate1D, bool canIntegrate2D, bool canIntegrateND,
103 bool canIntegrateOpenEnded, const char *depName)
104{
105 if (_map.find(name) != _map.end()) {
106 //cout << "RooNumIntFactory::storeIntegrator() ERROR: integrator '" << name << "' already registered" << std::endl ;
107 return true ;
108 }
109
110 // Add to factory
111 auto& info = _map[name];
112 info.creator = creator;
113 info.canIntegrate1D = canIntegrate1D;
114 info.canIntegrate2D = canIntegrate2D;
115 info.canIntegrateND = canIntegrateND;
116 info.canIntegrateOpenEnded = canIntegrateOpenEnded;
117 info.depName = depName;
118
119 // Add default config to master config
120 RooNumIntConfig::defaultConfig().addConfigSection(name,defConfig, canIntegrate1D, canIntegrate2D, canIntegrateND, canIntegrateOpenEnded) ;
121
122 return false ;
123}
124
125std::string RooNumIntFactory::getIntegratorName(RooAbsFunc& func, const RooNumIntConfig& config, int ndimPreset, bool isBinned) const
126{
127 // First determine dimensionality and domain of integrand
128 int ndim = ndimPreset>0 ? ndimPreset : ((int)func.getDimension()) ;
129
130 bool openEnded = false ;
131 int i ;
132 for (i=0 ; i<ndim ; i++) {
135 openEnded = true ;
136 }
137 }
138
139 // Find method defined configuration
140 std::string method ;
141 switch(ndim) {
142 case 1:
144 break ;
145
146 case 2:
148 break ;
149
150 default:
152 break ;
153 }
154
155 // If distribution is binned and not open-ended override with bin integrator
156 if (isBinned & !openEnded) {
157 method = "RooBinIntegrator" ;
158 }
159
160 // Check that a method was defined for this case
161 if (method == "N/A") {
162 oocoutE(nullptr,Integration) << "RooNumIntFactory: No integration method has been defined for "
163 << (openEnded?"an open ended ":"a ") << ndim << "-dimensional integral" << std::endl;
164 return {};
165 }
166
167 return method;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Construct a numeric integrator instance that operates on function 'func' and is configured
172/// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
173/// of the integration, otherwise it is queried from 'func'. This function iterators over list
174/// of available prototype integrators and returns an clone attached to the given function of
175/// the first class that matches the specifications of the requested integration considering
176/// the number of dimensions, the nature of the limits (open ended vs closed) and the user
177/// preference stated in 'config'
178
179std::unique_ptr<RooAbsIntegrator> RooNumIntFactory::createIntegrator(RooAbsFunc& func, const RooNumIntConfig& config, int ndimPreset, bool isBinned) const
180{
181 std::string method = getIntegratorName(func, config, ndimPreset, isBinned);
182
183 if(method.empty()) {
184 return nullptr;
185 }
186
187 // Retrieve proto integrator and return clone configured for the requested integration task
188 std::unique_ptr<RooAbsIntegrator> engine = getPluginInfo(method)->creator(func,config) ;
189 if (config.printEvalCounter()) {
190 engine->setPrintEvalCounter(true) ;
191 }
192 return engine ;
193}
#define oocoutE(o, a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:142
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
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
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
RooCategory & method2DOpen()
RooCategory & method2D()
RooCategory & methodND()
RooCategory & methodNDOpen()
RooCategory & method1D()
RooCategory & method1DOpen()
bool printEvalCounter() const
static RooNumIntConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
Factory to instantiate numeric integrators from a given function binding and a given configuration.
PluginInfo const * getPluginInfo(std::string const &name) const
std::unique_ptr< RooAbsIntegrator > createIntegrator(RooAbsFunc &func, const RooNumIntConfig &config, int ndim=0, bool isBinned=false) const
Construct a numeric integrator instance that operates on function 'func' and is configured with 'conf...
void init()
Register all known integrators by calling their static registration functions.
std::string getIntegratorName(RooAbsFunc &func, const RooNumIntConfig &config, int ndim=0, bool isBinned=false) const
std::function< std::unique_ptr< RooAbsIntegrator >(RooAbsFunc const &function, const RooNumIntConfig &config)> Creator
std::map< std::string, PluginInfo > _map
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
bool registerPlugin(std::string const &name, Creator const &creator, const RooArgSet &defConfig, bool canIntegrate1D, bool canIntegrate2D, bool canIntegrateND, bool canIntegrateOpenEnded, const char *depName="")
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Definition RooNumber.h:27
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1872