LDMX Software
simcore::hepmc::HepMCEvent Class Reference

Wrapper for HepMC3::GenEvent with convenience methods. More...

#include <HepMCEvent.h>

Public Member Functions

 HepMCEvent (std::shared_ptr< HepMC3::GenEvent > event)
 Class constructor.
 
virtual ~HepMCEvent ()=default
 Class destructor.
 
int getNumParticles () const
 Get the number of particles in the event.
 
double getEventWeight () const
 Get the event weight.
 
const double * getVertex () const
 Get the vertex location (in mm, as expected by Geant4).
 
double getVertexTime () const
 Get the vertex time (in ns, as expected by Geant4).
 
const std::vector< std::unique_ptr< HepMCParticle > > & getParticles () const
 Get the list of final state particles in the event.
 
std::shared_ptr< HepMC3::GenEvent > getGenEvent () const
 Get the underlying HepMC3 GenEvent.
 

Private Member Functions

void extractParticles () const
 Extract final state particles from the HepMC event.
 

Private Attributes

std::shared_ptr< HepMC3::GenEvent > event_
 The underlying HepMC3 GenEvent.
 
double vtx_ [3]
 Vertex location (in mm)
 
double vtxt_ {0.}
 Vertex time (in ns)
 
std::vector< std::unique_ptr< HepMCParticle > > particles_
 The list of final state particles to be tracked.
 
bool particles_extracted_ {false}
 Flag to indicate if particles have been extracted.
 

Detailed Description

Wrapper for HepMC3::GenEvent with convenience methods.

Note
Detailed information on the HepMC3 format is provided here: HepMC3: A modernized Monte Carlo event structure library.

Definition at line 34 of file HepMCEvent.h.

Constructor & Destructor Documentation

◆ HepMCEvent()

simcore::hepmc::HepMCEvent::HepMCEvent ( std::shared_ptr< HepMC3::GenEvent > event)

Class constructor.

Parameters
eventShared pointer to HepMC3 GenEvent

Definition at line 8 of file HepMCEvent.cxx.

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}
double vtxt_
Vertex time (in ns)
Definition HepMCEvent.h:98
double vtx_[3]
Vertex location (in mm)
Definition HepMCEvent.h:93
std::shared_ptr< HepMC3::GenEvent > event_
The underlying HepMC3 GenEvent.
Definition HepMCEvent.h:88

References event_, vtx_, and vtxt_.

Member Function Documentation

◆ extractParticles()

void simcore::hepmc::HepMCEvent::extractParticles ( ) const
private

Extract final state particles from the HepMC event.

Definition at line 72 of file HepMCEvent.cxx.

72 {
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}
bool particles_extracted_
Flag to indicate if particles have been extracted.
Definition HepMCEvent.h:108
std::vector< std::unique_ptr< HepMCParticle > > particles_
The list of final state particles to be tracked.
Definition HepMCEvent.h:103

References event_, particles_, and particles_extracted_.

Referenced by getNumParticles(), and getParticles().

◆ getEventWeight()

double simcore::hepmc::HepMCEvent::getEventWeight ( ) const

Get the event weight.

Returns
The event weight.

Definition at line 50 of file HepMCEvent.cxx.

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

References event_.

◆ getGenEvent()

std::shared_ptr< HepMC3::GenEvent > simcore::hepmc::HepMCEvent::getGenEvent ( ) const

Get the underlying HepMC3 GenEvent.

Returns
Shared pointer to the HepMC3 GenEvent

Definition at line 68 of file HepMCEvent.cxx.

68 {
69 return event_;
70}

References event_.

◆ getNumParticles()

int simcore::hepmc::HepMCEvent::getNumParticles ( ) const

Get the number of particles in the event.

Returns
The number of particles in event.

Definition at line 43 of file HepMCEvent.cxx.

43 {
46 }
47 return particles_.size();
48}
void extractParticles() const
Extract final state particles from the HepMC event.

References extractParticles(), particles_, and particles_extracted_.

◆ getParticles()

const std::vector< std::unique_ptr< HepMCParticle > > & simcore::hepmc::HepMCEvent::getParticles ( ) const

Get the list of final state particles in the event.

These are particles that should be tracked by Geant4.

Returns
The list of final state particles in the event.

Definition at line 60 of file HepMCEvent.cxx.

61 {
64 }
65 return particles_;
66}

References extractParticles(), particles_, and particles_extracted_.

◆ getVertex()

const double * simcore::hepmc::HepMCEvent::getVertex ( ) const

Get the vertex location (in mm, as expected by Geant4).

Returns
Array double[3] with x, y, z ordering

Definition at line 56 of file HepMCEvent.cxx.

56{ return vtx_; }

References vtx_.

◆ getVertexTime()

double simcore::hepmc::HepMCEvent::getVertexTime ( ) const

Get the vertex time (in ns, as expected by Geant4).

Returns
time of primary vertex.

Definition at line 58 of file HepMCEvent.cxx.

58{ return vtxt_; }

References vtxt_.

Member Data Documentation

◆ event_

std::shared_ptr<HepMC3::GenEvent> simcore::hepmc::HepMCEvent::event_
private

The underlying HepMC3 GenEvent.

Definition at line 88 of file HepMCEvent.h.

Referenced by extractParticles(), getEventWeight(), getGenEvent(), and HepMCEvent().

◆ particles_

std::vector<std::unique_ptr<HepMCParticle> > simcore::hepmc::HepMCEvent::particles_
mutableprivate

The list of final state particles to be tracked.

Definition at line 103 of file HepMCEvent.h.

Referenced by extractParticles(), getNumParticles(), and getParticles().

◆ particles_extracted_

bool simcore::hepmc::HepMCEvent::particles_extracted_ {false}
mutableprivate

Flag to indicate if particles have been extracted.

Definition at line 108 of file HepMCEvent.h.

108{false};

Referenced by extractParticles(), getNumParticles(), and getParticles().

◆ vtx_

double simcore::hepmc::HepMCEvent::vtx_[3]
mutableprivate

Vertex location (in mm)

Definition at line 93 of file HepMCEvent.h.

Referenced by getVertex(), and HepMCEvent().

◆ vtxt_

double simcore::hepmc::HepMCEvent::vtxt_ {0.}
mutableprivate

Vertex time (in ns)

Definition at line 98 of file HepMCEvent.h.

98{0.};

Referenced by getVertexTime(), and HepMCEvent().


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