MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Particle.hh
1 //
5 // This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6 //
7 // MARLEY is free software: you can redistribute it and/or modify it under the
8 // terms of version 3 of the GNU General Public License as published by the
9 // Free Software Foundation.
10 //
11 // For the full text of the license please see COPYING or
12 // visit http://opensource.org/licenses/GPL-3.0
13 //
14 // Please respect the MCnet academic usage guidelines. See GUIDELINES
15 // or visit https://www.montecarlonet.org/GUIDELINES for details.
16 
17 #pragma once
18 #include <fstream>
19 
20 
21 namespace marley {
22 
23  #ifndef __MAKECINT__
24  // Forward declare the JSON class so that we can define a function that
25  // creates a JSON representation of a Particle. Hide the JSON class from
26  // rootcint so that we won't have issues using marley::Particle objects with
27  // ROOT 5.
28  class JSON;
29  #endif
30 
32  class Particle {
33 
34  public:
35 
36  Particle();
37 
40  Particle(int pdg_code, double m);
41 
45  Particle(int pdg_code, double m, int q);
46 
52  Particle(int pdg_code, double px, double py, double pz, double m);
53 
60  Particle(int pdg_code, double px, double py, double pz, double m, int q);
61 
68  Particle(int pdg_code, double E, double px, double py, double pz,
69  double m);
70 
78  Particle(int pdg_code, double E, double px, double py, double pz,
79  double m, int q);
80 
82  inline double mass() const;
85  inline void set_mass(double m);
86 
88  inline double total_energy() const;
91  inline void set_total_energy(double Etot);
92 
94  inline double px() const;
97  inline void set_px(double px);
98 
100  inline double py() const;
103  inline void set_py(double py);
104 
106  inline double pz() const;
109  inline void set_pz(double pz);
110 
112  inline int pdg_code() const;
113 
115  inline double charge() const;
118  inline void set_charge(int q);
119 
121  double momentum_magnitude() const;
123  double kinetic_energy() const;
124 
126  void print(std::ostream& out) const;
127 
130  void read(std::istream& in);
131 
132  #ifndef __MAKECINT__
134  marley::JSON to_json() const;
135 
138  void from_json(const marley::JSON& json);
139  #endif
140 
142  void clear();
143 
144  protected:
145 
154  double four_momentum_[4];
155 
159  int pdg_code_ = 0;
160 
162  double mass_ = 0.;
163 
172  int charge_ = 0;
173  };
174 
175  // Inline function definitions
176  inline double Particle::mass() const { return mass_; }
177  inline void Particle::set_mass(double m) { mass_ = m; }
178 
179  inline double Particle::total_energy() const { return four_momentum_[0]; }
180  inline void Particle::set_total_energy(double Etot)
181  { four_momentum_[0] = Etot; }
182 
183  inline double Particle::px() const { return four_momentum_[1]; }
184  inline void Particle::set_px(double px) { four_momentum_[1] = px; }
185 
186  inline double Particle::py() const { return four_momentum_[2]; }
187  inline void Particle::set_py(double py) { four_momentum_[2] = py; }
188 
189  inline double Particle::pz() const { return four_momentum_[3]; }
190  inline void Particle::set_pz(double pz) { four_momentum_[3] = pz; }
191 
192  inline int Particle::pdg_code() const { return pdg_code_; }
193 
194  inline double Particle::charge() const { return charge_; }
195  inline void Particle::set_charge(int q) { charge_ = q; }
196 }
197 
198 // Operator for printing Particle objects to a std::ostream
199 inline std::ostream& operator<<(std::ostream& out, const marley::Particle& p)
200 {
201  p.print(out);
202  return out;
203 }
204 
205 // Operator for reading in Particle objects from a std::istream
206 inline std::istream& operator>>(std::istream& in, marley::Particle& p)
207 {
208  p.read(in);
209  return in;
210 }
Definition: JSON.hh:62
Momentum four-vector for a simulated particle.
Definition: Particle.hh:32
void set_mass(double m)
Set the particle's mass.
Definition: Particle.hh:177
int pdg_code_
Particle Data Group code identifying this particle
Definition: Particle.hh:159
double mass() const
Get the particle's mass (MeV)
Definition: Particle.hh:176
double kinetic_energy() const
Get the particle's kinetic energy (MeV)
Definition: Particle.cc:99
void set_total_energy(double Etot)
Set the particle's total energy.
Definition: Particle.hh:180
void set_charge(int q)
Set the particle's charge.
Definition: Particle.hh:195
double py() const
Get the y component of the particle's 3-momentum (MeV)
Definition: Particle.hh:186
double mass_
mass (MeV)
Definition: Particle.hh:162
void set_pz(double pz)
Set the z component of the particle's 3-momentum.
Definition: Particle.hh:190
void clear()
Resets all data members to zero.
Definition: Particle.cc:132
void set_py(double py)
Set the y component of the particle's 3-momentum.
Definition: Particle.hh:187
void from_json(const marley::JSON &json)
Replaces the existing object contents with new ones loaded from a JSON representation of a Particle.
Definition: Particle.cc:139
double charge() const
Get the particle's charge in units of the proton charge.
Definition: Particle.hh:194
double momentum_magnitude() const
Get the magnitude of the particle's 3-momentum (MeV)
Definition: Particle.cc:94
double four_momentum_[4]
momentum 4-vector for this particle (MeV)
Definition: Particle.hh:154
marley::JSON to_json() const
Create a JSON representation of this Particle.
Definition: Particle.cc:120
int charge_
Electric charge (net charge in the case of atoms) expressed as an integer multiple of the proton char...
Definition: Particle.hh:172
double total_energy() const
Get the particle's total energy (MeV)
Definition: Particle.hh:179
double pz() const
Get the z component of the particle's 3-momentum (MeV)
Definition: Particle.hh:189
void set_px(double px)
Set the x component of the particle's 3-momentum.
Definition: Particle.hh:184
int pdg_code() const
Get the Particle Data Group code for this particle.
Definition: Particle.hh:192
double px() const
Get the x component of the particle's 3-momentum (MeV)
Definition: Particle.hh:183
void read(std::istream &in)
Read in this particle from a std::istream. Any previous contents of this particle will be deleted.
Definition: Particle.cc:115
void print(std::ostream &out) const
Print information about this particle to a std::ostream.
Definition: Particle.cc:109