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 "RooFit.h"
35
36#include "RooNumGenFactory.h"
37#include "RooArgSet.h"
38#include "RooAbsFunc.h"
39#include "RooNumGenConfig.h"
40#include "RooNumber.h"
41
42#include "RooAcceptReject.h"
43#include "RooFoamGenerator.h"
44
45
46#include "RooMsgService.h"
47
48using namespace std ;
49
51
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// Constructor. Register all known integrators by calling
56/// their static registration functions
57
59{
62
63 // Prepare default
68
73
78
79}
80
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Destructor
85
87{
88 std::map<std::string,RooAbsNumGenerator*>::iterator iter = _map.begin() ;
89 while (iter != _map.end()) {
90 delete iter->second ;
91 ++iter ;
92 }
93}
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Copy constructor
98
100{
101}
102
103
104
105////////////////////////////////////////////////////////////////////////////////
106/// Static method returning reference to singleton instance of factory
107
109{
111 return instance;
112}
113
114
115////////////////////////////////////////////////////////////////////////////////
116/// Method accepting registration of a prototype numeric integrator along with a RooArgSet of its
117/// default configuration options and an optional list of names of other numeric integrators
118/// on which this integrator depends. Returns true if integrator was previously registered
119
121{
122 TString name = proto->IsA()->GetName() ;
123
124 if (getProtoSampler(name)) {
125 //cout << "RooNumGenFactory::storeSampler() ERROR: integrator '" << name << "' already registered" << endl ;
126 return kTRUE ;
127 }
128
129 // Add to factory
130 _map[name.Data()] = proto ;
131
132 // Add default config to master config
134
135 return kFALSE ;
136}
137
138
139
140////////////////////////////////////////////////////////////////////////////////
141/// Return prototype integrator with given (class) name
142
144{
145 if (_map.count(name)==0) {
146 return 0 ;
147 }
148
149 return _map[name] ;
150}
151
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Construct a numeric integrator instance that operates on function 'func' and is configured
156/// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
157/// of the integration, otherwise it is queried from 'func'. This function iterators over list
158/// of available prototype integrators and returns an clone attached to the given function of
159/// the first class that matches the specifications of the requested integration considering
160/// the number of dimensions, the nature of the limits (open ended vs closed) and the user
161/// preference stated in 'config'
162
163RooAbsNumGenerator* RooNumGenFactory::createSampler(RooAbsReal& func, const RooArgSet& genVars, const RooArgSet& condVars, const RooNumGenConfig& config, Bool_t verbose, RooAbsReal* maxFuncVal)
164{
165 // Find method defined configuration
166 Int_t ndim = genVars.getSize() ;
167 Bool_t cond = (condVars.getSize() > 0) ? kTRUE : kFALSE ;
168
169 Bool_t hasCat(kFALSE) ;
170 for (const auto arg : genVars) {
171 if (arg->IsA()==RooCategory::Class()) {
172 hasCat=kTRUE ;
173 break ;
174 }
175 }
176
177
178 TString method ;
179 switch(ndim) {
180 case 1:
181 method = config.method1D(cond,hasCat).getCurrentLabel() ;
182 break ;
183
184 case 2:
185 method = config.method2D(cond,hasCat).getCurrentLabel() ;
186 break ;
187
188 default:
189 method = config.methodND(cond,hasCat).getCurrentLabel() ;
190 break ;
191 }
192
193 // Check that a method was defined for this case
194 if (!method.CompareTo("N/A")) {
195 oocoutE((TObject*)0,Integration) << "RooNumGenFactory::createSampler: No sampler method has been defined for "
196 << (cond?"a conditional ":"a ") << ndim << "-dimensional p.d.f" << endl ;
197 return 0 ;
198 }
199
200 // Retrieve proto integrator and return clone configured for the requested integration task
201 const RooAbsNumGenerator* proto = getProtoSampler(method) ;
202 RooAbsNumGenerator* engine = proto->clone(func,genVars,condVars,config,verbose,maxFuncVal) ;
203 return engine ;
204}
#define oocoutE(o, a)
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:16613
virtual const char * getCurrentLabel() const
Return label string of current state.
Int_t getSize() const
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_t verbose=kFALSE, const RooAbsReal *maxFuncVal=0) const =0
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:35
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
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...
RooCategory & method2D(Bool_t cond, Bool_t cat)
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
RooCategory & methodND(Bool_t cond, Bool_t cat)
Bool_t addConfigSection(const RooAbsNumGenerator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
RooCategory & method1D(Bool_t cond, Bool_t 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_t verbose=kFALSE, RooAbsReal *maxFuncVal=0)
Construct a numeric integrator instance that operates on function 'func' and is configured with 'conf...
RooNumGenFactory()
Constructor.
virtual ~RooNumGenFactory()
Destructor.
std::map< std::string, RooAbsNumGenerator * > _map
const RooAbsNumGenerator * getProtoSampler(const char *name)
Return prototype integrator with given (class) name.
Bool_t storeProtoSampler(RooAbsNumGenerator *proto, const RooArgSet &defConfig)
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
Mother of all ROOT objects.
Definition TObject.h:41
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