Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22Holds 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 std::endl, std::ostream;
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 = new RooArgSet;
120 set->snapshot(*setCopy) ;
121 setCopy->setName(set->GetName()) ;
122 _configSets.Add(setCopy);
123 }
124}
125
126
127////////////////////////////////////////////////////////////////////////////////
128/// Assignment operator from other RooNumGenConfig
129
131{
132 // Prevent self-assignment
133 if (&other==this) {
134 return *this ;
135 }
136
137 // Copy common properties
142
147
152
153 // Delete old integrator-specific configuration data
155
156 // Copy new integrator-specific data
157 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
158 RooArgSet* setCopy = new RooArgSet;
159 set->snapshot(*setCopy);
160 setCopy->setName(set->GetName()) ;
161 _configSets.Add(setCopy);
162 }
163
164 return *this ;
165}
166
167
168
169
170////////////////////////////////////////////////////////////////////////////////
171
173{
174 if (cond && cat) return _method1DCondCat ;
175 if (cond) return _method1DCond ;
176 if (cat) return _method1DCat ;
177 return _method1D ;
178}
179
180
181
182////////////////////////////////////////////////////////////////////////////////
183
185{
186 if (cond && cat) return _method2DCondCat ;
187 if (cond) return _method2DCond ;
188 if (cat) return _method2DCat ;
189 return _method2D ;
190}
191
192
193
194////////////////////////////////////////////////////////////////////////////////
195
197{
198 if (cond && cat) return _methodNDCondCat ;
199 if (cond) return _methodNDCond ;
200 if (cat) return _methodNDCat ;
201 return _methodND ;
202}
203
204
205
206////////////////////////////////////////////////////////////////////////////////
207
208const RooCategory& RooNumGenConfig::method1D(bool cond, bool cat) const
209{
210 return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
211}
212
213
214
215////////////////////////////////////////////////////////////////////////////////
216
217const RooCategory& RooNumGenConfig::method2D(bool cond, bool cat) const
218{
219 return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
220}
221
222
223
224////////////////////////////////////////////////////////////////////////////////
225
226const RooCategory& RooNumGenConfig::methodND(bool cond, bool cat) const
227{
228 return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
229}
230
231
232
233////////////////////////////////////////////////////////////////////////////////
234/// Add a configuration section for a particular integrator. Integrator name and capabilities are
235/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
236/// as the default configuration for the integrator.
237
239{
240 std::string name = proto->generatorName();
241
242 // Register integrator for appropriate dimensionalities
243
247
248 if (proto->canSampleConditional()) {
252 }
253 if (proto->canSampleCategories()) {
257 }
258
259 if (proto->canSampleConditional() && proto->canSampleCategories()) {
263 }
264
265 // Store default configuration parameters
266 RooArgSet* config = new RooArgSet;
267 inDefaultConfig.snapshot(*config);
268 config->setName(name.c_str());
269 _configSets.Add(config) ;
270
271 return false ;
272}
273
274
275
276////////////////////////////////////////////////////////////////////////////////
277/// Return section with configuration parameters for integrator with given (class) name
278
280{
281 return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
282}
283
284
285////////////////////////////////////////////////////////////////////////////////
286/// Retrieve configuration information specific to integrator with given name
287
289{
290 static RooArgSet dummy ;
291 RooArgSet* config = static_cast<RooArgSet*>(_configSets.FindObject(name)) ;
292 if (!config) {
293 oocoutE(nullptr,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
294 return dummy ;
295 }
296 return *config ;
297}
298
299
300////////////////////////////////////////////////////////////////////////////////
301
303{
304 if (!opt) {
305 return kStandard ;
306 }
307
308 TString o(opt) ;
309 o.ToLower() ;
310
311 if (o.Contains("v")) {
312 return kVerbose ;
313 }
314 return kStandard ;
315}
316
317
318
319////////////////////////////////////////////////////////////////////////////////
320/// Detailed printing interface
321
322void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, bool verbose, TString indent) const
323{
324 os << endl ;
325 os << indent << "1-D sampling method: " << _method1D.getCurrentLabel() << endl ;
327 os << " (" << _method1DCat.getCurrentLabel() << " if with categories)" << endl ;
328 }
330 os << " (" << _method1DCond.getCurrentLabel() << " if conditional)" << endl ;
331 }
333 os << " (" << _method1DCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
334 }
335 os << endl ;
336
337 os << indent << "2-D sampling method: " << _method2D.getCurrentLabel() << endl ;
339 os << " (" << _method2DCat.getCurrentLabel() << " if with categories)" << endl ;
340 }
342 os << " (" << _method2DCond.getCurrentLabel() << " if conditional)" << endl ;
343 }
345 os << " (" << _method2DCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
346 }
347 os << endl ;
348
349 os << indent << "N-D sampling method: " << _methodND.getCurrentLabel() << endl ;
351 os << " (" << _methodNDCat.getCurrentLabel() << " if with categories)" << endl ;
352 }
354 os << " (" << _methodNDCond.getCurrentLabel() << " if conditional)" << endl ;
355 }
357 os << " (" << _methodNDCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
358 }
359 os << endl ;
360
361 if (verbose) {
362
363 os << endl << "Available sampling methods:" << endl << endl ;
364 for(auto * configSet : static_range_cast<RooArgSet*>(_configSets)) {
365
366 os << indent << "*** " << configSet->GetName() << " ***" << endl ;
367 os << indent << "Capabilities: " ;
368 const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
369 if (proto->canSampleConditional()) os << "[Conditional] " ;
370 if (proto->canSampleCategories()) os << "[Categories] " ;
371 os << endl ;
372
373 os << "Configuration: " << endl ;
374 configSet->printMultiline(os,kName|kValue|kTitle) ;
375 os << endl ;
376
377 }
378 }
379}
#define oocoutE(o, a)
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:17536
virtual const char * getCurrentLabel() const
Return label string of current state.
void setName(const char *name)
Abstract base class for MC event generator implementations like RooAcceptReject and RooFoam.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
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)
TObject * FindObject(const char *name) const override
Return pointer to object with given name.
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
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.
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632