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