LDMX Software
LHEReader.cxx
2
3// STL
4#include <iostream>
5
6namespace simcore::lhe {
7
8LHEReader::LHEReader(std::string& filename) {
9 std::cout << "Opening LHE file " << filename << std::endl;
10 ifs_.open(filename.c_str(), std::ifstream::in);
11}
12
14
16 std::string line;
17 bool foundEventElement = false;
18 while (getline(ifs_, line)) {
19 if (line == "<event>") {
20 foundEventElement = true;
21 break;
22 }
23 }
24
25 if (!foundEventElement) {
26 std::cerr << "WARNING: No next <event> element was found by the LHE reader."
27 << std::endl;
28 return nullptr;
29 }
30
31 getline(ifs_, line);
32
33 LHEEvent* nextEvent = new LHEEvent(line);
34
35 while (getline(ifs_, line)) {
36 if (line == "</event>" || line == "<mgrwt>") {
37 // break if the event ended or in LHE 3.0 if we reach the mgrwt block
38 break;
39 }
40
41 if (line.find("#") == std::string::npos) { // not a comment line
42 LHEParticle* particle = new LHEParticle(line);
43 nextEvent->addParticle(particle);
44 } else {
45 if (line.find("#vertex") != std::string::npos) {
46 nextEvent->setVertex(line);
47 }
48 }
49 }
50
51 const std::vector<LHEParticle*>& particles = nextEvent->getParticles();
52 int particleIndex = 0;
53 for (std::vector<LHEParticle*>::const_iterator it = particles.begin();
54 it != particles.end(); it++) {
55 LHEParticle* particle = (*it);
56 if (particle->getMOTHUP(0) != 0) {
57 int mother1 = particle->getMOTHUP(0);
58 int mother2 = particle->getMOTHUP(1);
59 if (mother1 > 0) {
60 particle->setMother(0, particles[mother1 - 1]);
61 }
62 if (mother2 > 0) {
63 particle->setMother(1, particles[mother2 - 1]);
64 }
65 }
66 ++particleIndex;
67 }
68
69 return nextEvent;
70}
71
72} // namespace simcore::lhe
Class for reading LHE event data.
LHE event with a list of particles and information from the header block.
Definition LHEEvent.h:29
void addParticle(LHEParticle *particle)
Add a particle to the event.
Definition LHEEvent.cxx:66
const std::vector< LHEParticle * > & getParticles()
Get the list of particles in the event.
Definition LHEEvent.cxx:70
void setVertex(double x, double y, double z)
Set the vertex location (careful to match units as expected!)
Definition LHEEvent.cxx:72
Single particle record in an LHE event.
Definition LHEParticle.h:20
int getMOTHUP(int) const
Get a mother particle index (MOTHUP) by index.
void setMother(int i, LHEParticle *particle)
Set a mother particle by index.
std::ifstream ifs_
The input file stream.
Definition LHEReader.h:45
LHEReader(std::string &fileName)
Class constructor.
Definition LHEReader.cxx:8
virtual ~LHEReader()
Class destructor.
Definition LHEReader.cxx:13
LHEEvent * readNextEvent()
Read the next event.
Definition LHEReader.cxx:15