LDMX Software
HepMCParticle.cxx
2
3#include <iostream>
4
5namespace simcore {
6namespace hepmc {
7
8HepMCParticle::HepMCParticle(std::shared_ptr<HepMC3::GenParticle> particle)
9 : particle_(particle) {
10 if (!particle_) {
11 EXCEPTION_RAISE("NullParticle",
12 "Attempted to create HepMCParticle with null GenParticle");
13 }
14}
15
16int HepMCParticle::getPdgId() const { return particle_->pid(); }
17
18int HepMCParticle::getStatus() const { return particle_->status(); }
19
20double HepMCParticle::getMomentum(int index) const {
21 const HepMC3::FourVector& momentum = particle_->momentum();
22 switch (index) {
23 case 0:
24 return momentum.px();
25 case 1:
26 return momentum.py();
27 case 2:
28 return momentum.pz();
29 case 3:
30 return momentum.e();
31 default:
32 EXCEPTION_RAISE(
33 "InvalidIndex",
34 "Momentum index must be 0 (px), 1 (py), 2 (pz), or 3 (E)");
35 }
36}
37
38double HepMCParticle::getMass() const { return particle_->generated_mass(); }
39
40std::shared_ptr<HepMC3::GenParticle> HepMCParticle::getGenParticle() const {
41 return particle_;
42}
43
44void HepMCParticle::print() const { std::cout << *this << std::endl; }
45
46std::ostream& operator<<(std::ostream& stream, const HepMCParticle& particle) {
47 stream << "HepMCParticle: " << "PDG=" << particle.getPdgId()
48 << " Status=" << particle.getStatus()
49 << " px=" << particle.getMomentum(0)
50 << " py=" << particle.getMomentum(1)
51 << " pz=" << particle.getMomentum(2)
52 << " E=" << particle.getMomentum(3) << " mass=" << particle.getMass();
53 return stream;
54}
55
56} // namespace hepmc
57} // namespace simcore
Class defining a single particle record in a HepMC event.
Wrapper class for HepMC3::GenParticle.
double getMomentum(int index) const
Get a momentum component by index.
double getMass() const
Get the particle's mass.
std::shared_ptr< HepMC3::GenParticle > particle_
The underlying HepMC3 GenParticle.
int getStatus() const
Get the status code.
void print() const
Print particle information to an output stream.
HepMCParticle(std::shared_ptr< HepMC3::GenParticle > particle)
Class constructor.
int getPdgId() const
Get the PDG code.
std::shared_ptr< HepMC3::GenParticle > getGenParticle() const
Get the underlying HepMC3 GenParticle.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...