Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
22 RooNumGenConfig holds the configuration parameters of the various
23 numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
24 use 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 
40 using namespace std;
41 
42 ClassImp(RooNumGenConfig);
43 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Return reference to instance of default numeric integrator configuration object
47 
48 RooNumGenConfig& RooNumGenConfig::defaultConfig()
49 {
50  static RooNumGenConfig defaultConfig;
51  return defaultConfig;
52 }
53 
54 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Constructor
58 
59 RooNumGenConfig::RooNumGenConfig() :
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) ;
79  _method1DCondCat.defineType("N/A",0) ;
80 
81  _method2D.defineType("N/A",0) ;
82  _method2DCat.defineType("N/A",0) ;
83  _method2DCond.defineType("N/A",0) ;
84  _method2DCondCat.defineType("N/A",0) ;
85 
86  _methodND.defineType("N/A",0) ;
87  _methodNDCat.defineType("N/A",0) ;
88  _methodNDCond.defineType("N/A",0) ;
89  _methodNDCondCat.defineType("N/A",0) ;
90 }
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Destructor
95 
96 RooNumGenConfig::~RooNumGenConfig()
97 {
98  // Delete all configuration data
99  _configSets.Delete() ;
100 }
101 
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Copy constructor
105 
106 RooNumGenConfig::RooNumGenConfig(const RooNumGenConfig& other) :
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  TIterator* iter = other._configSets.MakeIterator() ;
123  RooArgSet* set ;
124  while((set=(RooArgSet*)iter->Next())) {
125  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
126  setCopy->setName(set->GetName()) ;
127  _configSets.Add(setCopy);
128  }
129  delete iter ;
130 }
131 
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Assignment operator from other RooNumGenConfig
135 
136 RooNumGenConfig& RooNumGenConfig::operator=(const RooNumGenConfig& other)
137 {
138  // Prevent self-assignment
139  if (&other==this) {
140  return *this ;
141  }
142 
143  // Copy common properties
144  _method1D.setIndex(other._method1D.getIndex()) ;
145  _method1DCat.setIndex(other._method1DCat.getIndex()) ;
146  _method1DCond.setIndex(other._method1DCond.getIndex()) ;
147  _method1DCondCat.setIndex(other._method1DCondCat.getIndex()) ;
148 
149  _method2D.setIndex(other._method2D.getIndex()) ;
150  _method2DCat.setIndex(other._method2DCat.getIndex()) ;
151  _method2DCond.setIndex(other._method2DCond.getIndex()) ;
152  _method2DCondCat.setIndex(other._method2DCondCat.getIndex()) ;
153 
154  _methodND.setIndex(other._methodND.getIndex()) ;
155  _methodNDCat.setIndex(other._methodNDCat.getIndex()) ;
156  _methodNDCond.setIndex(other._methodNDCond.getIndex()) ;
157  _methodNDCondCat.setIndex(other._methodNDCondCat.getIndex()) ;
158 
159  // Delete old integrator-specific configuration data
160  _configSets.Delete() ;
161 
162  // Copy new integrator-specific data
163  TIterator* iter = other._configSets.MakeIterator() ;
164  RooArgSet* set ;
165  while((set=(RooArgSet*)iter->Next())) {
166  RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
167  setCopy->setName(set->GetName()) ;
168  _configSets.Add(setCopy);
169  }
170  delete iter ;
171 
172  return *this ;
173 }
174 
175 
176 
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 
180 RooCategory& RooNumGenConfig::method1D(Bool_t cond, Bool_t cat)
181 {
182  if (cond && cat) return _method1DCondCat ;
183  if (cond) return _method1DCond ;
184  if (cat) return _method1DCat ;
185  return _method1D ;
186 }
187 
188 
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 
192 RooCategory& RooNumGenConfig::method2D(Bool_t cond, Bool_t cat)
193 {
194  if (cond && cat) return _method2DCondCat ;
195  if (cond) return _method2DCond ;
196  if (cat) return _method2DCat ;
197  return _method2D ;
198 }
199 
200 
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 
204 RooCategory& RooNumGenConfig::methodND(Bool_t cond, Bool_t cat)
205 {
206  if (cond && cat) return _methodNDCondCat ;
207  if (cond) return _methodNDCond ;
208  if (cat) return _methodNDCat ;
209  return _methodND ;
210 }
211 
212 
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 
216 const RooCategory& RooNumGenConfig::method1D(Bool_t cond, Bool_t cat) const
217 {
218  return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
219 }
220 
221 
222 
223 ////////////////////////////////////////////////////////////////////////////////
224 
225 const RooCategory& RooNumGenConfig::method2D(Bool_t cond, Bool_t cat) const
226 {
227  return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
228 }
229 
230 
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 
234 const RooCategory& RooNumGenConfig::methodND(Bool_t cond, Bool_t cat) const
235 {
236  return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
237 }
238 
239 
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Add a configuration section for a particular integrator. Integrator name and capabilities are
243 /// automatically determined from instance passed as 'proto'. The defaultConfig object is associated
244 /// as the default configuration for the integrator.
245 
246 Bool_t RooNumGenConfig::addConfigSection(const RooAbsNumGenerator* proto, const RooArgSet& inDefaultConfig)
247 {
248  TString name = proto->IsA()->GetName() ;
249 
250  // Register integrator for appropriate dimensionalities
251 
252  _method1D.defineType(name) ;
253  _method2D.defineType(name) ;
254  _methodND.defineType(name) ;
255 
256  if (proto->canSampleConditional()) {
257  _method1DCond.defineType(name) ;
258  _method2DCond.defineType(name) ;
259  _methodNDCond.defineType(name) ;
260  }
261  if (proto->canSampleCategories()) {
262  _method1DCat.defineType(name) ;
263  _method2DCat.defineType(name) ;
264  _methodNDCat.defineType(name) ;
265  }
266 
267  if (proto->canSampleConditional() && proto->canSampleCategories()) {
268  _method1DCondCat.defineType(name) ;
269  _method2DCondCat.defineType(name) ;
270  _methodNDCondCat.defineType(name) ;
271  }
272 
273  // Store default configuration parameters
274  RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
275  config->setName(name) ;
276  _configSets.Add(config) ;
277 
278  return kFALSE ;
279 }
280 
281 
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// Return section with configuration parameters for integrator with given (class) name
285 
286 RooArgSet& RooNumGenConfig::getConfigSection(const char* name)
287 {
288  return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
289 }
290 
291 
292 ////////////////////////////////////////////////////////////////////////////////
293 /// Retrieve configuration information specific to integrator with given name
294 
295 const RooArgSet& RooNumGenConfig::getConfigSection(const char* name) const
296 {
297  static RooArgSet dummy ;
298  RooArgSet* config = (RooArgSet*) _configSets.FindObject(name) ;
299  if (!config) {
300  oocoutE((TObject*)0,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
301  return dummy ;
302  }
303  return *config ;
304 }
305 
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 
309 RooPrintable::StyleOption RooNumGenConfig::defaultPrintStyle(Option_t* opt) const
310 {
311  if (!opt) {
312  return kStandard ;
313  }
314 
315  TString o(opt) ;
316  o.ToLower() ;
317 
318  if (o.Contains("v")) {
319  return kVerbose ;
320  }
321  return kStandard ;
322 }
323 
324 
325 
326 ////////////////////////////////////////////////////////////////////////////////
327 /// Detailed printing interface
328 
329 void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
330 {
331  os << endl ;
332  os << indent << "1-D sampling method: " << _method1D.getLabel() << endl ;
333  if (_method1DCat.getIndex()!=_method1D.getIndex()) {
334  os << " (" << _method1DCat.getLabel() << " if with categories)" << endl ;
335  }
336  if (_method1DCond.getIndex()!=_method1D.getIndex()) {
337  os << " (" << _method1DCond.getLabel() << " if conditional)" << endl ;
338  }
339  if (_method1DCondCat.getIndex()!=_method1D.getIndex()) {
340  os << " (" << _method1DCondCat.getLabel() << " if conditional with categories)" << endl ;
341  }
342  os << endl ;
343 
344  os << indent << "2-D sampling method: " << _method2D.getLabel() << endl ;
345  if (_method2DCat.getIndex()!=_method2D.getIndex()) {
346  os << " (" << _method2DCat.getLabel() << " if with categories)" << endl ;
347  }
348  if (_method2DCond.getIndex()!=_method2D.getIndex()) {
349  os << " (" << _method2DCond.getLabel() << " if conditional)" << endl ;
350  }
351  if (_method2DCondCat.getIndex()!=_method2D.getIndex()) {
352  os << " (" << _method2DCondCat.getLabel() << " if conditional with categories)" << endl ;
353  }
354  os << endl ;
355 
356  os << indent << "N-D sampling method: " << _methodND.getLabel() << endl ;
357  if (_methodNDCat.getIndex()!=_methodND.getIndex()) {
358  os << " (" << _methodNDCat.getLabel() << " if with categories)" << endl ;
359  }
360  if (_methodNDCond.getIndex()!=_methodND.getIndex()) {
361  os << " (" << _methodNDCond.getLabel() << " if conditional)" << endl ;
362  }
363  if (_methodNDCondCat.getIndex()!=_methodND.getIndex()) {
364  os << " (" << _methodNDCondCat.getLabel() << " if conditional with categories)" << endl ;
365  }
366  os << endl ;
367 
368  if (verbose) {
369 
370  os << endl << "Available sampling methods:" << endl << endl ;
371  TIterator* cIter = _configSets.MakeIterator() ;
372  RooArgSet* configSet ;
373  while ((configSet=(RooArgSet*)cIter->Next())) {
374 
375  os << indent << "*** " << configSet->GetName() << " ***" << endl ;
376  os << indent << "Capabilities: " ;
377  const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
378  if (proto->canSampleConditional()) os << "[Conditional] " ;
379  if (proto->canSampleCategories()) os << "[Categories] " ;
380  os << endl ;
381 
382  os << "Configuration: " << endl ;
383  configSet->printMultiline(os,kName|kValue|kTitle) ;
384  os << endl ;
385 
386  }
387 
388  delete cIter ;
389  }
390 }