20#include "BDSException.hh"
21#include "BDSIonDefinition.hh"
22#include "BDSParticleDefinition.hh"
23#include "BDSPhysicalConstants.hh"
24#include "BDSUtilities.hh"
25#include "BDSWarning.hh"
27#include "G4ParticleDefinition.hh"
29#include "CLHEP/Units/SystemOfUnits.h"
39 G4double totalEnergyIn,
40 G4double kineticEnergyIn,
46 ionDefinition(nullptr),
48 name(particleIn->GetParticleName()),
49 mass(particleIn->GetPDGMass()),
56 brho(std::numeric_limits<double>::max()),
68 SetEnergies(totalEnergyIn, kineticEnergyIn, momentumIn);
74 G4double totalEnergyIn,
75 G4double kineticEnergyIn,
81 ionDefinition(nullptr),
91 brho(std::numeric_limits<double>::max()),
97 SetEnergies(totalEnergyIn, kineticEnergyIn, momentumIn);
101 G4double kineticEnergyIn,
106 if (totalEnergyIn <=
mass)
108 throw BDSException(__METHOD_NAME__,
"total energy (" + std::to_string(totalEnergyIn / CLHEP::GeV)
109 +
" GeV) is less than or equal to the mass (" + std::to_string(
mass / CLHEP::GeV)
110 +
" GeV) of the particle \"" +
name +
"\"");
118 if (kineticEnergyIn <= 0)
120 throw BDSException(__METHOD_NAME__,
"kinetic energy (" + std::to_string(kineticEnergyIn/CLHEP::GeV)
121 +
" GeV) must be > 0");
131 throw BDSException(__METHOD_NAME__,
"momentum (" + std::to_string(momentumIn/CLHEP::GeV)
132 +
" GeV) must be > 0");
137 {
throw BDSException(__METHOD_NAME__,
"sqrt(-ve) encountered in calculating total energy");}
141 {
throw BDSException(__METHOD_NAME__,
"total energy, kinetic energy and momentum 0 - one must be non-zero.");}
147 particle(other.particle),
148 ionPDGID(other.ionPDGID),
151 charge(other.charge),
152 totalEnergy(other.totalEnergy),
153 kineticEnergy(other.kineticEnergy),
154 momentum(other.momentum),
159 forwards(other.forwards)
168 particle(other.particle),
169 ionPDGID(other.ionPDGID),
172 charge(other.charge),
173 totalEnergy(other.totalEnergy),
174 kineticEnergy(other.kineticEnergy),
175 momentum(other.momentum),
180 forwards(other.forwards)
182 ionDefinition = other.ionDefinition;
183 other.ionDefinition =
nullptr;
190 delete ionDefinition;
192 other.ionDefinition =
nullptr;
194 particle = other.particle;
195 ionPDGID = other.ionPDGID;
199 totalEnergy = other.totalEnergy;
200 kineticEnergy = other.kineticEnergy;
201 momentum = other.momentum;
206 forwards = other.forwards;
211BDSParticleDefinition::~BDSParticleDefinition()
219 {
return particle->GetPDGEncoding();}
229 out <<
"Particle: \""<< def.
name <<
"\"" << G4endl;
230 out <<
"Mass: " << std::setprecision(pre) << def.
mass/CLHEP::GeV <<
" GeV" << G4endl;
231 out <<
"Charge: " << def.
charge <<
" e" << G4endl;
232 out <<
"Total Energy: " << std::setprecision(pre) << def.
totalEnergy/CLHEP::GeV <<
" GeV" << G4endl;
233 out <<
"Kinetic Energy: " << std::setprecision(pre) << def.
kineticEnergy/CLHEP::GeV <<
" GeV" << G4endl;
234 out <<
"Momentum: " << std::setprecision(pre) << def.
momentum/CLHEP::GeV <<
" GeV" << G4endl;
235 out <<
"Gamma: " << std::setprecision(pre) << def.
gamma << G4endl;
236 out <<
"Beta: " << std::setprecision(pre) << def.
beta << G4endl;
237 out <<
"FFact: " << std::setprecision(pre) << def.
ffact << G4endl;
238 out <<
"Rigidity (Brho): " << std::setprecision(pre) << def.
brho/(CLHEP::tesla*CLHEP::m) <<
" T*m" << G4endl;
246 catch (
const std::domain_error&)
247 {
throw BDSException(__METHOD_NAME__,
"Total energy insufficient to include mass or particle.");}
258 brho *= CLHEP::tesla*CLHEP::m;
266 beta = std::sqrt(1 - (1./std::pow(
gamma,2)) );
275 newEk = std::abs(newEk);
276 BDS::Warning(__METHOD_NAME__,
"particle change of direction");
General exception with possible name of object and message.
Class to parse an ion particle definition.
G4bool OverrideCharge() const
Accessor.
G4double Charge() const
Accessor.
G4double charge
In units of eplus.
Wrapper for particle definition.
void CalculateRigidity(const G4double &ffactIn)
Calculate and set rigidity based on charge and momentum.
G4double beta
Relativistic beta.
G4double totalEnergy
Particle total energy.
void CalculateLorentzFactors()
Calculate and set lorentz factors.
G4double gamma
Relativistic gamma.
void SetEnergies(G4double totalEnergyIn, G4double kineticEnergyIn, G4double momentumIn)
G4double momentum
Particle momentum.
BDSIonDefinition * ionDefinition
Optional ion definition. Does own.
G4double charge
Particle charge.
BDSParticleDefinition()=delete
No default constructor.
G4double ffact
Flip factor.
G4double mass
Particle mass.
BDSParticleDefinition & operator=(BDSParticleDefinition &&other) noexcept
Copy, move and assignment constructors specified as we have to copy the ionDefinition if it exists.
G4bool forwards
In case of change of direction.
void ApplyChangeInKineticEnergy(G4double dEk)
Utility function to update quantities by adding on dEK (can be negative).
G4String name
Particle name.
G4double brho
Particle rigidity.
G4int ionPDGID
Cache this for ions only.
G4ParticleDefinition * particle
Does not own.
void CalculateMomentum()
Calculate and set momentum based on totalEnergy and mass.
G4double kineticEnergy
Particle kinetic energy.
static const G4double cOverGeV
speed of light / 1 GeV, used for scaling in brho calculation
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())