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