Logo ROOT  
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
22RooNumGenConfig holds the configuration parameters of the various
23numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
24use this class in the (normalization) integral configuration interface
25**/
26
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
36using namespace std;
37
39
40
41////////////////////////////////////////////////////////////////////////////////
42/// Return reference to instance of default numeric integrator configuration object
43
45{
47 return defaultConfig;
48}
49
50
51
52////////////////////////////////////////////////////////////////////////////////
53/// Constructor
54
56 _method1D("method1D","1D sampling method"),
57 _method1DCat("method1DCat","1D sampling method for pdfs with categories"),
58 _method1DCond("method1DCond","1D sampling method for conditional pfs"),
59 _method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
60 _method2D("method2D","2D sampling method"),
61 _method2DCat("method2DCat","2D sampling method for pdfs with categories"),
62 _method2DCond("method2DCond","2D sampling method for conditional pfs"),
63 _method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
64 _methodND("methodND","ND sampling method"),
65 _methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
66 _methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
67 _methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
68{
69 // Set all methods to undefined
70 // Defined methods will be registered by static initialization routines
71 // of the various numeric integrator engines
72 _method1D.defineType("N/A",0) ;
73 _method1DCat.defineType("N/A",0) ;
74 _method1DCond.defineType("N/A",0) ;
76
77 _method2D.defineType("N/A",0) ;
78 _method2DCat.defineType("N/A",0) ;
79 _method2DCond.defineType("N/A",0) ;
81
82 _methodND.defineType("N/A",0) ;
83 _methodNDCat.defineType("N/A",0) ;
84 _methodNDCond.defineType("N/A",0) ;
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Destructor
91
93{
94 // Delete all configuration data
96}
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// Copy constructor
101
103 TObject(other), RooPrintable(other),
104 _method1D(other._method1D),
105 _method1DCat(other._method1DCat),
106 _method1DCond(other._method1DCond),
107 _method1DCondCat(other._method1DCondCat),
108 _method2D(other._method2D),
109 _method2DCat(other._method2DCat),
110 _method2DCond(other._method2DCond),
111 _method2DCondCat(other._method2DCondCat),
112 _methodND(other._methodND),
113 _methodNDCat(other._methodNDCat),
114 _methodNDCond(other._methodNDCond),
115 _methodNDCondCat(other._methodNDCondCat)
116{
117 // Clone all configuration dat
118 for (auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
119 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
120 setCopy->setName(set->GetName()) ;
121 _configSets.Add(setCopy);
122 }
123}
124
125
126////////////////////////////////////////////////////////////////////////////////
127/// Assignment operator from other RooNumGenConfig
128
130{
131 // Prevent self-assignment
132 if (&other==this) {
133 return *this ;
134 }
135
136 // Copy common properties
141
146
151
152 // Delete old integrator-specific configuration data
154
155 // Copy new integrator-specific data
156 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
157 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
158 setCopy->setName(set->GetName()) ;
159 _configSets.Add(setCopy);
160 }
161
162 return *this ;
163}
164
165
166
167
168////////////////////////////////////////////////////////////////////////////////
169
171{
172 if (cond && cat) return _method1DCondCat ;
173 if (cond) return _method1DCond ;
174 if (cat) return _method1DCat ;
175 return _method1D ;
176}
177
178
179
180////////////////////////////////////////////////////////////////////////////////
181
183{
184 if (cond && cat) return _method2DCondCat ;
185 if (cond) return _method2DCond ;
186 if (cat) return _method2DCat ;
187 return _method2D ;
188}
189
190
191
192////////////////////////////////////////////////////////////////////////////////
193
195{
196 if (cond && cat) return _methodNDCondCat ;
197 if (cond) return _methodNDCond ;
198 if (cat) return _methodNDCat ;
199 return _methodND ;
200}
201
202
203
204////////////////////////////////////////////////////////////////////////////////
205
206const RooCategory& RooNumGenConfig::method1D(bool cond, bool cat) const
207{
208 return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
209}
210
211
212
213////////////////////////////////////////////////////////////////////////////////
214
215const RooCategory& RooNumGenConfig::method2D(bool cond, bool cat) const
216{
217 return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
218}
219
220
221
222////////////////////////////////////////////////////////////////////////////////
223
224const RooCategory& RooNumGenConfig::methodND(bool cond, bool cat) const
225{
226 return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
227}
228
229
230
231////////////////////////////////////////////////////////////////////////////////
232/// Add a configuration section for a particular integrator. Integrator name and capabilities are
233/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
234/// as the default configuration for the integrator.
235
237{
238 std::string name = proto->ClassName();
239
240 // Register integrator for appropriate dimensionalities
241
245
246 if (proto->canSampleConditional()) {
250 }
251 if (proto->canSampleCategories()) {
255 }
256
257 if (proto->canSampleConditional() && proto->canSampleCategories()) {
261 }
262
263 // Store default configuration parameters
264 RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
265 config->setName(name.c_str());
266 _configSets.Add(config) ;
267
268 return false ;
269}
270
271
272
273////////////////////////////////////////////////////////////////////////////////
274/// Return section with configuration parameters for integrator with given (class) name
275
277{
278 return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
279}
280
281
282////////////////////////////////////////////////////////////////////////////////
283/// Retrieve configuration information specific to integrator with given name
284
286{
287 static RooArgSet dummy ;
289 if (!config) {
290 oocoutE(nullptr,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
291 return dummy ;
292 }
293 return *config ;
294}
295
296
297////////////////////////////////////////////////////////////////////////////////
298
300{
301 if (!opt) {
302 return kStandard ;
303 }
304
305 TString o(opt) ;
306 o.ToLower() ;
307
308 if (o.Contains("v")) {
309 return kVerbose ;
310 }
311 return kStandard ;
312}
313
314
315
316////////////////////////////////////////////////////////////////////////////////
317/// Detailed printing interface
318
319void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, bool verbose, TString indent) const
320{
321 os << endl ;
322 os << indent << "1-D sampling method: " << _method1D.getCurrentLabel() << endl ;
324 os << " (" << _method1DCat.getCurrentLabel() << " if with categories)" << endl ;
325 }
327 os << " (" << _method1DCond.getCurrentLabel() << " if conditional)" << endl ;
328 }
330 os << " (" << _method1DCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
331 }
332 os << endl ;
333
334 os << indent << "2-D sampling method: " << _method2D.getCurrentLabel() << endl ;
336 os << " (" << _method2DCat.getCurrentLabel() << " if with categories)" << endl ;
337 }
339 os << " (" << _method2DCond.getCurrentLabel() << " if conditional)" << endl ;
340 }
342 os << " (" << _method2DCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
343 }
344 os << endl ;
345
346 os << indent << "N-D sampling method: " << _methodND.getCurrentLabel() << endl ;
348 os << " (" << _methodNDCat.getCurrentLabel() << " if with categories)" << endl ;
349 }
351 os << " (" << _methodNDCond.getCurrentLabel() << " if conditional)" << endl ;
352 }
354 os << " (" << _methodNDCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
355 }
356 os << endl ;
357
358 if (verbose) {
359
360 os << endl << "Available sampling methods:" << endl << endl ;
361 for(auto * configSet : static_range_cast<RooArgSet*>(_configSets)) {
362
363 os << indent << "*** " << configSet->GetName() << " ***" << endl ;
364 os << indent << "Capabilities: " ;
365 const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
366 if (proto->canSampleConditional()) os << "[Conditional] " ;
367 if (proto->canSampleCategories()) os << "[Categories] " ;
368 os << endl ;
369
370 os << "Configuration: " << endl ;
371 configSet->printMultiline(os,kName|kValue|kTitle) ;
372 os << endl ;
373
374 }
375 }
376}
#define oocoutE(o, a)
Definition: RooMsgService.h:52
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:110
const char * proto
Definition: civetweb.c:17502
virtual const char * getCurrentLabel() const
Return label string of current state.
void setName(const char *name)
Class RooAbsNumGenerator is the abstract base class for MC event generator implementations like RooAc...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:179
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:28
bool setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
bool defineType(const std::string &label)
Define a state with given name.
value_type getCurrentIndex() const final
Return current index.
Definition: RooCategory.h:40
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:67
TObject * FindObject(const char *name) const override
Return pointer to obejct with given name.
RooNumGenConfig holds the configuration parameters of the various numeric integrators used by RooReal...
RooCategory _methodND
Selects integration method for ND p.d.f.s.
RooCategory _methodNDCondCat
Selects integration method for ND conditional p.d.f.s with categories.
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
RooNumGenConfig()
Constructor.
RooCategory & method2D(bool cond, bool cat)
void printMultiline(std::ostream &os, Int_t content, bool verbose, TString indent="") const override
Detailed printing interface.
RooCategory & method1D(bool cond, bool cat)
RooCategory _method2D
Selects integration method for 2D p.d.f.s.
RooCategory _method1DCondCat
Selects integration method for 1D conditional p.d.f.s with categories.
RooCategory _method2DCat
Selects integration method for 2D p.d.f.s with categories.
bool addConfigSection(const RooAbsNumGenerator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
RooCategory _method1DCond
Selects integration method for 1D conditional p.d.f.s.
RooCategory _method2DCondCat
Selects integration method for 2D conditional p.d.f.s with categories.
~RooNumGenConfig() override
Destructor.
RooCategory _method1DCat
Selects integration method for 1D p.d.f.s with categories.
RooCategory _method1D
Selects integration method for 1D p.d.f.s.
RooCategory _method2DCond
Selects integration method for 2D conditional p.d.f.s.
RooLinkedList _configSets
List of configuration sets for individual integration methods.
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
RooNumGenConfig & operator=(const RooNumGenConfig &other)
Assignment operator from other RooNumGenConfig.
RooCategory _methodNDCat
Selects integration method for ND p.d.f.s with categories.
RooCategory _methodNDCond
Selects integration method for ND conditional p.d.f.s.
StyleOption defaultPrintStyle(Option_t *opt) const override
RooCategory & methodND(bool cond, bool cat)
static RooNumGenFactory & instance()
Static method returning reference to singleton instance of factory.
const RooAbsNumGenerator * getProtoSampler(const char *name)
Return prototype integrator with given (class) name.
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
virtual void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const
Interface for detailed printing of object.
Mother of all ROOT objects.
Definition: TObject.h:41
Basic string class.
Definition: TString.h:136
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1159
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
@ InputArguments
Definition: RooGlobalFunc.h:62