10 #include <generators/modules/hepmcwriter/HepmcOutputModule.h>
12 #include <framework/datastore/StoreArray.h>
13 #include <framework/dataobjects/EventMetaData.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <framework/gearbox/Unit.h>
16 #include <mdst/dataobjects/MCParticle.h>
32 setDescription(
"HepMC file output. This module loads an event record from the MCParticle collection and store the content back into the HepMC (2) format. HepMC format is a standard event record format to contain an event record in a Monte Carlo-independent format.");
34 addParam(
"OutputFilename", m_filename,
"The filename of the output file");
35 addParam(
"StoreVirtualParticles", m_storeVirtualParticles,
"Store also virtual particles in the HepMC file.",
false);
39 void HepMCOutputModule::initialize()
41 m_ascii_io = std::make_unique<HepMC::IO_GenEvent>(m_filename, std::ios::out);
45 void HepMCOutputModule::event()
54 if (!m_storeVirtualParticles) {
55 for (
int iPart = 0; iPart < nPart; ++iPart) {
64 HepMC::HEPEVT_Wrapper::zero_everything();
65 HepMC::HEPEVT_Wrapper::set_event_number(eventMetaDataPtr->getEvent());
66 HepMC::HEPEVT_Wrapper::set_number_entries(nPart - nVirtualPart);
69 for (
int iPart = 1; iPart <= nPart; ++iPart) {
71 MCParticle& mcPart = *mcPartCollection[iPart - 1];
73 if (!m_storeVirtualParticles && mcPart.
isVirtual()) {
88 HepMC::HEPEVT_Wrapper::set_status(iPart, isthep);
89 HepMC::HEPEVT_Wrapper::set_id(iPart, mcPart.
getPDG());
90 HepMC::HEPEVT_Wrapper::set_parents(iPart, motherIndex, motherIndex);
92 HepMC::HEPEVT_Wrapper::set_momentum(iPart,
97 HepMC::HEPEVT_Wrapper::set_mass(iPart, mcPart.
getMass() * Unit::GeV);
98 HepMC::HEPEVT_Wrapper::set_position(iPart,
106 HepMC::GenEvent* evt = m_hepevtio.read_next_event();
107 evt->use_units(HepMC::Units::GEV, HepMC::Units::CM);
113 void HepMCOutputModule::terminate()