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
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// Return reference to instance of default numeric integrator configuration object
42
48
49
50
51////////////////////////////////////////////////////////////////////////////////
52/// Constructor
53
55 _method1D("method1D","1D sampling method"),
56 _method1DCat("method1DCat","1D sampling method for pdfs with categories"),
57 _method1DCond("method1DCond","1D sampling method for conditional pfs"),
58 _method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
59 _method2D("method2D","2D sampling method"),
60 _method2DCat("method2DCat","2D sampling method for pdfs with categories"),
61 _method2DCond("method2DCond","2D sampling method for conditional pfs"),
62 _method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
63 _methodND("methodND","ND sampling method"),
64 _methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
65 _methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
66 _methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
67{
68 // Set all methods to undefined
69 // Defined methods will be registered by static initialization routines
70 // of the various numeric integrator engines
71 _method1D.defineType("N/A",0) ;
72 _method1DCat.defineType("N/A",0) ;
73 _method1DCond.defineType("N/A",0) ;
75
76 _method2D.defineType("N/A",0) ;
77 _method2DCat.defineType("N/A",0) ;
78 _method2DCond.defineType("N/A",0) ;
80
81 _methodND.defineType("N/A",0) ;
82 _methodNDCat.defineType("N/A",0) ;
83 _methodNDCond.defineType("N/A",0) ;
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// Destructor
90
92{
93 // Delete all configuration data
95}
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Copy constructor
100
103 _method1D(other._method1D),
104 _method1DCat(other._method1DCat),
105 _method1DCond(other._method1DCond),
106 _method1DCondCat(other._method1DCondCat),
107 _method2D(other._method2D),
108 _method2DCat(other._method2DCat),
109 _method2DCond(other._method2DCond),
110 _method2DCondCat(other._method2DCondCat),
111 _methodND(other._methodND),
112 _methodNDCat(other._methodNDCat),
113 _methodNDCond(other._methodNDCond),
114 _methodNDCondCat(other._methodNDCondCat)
115{
116 // Clone all configuration dat
117 for (auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
119 set->snapshot(*setCopy) ;
120 setCopy->setName(set->GetName()) ;
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
137 _method1D.setIndex(other._method1D.getCurrentIndex()) ;
138 _method1DCat.setIndex(other._method1DCat.getCurrentIndex()) ;
139 _method1DCond.setIndex(other._method1DCond.getCurrentIndex()) ;
140 _method1DCondCat.setIndex(other._method1DCondCat.getCurrentIndex()) ;
141
142 _method2D.setIndex(other._method2D.getCurrentIndex()) ;
143 _method2DCat.setIndex(other._method2DCat.getCurrentIndex()) ;
144 _method2DCond.setIndex(other._method2DCond.getCurrentIndex()) ;
145 _method2DCondCat.setIndex(other._method2DCondCat.getCurrentIndex()) ;
146
147 _methodND.setIndex(other._methodND.getCurrentIndex()) ;
148 _methodNDCat.setIndex(other._methodNDCat.getCurrentIndex()) ;
149 _methodNDCond.setIndex(other._methodNDCond.getCurrentIndex()) ;
150 _methodNDCondCat.setIndex(other._methodNDCondCat.getCurrentIndex()) ;
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)) {
158 set->snapshot(*setCopy);
159 setCopy->setName(set->GetName()) ;
161 }
162
163 return *this ;
164}
165
166
167
168
169////////////////////////////////////////////////////////////////////////////////
170
172{
173 if (cond && cat) return _method1DCondCat ;
174 if (cond) return _method1DCond ;
175 if (cat) return _method1DCat ;
176 return _method1D ;
177}
178
179
180
181////////////////////////////////////////////////////////////////////////////////
182
184{
185 if (cond && cat) return _method2DCondCat ;
186 if (cond) return _method2DCond ;
187 if (cat) return _method2DCat ;
188 return _method2D ;
189}
190
191
192
193////////////////////////////////////////////////////////////////////////////////
194
196{
197 if (cond && cat) return _methodNDCondCat ;
198 if (cond) return _methodNDCond ;
199 if (cat) return _methodNDCat ;
200 return _methodND ;
201}
202
203
204
205////////////////////////////////////////////////////////////////////////////////
206
207const RooCategory& RooNumGenConfig::method1D(bool cond, bool cat) const
208{
209 return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
210}
211
212
213
214////////////////////////////////////////////////////////////////////////////////
215
216const RooCategory& RooNumGenConfig::method2D(bool cond, bool cat) const
217{
218 return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
219}
220
221
222
223////////////////////////////////////////////////////////////////////////////////
224
225const RooCategory& RooNumGenConfig::methodND(bool cond, bool cat) const
226{
227 return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
228}
229
230
231
232////////////////////////////////////////////////////////////////////////////////
233/// Add a configuration section for a particular integrator. Integrator name and capabilities are
234/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
235/// as the default configuration for the integrator.
236
238{
239 std::string name = proto->generatorName();
240
241 // Register integrator for appropriate dimensionalities
242
246
247 if (proto->canSampleConditional()) {
251 }
252 if (proto->canSampleCategories()) {
256 }
257
258 if (proto->canSampleConditional() && proto->canSampleCategories()) {
262 }
263
264 // Store default configuration parameters
265 RooArgSet* config = new RooArgSet;
266 inDefaultConfig.snapshot(*config);
267 config->setName(name.c_str());
268 _configSets.Add(config) ;
269
270 return false ;
271}
272
273
274
275////////////////////////////////////////////////////////////////////////////////
276/// Return section with configuration parameters for integrator with given (class) name
277
279{
280 return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
281}
282
283
284////////////////////////////////////////////////////////////////////////////////
285/// Retrieve configuration information specific to integrator with given name
286
288{
289 static RooArgSet dummy ;
290 RooArgSet* config = static_cast<RooArgSet*>(_configSets.FindObject(name)) ;
291 if (!config) {
292 oocoutE(nullptr,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << std::endl ;
293 return dummy ;
294 }
295 return *config ;
296}
297
298
299////////////////////////////////////////////////////////////////////////////////
300
302{
303 if (!opt) {
304 return kStandard ;
305 }
306
307 TString o(opt) ;
308 o.ToLower() ;
309
310 if (o.Contains("v")) {
311 return kVerbose ;
312 }
313 return kStandard ;
314}
315
316
317
318////////////////////////////////////////////////////////////////////////////////
319/// Detailed printing interface
320
321void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, bool verbose, TString indent) const
322{
323 os << std::endl ;
324 os << indent << "1-D sampling method: " << _method1D.getCurrentLabel() << std::endl ;
326 os << " (" << _method1DCat.getCurrentLabel() << " if with categories)" << std::endl ;
327 }
329 os << " (" << _method1DCond.getCurrentLabel() << " if conditional)" << std::endl ;
330 }
332 os << " (" << _method1DCondCat.getCurrentLabel() << " if conditional with categories)" << std::endl ;
333 }
334 os << std::endl ;
335
336 os << indent << "2-D sampling method: " << _method2D.getCurrentLabel() << std::endl ;
338 os << " (" << _method2DCat.getCurrentLabel() << " if with categories)" << std::endl ;
339 }
341 os << " (" << _method2DCond.getCurrentLabel() << " if conditional)" << std::endl ;
342 }
344 os << " (" << _method2DCondCat.getCurrentLabel() << " if conditional with categories)" << std::endl ;
345 }
346 os << std::endl ;
347
348 os << indent << "N-D sampling method: " << _methodND.getCurrentLabel() << std::endl ;
350 os << " (" << _methodNDCat.getCurrentLabel() << " if with categories)" << std::endl ;
351 }
353 os << " (" << _methodNDCond.getCurrentLabel() << " if conditional)" << std::endl ;
354 }
356 os << " (" << _methodNDCondCat.getCurrentLabel() << " if conditional with categories)" << std::endl ;
357 }
358 os << std::endl ;
359
360 if (verbose) {
361
362 os << std::endl << "Available sampling methods:" << std::endl << std::endl ;
364
365 os << indent << "*** " << configSet->GetName() << " ***" << std::endl ;
366 os << indent << "Capabilities: " ;
367 const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
368 if (proto->canSampleConditional()) os << "[Conditional] " ;
369 if (proto->canSampleCategories()) os << "[Categories] " ;
370 os << std::endl ;
371
372 os << "Configuration: " << std::endl ;
373 configSet->printMultiline(os,kName|kValue|kTitle) ;
374 os << std::endl ;
375
376 }
377 }
378}
#define oocoutE(o, a)
const char Option_t
Definition RtypesCore.h:66
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:110
const char * proto
Definition civetweb.c:17535
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: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