LDMX Software
Public Member Functions | Private Attributes | List of all members
simcore::lhe::LHEReader Class Reference

Reads LHE event data into an LHEEvent object. More...

#include <LHEReader.h>

Public Member Functions

 LHEReader (std::string &fileName)
 Class constructor.
 
virtual ~LHEReader ()
 Class destructor.
 
LHEEventreadNextEvent ()
 Read the next event.
 

Private Attributes

std::ifstream ifs_
 The input file stream.
 

Detailed Description

Reads LHE event data into an LHEEvent object.

Definition at line 22 of file LHEReader.h.

Constructor & Destructor Documentation

◆ LHEReader()

simcore::lhe::LHEReader::LHEReader ( std::string &  fileName)

Class constructor.

Parameters
fileNameThe input file name.

Definition at line 8 of file LHEReader.cxx.

8 {
9 std::cout << "Opening LHE file " << filename << std::endl;
10 ifs_.open(filename.c_str(), std::ifstream::in);
11}
std::ifstream ifs_
The input file stream.
Definition LHEReader.h:45

References ifs_.

◆ ~LHEReader()

simcore::lhe::LHEReader::~LHEReader ( )
virtual

Class destructor.

Definition at line 13 of file LHEReader.cxx.

13{ ifs_.close(); }

References ifs_.

Member Function Documentation

◆ readNextEvent()

LHEEvent * simcore::lhe::LHEReader::readNextEvent ( )

Read the next event.

Returns
The next LHE event.

Definition at line 15 of file LHEReader.cxx.

15 {
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}

References simcore::lhe::LHEEvent::addParticle(), simcore::lhe::LHEParticle::getMOTHUP(), simcore::lhe::LHEEvent::getParticles(), ifs_, simcore::lhe::LHEParticle::setMother(), and simcore::lhe::LHEEvent::setVertex().

Referenced by simcore::generators::LHEPrimaryGenerator::GeneratePrimaryVertex().

Member Data Documentation

◆ ifs_

std::ifstream simcore::lhe::LHEReader::ifs_
private

The input file stream.

Definition at line 45 of file LHEReader.h.

Referenced by LHEReader(), readNextEvent(), and ~LHEReader().


The documentation for this class was generated from the following files: