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#include "TClass.h"
36
37
38
39using namespace std;
40
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Return reference to instance of default numeric integrator configuration object
46
48{
50 return defaultConfig;
51}
52
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Constructor
57
59 _method1D("method1D","1D sampling method"),
60 _method1DCat("method1DCat","1D sampling method for pdfs with categories"),
61 _method1DCond("method1DCond","1D sampling method for conditional pfs"),
62 _method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
63 _method2D("method2D","2D sampling method"),
64 _method2DCat("method2DCat","2D sampling method for pdfs with categories"),
65 _method2DCond("method2DCond","2D sampling method for conditional pfs"),
66 _method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
67 _methodND("methodND","ND sampling method"),
68 _methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
69 _methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
70 _methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
71{
72 // Set all methods to undefined
73 // Defined methods will be registered by static initialization routines
74 // of the various numeric integrator engines
75 _method1D.defineType("N/A",0) ;
76 _method1DCat.defineType("N/A",0) ;
77 _method1DCond.defineType("N/A",0) ;
79
80 _method2D.defineType("N/A",0) ;
81 _method2DCat.defineType("N/A",0) ;
82 _method2DCond.defineType("N/A",0) ;
84
85 _methodND.defineType("N/A",0) ;
86 _methodNDCat.defineType("N/A",0) ;
87 _methodNDCond.defineType("N/A",0) ;
89}
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Destructor
94
96{
97 // Delete all configuration data
99}
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Copy constructor
104
106 TObject(other), RooPrintable(other),
107 _method1D(other._method1D),
108 _method1DCat(other._method1DCat),
109 _method1DCond(other._method1DCond),
110 _method1DCondCat(other._method1DCondCat),
111 _method2D(other._method2D),
112 _method2DCat(other._method2DCat),
113 _method2DCond(other._method2DCond),
114 _method2DCondCat(other._method2DCondCat),
115 _methodND(other._methodND),
116 _methodNDCat(other._methodNDCat),
117 _methodNDCond(other._methodNDCond),
118 _methodNDCondCat(other._methodNDCondCat)
119{
120 // Clone all configuration dat
121 for (auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
122 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
123 setCopy->setName(set->GetName()) ;
124 _configSets.Add(setCopy);
125 }
126}
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Assignment operator from other RooNumGenConfig
131
133{
134 // Prevent self-assignment
135 if (&other==this) {
136 return *this ;
137 }
138
139 // Copy common properties
144
149
154
155 // Delete old integrator-specific configuration data
157
158 // Copy new integrator-specific data
159 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
160 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
161 setCopy->setName(set->GetName()) ;
162 _configSets.Add(setCopy);
163 }
164
165 return *this ;
166}
167
168
169
170
171////////////////////////////////////////////////////////////////////////////////
172
174{
175 if (cond && cat) return _method1DCondCat ;
176 if (cond) return _method1DCond ;
177 if (cat) return _method1DCat ;
178 return _method1D ;
179}
180
181
182
183////////////////////////////////////////////////////////////////////////////////
184
186{
187 if (cond && cat) return _method2DCondCat ;
188 if (cond) return _method2DCond ;
189 if (cat) return _method2DCat ;
190 return _method2D ;
191}
192
193
194
195////////////////////////////////////////////////////////////////////////////////
196
198{
199 if (cond && cat) return _methodNDCondCat ;
200 if (cond) return _methodNDCond ;
201 if (cat) return _methodNDCat ;
202 return _methodND ;
203}
204
205
206
207////////////////////////////////////////////////////////////////////////////////
208
209const RooCategory& RooNumGenConfig::method1D(bool cond, bool cat) const
210{
211 return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
212}
213
214
215
216////////////////////////////////////////////////////////////////////////////////
217
218const RooCategory& RooNumGenConfig::method2D(bool cond, bool cat) const
219{
220 return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
221}
222
223
224
225////////////////////////////////////////////////////////////////////////////////
226
227const RooCategory& RooNumGenConfig::methodND(bool cond, bool cat) const
228{
229 return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
230}
231
232
233
234////////////////////////////////////////////////////////////////////////////////
235/// Add a configuration section for a particular integrator. Integrator name and capabilities are
236/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
237/// as the default configuration for the integrator.
238
240{
241 std::string name = proto->IsA()->GetName();
242
243 // Register integrator for appropriate dimensionalities
244
248
249 if (proto->canSampleConditional()) {
253 }
254 if (proto->canSampleCategories()) {
258 }
259
260 if (proto->canSampleConditional() && proto->canSampleCategories()) {
264 }
265
266 // Store default configuration parameters
267 RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
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 ;
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)
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:17493
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:57
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:180
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=0) 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:37
Basic string class.
Definition: TString.h:136
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1150
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
@ InputArguments
Definition: RooGlobalFunc.h:64