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 "RooNumGenConfig.h"
28#include "RooArgSet.h"
29#include "RooAbsNumGenerator.h"
30#include "RooNumGenFactory.h"
31#include "RooMsgService.h"
32
33#include <ostream>
34
35using std::endl, std::ostream;
36
37
38
39////////////////////////////////////////////////////////////////////////////////
40/// Return reference to instance of default numeric integrator configuration object
41
47
48
49
50////////////////////////////////////////////////////////////////////////////////
51/// Constructor
52
54 _method1D("method1D","1D sampling method"),
55 _method1DCat("method1DCat","1D sampling method for pdfs with categories"),
56 _method1DCond("method1DCond","1D sampling method for conditional pfs"),
57 _method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
58 _method2D("method2D","2D sampling method"),
59 _method2DCat("method2DCat","2D sampling method for pdfs with categories"),
60 _method2DCond("method2DCond","2D sampling method for conditional pfs"),
61 _method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
62 _methodND("methodND","ND sampling method"),
63 _methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
64 _methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
65 _methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
66{
67 // Set all methods to undefined
68 // Defined methods will be registered by static initialization routines
69 // of the various numeric integrator engines
70 _method1D.defineType("N/A",0) ;
71 _method1DCat.defineType("N/A",0) ;
72 _method1DCond.defineType("N/A",0) ;
74
75 _method2D.defineType("N/A",0) ;
76 _method2DCat.defineType("N/A",0) ;
77 _method2DCond.defineType("N/A",0) ;
79
80 _methodND.defineType("N/A",0) ;
81 _methodNDCat.defineType("N/A",0) ;
82 _methodNDCond.defineType("N/A",0) ;
84}
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Destructor
89
91{
92 // Delete all configuration data
94}
95
96
97////////////////////////////////////////////////////////////////////////////////
98/// Copy constructor
99
102 _method1D(other._method1D),
103 _method1DCat(other._method1DCat),
104 _method1DCond(other._method1DCond),
105 _method1DCondCat(other._method1DCondCat),
106 _method2D(other._method2D),
107 _method2DCat(other._method2DCat),
108 _method2DCond(other._method2DCond),
109 _method2DCondCat(other._method2DCondCat),
110 _methodND(other._methodND),
111 _methodNDCat(other._methodNDCat),
112 _methodNDCond(other._methodNDCond),
113 _methodNDCondCat(other._methodNDCondCat)
114{
115 // Clone all configuration dat
116 for (auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
118 set->snapshot(*setCopy) ;
119 setCopy->setName(set->GetName()) ;
121 }
122}
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// Assignment operator from other RooNumGenConfig
127
129{
130 // Prevent self-assignment
131 if (&other==this) {
132 return *this ;
133 }
134
135 // Copy common properties
136 _method1D.setIndex(other._method1D.getCurrentIndex()) ;
137 _method1DCat.setIndex(other._method1DCat.getCurrentIndex()) ;
138 _method1DCond.setIndex(other._method1DCond.getCurrentIndex()) ;
139 _method1DCondCat.setIndex(other._method1DCondCat.getCurrentIndex()) ;
140
141 _method2D.setIndex(other._method2D.getCurrentIndex()) ;
142 _method2DCat.setIndex(other._method2DCat.getCurrentIndex()) ;
143 _method2DCond.setIndex(other._method2DCond.getCurrentIndex()) ;
144 _method2DCondCat.setIndex(other._method2DCondCat.getCurrentIndex()) ;
145
146 _methodND.setIndex(other._methodND.getCurrentIndex()) ;
147 _methodNDCat.setIndex(other._methodNDCat.getCurrentIndex()) ;
148 _methodNDCond.setIndex(other._methodNDCond.getCurrentIndex()) ;
149 _methodNDCondCat.setIndex(other._methodNDCondCat.getCurrentIndex()) ;
150
151 // Delete old integrator-specific configuration data
153
154 // Copy new integrator-specific data
155 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
157 set->snapshot(*setCopy);
158 setCopy->setName(set->GetName()) ;
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->generatorName();
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 = new RooArgSet;
265 inDefaultConfig.snapshot(*config);
266 config->setName(name.c_str());
267 _configSets.Add(config) ;
268
269 return false ;
270}
271
272
273
274////////////////////////////////////////////////////////////////////////////////
275/// Return section with configuration parameters for integrator with given (class) name
276
278{
279 return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
280}
281
282
283////////////////////////////////////////////////////////////////////////////////
284/// Retrieve configuration information specific to integrator with given name
285
287{
288 static RooArgSet dummy ;
289 RooArgSet* config = static_cast<RooArgSet*>(_configSets.FindObject(name)) ;
290 if (!config) {
291 oocoutE(nullptr,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << std::endl ;
292 return dummy ;
293 }
294 return *config ;
295}
296
297
298////////////////////////////////////////////////////////////////////////////////
299
301{
302 if (!opt) {
303 return kStandard ;
304 }
305
306 TString o(opt) ;
307 o.ToLower() ;
308
309 if (o.Contains("v")) {
310 return kVerbose ;
311 }
312 return kStandard ;
313}
314
315
316
317////////////////////////////////////////////////////////////////////////////////
318/// Detailed printing interface
319
320void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, bool verbose, TString indent) const
321{
322 os << std::endl ;
323 os << indent << "1-D sampling method: " << _method1D.getCurrentLabel() << std::endl ;
325 os << " (" << _method1DCat.getCurrentLabel() << " if with categories)" << std::endl ;
326 }
328 os << " (" << _method1DCond.getCurrentLabel() << " if conditional)" << std::endl ;
329 }
331 os << " (" << _method1DCondCat.getCurrentLabel() << " if conditional with categories)" << std::endl ;
332 }
333 os << std::endl ;
334
335 os << indent << "2-D sampling method: " << _method2D.getCurrentLabel() << std::endl ;
337 os << " (" << _method2DCat.getCurrentLabel() << " if with categories)" << std::endl ;
338 }
340 os << " (" << _method2DCond.getCurrentLabel() << " if conditional)" << std::endl ;
341 }
343 os << " (" << _method2DCondCat.getCurrentLabel() << " if conditional with categories)" << std::endl ;
344 }
345 os << std::endl ;
346
347 os << indent << "N-D sampling method: " << _methodND.getCurrentLabel() << std::endl ;
349 os << " (" << _methodNDCat.getCurrentLabel() << " if with categories)" << std::endl ;
350 }
352 os << " (" << _methodNDCond.getCurrentLabel() << " if conditional)" << std::endl ;
353 }
355 os << " (" << _methodNDCondCat.getCurrentLabel() << " if conditional with categories)" << std::endl ;
356 }
357 os << std::endl ;
358
359 if (verbose) {
360
361 os << std::endl << "Available sampling methods:" << std::endl << std::endl ;
363
364 os << indent << "*** " << configSet->GetName() << " ***" << std::endl ;
365 os << indent << "Capabilities: " ;
366 const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
367 if (proto->canSampleConditional()) os << "[Conditional] " ;
368 if (proto->canSampleCategories()) os << "[Categories] " ;
369 os << std::endl ;
370
371 os << "Configuration: " << std::endl ;
372 configSet->printMultiline(os,kName|kValue|kTitle) ;
373 os << std::endl ;
374
375 }
376 }
377}
#define oocoutE(o, a)
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:142
virtual const char * getCurrentLabel() const
Return label string of current state.
void setName(const char *name)
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:159
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)
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
Mother of all ROOT objects.
Definition TObject.h:42
Basic string class.
Definition TString.h:137
void ToLower()
Change string to lower-case.
Definition TString.cxx:1190
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642