Logo ROOT  
Reference Guide
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
49
50
51
52////////////////////////////////////////////////////////////////////////////////
53/// Constructor. Register all known integrators by calling
54/// their static registration functions
55
57{
60
61 // Prepare default
62 RooNumGenConfig::defaultConfig().method1D(false,false).setLabel("RooFoamGenerator") ;
63 RooNumGenConfig::defaultConfig().method1D(true ,false).setLabel("RooAcceptReject") ;
64 RooNumGenConfig::defaultConfig().method1D(false,true ).setLabel("RooAcceptReject") ;
65 RooNumGenConfig::defaultConfig().method1D(true, true ).setLabel("RooAcceptReject") ;
66
67 RooNumGenConfig::defaultConfig().method2D(false,false).setLabel("RooFoamGenerator") ;
68 RooNumGenConfig::defaultConfig().method2D(true ,false).setLabel("RooAcceptReject") ;
69 RooNumGenConfig::defaultConfig().method2D(false,true ).setLabel("RooAcceptReject") ;
70 RooNumGenConfig::defaultConfig().method2D(true, true ).setLabel("RooAcceptReject") ;
71
72 RooNumGenConfig::defaultConfig().methodND(false,false).setLabel("RooFoamGenerator") ;
73 RooNumGenConfig::defaultConfig().methodND(true ,false).setLabel("RooAcceptReject") ;
74 RooNumGenConfig::defaultConfig().methodND(false,true ).setLabel("RooAcceptReject") ;
75 RooNumGenConfig::defaultConfig().methodND(true, true ).setLabel("RooAcceptReject") ;
76
77}
78
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Destructor
83
85{
86 std::map<std::string,RooAbsNumGenerator*>::iterator iter = _map.begin() ;
87 while (iter != _map.end()) {
88 delete iter->second ;
89 ++iter ;
90 }
91}
92
93
94////////////////////////////////////////////////////////////////////////////////
95/// Copy constructor
96
98{
99}
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Static method returning reference to singleton instance of factory
105
107{
109 return instance;
110}
111
112
113////////////////////////////////////////////////////////////////////////////////
114/// Method accepting registration of a prototype numeric integrator along with a RooArgSet of its
115/// default configuration options and an optional list of names of other numeric integrators
116/// on which this integrator depends. Returns true if integrator was previously registered
117
119{
120 TString name = proto->ClassName() ;
121
122 if (getProtoSampler(name)) {
123 //cout << "RooNumGenFactory::storeSampler() ERROR: integrator '" << name << "' already registered" << endl ;
124 return true ;
125 }
126
127 // Add to factory
128 _map[name.Data()] = proto ;
129
130 // Add default config to master config
132
133 return false ;
134}
135
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Return prototype integrator with given (class) name
140
142{
143 if (_map.count(name)==0) {
144 return 0 ;
145 }
146
147 return _map[name] ;
148}
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Construct a numeric integrator instance that operates on function 'func' and is configured
154/// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
155/// of the integration, otherwise it is queried from 'func'. This function iterators over list
156/// of available prototype integrators and returns an clone attached to the given function of
157/// the first class that matches the specifications of the requested integration considering
158/// the number of dimensions, the nature of the limits (open ended vs closed) and the user
159/// preference stated in 'config'
160
161RooAbsNumGenerator* RooNumGenFactory::createSampler(RooAbsReal& func, const RooArgSet& genVars, const RooArgSet& condVars, const RooNumGenConfig& config, bool verbose, RooAbsReal* maxFuncVal)
162{
163 // Find method defined configuration
164 Int_t ndim = genVars.getSize() ;
165 bool cond = (condVars.getSize() > 0) ? true : false ;
166
167 bool hasCat(false) ;
168 for (const auto arg : genVars) {
169 if (arg->IsA()==RooCategory::Class()) {
170 hasCat=true ;
171 break ;
172 }
173 }
174
175
176 TString method ;
177 switch(ndim) {
178 case 1:
179 method = config.method1D(cond,hasCat).getCurrentLabel() ;
180 break ;
181
182 case 2:
183 method = config.method2D(cond,hasCat).getCurrentLabel() ;
184 break ;
185
186 default:
187 method = config.methodND(cond,hasCat).getCurrentLabel() ;
188 break ;
189 }
190
191 // Check that a method was defined for this case
192 if (!method.CompareTo("N/A")) {
193 oocoutE(nullptr,Integration) << "RooNumGenFactory::createSampler: No sampler method has been defined for "
194 << (cond?"a conditional ":"a ") << ndim << "-dimensional p.d.f" << endl ;
195 return 0 ;
196 }
197
198 // Retrieve proto integrator and return clone configured for the requested integration task
199 const RooAbsNumGenerator* proto = getProtoSampler(method) ;
200 RooAbsNumGenerator* engine = proto->clone(func,genVars,condVars,config,verbose,maxFuncVal) ;
201 return engine ;
202}
#define oocoutE(o, a)
Definition: RooMsgService.h:52
#define ClassImp(name)
Definition: Rtypes.h:375
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...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:64
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:57
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 ...
static RooNumGenFactory & instance()
Static method returning reference to singleton instance of factory.
RooAbsNumGenerator * createSampler(RooAbsReal &func, const RooArgSet &genVars, const RooArgSet &condVars, const RooNumGenConfig &config, bool verbose=false, RooAbsReal *maxFuncVal=0)
Construct a numeric integrator instance that operates on function 'func' and is configured with 'conf...
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:37
Basic string class.
Definition: TString.h:136
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:442
@ Integration
Definition: RooGlobalFunc.h:63