Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-07 23:58:28

0001 // Framework headers
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/PluginManager/interface/ModuleDef.h"
0004 #include "FWCore/ServiceRegistry/interface/Service.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 #include "FWCore/Utilities/interface/InputTag.h"
0007 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 #include "IOMC/RandomEngine/interface/TRandomAdaptor.h"
0011 
0012 // SimpleConfigurable replacement
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 
0015 // HepMC headers
0016 #include "HepMC/GenEvent.h"
0017 
0018 // Hector headers
0019 #include "SimTransport/HectorProducer/interface/Hector.h"
0020 #include "SimTransport/HectorProducer/interface/HectorProducer.h"
0021 
0022 // SimDataFormats headers
0023 #include "SimDataFormats/Forward/interface/LHCTransportLinkContainer.h"
0024 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0025 
0026 #include <CLHEP/Random/RandomEngine.h>
0027 
0028 #include <iostream>
0029 #include <memory>
0030 #include <string>
0031 
0032 class TRandom3;
0033 
0034 HectorProducer::HectorProducer(edm::ParameterSet const &p)
0035     : m_HepMC(consumes<edm::HepMCProduct>(p.getParameter<edm::InputTag>("HepMCProductLabel"))) {
0036   tok_pdt_ = esConsumes<HepPDT::ParticleDataTable, PDTRecord>();
0037   m_verbosity = p.getParameter<bool>("Verbosity");
0038   m_FP420Transport = p.getParameter<bool>("FP420Transport");
0039   m_ZDCTransport = p.getParameter<bool>("ZDCTransport");
0040   m_evtAnalysed = 0;
0041 
0042   produces<edm::HepMCProduct>();
0043   produces<edm::LHCTransportLinkContainer>();
0044 
0045   m_Hector = new Hector(p, tok_pdt_, m_verbosity, m_FP420Transport, m_ZDCTransport);
0046 
0047   edm::Service<edm::RandomNumberGenerator> rng;
0048   if (!rng.isAvailable()) {
0049     throw cms::Exception("Configuration") << "LHCTransport (HectorProducer) requires the "
0050                                              "RandomNumberGeneratorService\n"
0051                                              "which is not present in the configuration file.  You must add the "
0052                                              "service\n"
0053                                              "in the configuration file or remove the modules that require it.";
0054   }
0055   edm::LogVerbatim("SimTransportHectorProducer") << "Hector is created";
0056 }
0057 
0058 HectorProducer::~HectorProducer() {}
0059 
0060 void HectorProducer::beginRun(const edm::Run &r, const edm::EventSetup &c) {}
0061 
0062 void HectorProducer::endRun(const edm::Run &r, const edm::EventSetup &c) {}
0063 
0064 void HectorProducer::produce(edm::Event &iEvent, const edm::EventSetup &es) {
0065   edm::Service<edm::RandomNumberGenerator> rng;
0066   CLHEP::HepRandomEngine *engine = &rng->getEngine(iEvent.streamID());
0067   if (engine->name() != "TRandom3") {
0068     throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with HectorProducer, "
0069                                           << "Random Number Generator Service not correctly configured!";
0070   }
0071   TRandom3 *rootEngine = ((edm::TRandomAdaptor *)engine)->getRootEngine();
0072 
0073   ++m_evtAnalysed;
0074 
0075   edm::LogVerbatim("SimTransportHectorProducer") << "produce evt " << m_evtAnalysed;
0076 
0077   edm::Handle<edm::HepMCProduct> HepMCEvt;
0078   iEvent.getByToken(m_HepMC, HepMCEvt);
0079 
0080   if (!HepMCEvt.isValid()) {
0081     throw cms::Exception("InvalidReference") << "Invalid reference to HepMCProduct\n";
0082   }
0083 
0084   if (HepMCEvt.provenance()->moduleLabel() == "LHCTransport") {
0085     throw cms::Exception("LogicError") << "HectorTrasported HepMCProduce already exists\n";
0086   }
0087 
0088   evt_ = new HepMC::GenEvent(*HepMCEvt->GetEvent());
0089   m_Hector->clearApertureFlags();
0090   if (m_FP420Transport) {
0091     m_Hector->clear();
0092     m_Hector->add(evt_, es);
0093     m_Hector->filterFP420(rootEngine);
0094   }
0095   if (m_ZDCTransport) {
0096     m_Hector->clear();
0097     m_Hector->add(evt_, es);
0098     m_Hector->filterZDC(rootEngine);
0099 
0100     m_Hector->clear();
0101     m_Hector->add(evt_, es);
0102     m_Hector->filterD1(rootEngine);
0103   }
0104   evt_ = m_Hector->addPartToHepMC(evt_);
0105   if (m_verbosity)
0106     evt_->print();
0107 
0108   edm::LogVerbatim("SimTransportHectorProducer") << "new HepMC product ";
0109 
0110   unique_ptr<edm::HepMCProduct> NewProduct(new edm::HepMCProduct());
0111   NewProduct->addHepMCData(evt_);
0112 
0113   iEvent.put(std::move(NewProduct));
0114 
0115   edm::LogVerbatim("SimTransportHectorProducer") << "new LHCTransportLinkContainer ";
0116   unique_ptr<edm::LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
0117   edm::LHCTransportLinkContainer thisLink(m_Hector->getCorrespondenceMap());
0118   (*NewCorrespondenceMap).swap(thisLink);
0119 
0120   if (m_verbosity) {
0121     for (unsigned int i = 0; i < (*NewCorrespondenceMap).size(); ++i)
0122       edm::LogVerbatim("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
0123   }
0124 
0125   iEvent.put(std::move(NewCorrespondenceMap));
0126   edm::LogVerbatim("SimTransportHectorProducer") << "produce end ";
0127 }
0128 
0129 DEFINE_FWK_MODULE(HectorProducer);