RooNumIntConfig.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooNumIntConfig.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 // RooNumIntConfig 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 "RooNumIntConfig.h"
00030 #include "RooArgSet.h"
00031 #include "RooAbsIntegrator.h"
00032 #include "RooNumIntFactory.h"
00033 #include "RooMsgService.h"
00034 
00035 #include "TClass.h"
00036 
00037 
00038 
00039 ClassImp(RooNumIntConfig)
00040 ;
00041 
00042 RooNumIntConfig* RooNumIntConfig::_default = 0 ;
00043 
00044 
00045 //_____________________________________________________________________________
00046 void RooNumIntConfig::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 RooNumIntConfig& RooNumIntConfig::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 RooNumIntConfig ;    
00066     RooNumIntFactory::instance() ;
00067   }
00068   return *_default ;
00069 }
00070 
00071 
00072 
00073 //_____________________________________________________________________________
00074 RooNumIntConfig::RooNumIntConfig() : 
00075   _epsAbs(1e-7),
00076   _epsRel(1e-7),
00077   _printEvalCounter(kFALSE),
00078   _method1D("method1D","1D integration method"),
00079   _method2D("method2D","2D integration method"),
00080   _methodND("methodND","ND integration method"),
00081   _method1DOpen("method1DOpen","1D integration method in open domain"),
00082   _method2DOpen("method2DOpen","2D integration method in open domain"),
00083   _methodNDOpen("methodNDOpen","ND integration method in open domain")
00084 {
00085   // Constructor 
00086 
00087   // Set all methods to undefined
00088   // Defined methods will be registered by static initialization routines
00089   // of the various numeric integrator engines
00090   _method1D.defineType("N/A",0) ;
00091   _method2D.defineType("N/A",0) ;
00092   _methodND.defineType("N/A",0) ;
00093   _method1DOpen.defineType("N/A",0) ;
00094   _method2DOpen.defineType("N/A",0) ;
00095   _methodNDOpen.defineType("N/A",0) ;
00096 }
00097 
00098 
00099 //_____________________________________________________________________________
00100 RooNumIntConfig::~RooNumIntConfig()
00101 {
00102   // Destructor
00103 
00104   // Delete all configuration data
00105   _configSets.Delete() ;
00106 }
00107 
00108 
00109 //_____________________________________________________________________________
00110 RooNumIntConfig::RooNumIntConfig(const RooNumIntConfig& other) :
00111   TObject(other), RooPrintable(other),
00112   _epsAbs(other._epsAbs),
00113   _epsRel(other._epsRel),
00114   _printEvalCounter(other._printEvalCounter),
00115   _method1D(other._method1D),
00116   _method2D(other._method2D),
00117   _methodND(other._methodND),
00118   _method1DOpen(other._method1DOpen),
00119   _method2DOpen(other._method2DOpen),
00120   _methodNDOpen(other._methodNDOpen)
00121 {
00122   // Copy constructor
00123   
00124   // Clone all configuration dat
00125   TIterator* iter = other._configSets.MakeIterator() ;
00126   RooArgSet* set ;
00127   while((set=(RooArgSet*)iter->Next())) {
00128     RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
00129     setCopy->setName(set->GetName()) ;
00130    _configSets.Add(setCopy);
00131   }
00132   delete iter ;
00133 }
00134 
00135 
00136 //_____________________________________________________________________________
00137 RooNumIntConfig& RooNumIntConfig::operator=(const RooNumIntConfig& other) 
00138 {
00139   // Assignment operator from other RooNumIntConfig
00140 
00141   // Prevent self-assignment 
00142   if (&other==this) {
00143     return *this ;
00144   }
00145 
00146   // Copy common properties
00147   _epsAbs = other._epsAbs ;
00148   _epsRel = other._epsRel ;
00149   _method1D.setIndex(other._method1D.getIndex()) ;
00150   _method2D.setIndex(other._method2D.getIndex()) ;
00151   _methodND.setIndex(other._methodND.getIndex()) ;
00152   _method1DOpen.setIndex(other._method1DOpen.getIndex()) ;
00153   _method2DOpen.setIndex(other._method2DOpen.getIndex()) ;
00154   _methodNDOpen.setIndex(other._methodNDOpen.getIndex()) ;
00155 
00156   // Delete old integrator-specific configuration data
00157   _configSets.Delete() ;
00158 
00159   // Copy new integrator-specific data
00160   TIterator* iter = other._configSets.MakeIterator() ;
00161   RooArgSet* set ;
00162   while((set=(RooArgSet*)iter->Next())) {
00163     RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
00164     setCopy->setName(set->GetName()) ;
00165    _configSets.Add(setCopy);
00166   }
00167   delete iter ;
00168 
00169   return *this ;
00170 }
00171 
00172 
00173 
00174 //_____________________________________________________________________________
00175 Bool_t RooNumIntConfig::addConfigSection(const RooAbsIntegrator* proto, const RooArgSet& inDefaultConfig)
00176 {
00177   // Add a configuration section for a particular integrator. Integrator name and capabilities are
00178   // automatically determined from instance passed as 'proto'. The defaultConfig object is associated
00179   // as the default configuration for the integrator. 
00180 
00181   TString name = proto->IsA()->GetName() ;
00182 
00183   // Register integrator for appropriate dimensionalities
00184   if (proto->canIntegrate1D()) {
00185     _method1D.defineType(name) ;
00186     if (proto->canIntegrateOpenEnded()) {
00187       _method1DOpen.defineType(name) ;
00188     }
00189   }
00190 
00191   if (proto->canIntegrate2D()) {
00192     _method2D.defineType(name) ;
00193     if (proto->canIntegrateOpenEnded()) {
00194       _method2DOpen.defineType(name) ;
00195     }
00196   }
00197 
00198   if (proto->canIntegrateND()) {
00199     _methodND.defineType(name) ;
00200     if (proto->canIntegrateOpenEnded()) {
00201       _methodNDOpen.defineType(name) ;
00202     }
00203   }
00204   
00205   // Store default configuration parameters
00206   RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
00207   config->setName(name) ;
00208   _configSets.Add(config) ;
00209 
00210   return kFALSE ;
00211 }
00212 
00213 
00214 
00215 //_____________________________________________________________________________
00216 RooArgSet& RooNumIntConfig::getConfigSection(const char* name)  
00217 {
00218   // Return section with configuration parameters for integrator with given (class) name
00219 
00220   return const_cast<RooArgSet&>((const_cast<const RooNumIntConfig*>(this)->getConfigSection(name))) ;
00221 }
00222 
00223 
00224 //_____________________________________________________________________________
00225 const RooArgSet& RooNumIntConfig::getConfigSection(const char* name) const
00226 {
00227   // Retrieve configuration information specific to integrator with given name
00228 
00229   static RooArgSet dummy ;
00230   RooArgSet* config = (RooArgSet*) _configSets.FindObject(name) ;
00231   if (!config) {
00232     oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
00233     return dummy ;
00234   }
00235   return *config ;
00236 }
00237 
00238 
00239 
00240 //_____________________________________________________________________________
00241 void RooNumIntConfig::setEpsAbs(Double_t newEpsAbs)
00242 {
00243   // Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
00244 
00245   if (newEpsAbs<=0) {
00246     oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsAbs: ERROR: target absolute precision must be greater than zero" << endl ;
00247     return ;
00248   }
00249   _epsAbs = newEpsAbs ;
00250 }
00251 
00252 
00253 RooPrintable::StyleOption RooNumIntConfig::defaultPrintStyle(Option_t* opt) const 
00254 { 
00255   if (!opt) {
00256     return kStandard ;
00257   }
00258 
00259   TString o(opt) ;
00260   o.ToLower() ;
00261 
00262   if (o.Contains("v")) {
00263     return kVerbose ;
00264   }
00265   return kStandard ; 
00266 }
00267 
00268 
00269 
00270 //_____________________________________________________________________________
00271 void RooNumIntConfig::setEpsRel(Double_t newEpsRel) 
00272 {
00273   // Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
00274 
00275   if (newEpsRel<=0) {
00276     oocoutE((TObject*)0,InputArguments) << "RooNumIntConfig::setEpsRel: ERROR: target absolute precision must be greater than zero" << endl ;
00277     return ;
00278   }
00279   _epsRel = newEpsRel ;
00280 }
00281 
00282 
00283 
00284 //_____________________________________________________________________________
00285 void RooNumIntConfig::printMultiline(ostream &os, Int_t /*content*/, Bool_t verbose, TString indent) const
00286 {
00287   // Detailed printing interface
00288 
00289   os << indent << "Requested precision: " << _epsAbs << " absolute, " << _epsRel << " relative" << endl << endl ;
00290   if (_printEvalCounter) {
00291     os << indent << "Printing of function evaluation counter for each integration enabled" << endl << endl ;
00292   }
00293   
00294   os << indent << "1-D integration method: " << _method1D.getLabel() ;
00295   if (_method1DOpen.getIndex()!=_method1D.getIndex()) {
00296     os << " (" << _method1DOpen.getLabel() << " if open-ended)" << endl ;
00297   } else {
00298     os << endl ;
00299   }
00300   os << indent << "2-D integration method: " << _method2D.getLabel() ;
00301   if (_method2DOpen.getIndex()!=_method2D.getIndex()) {
00302     os << " (" << _method2DOpen.getLabel() << " if open-ended)" << endl ;
00303   } else {
00304     os << endl ;
00305   }
00306   os << indent << "N-D integration method: " << _methodND.getLabel() ;
00307   if (_methodNDOpen.getIndex()!=_methodND.getIndex()) {
00308     os << " (" << _methodNDOpen.getLabel() << " if open-ended)" << endl ;
00309   } else {
00310     os << endl ;
00311   }
00312   
00313   if (verbose) {
00314 
00315     os << endl << "Available integration methods:" << endl << endl ;
00316     TIterator* cIter = _configSets.MakeIterator() ;
00317     RooArgSet* configSet ;
00318     while ((configSet=(RooArgSet*)cIter->Next())) {
00319 
00320       os << indent << "*** " << configSet->GetName() << " ***" << endl ;
00321       os << indent << "Capabilities: " ;
00322       const RooAbsIntegrator* proto = RooNumIntFactory::instance().getProtoIntegrator(configSet->GetName()) ;
00323       if (proto->canIntegrate1D()) os << "[1-D] " ;
00324       if (proto->canIntegrate2D()) os << "[2-D] " ;
00325       if (proto->canIntegrateND()) os << "[N-D] " ;
00326       if (proto->canIntegrateOpenEnded()) os << "[OpenEnded] " ;
00327       os << endl ;
00328 
00329       os << "Configuration: " << endl ;
00330       configSet->printMultiline(os,kName|kValue) ;
00331       //configSet->writeToStream(os,kFALSE) ;
00332 
00333       const char* depName = RooNumIntFactory::instance().getDepIntegratorName(configSet->GetName()) ;
00334       if (strlen(depName)>0) {
00335         os << indent << "(Depends on '" << depName << "')" << endl ;
00336       }
00337       os << endl ;
00338 
00339     }
00340 
00341     delete cIter ;
00342   }
00343 }

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