LDMX Software
simcore::hepmc::HepMCParticle Class Reference

Wrapper class for HepMC3::GenParticle. More...

#include <HepMCParticle.h>

Public Member Functions

 HepMCParticle (std::shared_ptr< HepMC3::GenParticle > particle)
 Class constructor.
 
int getPdgId () const
 Get the PDG code.
 
int getStatus () const
 Get the status code.
 
double getMomentum (int index) const
 Get a momentum component by index.
 
double getMass () const
 Get the particle's mass.
 
int getProductionVertexId () const
 Get the production vertex id, 0 if the particle has none.
 
HepMC3::FourVector getProductionPosition () const
 Get the production position (x, y, z in mm, t in mm/c).
 
std::shared_ptr< HepMC3::GenParticle > getGenParticle () const
 Get the underlying HepMC3 GenParticle.
 
void print () const
 Print particle information to an output stream.
 

Private Attributes

std::shared_ptr< HepMC3::GenParticle > particle_
 The underlying HepMC3 GenParticle.
 

Friends

std::ostream & operator<< (std::ostream &stream, const HepMCParticle &particle)
 Overloaded stream operator.
 

Detailed Description

Wrapper class for HepMC3::GenParticle.

Definition at line 28 of file HepMCParticle.h.

Constructor & Destructor Documentation

◆ HepMCParticle()

simcore::hepmc::HepMCParticle::HepMCParticle ( std::shared_ptr< HepMC3::GenParticle > particle)

Class constructor.

Parameters
particleShared pointer to HepMC3 GenParticle

Definition at line 13 of file HepMCParticle.cxx.

14 : particle_(particle) {
15 if (!particle_) {
16 EXCEPTION_RAISE("NullParticle",
17 "Attempted to create HepMCParticle with null GenParticle");
18 }
19}
std::shared_ptr< HepMC3::GenParticle > particle_
The underlying HepMC3 GenParticle.

References particle_.

Member Function Documentation

◆ getGenParticle()

std::shared_ptr< HepMC3::GenParticle > simcore::hepmc::HepMCParticle::getGenParticle ( ) const

Get the underlying HepMC3 GenParticle.

Returns
Shared pointer to the HepMC3 GenParticle

Definition at line 57 of file HepMCParticle.cxx.

57 {
58 return particle_;
59}

References particle_.

◆ getMass()

double simcore::hepmc::HepMCParticle::getMass ( ) const

Get the particle's mass.

Returns
The particle's mass.

Definition at line 43 of file HepMCParticle.cxx.

43{ return particle_->generated_mass(); }

References particle_.

◆ getMomentum()

double simcore::hepmc::HepMCParticle::getMomentum ( int index) const

Get a momentum component by index.

Index 0: px, 1: py, 2: pz, 3: E

Returns
The momentum component by index.

Definition at line 25 of file HepMCParticle.cxx.

25 {
26 const HepMC3::FourVector& momentum = particle_->momentum();
27 switch (index) {
28 case 0:
29 return momentum.px();
30 case 1:
31 return momentum.py();
32 case 2:
33 return momentum.pz();
34 case 3:
35 return momentum.e();
36 default:
37 EXCEPTION_RAISE(
38 "InvalidIndex",
39 "Momentum index must be 0 (px), 1 (py), 2 (pz), or 3 (E)");
40 }
41}

References particle_.

◆ getPdgId()

int simcore::hepmc::HepMCParticle::getPdgId ( ) const

Get the PDG code.

Returns
The PDG code.

Definition at line 21 of file HepMCParticle.cxx.

21{ return particle_->pid(); }

References particle_.

◆ getProductionPosition()

HepMC3::FourVector simcore::hepmc::HepMCParticle::getProductionPosition ( ) const

Get the production position (x, y, z in mm, t in mm/c).

Falls back to the event position if there is no production vertex.

Returns
The production four-position.

Definition at line 50 of file HepMCParticle.cxx.

50 {
51 // GenVertex::position falls back to ancestors and then the event position
52 if (auto vertex = particle_->production_vertex()) return vertex->position();
53 if (auto event = particle_->parent_event()) return event->event_pos();
54 return HepMC3::FourVector::ZERO_VECTOR();
55}

References particle_.

◆ getProductionVertexId()

int simcore::hepmc::HepMCParticle::getProductionVertexId ( ) const

Get the production vertex id, 0 if the particle has none.

Returns
The HepMC3 production vertex id.

Definition at line 45 of file HepMCParticle.cxx.

45 {
46 auto vertex = particle_->production_vertex();
47 return vertex ? vertex->id() : 0;
48}

References particle_.

◆ getStatus()

int simcore::hepmc::HepMCParticle::getStatus ( ) const

Get the status code.

Returns
The status code.

Definition at line 23 of file HepMCParticle.cxx.

23{ return particle_->status(); }

References particle_.

◆ print()

void simcore::hepmc::HepMCParticle::print ( ) const

Print particle information to an output stream.

Definition at line 61 of file HepMCParticle.cxx.

61{ std::cout << *this << std::endl; }

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & stream,
const HepMCParticle & particle )
friend

Overloaded stream operator.

Parameters
streamThe output stream.
particleThe particle to print.

Definition at line 63 of file HepMCParticle.cxx.

63 {
64 stream << "HepMCParticle: " << "PDG=" << particle.getPdgId()
65 << " Status=" << particle.getStatus()
66 << " px=" << particle.getMomentum(0)
67 << " py=" << particle.getMomentum(1)
68 << " pz=" << particle.getMomentum(2)
69 << " E=" << particle.getMomentum(3) << " mass=" << particle.getMass();
70 return stream;
71}

Member Data Documentation

◆ particle_

std::shared_ptr<HepMC3::GenParticle> simcore::hepmc::HepMCParticle::particle_
private

The underlying HepMC3 GenParticle.

Definition at line 97 of file HepMCParticle.h.

Referenced by getGenParticle(), getMass(), getMomentum(), getPdgId(), getProductionPosition(), getProductionVertexId(), getStatus(), and HepMCParticle().


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