This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LHEReader.cxx
73 lines (58 loc) · 1.94 KB
/
LHEReader.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "SimCore/LHEReader.h"
// STL
#include <iostream>
namespace ldmx {
LHEReader::LHEReader(std::string& filename) {
std::cout << "Opening LHE file " << filename << std::endl;
ifs_.open(filename.c_str(), std::ifstream::in);
}
LHEReader::~LHEReader() {
ifs_.close();
}
LHEEvent* LHEReader::readNextEvent() {
std::string line;
bool foundEventElement = false;
while (getline(ifs_, line)) {
if (line == "<event>") {
foundEventElement = true;
break;
}
}
if (!foundEventElement) {
std::cerr << "WARNING: No next <event> element was found by the LHE reader." << std::endl;
return NULL;
}
getline(ifs_, line);
LHEEvent* nextEvent = new LHEEvent(line);
while (getline(ifs_, line)) {
if (line == "</event>") {
break;
}
if (line.find("#")==std::string::npos) { // not a comment line
LHEParticle* particle = new LHEParticle(line);
nextEvent->addParticle(particle);
} else {
if (line.find("#vertex")!=std::string::npos) {
nextEvent->setVertex(line);
}
}
}
const std::vector<LHEParticle*>& particles = nextEvent->getParticles();
int particleIndex = 0;
for (std::vector<LHEParticle*>::const_iterator it = particles.begin(); it != particles.end(); it++) {
LHEParticle* particle = (*it);
if (particle->getMOTHUP(0) != 0) {
int mother1 = particle->getMOTHUP(0);
int mother2 = particle->getMOTHUP(1);
if (mother1 > 0) {
particle->setMother(0, particles[mother1 - 1]);
}
if (mother2 > 0) {
particle->setMother(1, particles[mother2 - 1]);
}
}
++particleIndex;
}
return nextEvent;
}
}