Logo ROOT   6.08/07
Reference Guide
RooNumGenConfig.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 RooNumGenConfig.cxx
19 \class RooNumGenConfig
20 \ingroup Roofitcore
21 
22 RooNumGenConfig holds the configuration parameters of the various
23 numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
24 use this class in the (normalization) integral configuration interface
25 **/
26 
27 #include "RooFit.h"
28 #include "Riostream.h"
29 
30 #include "RooNumGenConfig.h"
31 #include "RooArgSet.h"
32 #include "RooAbsNumGenerator.h"
33 #include "RooNumGenFactory.h"
34 #include "RooMsgService.h"
35 
36 #include "TClass.h"
37 
38 
39 
40 using namespace std;
41 
43 ;
44 
46 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Function called by atexit() handler installed by RooSentinel to
50 /// cleanup global objects at end of job
51 
53 {
54  if (_default) {
55  delete _default ;
56  _default = 0 ;
57  }
58 }
59 
60 
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Return reference to instance of default numeric integrator configuration object
64 
66 {
67  // Instantiate object if it doesn't exist yet
68  if (_default==0) {
69  _default = new RooNumGenConfig ;
71  }
72  return *_default ;
73 }
74 
75 
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Constructor
79 
81  _method1D("method1D","1D sampling method"),
82  _method1DCat("method1DCat","1D sampling method for pdfs with categories"),
83  _method1DCond("method1DCond","1D sampling method for conditional pfs"),
84  _method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
85  _method2D("method2D","2D sampling method"),
86  _method2DCat("method2DCat","2D sampling method for pdfs with categories"),
87  _method2DCond("method2DCond","2D sampling method for conditional pfs"),
88  _method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
89  _methodND("methodND","ND sampling method"),
90  _methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
91  _methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
92  _methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
93 {
94  // Set all methods to undefined
95  // Defined methods will be registered by static initialization routines
96  // of the various numeric integrator engines
97  _method1D.defineType("N/A",0) ;
98  _method1DCat.defineType("N/A",0) ;
99  _method1DCond.defineType("N/A",0) ;
100  _method1DCondCat.defineType("N/A",0) ;
101 
102  _method2D.defineType("N/A",0) ;
103  _method2DCat.defineType("N/A",0) ;
104  _method2DCond.defineType("N/A",0) ;
105  _method2DCondCat.defineType("N/A",0) ;
106 
107  _methodND.defineType("N/A",0) ;
108  _methodNDCat.defineType("N/A",0) ;
109  _methodNDCond.defineType("N/A",0) ;
110  _methodNDCondCat.defineType("N/A",0) ;
111 }
112 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Destructor
116 
118 {
119  // Delete all configuration data
120  _configSets.Delete() ;
121 }
122 
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Copy constructor
126 
128  TObject(other), RooPrintable(other),
129  _method1D(other._method1D),
130  _method1DCat(other._method1DCat),
133  _method2D(other._method2D),
134  _method2DCat(other._method2DCat),
137  _methodND(other._methodND),
138  _methodNDCat(other._methodNDCat),
141 {
142  // Clone all configuration dat
143  TIterator* iter = other._configSets.MakeIterator() ;
144  RooArgSet* set ;
145  while((set=(RooArgSet*)iter->Next())) {
146  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
147  setCopy->setName(set->GetName()) ;
148  _configSets.Add(setCopy);
149  }
150  delete iter ;
151 }
152 
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Assignment operator from other RooNumGenConfig
156 
158 {
159  // Prevent self-assignment
160  if (&other==this) {
161  return *this ;
162  }
163 
164  // Copy common properties
169 
174 
179 
180  // Delete old integrator-specific configuration data
181  _configSets.Delete() ;
182 
183  // Copy new integrator-specific data
184  TIterator* iter = other._configSets.MakeIterator() ;
185  RooArgSet* set ;
186  while((set=(RooArgSet*)iter->Next())) {
187  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
188  setCopy->setName(set->GetName()) ;
189  _configSets.Add(setCopy);
190  }
191  delete iter ;
192 
193  return *this ;
194 }
195 
196 
197 
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 
202 {
203  if (cond && cat) return _method1DCondCat ;
204  if (cond) return _method1DCond ;
205  if (cat) return _method1DCat ;
206  return _method1D ;
207 }
208 
209 
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 
214 {
215  if (cond && cat) return _method2DCondCat ;
216  if (cond) return _method2DCond ;
217  if (cat) return _method2DCat ;
218  return _method2D ;
219 }
220 
221 
222 
223 ////////////////////////////////////////////////////////////////////////////////
224 
226 {
227  if (cond && cat) return _methodNDCondCat ;
228  if (cond) return _methodNDCond ;
229  if (cat) return _methodNDCat ;
230  return _methodND ;
231 }
232 
233 
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 
238 {
239  return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
240 }
241 
242 
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 
247 {
248  return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
249 }
250 
251 
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 
256 {
257  return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
258 }
259 
260 
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 /// Add a configuration section for a particular integrator. Integrator name and capabilities are
264 /// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
265 /// as the default configuration for the integrator.
266 
268 {
269  TString name = proto->IsA()->GetName() ;
270 
271  // Register integrator for appropriate dimensionalities
272 
273  _method1D.defineType(name) ;
274  _method2D.defineType(name) ;
275  _methodND.defineType(name) ;
276 
277  if (proto->canSampleConditional()) {
278  _method1DCond.defineType(name) ;
279  _method2DCond.defineType(name) ;
280  _methodNDCond.defineType(name) ;
281  }
282  if (proto->canSampleCategories()) {
283  _method1DCat.defineType(name) ;
284  _method2DCat.defineType(name) ;
285  _methodNDCat.defineType(name) ;
286  }
287 
288  if (proto->canSampleConditional() && proto->canSampleCategories()) {
292  }
293 
294  // Store default configuration parameters
295  RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
296  config->setName(name) ;
297  _configSets.Add(config) ;
298 
299  return kFALSE ;
300 }
301 
302 
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Return section with configuration parameters for integrator with given (class) name
306 
308 {
309  return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
310 }
311 
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Retrieve configuration information specific to integrator with given name
315 
317 {
318  static RooArgSet dummy ;
319  RooArgSet* config = (RooArgSet*) _configSets.FindObject(name) ;
320  if (!config) {
321  oocoutE((TObject*)0,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
322  return dummy ;
323  }
324  return *config ;
325 }
326 
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 
331 {
332  if (!opt) {
333  return kStandard ;
334  }
335 
336  TString o(opt) ;
337  o.ToLower() ;
338 
339  if (o.Contains("v")) {
340  return kVerbose ;
341  }
342  return kStandard ;
343 }
344 
345 
346 
347 ////////////////////////////////////////////////////////////////////////////////
348 /// Detailed printing interface
349 
350 void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
351 {
352  os << endl ;
353  os << indent << "1-D sampling method: " << _method1D.getLabel() << endl ;
355  os << " (" << _method1DCat.getLabel() << " if with categories)" << endl ;
356  }
358  os << " (" << _method1DCond.getLabel() << " if conditional)" << endl ;
359  }
361  os << " (" << _method1DCondCat.getLabel() << " if conditional with categories)" << endl ;
362  }
363  os << endl ;
364 
365  os << indent << "2-D sampling method: " << _method2D.getLabel() << endl ;
367  os << " (" << _method2DCat.getLabel() << " if with categories)" << endl ;
368  }
370  os << " (" << _method2DCond.getLabel() << " if conditional)" << endl ;
371  }
373  os << " (" << _method2DCondCat.getLabel() << " if conditional with categories)" << endl ;
374  }
375  os << endl ;
376 
377  os << indent << "N-D sampling method: " << _methodND.getLabel() << endl ;
379  os << " (" << _methodNDCat.getLabel() << " if with categories)" << endl ;
380  }
382  os << " (" << _methodNDCond.getLabel() << " if conditional)" << endl ;
383  }
385  os << " (" << _methodNDCondCat.getLabel() << " if conditional with categories)" << endl ;
386  }
387  os << endl ;
388 
389  if (verbose) {
390 
391  os << endl << "Available sampling methods:" << endl << endl ;
392  TIterator* cIter = _configSets.MakeIterator() ;
393  RooArgSet* configSet ;
394  while ((configSet=(RooArgSet*)cIter->Next())) {
395 
396  os << indent << "*** " << configSet->GetName() << " ***" << endl ;
397  os << indent << "Capabilities: " ;
399  if (proto->canSampleConditional()) os << "[Conditional] " ;
400  if (proto->canSampleCategories()) os << "[Categories] " ;
401  os << endl ;
402 
403  os << "Configuration: " << endl ;
404  configSet->printMultiline(os,kName|kValue|kTitle) ;
405  os << endl ;
406 
407  }
408 
409  delete cIter ;
410  }
411 }
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
RooCategory & methodND(Bool_t cond, Bool_t cat)
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
const RooAbsNumGenerator * getProtoSampler(const char *name)
Return prototype integrator with given (class) name.
RooLinkedList _configSets
RooCategory _method1DCond
const char Option_t
Definition: RtypesCore.h:62
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)
Set value by specifying the index code of the desired state.
virtual Bool_t canSampleConditional() const
RooCategory _methodNDCondCat
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
RooCategory _methodNDCat
Iterator abstract base class.
Definition: TIterator.h:32
RooPlotable is a &#39;mix-in&#39; base class that define the standard RooFit plotting and printing methods...
Definition: RooPrintable.h:26
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose, TString indent="") const
Detailed printing interface.
#define oocoutE(o, a)
Definition: RooMsgService.h:48
virtual Bool_t canSampleCategories() const
RooNumGenConfig & operator=(const RooNumGenConfig &other)
Assignment operator from other RooNumGenConfig.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
RooCategory _method1D
bool verbose
Class RooAbsNumGenerator is the abstract base class for MC event generator implementations like RooAc...
static void indent(ostringstream &buf, int indent_level)
RooCategory _method2D
virtual ~RooNumGenConfig()
Destructor.
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:25
virtual Int_t getIndex() const
Return index number of current state.
Definition: RooCategory.h:35
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements...
#define ClassImp(name)
Definition: Rtypes.h:279
RooNumGenConfig()
Constructor.
RooCategory _methodNDCond
RooCategory _methodND
static RooMathCoreReg dummy
RooCategory _method2DCat
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Implement multiline printin of collection, one line for each ontained object showing the requested co...
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
RooCategory _method2DCond
RooCategory _method1DCat
const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
Definition: TObject.h:37
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
virtual TObject * Next()=0
RooCategory _method2DCondCat
void setName(const char *name)
static RooNumGenFactory & instance()
Static method returning reference to singleton instance of factory.
RooCategory _method1DCondCat
const char * proto
Definition: civetweb.c:11652
Bool_t defineType(const char *label)
Define a state with given name, the lowest available positive integer is assigned as index...
RooNumGenConfig holds the configuration parameters of the various numeric integrators used by RooReal...
static RooNumGenConfig * _default
static void cleanup()
Function called by atexit() handler installed by RooSentinel to cleanup global objects at end of job...
char name[80]
Definition: TGX11.cxx:109
RooCategory & method2D(Bool_t cond, Bool_t cat)
RooCategory & method1D(Bool_t cond, Bool_t cat)