LDMX Software
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 ()=default
 Class destructor.
 
std::unique_ptr< LHEEvent > readNextEvent ()
 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 24 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 ldmx_log(info) << "Opening LHE file " << filename;
10 ifs_.open(filename.c_str(), std::ifstream::in);
11
12 if (!ifs_.is_open()) {
13 EXCEPTION_RAISE("BadFile", "Failed to open LHE file: " + filename);
14 }
15}
std::ifstream ifs_
The input file stream.
Definition LHEReader.h:47

References ifs_.

Member Function Documentation

◆ readNextEvent()

std::unique_ptr< LHEEvent > simcore::lhe::LHEReader::readNextEvent ( )

Read the next event.

Returns
The next LHE event.

Definition at line 17 of file LHEReader.cxx.

17 {
18 std::string line;
19 bool found_event_element = false;
20 while (getline(ifs_, line)) {
21 auto back =
22 std::find_if_not(line.rbegin(), line.rend(), [](unsigned char c) {
23 return std::isspace(c);
24 }).base();
25 line.erase(back, line.end());
26 if (line == "<event>") {
27 found_event_element = true;
28 break;
29 }
30 }
31
32 if (!found_event_element) {
33 ldmx_log(warn) << "No next <event> element was found by the LHE reader.";
34 return nullptr;
35 }
36
37 getline(ifs_, line);
38
39 // Create the LHEEvent using std::make_unique
40 auto next_event = std::make_unique<LHEEvent>(line);
41
42 while (getline(ifs_, line)) {
43 auto back =
44 std::find_if_not(line.rbegin(), line.rend(), [](unsigned char c) {
45 return std::isspace(c);
46 }).base();
47 line.erase(back, line.end());
48 if (line == "</event>" || line == "<mgrwt>") {
49 // break if the event ended or in LHE 3.0 if we reach the mgrwt block
50 break;
51 }
52
53 if (line.find("#") == std::string::npos) { // not a comment line
54 // Create LHEParticle using std::make_unique and add it to the event
55 auto particle = std::make_unique<LHEParticle>(line);
56 next_event->addParticle(std::move(particle));
57 } else {
58 if (line.find("#vertex") != std::string::npos) {
59 next_event->setVertex(line);
60 }
61 }
62 }
63
64 const std::vector<std::unique_ptr<LHEParticle>>& particles =
65 next_event->getParticles();
66 for (const auto& particle : particles) {
67 if (particle->getMother(0) != 0) {
68 int mother1 = particle->getMother(0);
69 int mother2 = particle->getMother(1);
70 if (mother1 > 0) {
71 particle->setMother(0, particles[mother1 - 1].get());
72 }
73 if (mother2 > 0) {
74 particle->setMother(1, particles[mother2 - 1].get());
75 }
76 }
77 }
78
79 return next_event;
80}

References ifs_.

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

Member Data Documentation

◆ ifs_

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

The input file stream.

Definition at line 47 of file LHEReader.h.

Referenced by LHEReader(), and readNextEvent().


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