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
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 "RooFit.h"
28#include "Riostream.h"
29
30#include "RooNumGenConfig.h"
31#include "RooArgSet.h"
32#include "RooAbsNumGenerator.h"
33#include "RooNumGenFactory.h"
34#include "RooMsgService.h"
35
36#include "TClass.h"
37
38
39
40using namespace std;
41
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Return reference to instance of default numeric integrator configuration object
47
49{
51 return defaultConfig;
52}
53
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor
58
60 _method1D("method1D","1D sampling method"),
61 _method1DCat("method1DCat","1D sampling method for pdfs with categories"),
62 _method1DCond("method1DCond","1D sampling method for conditional pfs"),
63 _method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
64 _method2D("method2D","2D sampling method"),
65 _method2DCat("method2DCat","2D sampling method for pdfs with categories"),
66 _method2DCond("method2DCond","2D sampling method for conditional pfs"),
67 _method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
68 _methodND("methodND","ND sampling method"),
69 _methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
70 _methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
71 _methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
72{
73 // Set all methods to undefined
74 // Defined methods will be registered by static initialization routines
75 // of the various numeric integrator engines
76 _method1D.defineType("N/A",0) ;
77 _method1DCat.defineType("N/A",0) ;
78 _method1DCond.defineType("N/A",0) ;
80
81 _method2D.defineType("N/A",0) ;
82 _method2DCat.defineType("N/A",0) ;
83 _method2DCond.defineType("N/A",0) ;
85
86 _methodND.defineType("N/A",0) ;
87 _methodNDCat.defineType("N/A",0) ;
88 _methodNDCond.defineType("N/A",0) ;
90}
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Destructor
95
97{
98 // Delete all configuration data
100}
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Copy constructor
105
107 TObject(other), RooPrintable(other),
108 _method1D(other._method1D),
109 _method1DCat(other._method1DCat),
110 _method1DCond(other._method1DCond),
111 _method1DCondCat(other._method1DCondCat),
112 _method2D(other._method2D),
113 _method2DCat(other._method2DCat),
114 _method2DCond(other._method2DCond),
115 _method2DCondCat(other._method2DCondCat),
116 _methodND(other._methodND),
117 _methodNDCat(other._methodNDCat),
118 _methodNDCond(other._methodNDCond),
119 _methodNDCondCat(other._methodNDCondCat)
120{
121 // Clone all configuration dat
122 for (auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
123 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
124 setCopy->setName(set->GetName()) ;
125 _configSets.Add(setCopy);
126 }
127}
128
129
130////////////////////////////////////////////////////////////////////////////////
131/// Assignment operator from other RooNumGenConfig
132
134{
135 // Prevent self-assignment
136 if (&other==this) {
137 return *this ;
138 }
139
140 // Copy common properties
145
150
155
156 // Delete old integrator-specific configuration data
158
159 // Copy new integrator-specific data
160 for(auto * set : static_range_cast<RooArgSet*>(other._configSets)) {
161 RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
162 setCopy->setName(set->GetName()) ;
163 _configSets.Add(setCopy);
164 }
165
166 return *this ;
167}
168
169
170
171
172////////////////////////////////////////////////////////////////////////////////
173
175{
176 if (cond && cat) return _method1DCondCat ;
177 if (cond) return _method1DCond ;
178 if (cat) return _method1DCat ;
179 return _method1D ;
180}
181
182
183
184////////////////////////////////////////////////////////////////////////////////
185
187{
188 if (cond && cat) return _method2DCondCat ;
189 if (cond) return _method2DCond ;
190 if (cat) return _method2DCat ;
191 return _method2D ;
192}
193
194
195
196////////////////////////////////////////////////////////////////////////////////
197
199{
200 if (cond && cat) return _methodNDCondCat ;
201 if (cond) return _methodNDCond ;
202 if (cat) return _methodNDCat ;
203 return _methodND ;
204}
205
206
207
208////////////////////////////////////////////////////////////////////////////////
209
211{
212 return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
213}
214
215
216
217////////////////////////////////////////////////////////////////////////////////
218
220{
221 return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
222}
223
224
225
226////////////////////////////////////////////////////////////////////////////////
227
229{
230 return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
231}
232
233
234
235////////////////////////////////////////////////////////////////////////////////
236/// Add a configuration section for a particular integrator. Integrator name and capabilities are
237/// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
238/// as the default configuration for the integrator.
239
241{
242 std::string name = proto->IsA()->GetName();
243
244 // Register integrator for appropriate dimensionalities
245
249
250 if (proto->canSampleConditional()) {
254 }
255 if (proto->canSampleCategories()) {
259 }
260
261 if (proto->canSampleConditional() && proto->canSampleCategories()) {
265 }
266
267 // Store default configuration parameters
268 RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
269 config->setName(name.c_str());
270 _configSets.Add(config) ;
271
272 return kFALSE ;
273}
274
275
276
277////////////////////////////////////////////////////////////////////////////////
278/// Return section with configuration parameters for integrator with given (class) name
279
281{
282 return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
283}
284
285
286////////////////////////////////////////////////////////////////////////////////
287/// Retrieve configuration information specific to integrator with given name
288
290{
291 static RooArgSet dummy ;
293 if (!config) {
294 oocoutE((TObject*)0,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
295 return dummy ;
296 }
297 return *config ;
298}
299
300
301////////////////////////////////////////////////////////////////////////////////
302
304{
305 if (!opt) {
306 return kStandard ;
307 }
308
309 TString o(opt) ;
310 o.ToLower() ;
311
312 if (o.Contains("v")) {
313 return kVerbose ;
314 }
315 return kStandard ;
316}
317
318
319
320////////////////////////////////////////////////////////////////////////////////
321/// Detailed printing interface
322
323void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
324{
325 os << endl ;
326 os << indent << "1-D sampling method: " << _method1D.getCurrentLabel() << endl ;
328 os << " (" << _method1DCat.getCurrentLabel() << " if with categories)" << endl ;
329 }
331 os << " (" << _method1DCond.getCurrentLabel() << " if conditional)" << endl ;
332 }
334 os << " (" << _method1DCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
335 }
336 os << endl ;
337
338 os << indent << "2-D sampling method: " << _method2D.getCurrentLabel() << endl ;
340 os << " (" << _method2DCat.getCurrentLabel() << " if with categories)" << endl ;
341 }
343 os << " (" << _method2DCond.getCurrentLabel() << " if conditional)" << endl ;
344 }
346 os << " (" << _method2DCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
347 }
348 os << endl ;
349
350 os << indent << "N-D sampling method: " << _methodND.getCurrentLabel() << endl ;
352 os << " (" << _methodNDCat.getCurrentLabel() << " if with categories)" << endl ;
353 }
355 os << " (" << _methodNDCond.getCurrentLabel() << " if conditional)" << endl ;
356 }
358 os << " (" << _methodNDCondCat.getCurrentLabel() << " if conditional with categories)" << endl ;
359 }
360 os << endl ;
361
362 if (verbose) {
363
364 os << endl << "Available sampling methods:" << endl << endl ;
365 for(auto * configSet : static_range_cast<RooArgSet*>(_configSets)) {
366
367 os << indent << "*** " << configSet->GetName() << " ***" << endl ;
368 os << indent << "Capabilities: " ;
369 const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
370 if (proto->canSampleConditional()) os << "[Conditional] " ;
371 if (proto->canSampleCategories()) os << "[Categories] " ;
372 os << endl ;
373
374 os << "Configuration: " << endl ;
375 configSet->printMultiline(os,kName|kValue|kTitle) ;
376 os << endl ;
377
378 }
379 }
380}
#define oocoutE(o, a)
const Bool_t kFALSE
Definition RtypesCore.h:101
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
const char * proto
Definition civetweb.c:16613
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:35
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:158
RooCategory is an object to represent discrete states.
Definition RooCategory.h:27
bool defineType(const std::string &label)
Define a state with given name.
virtual value_type getCurrentIndex() const override final
Return current index.
Definition RooCategory.h:39
virtual Bool_t setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
RooNumGenConfig holds the configuration parameters of the various numeric integrators used by RooReal...
RooCategory & method2D(Bool_t cond, Bool_t cat)
RooCategory _methodND
RooCategory _methodNDCondCat
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
virtual ~RooNumGenConfig()
Destructor.
RooNumGenConfig()
Constructor.
RooCategory _method2D
RooCategory _method1DCondCat
RooCategory _method2DCat
RooCategory _method1DCond
RooCategory _method2DCondCat
virtual StyleOption defaultPrintStyle(Option_t *opt) const
RooCategory & methodND(Bool_t cond, Bool_t cat)
RooCategory _method1DCat
Bool_t addConfigSection(const RooAbsNumGenerator *proto, const RooArgSet &defaultConfig)
Add a configuration section for a particular integrator.
RooCategory & method1D(Bool_t cond, Bool_t cat)
RooCategory _method1D
RooCategory _method2DCond
RooLinkedList _configSets
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
RooCategory _methodNDCond
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose, TString indent="") const
Detailed printing interface.
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.
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, 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:1150
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624