// RooNumGenConfig holds the configuration parameters of the various
// numeric integrators used by RooRealIntegral. RooRealIntegral and RooAbsPdf
// use this class in the (normalization) integral configuration interface
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "RooNumGenConfig.h"
#include "RooArgSet.h"
#include "RooAbsNumGenerator.h"
#include "RooNumGenFactory.h"
#include "RooMsgService.h"
#include "TClass.h"
ClassImp(RooNumGenConfig)
;
RooNumGenConfig* RooNumGenConfig::_default = 0 ;
void RooNumGenConfig::cleanup()
{
if (_default) {
delete _default ;
_default = 0 ;
}
}
RooNumGenConfig& RooNumGenConfig::defaultConfig()
{
if (_default==0) {
_default = new RooNumGenConfig ;
RooNumGenFactory::instance() ;
}
return *_default ;
}
RooNumGenConfig::RooNumGenConfig() :
_method1D("method1D","1D sampling method"),
_method1DCat("method1DCat","1D sampling method for pdfs with categories"),
_method1DCond("method1DCond","1D sampling method for conditional pfs"),
_method1DCondCat("method1DCond","1D sampling method for conditional pfs with categories"),
_method2D("method2D","2D sampling method"),
_method2DCat("method2DCat","2D sampling method for pdfs with categories"),
_method2DCond("method2DCond","2D sampling method for conditional pfs"),
_method2DCondCat("method2DCond","2D sampling method for conditional pfs with categories"),
_methodND("methodND","ND sampling method"),
_methodNDCat("methodNDCat","ND sampling method for pdfs with categories"),
_methodNDCond("methodNDCond","ND sampling method for conditional pfs"),
_methodNDCondCat("methodNDCond","ND sampling method for conditional pfs with categories")
{
_method1D.defineType("N/A",0) ;
_method1DCat.defineType("N/A",0) ;
_method1DCond.defineType("N/A",0) ;
_method1DCondCat.defineType("N/A",0) ;
_method2D.defineType("N/A",0) ;
_method2DCat.defineType("N/A",0) ;
_method2DCond.defineType("N/A",0) ;
_method2DCondCat.defineType("N/A",0) ;
_methodND.defineType("N/A",0) ;
_methodNDCat.defineType("N/A",0) ;
_methodNDCond.defineType("N/A",0) ;
_methodNDCondCat.defineType("N/A",0) ;
}
RooNumGenConfig::~RooNumGenConfig()
{
_configSets.Delete() ;
}
RooNumGenConfig::RooNumGenConfig(const RooNumGenConfig& other) :
TObject(other), RooPrintable(other),
_method1D(other._method1D),
_method1DCat(other._method1DCat),
_method1DCond(other._method1DCond),
_method1DCondCat(other._method1DCondCat),
_method2D(other._method2D),
_method2DCat(other._method2DCat),
_method2DCond(other._method2DCond),
_method2DCondCat(other._method2DCondCat),
_methodND(other._methodND),
_methodNDCat(other._methodNDCat),
_methodNDCond(other._methodNDCond),
_methodNDCondCat(other._methodNDCondCat)
{
TIterator* iter = other._configSets.MakeIterator() ;
RooArgSet* set ;
while((set=(RooArgSet*)iter->Next())) {
RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
setCopy->setName(set->GetName()) ;
_configSets.Add(setCopy);
}
delete iter ;
}
RooNumGenConfig& RooNumGenConfig::operator=(const RooNumGenConfig& other)
{
if (&other==this) {
return *this ;
}
_method1D.setIndex(other._method1D.getIndex()) ;
_method1DCat.setIndex(other._method1DCat.getIndex()) ;
_method1DCond.setIndex(other._method1DCond.getIndex()) ;
_method1DCondCat.setIndex(other._method1DCondCat.getIndex()) ;
_method2D.setIndex(other._method2D.getIndex()) ;
_method2DCat.setIndex(other._method2DCat.getIndex()) ;
_method2DCond.setIndex(other._method2DCond.getIndex()) ;
_method2DCondCat.setIndex(other._method2DCondCat.getIndex()) ;
_methodND.setIndex(other._methodND.getIndex()) ;
_methodNDCat.setIndex(other._methodNDCat.getIndex()) ;
_methodNDCond.setIndex(other._methodNDCond.getIndex()) ;
_methodNDCondCat.setIndex(other._methodNDCondCat.getIndex()) ;
_configSets.Delete() ;
TIterator* iter = other._configSets.MakeIterator() ;
RooArgSet* set ;
while((set=(RooArgSet*)iter->Next())) {
RooArgSet* setCopy = (RooArgSet*) set->snapshot() ;
setCopy->setName(set->GetName()) ;
_configSets.Add(setCopy);
}
delete iter ;
return *this ;
}
RooCategory& RooNumGenConfig::method1D(Bool_t cond, Bool_t cat)
{
if (cond && cat) return _method1DCondCat ;
if (cond) return _method1DCond ;
if (cat) return _method1DCat ;
return _method1D ;
}
RooCategory& RooNumGenConfig::method2D(Bool_t cond, Bool_t cat)
{
if (cond && cat) return _method2DCondCat ;
if (cond) return _method2DCond ;
if (cat) return _method2DCat ;
return _method2D ;
}
RooCategory& RooNumGenConfig::methodND(Bool_t cond, Bool_t cat)
{
if (cond && cat) return _methodNDCondCat ;
if (cond) return _methodNDCond ;
if (cat) return _methodNDCat ;
return _methodND ;
}
const RooCategory& RooNumGenConfig::method1D(Bool_t cond, Bool_t cat) const
{
return const_cast<RooNumGenConfig*>(this)->method1D(cond,cat) ;
}
const RooCategory& RooNumGenConfig::method2D(Bool_t cond, Bool_t cat) const
{
return const_cast<RooNumGenConfig*>(this)->method2D(cond,cat) ;
}
const RooCategory& RooNumGenConfig::methodND(Bool_t cond, Bool_t cat) const
{
return const_cast<RooNumGenConfig*>(this)->methodND(cond,cat) ;
}
Bool_t RooNumGenConfig::addConfigSection(const RooAbsNumGenerator* proto, const RooArgSet& inDefaultConfig)
{
TString name = proto->IsA()->GetName() ;
_method1D.defineType(name) ;
_method2D.defineType(name) ;
_methodND.defineType(name) ;
if (proto->canSampleConditional()) {
_method1DCond.defineType(name) ;
_method2DCond.defineType(name) ;
_methodNDCond.defineType(name) ;
}
if (proto->canSampleCategories()) {
_method1DCat.defineType(name) ;
_method2DCat.defineType(name) ;
_methodNDCat.defineType(name) ;
}
if (proto->canSampleConditional() && proto->canSampleCategories()) {
_method1DCondCat.defineType(name) ;
_method2DCondCat.defineType(name) ;
_methodNDCondCat.defineType(name) ;
}
RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ;
config->setName(name) ;
_configSets.Add(config) ;
return kFALSE ;
}
RooArgSet& RooNumGenConfig::getConfigSection(const char* name)
{
return const_cast<RooArgSet&>((const_cast<const RooNumGenConfig*>(this)->getConfigSection(name))) ;
}
const RooArgSet& RooNumGenConfig::getConfigSection(const char* name) const
{
static RooArgSet dummy ;
RooArgSet* config = (RooArgSet*) _configSets.FindObject(name) ;
if (!config) {
oocoutE((TObject*)0,InputArguments) << "RooNumGenConfig::getIntegrator: ERROR: no configuration stored for integrator '" << name << "'" << endl ;
return dummy ;
}
return *config ;
}
RooPrintable::StyleOption RooNumGenConfig::defaultPrintStyle(Option_t* opt) const
{
if (!opt) {
return kStandard ;
}
TString o(opt) ;
o.ToLower() ;
if (o.Contains("v")) {
return kVerbose ;
}
return kStandard ;
}
void RooNumGenConfig::printMultiline(ostream &os, Int_t , Bool_t verbose, TString indent) const
{
os << endl ;
os << indent << "1-D sampling method: " << _method1D.getLabel() << endl ;
if (_method1DCat.getIndex()!=_method1D.getIndex()) {
os << " (" << _method1DCat.getLabel() << " if with categories)" << endl ;
}
if (_method1DCond.getIndex()!=_method1D.getIndex()) {
os << " (" << _method1DCond.getLabel() << " if conditional)" << endl ;
}
if (_method1DCondCat.getIndex()!=_method1D.getIndex()) {
os << " (" << _method1DCondCat.getLabel() << " if conditional with categories)" << endl ;
}
os << endl ;
os << indent << "2-D sampling method: " << _method2D.getLabel() << endl ;
if (_method2DCat.getIndex()!=_method2D.getIndex()) {
os << " (" << _method2DCat.getLabel() << " if with categories)" << endl ;
}
if (_method2DCond.getIndex()!=_method2D.getIndex()) {
os << " (" << _method2DCond.getLabel() << " if conditional)" << endl ;
}
if (_method2DCondCat.getIndex()!=_method2D.getIndex()) {
os << " (" << _method2DCondCat.getLabel() << " if conditional with categories)" << endl ;
}
os << endl ;
os << indent << "N-D sampling method: " << _methodND.getLabel() << endl ;
if (_methodNDCat.getIndex()!=_methodND.getIndex()) {
os << " (" << _methodNDCat.getLabel() << " if with categories)" << endl ;
}
if (_methodNDCond.getIndex()!=_methodND.getIndex()) {
os << " (" << _methodNDCond.getLabel() << " if conditional)" << endl ;
}
if (_methodNDCondCat.getIndex()!=_methodND.getIndex()) {
os << " (" << _methodNDCondCat.getLabel() << " if conditional with categories)" << endl ;
}
os << endl ;
if (verbose) {
os << endl << "Available sampling methods:" << endl << endl ;
TIterator* cIter = _configSets.MakeIterator() ;
RooArgSet* configSet ;
while ((configSet=(RooArgSet*)cIter->Next())) {
os << indent << "*** " << configSet->GetName() << " ***" << endl ;
os << indent << "Capabilities: " ;
const RooAbsNumGenerator* proto = RooNumGenFactory::instance().getProtoSampler(configSet->GetName()) ;
if (proto->canSampleConditional()) os << "[Conditional] " ;
if (proto->canSampleCategories()) os << "[Categories] " ;
os << endl ;
os << "Configuration: " << endl ;
configSet->printMultiline(os,kName|kValue|kTitle) ;
os << endl ;
}
delete cIter ;
}
}