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
22RooNumGenFactory 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 "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
46using namespace std ;
47
48
49////////////////////////////////////////////////////////////////////////////////
50/// Constructor. Register all known integrators by calling
51/// their static registration functions
52
54{
57
58 // Prepare default
59 RooNumGenConfig::defaultConfig().method1D(false,false).setLabel("RooFoamGenerator") ;
60 RooNumGenConfig::defaultConfig().method1D(true ,false).setLabel("RooAcceptReject") ;
61 RooNumGenConfig::defaultConfig().method1D(false,true ).setLabel("RooAcceptReject") ;
62 RooNumGenConfig::defaultConfig().method1D(true, true ).setLabel("RooAcceptReject") ;
63
64 RooNumGenConfig::defaultConfig().method2D(false,false).setLabel("RooFoamGenerator") ;
65 RooNumGenConfig::defaultConfig().method2D(true ,false).setLabel("RooAcceptReject") ;
66 RooNumGenConfig::defaultConfig().method2D(false,true ).setLabel("RooAcceptReject") ;
67 RooNumGenConfig::defaultConfig().method2D(true, true ).setLabel("RooAcceptReject") ;
68
69 RooNumGenConfig::defaultConfig().methodND(false,false).setLabel("RooFoamGenerator") ;
70 RooNumGenConfig::defaultConfig().methodND(true ,false).setLabel("RooAcceptReject") ;
71 RooNumGenConfig::defaultConfig().methodND(false,true ).setLabel("RooAcceptReject") ;
72 RooNumGenConfig::defaultConfig().methodND(true, true ).setLabel("RooAcceptReject") ;
73
74}
75
76
77
78////////////////////////////////////////////////////////////////////////////////
79/// Destructor
80
82{
83 std::map<std::string,RooAbsNumGenerator*>::iterator iter = _map.begin() ;
84 while (iter != _map.end()) {
85 delete iter->second ;
86 ++iter ;
87 }
88}
89
90
91////////////////////////////////////////////////////////////////////////////////
92/// Copy constructor
93
95{
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Static method returning reference to singleton instance of factory
102
104{
106 return instance;
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
116{
117 TString name = proto->generatorName() ;
118
119 if (getProtoSampler(name)) {
120 //cout << "RooNumGenFactory::storeSampler() ERROR: integrator '" << name << "' already registered" << endl ;
121 return true ;
122 }
123
124 // Add to factory
125 _map[name.Data()] = proto ;
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 if (_map.count(name)==0) {
141 return 0 ;
142 }
143
144 return _map[name] ;
145}
146
147
148
149////////////////////////////////////////////////////////////////////////////////
150/// Construct a numeric integrator instance that operates on function 'func' and is configured
151/// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
152/// of the integration, otherwise it is queried from 'func'. This function iterators over list
153/// of available prototype integrators and returns an clone attached to the given function of
154/// the first class that matches the specifications of the requested integration considering
155/// the number of dimensions, the nature of the limits (open ended vs closed) and the user
156/// preference stated in 'config'
157
158RooAbsNumGenerator* RooNumGenFactory::createSampler(RooAbsReal& func, const RooArgSet& genVars, const RooArgSet& condVars, const RooNumGenConfig& config, bool verbose, RooAbsReal* maxFuncVal)
159{
160 // Find method defined configuration
161 Int_t ndim = genVars.getSize() ;
162 bool cond = (condVars.getSize() > 0) ? true : false ;
163
164 bool hasCat(false) ;
165 for (const auto arg : genVars) {
166 if (arg->IsA()==RooCategory::Class()) {
167 hasCat=true ;
168 break ;
169 }
170 }
171
172
173 TString method ;
174 switch(ndim) {
175 case 1:
176 method = config.method1D(cond,hasCat).getCurrentLabel() ;
177 break ;
178
179 case 2:
180 method = config.method2D(cond,hasCat).getCurrentLabel() ;
181 break ;
182
183 default:
184 method = config.methodND(cond,hasCat).getCurrentLabel() ;
185 break ;
186 }
187
188 // Check that a method was defined for this case
189 if (!method.CompareTo("N/A")) {
190 oocoutE(nullptr,Integration) << "RooNumGenFactory::createSampler: No sampler method has been defined for "
191 << (cond?"a conditional ":"a ") << ndim << "-dimensional p.d.f" << endl ;
192 return 0 ;
193 }
194
195 // Retrieve proto integrator and return clone configured for the requested integration task
196 const RooAbsNumGenerator* proto = getProtoSampler(method) ;
197 RooAbsNumGenerator* engine = proto->clone(func,genVars,condVars,config,verbose,maxFuncVal) ;
198 return engine ;
199}
#define oocoutE(o, a)
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:17502
virtual const char * getCurrentLabel() const
Return label string of current state.
Int_t getSize() const
Return the number of elements in the collection.
Class RooAbsNumGenerator is the abstract base class for MC event generator implementations like RooAc...
virtual RooAbsNumGenerator * clone(const RooAbsReal &, const RooArgSet &genVars, const RooArgSet &condVars, const RooNumGenConfig &config, bool verbose=false, const RooAbsReal *maxFuncVal=nullptr) const =0
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
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:55
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.
RooNumGenConfig holds the configuration parameters of the various numeric integrators used by RooReal...
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)
RooNumGenFactory is a factory to instantiate numeric integrators from a given function binding and a ...
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:450