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