Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RooNumGenFactory.cxx
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*****************************************************************************
4 * Project: RooFit *
5 * Package: RooFitCore *
6 * @(#)root/roofitcore:$Id$
7 * Authors: *
8 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
9 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
10 * *
11 * Copyright (c) 2000-2005, Regents of the University of California *
12 * and Stanford University. All rights reserved. *
13 * *
14 * Redistribution and use in source and binary forms, *
15 * with or without modification, are permitted according to the terms *
16 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
17 *****************************************************************************/
18
19/**
20\file RooNumGenFactory.cxx
21\class RooNumGenFactory
22\ingroup Roofitcore
23
24%Factory to instantiate numeric integrators
25from a given function binding and a given configuration. The factory
26searches for a numeric integrator registered with the factory that
27has the ability to perform the numeric integration. The choice of
28method may depend on the number of dimensions integrated,
29the nature of the integration limits (closed or open ended) and
30the preference of the caller as encoded in the configuration object.
31**/
32
33#include "TClass.h"
34#include "Riostream.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
48
49////////////////////////////////////////////////////////////////////////////////
50/// Constructor. Register all known integrators by calling
51/// their static registration functions
52
53RooNumGenFactory::RooNumGenFactory()
54{
55 RooAcceptReject::registerSampler(*this) ;
56 RooFoamGenerator::registerSampler(*this) ;
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
81RooNumGenFactory::~RooNumGenFactory()
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
94RooNumGenFactory::RooNumGenFactory(const RooNumGenFactory& other) : TObject(other)
95{
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Static method returning reference to singleton instance of factory
102
103RooNumGenFactory& RooNumGenFactory::instance()
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
115bool RooNumGenFactory::storeProtoSampler(RooAbsNumGenerator* proto, const RooArgSet& defConfig)
116{
117 TString name = proto->generatorName() ;
118
119 if (getProtoSampler(name)) {
120 //cout << "RooNumGenFactory::storeSampler() ERROR: integrator '" << name << "' already registered" << std::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
138const RooAbsNumGenerator* RooNumGenFactory::getProtoSampler(const char* name)
139{
140 if (_map.count(name)==0) {
141 return nullptr ;
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.size() ;
162 bool cond = (!condVars.empty()) ? 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
174 switch(ndim) {
175 case 1:
177 break ;
178
179 case 2:
181 break ;
182
183 default:
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" << std::endl;
192 return nullptr ;
193 }
194
195 // Retrieve proto integrator and return clone configured for the requested integration task
197 RooAbsNumGenerator* engine = proto->clone(func,genVars,condVars,config,verbose,maxFuncVal) ;
198 return engine ;
199}
200
201/// \endcond
static Roo_reg_AGKInteg1D instance
#define oocoutE(o, a)
int Int_t
Definition RtypesCore.h:45
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:17535
const_iterator begin() const
virtual const char * getCurrentLabel() const
Return label string of current state.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
static TClass * Class()
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)
RooCategory & methodND(bool cond, bool cat)
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139