CMS 3D CMS Logo

HectorProducer.cc
Go to the documentation of this file.
1 // Framework headers
9 
11 
12 // SimpleConfigurable replacement
14 
15 // HepMC headers
16 #include "HepMC/GenEvent.h"
17 
18 // Hector headers
21 
22 // SimDataFormats headers
25 
26 #include <CLHEP/Random/RandomEngine.h>
27 
28 #include <iostream>
29 #include <memory>
30 #include <string>
31 
32 class TRandom3;
33 
35  : m_HepMC(consumes<edm::HepMCProduct>(p.getParameter<edm::InputTag>("HepMCProductLabel"))) {
36  tok_pdt_ = esConsumes<HepPDT::ParticleDataTable, PDTRecord>();
37  m_verbosity = p.getParameter<bool>("Verbosity");
38  m_FP420Transport = p.getParameter<bool>("FP420Transport");
39  m_ZDCTransport = p.getParameter<bool>("ZDCTransport");
40  m_evtAnalysed = 0;
41 
42  produces<edm::HepMCProduct>();
43  produces<edm::LHCTransportLinkContainer>();
44 
45  usesResource("Hector");
46  m_Hector = std::make_unique<Hector>(p, tok_pdt_, m_verbosity, m_FP420Transport, m_ZDCTransport);
47 
49  if (!rng.isAvailable()) {
50  throw cms::Exception("Configuration") << "LHCTransport (HectorProducer) requires the "
51  "RandomNumberGeneratorService\n"
52  "which is not present in the configuration file. You must add the "
53  "service\n"
54  "in the configuration file or remove the modules that require it.";
55  }
56  edm::LogVerbatim("SimTransportHectorProducer") << "Hector is created";
57 }
58 
60 
63  CLHEP::HepRandomEngine *engine = &rng->getEngine(iEvent.streamID());
64  if (engine->name() != "TRandom3") {
65  throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with HectorProducer, "
66  << "Random Number Generator Service not correctly configured!";
67  }
68  TRandom3 *rootEngine = ((edm::TRandomAdaptor *)engine)->getRootEngine();
69 
70  ++m_evtAnalysed;
71 
72  edm::LogVerbatim("SimTransportHectorProducer") << "produce evt " << m_evtAnalysed;
73 
75  iEvent.getByToken(m_HepMC, HepMCEvt);
76 
77  if (!HepMCEvt.isValid()) {
78  throw cms::Exception("InvalidReference") << "Invalid reference to HepMCProduct\n";
79  }
80 
81  if (HepMCEvt.provenance()->moduleLabel() == "LHCTransport") {
82  throw cms::Exception("LogicError") << "HectorTrasported HepMCProduce already exists\n";
83  }
84 
85  auto evt = new HepMC::GenEvent(*HepMCEvt->GetEvent());
86  m_Hector->clearApertureFlags();
87  if (m_FP420Transport) {
88  m_Hector->clear();
89  m_Hector->add(evt, es);
90  m_Hector->filterFP420(rootEngine);
91  }
92  if (m_ZDCTransport) {
93  m_Hector->clear();
94  m_Hector->add(evt, es);
95  m_Hector->filterZDC(rootEngine);
96 
97  m_Hector->clear();
98  m_Hector->add(evt, es);
99  m_Hector->filterD1(rootEngine);
100  }
101  evt = m_Hector->addPartToHepMC(evt);
102  if (m_verbosity)
103  evt->print();
104 
105  edm::LogVerbatim("SimTransportHectorProducer") << "new HepMC product ";
106 
107  unique_ptr<edm::HepMCProduct> NewProduct(new edm::HepMCProduct());
108  NewProduct->addHepMCData(evt);
109 
110  iEvent.put(std::move(NewProduct));
111 
112  edm::LogVerbatim("SimTransportHectorProducer") << "new LHCTransportLinkContainer ";
113  unique_ptr<edm::LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
114  edm::LHCTransportLinkContainer thisLink(m_Hector->getCorrespondenceMap());
115  (*NewCorrespondenceMap).swap(thisLink);
116 
117  if (m_verbosity) {
118  for (unsigned int i = 0; i < (*NewCorrespondenceMap).size(); ++i)
119  edm::LogVerbatim("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
120  }
121 
122  iEvent.put(std::move(NewCorrespondenceMap));
123  edm::LogVerbatim("SimTransportHectorProducer") << "produce end ";
124 }
125 
Log< level::Info, true > LogVerbatim
int m_evtAnalysed
just to count events that have been analysed
edm::EDGetTokenT< edm::HepMCProduct > m_HepMC
HectorProducer(edm::ParameterSet const &p)
Provenance const * provenance() const
Definition: HandleBase.h:74
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
edm::ESGetToken< HepPDT::ParticleDataTable, PDTRecord > tok_pdt_
~HectorProducer() override
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
std::vector< LHCTransportLink > LHCTransportLinkContainer
std::unique_ptr< Hector > m_Hector
std::string const & moduleLabel() const
Definition: Provenance.h:55
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &e, const edm::EventSetup &c) override