Logo ROOT   6.08/07
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 #include "RooSentinel.h"
45 
46 
47 #include "RooMsgService.h"
48 
49 using namespace std ;
50 
52 ;
53 
55 
56 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Constructor. Register all known integrators by calling
60 /// their static registration functions
61 
63 {
64  _instance = this ;
65 
68 
69  // Prepare default
74 
79 
84 
85 }
86 
87 
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Destructor
91 
93 {
94  std::map<std::string,RooAbsNumGenerator*>::iterator iter = _map.begin() ;
95  while (iter != _map.end()) {
96  delete iter->second ;
97  ++iter ;
98  }
99 }
100 
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Copy constructor
104 
106 {
107 }
108 
109 
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Static method returning reference to singleton instance of factory
113 
115 {
116  if (_instance==0) {
117  new RooNumGenFactory ;
119  }
120  return *_instance ;
121 }
122 
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Cleanup routine called by atexit() handler installed by RooSentinel
126 
128 {
129  if (_instance) {
130  delete _instance ;
131  _instance = 0 ;
132  }
133 }
134 
135 
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Method accepting registration of a prototype numeric integrator along with a RooArgSet of its
139 /// default configuration options and an optional list of names of other numeric integrators
140 /// on which this integrator depends. Returns true if integrator was previously registered
141 
143 {
144  TString name = proto->IsA()->GetName() ;
145 
146  if (getProtoSampler(name)) {
147  //cout << "RooNumGenFactory::storeSampler() ERROR: integrator '" << name << "' already registered" << endl ;
148  return kTRUE ;
149  }
150 
151  // Add to factory
152  _map[name.Data()] = proto ;
153 
154  // Add default config to master config
156 
157  return kFALSE ;
158 }
159 
160 
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Return prototype integrator with given (class) name
164 
166 {
167  if (_map.count(name)==0) {
168  return 0 ;
169  }
170 
171  return _map[name] ;
172 }
173 
174 
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Construct a numeric integrator instance that operates on function 'func' and is configured
178 /// with 'config'. If ndimPreset is greater than zero that number is taken as the dimensionality
179 /// of the integration, otherwise it is queried from 'func'. This function iterators over list
180 /// of available prototype integrators and returns an clone attached to the given function of
181 /// the first class that matches the specifications of the requested integration considering
182 /// the number of dimensions, the nature of the limits (open ended vs closed) and the user
183 /// preference stated in 'config'
184 
186 {
187  // Find method defined configuration
188  Int_t ndim = genVars.getSize() ;
189  Bool_t cond = (condVars.getSize() > 0) ? kTRUE : kFALSE ;
190 
191  Bool_t hasCat(kFALSE) ;
192  TIterator* iter = genVars.createIterator() ;
193  RooAbsArg* arg ;
194  while ((arg=(RooAbsArg*)iter->Next())) {
195  if (arg->IsA()==RooCategory::Class()) {
196  hasCat=kTRUE ;
197  break ;
198  }
199  }
200  delete iter ;
201 
202 
203  TString method ;
204  switch(ndim) {
205  case 1:
206  method = config.method1D(cond,hasCat).getLabel() ;
207  break ;
208 
209  case 2:
210  method = config.method2D(cond,hasCat).getLabel() ;
211  break ;
212 
213  default:
214  method = config.methodND(cond,hasCat).getLabel() ;
215  break ;
216  }
217 
218  // Check that a method was defined for this case
219  if (!method.CompareTo("N/A")) {
220  oocoutE((TObject*)0,Integration) << "RooNumGenFactory::createSampler: No sampler method has been defined for "
221  << (cond?"a conditional ":"a ") << ndim << "-dimensional p.d.f" << endl ;
222  return 0 ;
223  }
224 
225  // Retrieve proto integrator and return clone configured for the requested integration task
226  const RooAbsNumGenerator* proto = getProtoSampler(method) ;
227  RooAbsNumGenerator* engine = proto->clone(func,genVars,condVars,config,verbose,maxFuncVal) ;
228  return engine ;
229 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TIterator * createIterator(Bool_t dir=kIterForward) const
RooCategory & methodND(Bool_t cond, Bool_t cat)
const RooAbsNumGenerator * getProtoSampler(const char *name)
Return prototype integrator with given (class) name.
virtual RooAbsNumGenerator * clone(const RooAbsReal &, const RooArgSet &genVars, const RooArgSet &condVars, const RooNumGenConfig &config, Bool_t verbose=kFALSE, const RooAbsReal *maxFuncVal=0) const =0
virtual ~RooNumGenFactory()
Destructor.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
const char * Class
Definition: TXMLSetup.cxx:64
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 &#39;func&#39; and is configured with &#39;conf...
static void cleanup()
Cleanup routine called by atexit() handler installed by RooSentinel.
Iterator abstract base class.
Definition: TIterator.h:32
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
#define oocoutE(o, a)
Definition: RooMsgService.h:48
RooNumGenFactory()
Constructor.
Int_t getSize() const
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
bool verbose
Class RooAbsNumGenerator is the abstract base class for MC event generator implementations like RooAc...
Bool_t storeProtoSampler(RooAbsNumGenerator *proto, const RooArgSet &defConfig)
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
Definition: RooSentinel.cxx:71
#define ClassImp(name)
Definition: Rtypes.h:279
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
double func(double *x, double *p)
Definition: stressTF1.cxx:213
Bool_t addConfigSection(const RooAbsNumGenerator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
virtual const char * getLabel() const
Return label string of current state.
Definition: RooCategory.h:40
std::map< std::string, RooAbsNumGenerator * > _map
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Next()=0
static RooNumGenFactory & instance()
Static method returning reference to singleton instance of factory.
const char * proto
Definition: civetweb.c:11652
RooNumGenConfig holds the configuration parameters of the various numeric integrators used by RooReal...
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
RooNumGenFactory is a factory to instantiate numeric integrators from a given function binding and a ...
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
char name[80]
Definition: TGX11.cxx:109
static RooNumGenFactory * _instance
RooCategory & method2D(Bool_t cond, Bool_t cat)
RooCategory & method1D(Bool_t cond, Bool_t cat)