CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  m_Hector = new Hector(p, tok_pdt_, m_verbosity, m_FP420Transport, m_ZDCTransport);
46 
48  if (!rng.isAvailable()) {
49  throw cms::Exception("Configuration") << "LHCTransport (HectorProducer) requires the "
50  "RandomNumberGeneratorService\n"
51  "which is not present in the configuration file. You must add the "
52  "service\n"
53  "in the configuration file or remove the modules that require it.";
54  }
55  edm::LogVerbatim("SimTransportHectorProducer") << "Hector is created";
56 }
57 
59 
61 
63 
66  CLHEP::HepRandomEngine *engine = &rng->getEngine(iEvent.streamID());
67  if (engine->name() != "TRandom3") {
68  throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with HectorProducer, "
69  << "Random Number Generator Service not correctly configured!";
70  }
71  TRandom3 *rootEngine = ((edm::TRandomAdaptor *)engine)->getRootEngine();
72 
73  ++m_evtAnalysed;
74 
75  edm::LogVerbatim("SimTransportHectorProducer") << "produce evt " << m_evtAnalysed;
76 
78  iEvent.getByToken(m_HepMC, HepMCEvt);
79 
80  if (!HepMCEvt.isValid()) {
81  throw cms::Exception("InvalidReference") << "Invalid reference to HepMCProduct\n";
82  }
83 
84  if (HepMCEvt.provenance()->moduleLabel() == "LHCTransport") {
85  throw cms::Exception("LogicError") << "HectorTrasported HepMCProduce already exists\n";
86  }
87 
88  evt_ = new HepMC::GenEvent(*HepMCEvt->GetEvent());
90  if (m_FP420Transport) {
91  m_Hector->clear();
92  m_Hector->add(evt_, es);
93  m_Hector->filterFP420(rootEngine);
94  }
95  if (m_ZDCTransport) {
96  m_Hector->clear();
97  m_Hector->add(evt_, es);
98  m_Hector->filterZDC(rootEngine);
99 
100  m_Hector->clear();
101  m_Hector->add(evt_, es);
102  m_Hector->filterD1(rootEngine);
103  }
105  if (m_verbosity)
106  evt_->print();
107 
108  edm::LogVerbatim("SimTransportHectorProducer") << "new HepMC product ";
109 
110  unique_ptr<edm::HepMCProduct> NewProduct(new edm::HepMCProduct());
111  NewProduct->addHepMCData(evt_);
112 
113  iEvent.put(std::move(NewProduct));
114 
115  edm::LogVerbatim("SimTransportHectorProducer") << "new LHCTransportLinkContainer ";
116  unique_ptr<edm::LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
118  (*NewCorrespondenceMap).swap(thisLink);
119 
120  if (m_verbosity) {
121  for (unsigned int i = 0; i < (*NewCorrespondenceMap).size(); ++i)
122  edm::LogVerbatim("HectorEventProcessing") << "Hector correspondence table: " << (*NewCorrespondenceMap)[i];
123  }
124 
125  iEvent.put(std::move(NewCorrespondenceMap));
126  edm::LogVerbatim("SimTransportHectorProducer") << "produce end ";
127 }
128 
Log< level::Info, true > LogVerbatim
int m_evtAnalysed
just to count events that have been analysed
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EventSetup & c
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
edm::EDGetTokenT< edm::HepMCProduct > m_HepMC
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HectorProducer(edm::ParameterSet const &p)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
Definition: Hector.h:40
void clear()
Definition: Hector.cc:155
void endRun(const edm::Run &r, const edm::EventSetup &c) override
int iEvent
Definition: GenABIO.cc:224
void filterD1(TRandom3 *)
Definition: Hector.cc:405
def move
Definition: eostools.py:511
bool isAvailable() const
Definition: Service.h:40
void filterFP420(TRandom3 *)
Definition: Hector.cc:230
bool isValid() const
Definition: HandleBase.h:70
edm::ESGetToken< HepPDT::ParticleDataTable, PDTRecord > tok_pdt_
void filterZDC(TRandom3 *)
Definition: Hector.cc:322
~HectorProducer() override
Hector * m_Hector
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string const & moduleLabel() const
Definition: Provenance.h:55
void add(const HepMC::GenEvent *ev, const edm::EventSetup &es)
Definition: Hector.cc:167
std::vector< LHCTransportLink > & getCorrespondenceMap()
Definition: Hector.h:77
HepMC::GenEvent * addPartToHepMC(HepMC::GenEvent *event)
Definition: Hector.cc:506
StreamID streamID() const
Definition: Event.h:98
std::vector< LHCTransportLink > LHCTransportLinkContainer
HepMC::GenEvent * evt_
Definition: Run.h:45
Provenance const * provenance() const
Definition: HandleBase.h:74
void clearApertureFlags()
Definition: Hector.cc:149
void produce(edm::Event &e, const edm::EventSetup &c) override