RooNumGenConfig.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooNumGenConfig.cxx 28259 2009-04-16 16:21:16Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // RooNumGenConfig holds the configuration parameters of the various
00021 // numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
00022 // use this class in the (normalization) integral configuration interface
00023 // END_HTML
00024 //
00025 
00026 #include "RooFit.h"
00027 #include "Riostream.h"
00028 
00029 #include "RooNumGenConfig.h"
00030 #include "RooArgSet.h"
00031 #include "RooAbsNumGenerator.h"
00032 #include "RooNumGenFactory.h"
00033 #include "RooMsgService.h"
00034 
00035 #include "TClass.h"
00036 
00037 
00038 
00039 ClassImp(RooNumGenConfig)
00040 ;
00041 
00042 RooNumGenConfig* RooNumGenConfig::_default = 0 ;
00043 
00044 
00045 //_____________________________________________________________________________
00046 void RooNumGenConfig::cleanup()
00047 {
00048   // Function called by atexit() handler installed by RooSentinel to
00049   // cleanup global objects at end of job
00050   if (_default) {
00051     delete _default ;
00052     _default = 0 ;
00053   }
00054 }
00055 
00056 
00057 
00058 //_____________________________________________________________________________
00059 RooNumGenConfig& RooNumGenConfig::defaultConfig() 
00060 {
00061   // Return reference to instance of default numeric integrator configuration object
00062   
00063   // Instantiate object if it doesn't exist yet
00064   if (_default==0) {
00065     _default = new RooNumGenConfig ;    
00066     RooNumGenFactory::instance() ;
00067   }
00068   return *_default ;
00069 }
00070 
00071 
00072 
00073 //_____________________________________________________________________________
00074 RooNumGenConfig::RooNumGenConfig() : 
00075   _method1D("method1D","1D sampling method"),
00076   _method1DCat("method1DCat","1D sampling method for pdfs with categories"),
00077   _method1DCond("method1DCond","1D sampling method for conditional pfs"),
00078   _method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
00079   _method2D("method2D","2D sampling method"),
00080   _method2DCat("method2DCat","2D sampling method for pdfs with categories"),
00081   _method2DCond("method2DCond","2D sampling method for conditional pfs"),
00082   _method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
00083   _methodND("methodND","ND sampling method"),
00084   _methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
00085   _methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
00086   _methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
00087 {
00088   // Constructor 
00089 
00090   // Set all methods to undefined
00091   // Defined methods will be registered by static initialization routines
00092   // of the various numeric integrator engines
00093   _method1D.defineType("N/A",0) ;
00094   _method1DCat.defineType("N/A",0) ;
00095   _method1DCond.defineType("N/A",0) ;
00096   _method1DCondCat.defineType("N/A",0) ;
00097 
00098   _method2D.defineType("N/A",0) ;
00099   _method2DCat.defineType("N/A",0) ;
00100   _method2DCond.defineType("N/A",0) ;
00101   _method2DCondCat.defineType("N/A",0) ;
00102 
00103   _methodND.defineType("N/A",0) ;
00104   _methodNDCat.defineType("N/A",0) ;
00105   _methodNDCond.defineType("N/A",0) ;
00106   _methodNDCondCat.defineType("N/A",0) ;
00107 }
00108 
00109 
00110 //_____________________________________________________________________________
00111 RooNumGenConfig::~RooNumGenConfig()
00112 {
00113   // Destructor
00114 
00115   // Delete all configuration data
00116   _configSets.Delete() ;
00117 }
00118 
00119 
00120 //_____________________________________________________________________________
00121 RooNumGenConfig::RooNumGenConfig(const RooNumGenConfig& other) :
00122   TObject(other), RooPrintable(other),
00123   _method1D(other._method1D),
00124   _method1DCat(other._method1DCat),
00125   _method1DCond(other._method1DCond),
00126   _method1DCondCat(other._method1DCondCat),
00127   _method2D(other._method2D),
00128   _method2DCat(other._method2DCat),
00129   _method2DCond(other._method2DCond),
00130   _method2DCondCat(other._method2DCondCat),
00131   _methodND(other._methodND),
00132   _methodNDCat(other._methodNDCat),
00133   _methodNDCond(other._methodNDCond),
00134   _methodNDCondCat(other._methodNDCondCat)
00135 {
00136   // Copy constructor
00137   
00138   // Clone all configuration dat
00139   TIterator* iter = other._configSets.MakeIterator() ;
00140   RooArgSet* set ;
00141   while((set=(RooArgSet*)iter->Next())) {
00142     RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
00143     setCopy->setName(set->GetName()) ;
00144    _configSets.Add(setCopy);
00145   }
00146   delete iter ;
00147 }
00148 
00149 
00150 //_____________________________________________________________________________
00151 RooNumGenConfig& RooNumGenConfig::operator=(const RooNumGenConfig& other) 
00152 {
00153   // Assignment operator from other RooNumGenConfig
00154 
00155   // Prevent self-assignment 
00156   if (&other==this) {
00157     return *this ;
00158   }
00159 
00160   // Copy common properties
00161   _method1D.setIndex(other._method1D.getIndex()) ;
00162   _method1DCat.setIndex(other._method1DCat.getIndex()) ;
00163   _method1DCond.setIndex(other._method1DCond.getIndex()) ;
00164   _method1DCondCat.setIndex(other._method1DCondCat.getIndex()) ;
00165 
00166   _method2D.setIndex(other._method2D.getIndex()) ;
00167   _method2DCat.setIndex(other._method2DCat.getIndex()) ;
00168   _method2DCond.setIndex(other._method2DCond.getIndex()) ;
00169   _method2DCondCat.setIndex(other._method2DCondCat.getIndex()) ;
00170 
00171   _methodND.setIndex(other._methodND.getIndex()) ;
00172   _methodNDCat.setIndex(other._methodNDCat.getIndex()) ;
00173   _methodNDCond.setIndex(other._methodNDCond.getIndex()) ;
00174   _methodNDCondCat.setIndex(other._methodNDCondCat.getIndex()) ;
00175 
00176   // Delete old integrator-specific configuration data
00177   _configSets.Delete() ;
00178 
00179   // Copy new integrator-specific data
00180   TIterator* iter = other._configSets.MakeIterator() ;
00181   RooArgSet* set ;
00182   while((set=(RooArgSet*)iter->Next())) {
00183     RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
00184     setCopy->setName(set->GetName()) ;
00185    _configSets.Add(setCopy);
00186   }
00187   delete iter ;
00188 
00189   return *this ;
00190 }
00191 
00192 
00193 
00194 
00195 //_____________________________________________________________________________
00196 RooCategory& RooNumGenConfig::method1D(Bool_t cond, Bool_t cat) 
00197 {
00198   if (cond && cat) return _method1DCondCat ;
00199   if (cond) return _method1DCond ;
00200   if (cat) return _method1DCat ;
00201   return _method1D ;
00202 }
00203 
00204 
00205 
00206 //_____________________________________________________________________________
00207 RooCategory& RooNumGenConfig::method2D(Bool_t cond, Bool_t cat) 
00208 {
00209   if (cond && cat) return _method2DCondCat ;
00210   if (cond) return _method2DCond ;
00211   if (cat) return _method2DCat ;
00212   return _method2D ;
00213 }
00214 
00215 
00216 
00217 //_____________________________________________________________________________
00218 RooCategory& RooNumGenConfig::methodND(Bool_t cond, Bool_t cat) 
00219 {
00220   if (cond && cat) return _methodNDCondCat ;
00221   if (cond) return _methodNDCond ;
00222   if (cat) return _methodNDCat ;
00223   return _methodND ;
00224 }
00225 
00226 
00227 
00228 //_____________________________________________________________________________
00229 const RooCategory& RooNumGenConfig::method1D(Bool_t cond, Bool_t cat) const 
00230 {
00231   return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
00232 }
00233 
00234 
00235 
00236 //_____________________________________________________________________________
00237 const RooCategory& RooNumGenConfig::method2D(Bool_t cond, Bool_t cat) const 
00238 {
00239   return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
00240 }
00241 
00242 
00243 
00244 //_____________________________________________________________________________
00245 const RooCategory& RooNumGenConfig::methodND(Bool_t cond, Bool_t cat) const 
00246 {
00247   return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
00248 }
00249 
00250 
00251 
00252 //_____________________________________________________________________________
00253 Bool_t RooNumGenConfig::addConfigSection(const RooAbsNumGenerator* proto, const RooArgSet& inDefaultConfig)
00254 {
00255   // Add a configuration section for a particular integrator. Integrator name and capabilities are
00256   // automatically determined from instance passed as 'proto'. The defaultConfig object is associated
00257   // as the default configuration for the integrator. 
00258 
00259   TString name = proto->IsA()->GetName() ;
00260 
00261   // Register integrator for appropriate dimensionalities
00262   
00263   _method1D.defineType(name) ;
00264   _method2D.defineType(name) ; 
00265   _methodND.defineType(name) ;
00266 
00267   if (proto->canSampleConditional()) {
00268     _method1DCond.defineType(name) ;
00269     _method2DCond.defineType(name) ;
00270     _methodNDCond.defineType(name) ;
00271   }
00272   if (proto->canSampleCategories()) {
00273     _method1DCat.defineType(name) ;
00274     _method2DCat.defineType(name) ;
00275     _methodNDCat.defineType(name) ;
00276   }
00277 
00278   if (proto->canSampleConditional() && proto->canSampleCategories()) {
00279     _method1DCondCat.defineType(name) ;
00280     _method2DCondCat.defineType(name) ;
00281     _methodNDCondCat.defineType(name) ;
00282   }
00283   
00284   // Store default configuration parameters
00285   RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
00286   config->setName(name) ;
00287   _configSets.Add(config) ;
00288 
00289   return kFALSE ;
00290 }
00291 
00292 
00293 
00294 //_____________________________________________________________________________
00295 RooArgSet& RooNumGenConfig::getConfigSection(const char* name)  
00296 {
00297   // Return section with configuration parameters for integrator with given (class) name
00298 
00299   return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
00300 }
00301 
00302 
00303 //_____________________________________________________________________________
00304 const RooArgSet& RooNumGenConfig::getConfigSection(const char* name) const
00305 {
00306   // Retrieve configuration information specific to integrator with given name
00307 
00308   static RooArgSet dummy ;
00309   RooArgSet* config = (RooArgSet*) _configSets.FindObject(name) ;
00310   if (!config) {
00311     oocoutE((TObject*)0,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
00312     return dummy ;
00313   }
00314   return *config ;
00315 }
00316 
00317 
00318 //_____________________________________________________________________________
00319 RooPrintable::StyleOption RooNumGenConfig::defaultPrintStyle(Option_t* opt) const
00320 { 
00321   if (!opt) {
00322     return kStandard ;
00323   }
00324 
00325   TString o(opt) ;
00326   o.ToLower() ;
00327 
00328   if (o.Contains("v")) {
00329     return kVerbose ;
00330   } 
00331   return kStandard ;
00332 }
00333 
00334 
00335 
00336 //_____________________________________________________________________________
00337 void RooNumGenConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
00338 {
00339   // Detailed printing interface
00340   os << endl ;
00341   os << indent << "1-D sampling method: " << _method1D.getLabel() << endl ;
00342   if (_method1DCat.getIndex()!=_method1D.getIndex()) {
00343     os << " (" << _method1DCat.getLabel() << " if with categories)" << endl ;
00344   }
00345   if (_method1DCond.getIndex()!=_method1D.getIndex()) {
00346     os << " (" << _method1DCond.getLabel() << " if conditional)" << endl ;
00347   }
00348   if (_method1DCondCat.getIndex()!=_method1D.getIndex()) {
00349     os << " (" << _method1DCondCat.getLabel() << " if conditional with categories)" << endl ;    
00350   }
00351   os << endl ;
00352 
00353   os << indent << "2-D sampling method: " << _method2D.getLabel() << endl ;
00354   if (_method2DCat.getIndex()!=_method2D.getIndex()) {
00355     os << " (" << _method2DCat.getLabel() << " if with categories)" << endl ;
00356   }
00357   if (_method2DCond.getIndex()!=_method2D.getIndex()) {
00358     os << " (" << _method2DCond.getLabel() << " if conditional)" << endl ;
00359   }
00360   if (_method2DCondCat.getIndex()!=_method2D.getIndex()) {
00361     os << " (" << _method2DCondCat.getLabel() << " if conditional with categories)" << endl ;
00362   }
00363   os << endl ;
00364 
00365   os << indent << "N-D sampling method: " << _methodND.getLabel() << endl ;
00366   if (_methodNDCat.getIndex()!=_methodND.getIndex()) {
00367     os << " (" << _methodNDCat.getLabel() << " if with categories)" << endl ;
00368   }
00369   if (_methodNDCond.getIndex()!=_methodND.getIndex()) {
00370     os << " (" << _methodNDCond.getLabel() << " if conditional)" << endl ;
00371   }
00372   if (_methodNDCondCat.getIndex()!=_methodND.getIndex()) {
00373     os << " (" << _methodNDCondCat.getLabel() << " if conditional with categories)" << endl ;
00374   }
00375   os << endl ;
00376    
00377   if (verbose) {
00378 
00379     os << endl << "Available sampling methods:" << endl << endl ;
00380     TIterator* cIter = _configSets.MakeIterator() ;
00381     RooArgSet* configSet ;
00382     while ((configSet=(RooArgSet*)cIter->Next())) {
00383 
00384       os << indent << "*** " << configSet->GetName() << " ***" << endl ;
00385       os << indent << "Capabilities: " ;
00386       const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
00387      if (proto->canSampleConditional()) os << "[Conditional] " ;
00388      if (proto->canSampleCategories()) os << "[Categories] " ;
00389       os << endl ;
00390 
00391       os << "Configuration: " << endl ;
00392       configSet->printMultiline(os,kName|kValue|kTitle) ;
00393       os << endl ;
00394 
00395     }
00396 
00397     delete cIter ;
00398   }
00399 }

Generated on Tue Jul 5 15:06:53 2011 for ROOT_528-00b_version by  doxygen 1.5.1