LDMX Software
HepMCEvent.cxx
2
3#include "Framework/Exception/Exception.h"
4
5namespace simcore {
6namespace hepmc {
7
8HepMCEvent::HepMCEvent(std::shared_ptr<HepMC3::GenEvent> event)
9 : event_(event) {
10 if (!event_) {
11 EXCEPTION_RAISE("NullEvent",
12 "Attempted to create HepMCEvent with null GenEvent");
13 }
14
15 // Extract vertex information from the signal process vertex
16 // or the first vertex if no signal process is defined
17 std::shared_ptr<HepMC3::GenVertex> vertex;
18
19 // Try to get the signal process vertex first
20 if (event_->vertices().size() > 0) {
21 vertex = event_->vertices()[0];
22 }
23
24 if (vertex) {
25 // HepMC3 uses mm for length and mm/c for time by default
26 const HepMC3::FourVector& pos = vertex->position();
27 vtx_[0] = pos.x(); // mm
28 vtx_[1] = pos.y(); // mm
29 vtx_[2] = pos.z(); // mm
30 vtxt_ = pos.t(); // mm/c, needs conversion to ns for Geant4
31
32 // Convert time from mm/c to ns: t[ns] = t[mm/c] / c[mm/ns]
33 // c = 299.792458 mm/ns
34 vtxt_ = vtxt_ / 299.792458;
35 } else {
36 vtx_[0] = 0.0;
37 vtx_[1] = 0.0;
38 vtx_[2] = 0.0;
39 vtxt_ = 0.0;
40 }
41}
42
46 }
47 return particles_.size();
48}
49
51 // HepMC3 events can have multiple weights, we take the first one
52 const std::vector<double>& weights = event_->weights();
53 return weights.empty() ? 1.0 : weights[0];
54}
55
56const double* HepMCEvent::getVertex() const { return vtx_; }
57
58double HepMCEvent::getVertexTime() const { return vtxt_; }
59
60const std::vector<std::unique_ptr<HepMCParticle>>& HepMCEvent::getParticles()
61 const {
64 }
65 return particles_;
66}
67
68std::shared_ptr<HepMC3::GenEvent> HepMCEvent::getGenEvent() const {
69 return event_;
70}
71
73 particles_.clear();
74
75 // Get all particles from the event
76 for (const auto& particle : event_->particles()) {
77 // In HepMC3, status code 1 typically means final state particle
78 // Status codes vary by generator, but generally:
79 // status = 1: final state particle
80 // status = 2: intermediate/decayed particle
81 // status > 2: generator-specific codes
82
83 // We include particles with status code 1 (final state)
84 if (particle->status() == 1) {
85 particles_.push_back(std::make_unique<HepMCParticle>(particle));
86 }
87 }
88
90}
91
92} // namespace hepmc
93} // namespace simcore
Class defining a HepMC event with a list of particles.
double vtxt_
Vertex time (in ns)
Definition HepMCEvent.h:98
const std::vector< std::unique_ptr< HepMCParticle > > & getParticles() const
Get the list of final state particles in the event.
bool particles_extracted_
Flag to indicate if particles have been extracted.
Definition HepMCEvent.h:108
const double * getVertex() const
Get the vertex location (in mm, as expected by Geant4).
HepMCEvent(std::shared_ptr< HepMC3::GenEvent > event)
Class constructor.
Definition HepMCEvent.cxx:8
void extractParticles() const
Extract final state particles from the HepMC event.
double getEventWeight() const
Get the event weight.
double vtx_[3]
Vertex location (in mm)
Definition HepMCEvent.h:93
double getVertexTime() const
Get the vertex time (in ns, as expected by Geant4).
std::vector< std::unique_ptr< HepMCParticle > > particles_
The list of final state particles to be tracked.
Definition HepMCEvent.h:103
std::shared_ptr< HepMC3::GenEvent > getGenEvent() const
Get the underlying HepMC3 GenEvent.
int getNumParticles() const
Get the number of particles in the event.
std::shared_ptr< HepMC3::GenEvent > event_
The underlying HepMC3 GenEvent.
Definition HepMCEvent.h:88
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...