00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00049
00050 if (_default) {
00051 delete _default ;
00052 _default = 0 ;
00053 }
00054 }
00055
00056
00057
00058
00059 RooNumGenConfig& RooNumGenConfig::defaultConfig()
00060 {
00061
00062
00063
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
00089
00090
00091
00092
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
00114
00115
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
00137
00138
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
00154
00155
00156 if (&other==this) {
00157 return *this ;
00158 }
00159
00160
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
00177 _configSets.Delete() ;
00178
00179
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
00256
00257
00258
00259 TString name = proto->IsA()->GetName() ;
00260
00261
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
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
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
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 , Bool_t verbose, TString indent) const
00338 {
00339
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 }