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< 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 25 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 6 of file LHEReader.cxx.

6 {
7 ldmx_log(info) << "Opening LHE file " << filename;
8 ifs_.open(filename.c_str(), std::ifstream::in);
9
10 if (!ifs_.is_open()) {
11 EXCEPTION_RAISE("BadFile", "Failed to open LHE file: " + filename);
12 }
13}
std::ifstream ifs_
The input file stream.
Definition LHEReader.h:48

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 15 of file LHEReader.cxx.

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

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 48 of file LHEReader.h.

Referenced by LHEReader(), and readNextEvent().


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