10 #include <generators/modules/hepmcreader/HepmcInputModule.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/datastore/DataStore.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/dataobjects/EventMetaData.h>
16 #include <framework/datastore/StoreObjPtr.h>
17 #include <framework/core/Environment.h>
34 setDescription(
"HepMC file input. This module loads an event record from HEPMC2 format and store the content into the MCParticle collection. HEPMC format is used by for example pythia8.");
38 addParam(
"inputFileList", m_inputFileNames,
"List of names of HepMC2 files");
39 addParam(
"ignoreReadEventNr", m_ignorereadEventNr,
"Parallel pythia can have dublicate event nrs.",
false);
40 addParam(
"runNum", m_runNum,
"run number to start from", 0);
41 addParam(
"expNum", m_expNum,
"ExpNum to start from", 0);
42 addParam(
"minEvt", m_minEvent,
"Start converting at event number.", -1);
43 addParam(
"maxEvt", m_maxEvent,
"Stop converting at Event number.", INT_MAX);
44 addParam(
"useWeights", m_useWeights,
"Set to 'true' to if generator weights should be propagated.",
false);
45 addParam(
"nVirtualParticles", m_nVirtual,
"Number of particles at the beginning of the events that should be made virtual.", 0);
46 addParam(
"boost2Lab", m_boost2Lab,
"Boolean to indicate whether the particles should be boosted from CM frame to lab frame",
false);
47 addParam(
"wrongSignPz", m_wrongSignPz,
"Boolean to signal that directions of HER and LER were switched",
false);
51 void HepMCInputModule::initialize()
53 m_hepmcreader.reset(
new HepMCReader(m_minEvent, m_maxEvent));
54 TLorentzRotation m_labboost;
56 if (m_runNum != 0 || m_expNum != 0) {
57 B2WARNING(
"Initialising the first read events with expNr or runNr != 0. This can lead to downloading the wrong payloads from the database if you are using MC!");
60 m_initial.initialize();
61 m_eventMetaDataPtr.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
63 if (m_inputFileNames.size() == 0) {
65 B2FATAL(
"invalid list of input files. No entries found.");
68 m_inputFileName = m_inputFileNames[m_iFile];
71 B2INFO(
"Opening first file: " << m_inputFileName);
72 m_hepmcreader->open(m_inputFileName);
74 }
catch (runtime_error& e) {
77 m_hepmcreader->m_nVirtual = m_nVirtual;
78 m_hepmcreader->m_wrongSignPz = m_wrongSignPz;
84 m_hepmcreader->m_labboost = boost;
88 B2INFO(
"HEPMC reader acts as master module for data processing. This means the event numbers etc will be set by this module.");
89 if (m_runNum == 0 && m_expNum == 0) {
90 B2WARNING(
"HEPMC reader acts as master module, but no run and experiment number set. Using defaults.");
95 mcparticle.registerInDataStore();
96 m_totalEvents = m_hepmcreader->countEvents(m_inputFileName);
97 Environment::Instance().setNumberOfMCEvents(m_totalEvents);
102 void HepMCInputModule::event()
106 "Event ________________________________________________________________________________________________________________________________________________________________________________________________");
107 if (m_beamParams.hasChanged()) {
111 m_hepmcreader->m_labboost = boost;
113 B2WARNING(
"HepmcInputModule::event(): BeamParameters have changed within a job!");
116 if (!m_eventMetaDataPtr) { m_eventMetaDataPtr.create(); }
118 m_mcParticleGraph.clear();
120 int id = m_hepmcreader->getEvent(m_mcParticleGraph, weight);
121 if (
id > -1 && !m_ignorereadEventNr) {
126 B2DEBUG(20,
"Setting exp " << m_expNum <<
" run " << m_runNum <<
" event " <<
id <<
".");
127 m_eventMetaDataPtr->setExperiment(m_expNum);
128 m_eventMetaDataPtr->setRun(m_runNum);
129 m_eventMetaDataPtr->setEvent(
id);
130 if (m_useWeights) { m_eventMetaDataPtr->setGeneratedWeight(weight); }
131 m_mcParticleGraph.generateList(
"", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
132 }
catch (HepMCReader::HepMCInvalidEventError&) {
133 B2DEBUG(20,
"Reached end of HepMC file.");
134 m_hepmcreader->closeCurrentInputFile();
136 if (m_iFile < m_inputFileNames.size()) {
138 m_inputFileName = m_inputFileNames[m_iFile];
139 B2INFO(
"Opening next file: " << m_inputFileName);
140 m_hepmcreader->open(m_inputFileName);
141 }
catch (runtime_error& e) {
145 m_eventMetaDataPtr->setEndOfData();
146 B2DEBUG(20,
"Reached end of all HepMC files.");
148 }
catch (runtime_error& e) {
153 void HepMCInputModule::terminate()
155 if (m_evtNum != m_totalEvents) { B2WARNING(
"Eventnumber mismatch. (ignore if more than one file was read.)");}