LDMX Software
HepMCParticle.cxx
2
3#include <iostream>
4
5#include "Framework/Exception/Exception.h"
6#include "HepMC3/FourVector.h"
7
8namespace simcore {
9namespace hepmc {
10
11HepMCParticle::HepMCParticle(std::shared_ptr<HepMC3::GenParticle> particle)
12 : particle_(particle) {
13 if (!particle_) {
14 EXCEPTION_RAISE("NullParticle",
15 "Attempted to create HepMCParticle with null GenParticle");
16 }
17}
18
19int HepMCParticle::getPdgId() const { return particle_->pid(); }
20
21int HepMCParticle::getStatus() const { return particle_->status(); }
22
23double HepMCParticle::getMomentum(int index) const {
24 const HepMC3::FourVector& momentum = particle_->momentum();
25 switch (index) {
26 case 0:
27 return momentum.px();
28 case 1:
29 return momentum.py();
30 case 2:
31 return momentum.pz();
32 case 3:
33 return momentum.e();
34 default:
35 EXCEPTION_RAISE(
36 "InvalidIndex",
37 "Momentum index must be 0 (px), 1 (py), 2 (pz), or 3 (E)");
38 }
39}
40
41double HepMCParticle::getMass() const { return particle_->generated_mass(); }
42
43std::shared_ptr<HepMC3::GenParticle> HepMCParticle::getGenParticle() const {
44 return particle_;
45}
46
47void HepMCParticle::print() const { std::cout << *this << std::endl; }
48
49std::ostream& operator<<(std::ostream& stream, const HepMCParticle& particle) {
50 stream << "HepMCParticle: " << "PDG=" << particle.getPdgId()
51 << " Status=" << particle.getStatus()
52 << " px=" << particle.getMomentum(0)
53 << " py=" << particle.getMomentum(1)
54 << " pz=" << particle.getMomentum(2)
55 << " E=" << particle.getMomentum(3) << " mass=" << particle.getMass();
56 return stream;
57}
58
59} // namespace hepmc
60} // 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 ...