10 #include <generators/modules/LHEInputModule.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>
39 setDescription(
"LHE file input. This module loads an event record from LHE format and store the content into the MCParticle collection. LHE format is a standard event record format to contain an event record in a Monte Carlo-independent format.");
43 addParam(
"inputFileList", m_inputFileNames,
"List of names of LHE files");
44 addParam(
"makeMaster", m_makeMaster,
"Boolean to indicate whether the event numbers from input file should be used.",
false);
45 addParam(
"runNum", m_runNum,
"Run number (should be set if makeMaster=true)", 0);
46 addParam(
"expNum", m_expNum,
"Experiment number (should be set if makeMaster=true)", 0);
47 addParam(
"skipEvents", m_skipEventNumber,
"Skip this number of events before starting.", 0);
48 addParam(
"useWeights", m_useWeights,
"Set to 'true' to if generator weights should be propagated (not implemented yet).",
false);
49 addParam(
"nInitialParticles", m_nInitial,
"Number of MCParticles at the beginning of the events that should be flagged c_Initial.",
51 addParam(
"nVirtualParticles", m_nVirtual,
52 "Number of MCParticles at the beginning of the events that should be flagged c_IsVirtual.", 0);
53 addParam(
"boost2Lab", m_boost2Lab,
"Boolean to indicate whether the particles should be boosted from CM frame to lab frame",
false);
54 addParam(
"wrongSignPz", m_wrongSignPz,
"Boolean to signal that directions of HER and LER were switched",
true);
55 addParam(
"meanDecayLength", m_meanDecayLength,
56 "Mean decay length(mean lifetime * c) between displaced vertex to IP, default to be zero, unit in cm", 0.);
57 addParam(
"Rmin", m_Rmin,
"Minimum of distance between displaced vertex to IP", 0.);
58 addParam(
"Rmax", m_Rmax,
"Maximum of distance between displaced vertex to IP", 1000000.);
59 addParam(
"pdg_displaced", m_pdg_displaced,
"PDG code of the displaced particle being studied", 9000008);
63 void LHEInputModule::initialize()
66 m_initial.initialize();
69 if (m_inputFileNames.size() == 0) {
71 B2FATAL(
"Invalid list of input files. No entries found.");
74 m_inputFileName = m_inputFileNames[m_iFile];
77 B2INFO(
"Opening first file: " << m_inputFileName);
78 m_lhe.open(m_inputFileName);
79 m_lhe.skipEvents(m_skipEventNumber);
80 }
catch (runtime_error& e) {
83 m_lhe.setInitialIndex(m_nInitial);
84 m_lhe.setVirtualIndex(m_nInitial + m_nVirtual);
85 m_lhe.m_wrongSignPz = m_wrongSignPz;
91 m_lhe.m_labboost = boost;
95 m_lhe.m_meanDecayLength = m_meanDecayLength;
96 m_lhe.m_Rmin = m_Rmin;
97 m_lhe.m_Rmax = m_Rmax;
98 m_lhe.m_pdgDisplaced = m_pdg_displaced;
100 if (m_Rmin != 0 || m_Rmax != 1000000) {
101 TF1 fr(
"fr",
"exp(-x/[0])", 0, 1000000);
103 factor = fr.Integral(m_Rmin, m_Rmax) / fr.Integral(0, 1000000);
104 B2WARNING(
"Default range of R is changed, new range is from " << m_Rmin <<
"cm to " << m_Rmax <<
105 " cm. This will change the cross section by a factor of " << factor);
110 B2INFO(
"LHE reader acts as master module for data processing.");
111 if (m_runNum == 0 && m_expNum == 0)
112 B2WARNING(
"LHE reader acts as master module, but no run and experiment number set. Using defaults.");
115 eventmetadata.registerInDataStore();
120 mcparticle.registerInDataStore();
125 void LHEInputModule::event()
129 if (!eventMetaDataPtr) eventMetaDataPtr.create();
130 B2DEBUG(100,
"LHE processes event nbr " << eventMetaDataPtr->getEvent());
135 int id = m_lhe.getEvent(mpg, weight);
144 eventMetaDataPtr->setExperiment(m_expNum);
145 eventMetaDataPtr->setRun(m_runNum);
146 eventMetaDataPtr->setEvent(
id);
149 eventMetaDataPtr->setGeneratedWeight(weight);
150 mpg.generateList(
"", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
151 }
catch (LHEReader::LHEEmptyEventError&) {
152 B2DEBUG(100,
"Reached end of LHE file.");
153 m_lhe.closeCurrentInputFile();
155 if (m_iFile < m_inputFileNames.size()) {
157 m_inputFileName = m_inputFileNames[m_iFile];
158 B2INFO(
"Opening next file: " << m_inputFileName);
159 m_lhe.open(m_inputFileName);
160 }
catch (runtime_error& e) {
164 eventMetaDataPtr->setEndOfData();
165 B2DEBUG(100,
"Reached end of all LHE files.");
167 }
catch (runtime_error& e) {