Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-10 05:40:59

0001 #include "GeneratorInterface/ExternalDecays/interface/ExternalDecayDriver.h"
0002 
0003 #include "GeneratorInterface/Core/interface/FortranInstance.h"
0004 #include "GeneratorInterface/EvtGenInterface/interface/EvtGenFactory.h"
0005 #include "GeneratorInterface/EvtGenInterface/interface/EvtGenInterfaceBase.h"
0006 #include "GeneratorInterface/TauolaInterface/interface/TauolaFactory.h"
0007 #include "GeneratorInterface/TauolaInterface/interface/TauolaInterfaceBase.h"
0008 #include "GeneratorInterface/PhotosInterface/interface/PhotosFactory.h"
0009 #include "GeneratorInterface/PhotosInterface/interface/PhotosInterfaceBase.h"
0010 #include "HepMC/GenEvent.h"
0011 #include "FWCore/Concurrency/interface/SharedResourceNames.h"
0012 // LHE Run
0013 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
0014 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h"
0015 
0016 // LHE Event
0017 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
0018 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
0019 
0020 using namespace gen;
0021 using namespace edm;
0022 
0023 ExternalDecayDriver::ExternalDecayDriver(const ParameterSet& pset, edm::ConsumesCollector iCollector)
0024     : fIsInitialized(false) {
0025   std::vector<std::string> extGenNames = pset.getParameter<std::vector<std::string> >("parameterSets");
0026 
0027   for (unsigned int ip = 0; ip < extGenNames.size(); ++ip) {
0028     std::string curSet = extGenNames[ip];
0029     if (curSet == "EvtGen") {
0030       fEvtGenInterface = std::unique_ptr<EvtGenInterfaceBase>(
0031           EvtGenFactory::get()->create("EvtGen", pset.getUntrackedParameter<ParameterSet>(curSet)));
0032       exSharedResources.emplace_back(edm::SharedResourceNames::kEvtGen);
0033       exSharedResources.emplace_back(edm::SharedResourceNames::kPythia6);
0034       exSharedResources.emplace_back(gen::FortranInstance::kFortranInstance);
0035     } else if (curSet == "EvtGen1" || curSet == "EvtGen130") {
0036       fEvtGenInterface = std::unique_ptr<EvtGenInterfaceBase>(
0037           EvtGenFactory::get()->create("EvtGen130", pset.getUntrackedParameter<ParameterSet>(curSet)));
0038       exSharedResources.emplace_back(edm::SharedResourceNames::kEvtGen);
0039       exSharedResources.emplace_back(edm::SharedResourceNames::kPythia8);
0040       exSharedResources.emplace_back(edm::SharedResourceNames::kTauola);
0041       exSharedResources.emplace_back(edm::SharedResourceNames::kPhotos);
0042       exSharedResources.emplace_back(gen::FortranInstance::kFortranInstance);
0043     } else if (curSet == "Tauola" || curSet == "Tauolapp" || curSet == "Tauolapp114") {
0044       fTauolaInterface = std::unique_ptr<TauolaInterfaceBase>(
0045           TauolaFactory::get()->create("Tauolapp114", pset.getUntrackedParameter<ParameterSet>(curSet), iCollector));
0046       exSharedResources.emplace_back(edm::SharedResourceNames::kTauola);
0047       exSharedResources.emplace_back(edm::SharedResourceNames::kPhotos);
0048     } else if (curSet == "Photospp" || curSet == "Photospp356") {
0049       if (!fPhotosInterface) {
0050         fPhotosInterface = std::unique_ptr<PhotosInterfaceBase>(
0051             PhotosFactory::get()->create("Photospp356", pset.getUntrackedParameter<ParameterSet>(curSet)));
0052         exSharedResources.emplace_back(edm::SharedResourceNames::kPhotos);
0053       }
0054     }
0055   }
0056 }
0057 
0058 ExternalDecayDriver::~ExternalDecayDriver() = default;
0059 
0060 HepMC::GenEvent* ExternalDecayDriver::decay(HepMC::GenEvent* evt, lhef::LHEEvent* lheEvent) {
0061   if (fTauolaInterface)
0062     fTauolaInterface->SetLHE(lheEvent);
0063   return decay(evt);
0064 }
0065 
0066 HepMC::GenEvent* ExternalDecayDriver::decay(HepMC::GenEvent* evt) {
0067   if (!fIsInitialized)
0068     return evt;
0069 
0070   if (fEvtGenInterface) {
0071     evt = fEvtGenInterface->decay(evt);
0072     if (!evt)
0073       return nullptr;
0074   }
0075 
0076   if (fTauolaInterface) {
0077     evt = fTauolaInterface->decay(evt);
0078     if (!evt)
0079       return nullptr;
0080   }
0081 
0082   if (fPhotosInterface) {
0083     evt = fPhotosInterface->apply(evt);
0084     if (!evt)
0085       return nullptr;
0086   }
0087 
0088   return evt;
0089 }
0090 
0091 void ExternalDecayDriver::init(const edm::EventSetup& es) {
0092   if (fIsInitialized)
0093     return;
0094 
0095   if (fTauolaInterface) {
0096     fTauolaInterface->init(es);
0097     for (std::vector<int>::const_iterator i = fTauolaInterface->operatesOnParticles().begin();
0098          i != fTauolaInterface->operatesOnParticles().end();
0099          i++)
0100       fPDGs.push_back(*i);
0101   }
0102 
0103   if (fEvtGenInterface) {
0104     fEvtGenInterface->init();
0105     for (std::vector<int>::const_iterator i = fEvtGenInterface->operatesOnParticles().begin();
0106          i != fEvtGenInterface->operatesOnParticles().end();
0107          i++)
0108       fPDGs.push_back(*i);
0109     for (unsigned int iss = 0; iss < fEvtGenInterface->specialSettings().size(); iss++) {
0110       fSpecialSettings.push_back(fEvtGenInterface->specialSettings()[iss]);
0111     }
0112   }
0113 
0114   if (fPhotosInterface) {
0115     fPhotosInterface->init();
0116     //   for tauola++
0117     if (fPhotosInterface) {
0118       for (unsigned int iss = 0; iss < fPhotosInterface->specialSettings().size(); iss++) {
0119         fSpecialSettings.push_back(fPhotosInterface->specialSettings()[iss]);
0120       }
0121     }
0122   }
0123 
0124   fIsInitialized = true;
0125 
0126   return;
0127 }
0128 
0129 void ExternalDecayDriver::statistics() const {
0130   if (fTauolaInterface)
0131     fTauolaInterface->statistics();
0132   if (fPhotosInterface)
0133     fPhotosInterface->statistics();
0134   // similar for EvtGen if needed
0135   return;
0136 }
0137 
0138 void ExternalDecayDriver::setRandomEngine(CLHEP::HepRandomEngine* v) {
0139   if (fTauolaInterface)
0140     fTauolaInterface->setRandomEngine(v);
0141   if (fEvtGenInterface)
0142     fEvtGenInterface->setRandomEngine(v);
0143   if (fPhotosInterface)
0144     fPhotosInterface->setRandomEngine(v);
0145 }