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