9 #include <generators/modules/LHEInputModule.h>
11 #include <framework/logging/Logger.h>
12 #include <framework/datastore/DataStore.h>
13 #include <framework/datastore/StoreArray.h>
28 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.");
32 addParam(
"inputFileList", m_inputFileNames,
"List of names of LHE files");
33 addParam(
"makeMaster", m_makeMaster,
"Boolean to indicate whether the event numbers from input file should be used.",
false);
34 addParam(
"runNum", m_runNum,
"Run number", -1);
35 addParam(
"expNum", m_expNum,
"Experiment number", -1);
36 addParam(
"skipEvents", m_skipEventNumber,
"Skip this number of events before starting.", 0);
37 addParam(
"useWeights", m_useWeights,
"Set to 'true' to if generator weights should be propagated (not implemented yet).",
false);
38 addParam(
"nInitialParticles", m_nInitial,
"Number of MCParticles at the beginning of the events that should be flagged c_Initial.",
40 addParam(
"nVirtualParticles", m_nVirtual,
41 "Number of MCParticles at the beginning of the events that should be flagged c_IsVirtual.", 0);
42 addParam(
"wrongSignPz", m_wrongSignPz,
"Boolean to signal that directions of HER and LER were switched",
true);
43 addParam(
"meanDecayLength", m_meanDecayLength,
44 "Mean decay length(mean lifetime * c) between displaced vertex to IP in the CM frame, default to be zero, unit in cm", 0.);
45 addParam(
"Rmin", m_Rmin,
"Minimum of distance between displaced vertex to IP in CM frame", 0.);
46 addParam(
"Rmax", m_Rmax,
"Maximum of distance between displaced vertex to IP in CM frame", 1000000.);
47 addParam(
"pdg_displaced", m_pdg_displaced,
"PDG code of the displaced particle being studied", 9000008);
51 void LHEInputModule::initialize()
53 if (m_expNum < 0 or m_runNum < 0)
54 B2FATAL(
"The exp. and run numbers are not properly initialized: please set the 'expNum' and 'runNum' parameters of the LHEInput module.");
56 m_eventMetaData.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
57 B2INFO(
"LHEInput acts as input module for this process. This means the exp., run and event numbers will be set by this module.");
60 if (m_inputFileNames.size() == 0) {
62 B2FATAL(
"Invalid list of input files, no entries found.");
65 m_inputFileName = m_inputFileNames[m_iFile];
68 B2INFO(
"Opening first file: " << m_inputFileName);
69 m_lhe.open(m_inputFileName);
70 m_lhe.skipEvents(m_skipEventNumber);
71 }
catch (runtime_error& e) {
74 m_lhe.setInitialIndex(m_nInitial);
75 m_lhe.setVirtualIndex(m_nInitial + m_nVirtual);
76 m_lhe.m_wrongSignPz = m_wrongSignPz;
79 m_lhe.m_meanDecayLength = m_meanDecayLength;
80 m_lhe.m_Rmin = m_Rmin;
81 m_lhe.m_Rmax = m_Rmax;
82 m_lhe.m_pdgDisplaced = m_pdg_displaced;
84 if (m_Rmin != 0 || m_Rmax != 1000000) {
85 TF1 fr(
"fr",
"exp(-x/[0])", 0, 1000000);
87 factor = fr.Integral(m_Rmin, m_Rmax) / fr.Integral(0, 1000000);
88 B2WARNING(
"Default range of R is changed, new range is from " << m_Rmin <<
"cm to " << m_Rmax <<
89 " cm. This will change the cross section by a factor of " << factor);
97 void LHEInputModule::event()
100 m_eventMetaData.create();
104 int id = m_lhe.getEvent(mpg, weight);
111 m_eventMetaData->setExperiment(m_expNum);
112 m_eventMetaData->setRun(m_runNum);
113 m_eventMetaData->setEvent(
id);
116 m_eventMetaData->setGeneratedWeight(weight);
117 mpg.generateList(
"", MCParticleGraph::c_setDecayInfo | MCParticleGraph::c_checkCyclic);
118 }
catch (LHEReader::LHEEmptyEventError&) {
119 B2DEBUG(100,
"Reached end of LHE file.");
120 m_lhe.closeCurrentInputFile();
122 if (m_iFile < m_inputFileNames.size()) {
124 m_inputFileName = m_inputFileNames[m_iFile];
125 B2INFO(
"Opening next file: " << m_inputFileName);
126 m_lhe.open(m_inputFileName);
127 }
catch (runtime_error& e) {
131 m_eventMetaData->setEndOfData();
132 B2DEBUG(100,
"Reached end of all LHE files.");
134 }
catch (runtime_error& e) {
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.