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 
22 RooNumGenFactory is a factory to instantiate numeric integrators
23 from a given function binding and a given configuration. The factory
24 searches for a numeric integrator registered with the factory that
25 has the ability to perform the numeric integration. The choice of
26 method may depend on the number of dimensions integrated,
27 the nature of the integration limits (closed or open ended) and
28 the 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 
48 using 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 {
110  static RooNumGenFactory instance;
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 
163 RooAbsNumGenerator* 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 }
RooFoamGenerator::registerSampler
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
Definition: RooFoamGenerator.cxx:70
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooMsgService.h
RooFit.h
RooArgSet.h
RooNumGenConfig::addConfigSection
Bool_t addConfigSection(const RooAbsNumGenerator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
Definition: RooNumGenConfig.cxx:246
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooFoamGenerator.h
RooAcceptReject::registerSampler
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
Definition: RooAcceptReject.cxx:61
RooNumGenFactory.h
RooNumGenConfig::methodND
RooCategory & methodND(Bool_t cond, Bool_t cat)
Definition: RooNumGenConfig.cxx:204
RooAbsFunc.h
TClass.h
RooAbsReal
Definition: RooAbsReal.h:61
RooNumGenConfig::method2D
RooCategory & method2D(Bool_t cond, Bool_t cat)
Definition: RooNumGenConfig.cxx:192
oocoutE
#define oocoutE(o, a)
Definition: RooMsgService.h:48
TString
Definition: TString.h:136
RooNumGenFactory::storeProtoSampler
Bool_t storeProtoSampler(RooAbsNumGenerator *proto, const RooArgSet &defConfig)
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
Definition: RooNumGenFactory.cxx:120
RooAbsCategory::getCurrentLabel
virtual const char * getCurrentLabel() const
Return label string of current state.
Definition: RooAbsCategory.cxx:130
RooNumGenFactory
Definition: RooNumGenFactory.h:30
bool
RooNumGenFactory::~RooNumGenFactory
virtual ~RooNumGenFactory()
Destructor.
Definition: RooNumGenFactory.cxx:86
RooNumGenFactory::_map
std::map< std::string, RooAbsNumGenerator * > _map
Definition: RooNumGenFactory.h:47
RooCategory::setLabel
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Definition: RooCategory.cxx:185
RooAcceptReject.h
RooNumGenFactory::createSampler
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...
Definition: RooNumGenFactory.cxx:163
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooAbsNumGenerator
Definition: RooAbsNumGenerator.h:30
RooNumGenConfig::method1D
RooCategory & method1D(Bool_t cond, Bool_t cat)
Definition: RooNumGenConfig.cxx:180
RooNumGenConfig::defaultConfig
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
Definition: RooNumGenConfig.cxx:48
RooNumGenFactory::RooNumGenFactory
RooNumGenFactory()
Constructor.
Definition: RooNumGenFactory.cxx:58
RooNumber.h
proto
const char * proto
Definition: civetweb.c:16604
TString::CompareTo
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
RooNumGenConfig
Definition: RooNumGenConfig.h:25
RooNumGenFactory::instance
static RooNumGenFactory & instance()
Static method returning reference to singleton instance of factory.
Definition: RooNumGenFactory.cxx:108
TObject
Definition: TObject.h:37
RooNumGenConfig.h
name
char name[80]
Definition: TGX11.cxx:110
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
Class
void Class()
Definition: Class.C:29
RooFit::Integration
@ Integration
Definition: RooGlobalFunc.h:67
Riostream.h
RooNumGenFactory::getProtoSampler
const RooAbsNumGenerator * getProtoSampler(const char *name)
Return prototype integrator with given (class) name.
Definition: RooNumGenFactory.cxx:143
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooArgSet
Definition: RooArgSet.h:28
int