9 #include <generators/modules/hepmcwriter/HepmcOutputModule.h>
11 #include <framework/datastore/StoreArray.h>
12 #include <framework/dataobjects/EventMetaData.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/gearbox/Unit.h>
15 #include <mdst/dataobjects/MCParticle.h>
31 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.");
33 addParam(
"OutputFilename", m_filename,
"The filename of the output file");
34 addParam(
"StoreVirtualParticles", m_storeVirtualParticles,
"Store also virtual particles in the HepMC file.",
false);
38 void HepMCOutputModule::initialize()
40 m_ascii_io = std::make_unique<HepMC::IO_GenEvent>(m_filename, std::ios::out);
44 void HepMCOutputModule::event()
53 if (!m_storeVirtualParticles) {
54 for (
int iPart = 0; iPart < nPart; ++iPart) {
63 HepMC::HEPEVT_Wrapper::zero_everything();
64 HepMC::HEPEVT_Wrapper::set_event_number(eventMetaDataPtr->getEvent());
65 HepMC::HEPEVT_Wrapper::set_number_entries(nPart - nVirtualPart);
68 for (
int iPart = 1; iPart <= nPart; ++iPart) {
70 MCParticle& mcPart = *mcPartCollection[iPart - 1];
72 if (!m_storeVirtualParticles && mcPart.
isVirtual()) {
87 HepMC::HEPEVT_Wrapper::set_status(iPart, isthep);
88 HepMC::HEPEVT_Wrapper::set_id(iPart, mcPart.
getPDG());
89 HepMC::HEPEVT_Wrapper::set_parents(iPart, motherIndex, motherIndex);
91 HepMC::HEPEVT_Wrapper::set_momentum(iPart,
96 HepMC::HEPEVT_Wrapper::set_mass(iPart, mcPart.
getMass() * Unit::GeV);
97 HepMC::HEPEVT_Wrapper::set_position(iPart,
105 HepMC::GenEvent* evt = m_hepevtio.read_next_event();
106 evt->use_units(HepMC::Units::GEV, HepMC::Units::CM);
112 void HepMCOutputModule::terminate()
A Class to store the Monte Carlo particle information.
float getEnergy() const
Return particle energy in GeV.
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
float getMass() const
Return the particle mass in GeV.
TVector3 getVertex() const
Return production vertex position, shorthand for getProductionVertex().
TVector3 getMomentum() const
Return momentum.
int getLastDaughter() const
Get 1-based index of last daughter, 0 if no daughters.
int getPDG() const
Return PDG code of particle.
float getProductionTime() const
Return production time in ns.
int getFirstDaughter() const
Get 1-based index of first daughter, 0 if no daughters.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
bool isInitial() const
Check if particle is an initial particle such as ISR.
MCParticle * getMother() const
Returns a pointer to the mother particle.
bool isVirtual() const
Check if particle is virtual.
Abstract base class for different kinds of events.