Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooNumGenFactory.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 RooNumGenFactory.cxx
19\class RooNumGenFactory
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 "Riostream.h"
33
34#include "RooNumGenFactory.h"
35#include "RooArgSet.h"
36#include "RooAbsFunc.h"
37#include "RooNumGenConfig.h"
38#include "RooNumber.h"
39
40#include "RooAcceptReject.h"
41#include "RooFoamGenerator.h"
42
43
44#include "RooMsgService.h"
45
46
47////////////////////////////////////////////////////////////////////////////////
48/// Constructor. Register all known integrators by calling
49/// their static registration functions
50
52{
55
56 // Prepare default
57 RooNumGenConfig::defaultConfig().method1D(false,false).setLabel("RooFoamGenerator") ;
58 RooNumGenConfig::defaultConfig().method1D(true ,false).setLabel("RooAcceptReject") ;
59 RooNumGenConfig::defaultConfig().method1D(false,true ).setLabel("RooAcceptReject") ;
60 RooNumGenConfig::defaultConfig().method1D(true, true ).setLabel("RooAcceptReject") ;
61
62 RooNumGenConfig::defaultConfig().method2D(false,false).setLabel("RooFoamGenerator") ;
63 RooNumGenConfig::defaultConfig().method2D(true ,false).setLabel("RooAcceptReject") ;
64 RooNumGenConfig::defaultConfig().method2D(false,true ).setLabel("RooAcceptReject") ;
65 RooNumGenConfig::defaultConfig().method2D(true, true ).setLabel("RooAcceptReject") ;
66
67 RooNumGenConfig::defaultConfig().methodND(false,false).setLabel("RooFoamGenerator") ;
68 RooNumGenConfig::defaultConfig().methodND(true ,false).setLabel("RooAcceptReject") ;
69 RooNumGenConfig::defaultConfig().methodND(false,true ).setLabel("RooAcceptReject") ;
70 RooNumGenConfig::defaultConfig().methodND(true, true ).setLabel("RooAcceptReject") ;
71
72}
73
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Destructor
78
80{
81 std::map<std::string,RooAbsNumGenerator*>::iterator iter = _map.begin() ;
82 while (iter != _map.end()) {
83 delete iter->second ;
84 ++iter ;
85 }
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Copy constructor
91
93{
94}
95
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Static method returning reference to singleton instance of factory
100
102{
104 return instance;
105}
106
107
108////////////////////////////////////////////////////////////////////////////////
109/// Method accepting registration of a prototype numeric integrator along with a RooArgSet of its
110/// default configuration options and an optional list of names of other numeric integrators
111/// on which this integrator depends. Returns true if integrator was previously registered
112
114{
115 TString name = proto->generatorName() ;
116
117 if (getProtoSampler(name)) {
118 //cout << "RooNumGenFactory::storeSampler() ERROR: integrator '" << name << "' already registered" << endl ;
119 return true ;
120 }
121
122 // Add to factory
123 _map[name.Data()] = proto ;
124
125 // Add default config to master config
127
128 return false ;
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Return prototype integrator with given (class) name
135
137{
138 if (_map.count(name)==0) {
139 return nullptr ;
140 }
141
142 return _map[name] ;
143}
144
145
146
147////////////////////////////////////////////////////////////////////////////////
148/// Construct a numeric integrator instance that operates on function 'func' and is configured
149/// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
150/// of the integration, otherwise it is queried from 'func'. This function iterators over list
151/// of available prototype integrators and returns an clone attached to the given function of
152/// the first class that matches the specifications of the requested integration considering
153/// the number of dimensions, the nature of the limits (open ended vs closed) and the user
154/// preference stated in 'config'
155
156RooAbsNumGenerator* RooNumGenFactory::createSampler(RooAbsReal& func, const RooArgSet& genVars, const RooArgSet& condVars, const RooNumGenConfig& config, bool verbose, RooAbsReal* maxFuncVal)
157{
158 // Find method defined configuration
159 Int_t ndim = genVars.size() ;
160 bool cond = (!condVars.empty()) ? true : false ;
161
162 bool hasCat(false) ;
163 for (const auto arg : genVars) {
164 if (arg->IsA()==RooCategory::Class()) {
165 hasCat=true ;
166 break ;
167 }
168 }
169
170
171 TString method ;
172 switch(ndim) {
173 case 1:
174 method = config.method1D(cond,hasCat).getCurrentLabel() ;
175 break ;
176
177 case 2:
178 method = config.method2D(cond,hasCat).getCurrentLabel() ;
179 break ;
180
181 default:
182 method = config.methodND(cond,hasCat).getCurrentLabel() ;
183 break ;
184 }
185
186 // Check that a method was defined for this case
187 if (!method.CompareTo("N/A")) {
188 oocoutE(nullptr,Integration) << "RooNumGenFactory::createSampler: No sampler method has been defined for "
189 << (cond?"a conditional ":"a ") << ndim << "-dimensional p.d.f" << std::endl;
190 return nullptr ;
191 }
192
193 // Retrieve proto integrator and return clone configured for the requested integration task
194 const RooAbsNumGenerator* proto = getProtoSampler(method) ;
195 RooAbsNumGenerator* engine = proto->clone(func,genVars,condVars,config,verbose,maxFuncVal) ;
196 return engine ;
197}
#define oocoutE(o, a)
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:17535
virtual const char * getCurrentLabel() const
Return label string of current state.
Storage_t::size_type size() const
Abstract base class for MC event generator implementations like RooAcceptReject and RooFoam.
virtual RooAbsNumGenerator * clone(const RooAbsReal &, const RooArgSet &genVars, const RooArgSet &condVars, const RooNumGenConfig &config, bool verbose=false, const RooAbsReal *maxFuncVal=nullptr) const =0
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
static TClass * Class()
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
RooCategory & method2D(bool cond, bool cat)
RooCategory & method1D(bool cond, bool cat)
bool addConfigSection(const RooAbsNumGenerator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
RooCategory & methodND(bool cond, bool cat)
Factory to instantiate numeric integrators from a given function binding and a given configuration.
RooAbsNumGenerator * createSampler(RooAbsReal &func, const RooArgSet &genVars, const RooArgSet &condVars, const RooNumGenConfig &config, bool verbose=false, RooAbsReal *maxFuncVal=nullptr)
Construct a numeric integrator instance that operates on function 'func' and is configured with 'conf...
static RooNumGenFactory & instance()
Static method returning reference to singleton instance of factory.
bool storeProtoSampler(RooAbsNumGenerator *proto, const RooArgSet &defConfig)
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
~RooNumGenFactory() override
Destructor.
RooNumGenFactory()
Constructor.
std::map< std::string, RooAbsNumGenerator * > _map
const RooAbsNumGenerator * getProtoSampler(const char *name)
Return prototype integrator with given (class) name.
Mother of all ROOT objects.
Definition TObject.h:41
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:457