20#include "BDSException.hh"
21#include "BDSIonDefinition.hh"
22#include "BDSParticleDefinition.hh"
23#include "BDSPhysicalConstants.hh"
24#include "BDSUtilities.hh"
26#include "G4ParticleDefinition.hh"
28#include "CLHEP/Units/SystemOfUnits.h"
38 G4double totalEnergyIn,
39 G4double kineticEnergyIn,
45 ionDefinition(nullptr),
47 name(particleIn->GetParticleName()),
48 mass(particleIn->GetPDGMass()),
55 brho(std::numeric_limits<double>::max()),
66 SetEnergies(totalEnergyIn, kineticEnergyIn, momentumIn);
72 G4double totalEnergyIn,
73 G4double kineticEnergyIn,
79 ionDefinition(nullptr),
89 brho(std::numeric_limits<double>::max()),
94 SetEnergies(totalEnergyIn, kineticEnergyIn, momentumIn);
98 G4double kineticEnergyIn,
103 if (totalEnergyIn <=
mass)
105 throw BDSException(__METHOD_NAME__,
"total energy (" + std::to_string(totalEnergyIn / CLHEP::GeV)
106 +
" GeV) is less than or equal to the mass (" + std::to_string(
mass / CLHEP::GeV)
107 +
" GeV) of the particle \"" +
name +
"\"");
115 if (kineticEnergyIn <= 0)
117 throw BDSException(__METHOD_NAME__,
"kinetic energy (" + std::to_string(kineticEnergyIn/CLHEP::GeV)
118 +
" GeV) must be > 0");
128 throw BDSException(__METHOD_NAME__,
"momentum (" + std::to_string(momentumIn/CLHEP::GeV)
129 +
" GeV) must be > 0");
134 {
throw BDSException(__METHOD_NAME__,
"sqrt(-ve) encountered in calculating total energy");}
138 {
throw BDSException(__METHOD_NAME__,
"total energy, kinetic energy and momentum 0 - one must be non-zero.");}
144 particle(other.particle),
145 ionPDGID(other.ionPDGID),
148 charge(other.charge),
149 totalEnergy(other.totalEnergy),
150 kineticEnergy(other.kineticEnergy),
151 momentum(other.momentum),
164 particle(other.particle),
165 ionPDGID(other.ionPDGID),
168 charge(other.charge),
169 totalEnergy(other.totalEnergy),
170 kineticEnergy(other.kineticEnergy),
171 momentum(other.momentum),
177 ionDefinition = other.ionDefinition;
178 other.ionDefinition =
nullptr;
185 delete ionDefinition;
187 other.ionDefinition =
nullptr;
189 particle = other.particle;
190 ionPDGID = other.ionPDGID;
194 totalEnergy = other.totalEnergy;
195 kineticEnergy = other.kineticEnergy;
196 momentum = other.momentum;
205BDSParticleDefinition::~BDSParticleDefinition()
213 {
return particle->GetPDGEncoding();}
223 out <<
"Particle: \""<< def.
name <<
"\"" << G4endl;
224 out <<
"Mass: " << std::setprecision(pre) << def.
mass/CLHEP::GeV <<
" GeV" << G4endl;
225 out <<
"Charge: " << def.
charge <<
" e" << G4endl;
226 out <<
"Total Energy: " << std::setprecision(pre) << def.
totalEnergy/CLHEP::GeV <<
" GeV" << G4endl;
227 out <<
"Kinetic Energy: " << std::setprecision(pre) << def.
kineticEnergy/CLHEP::GeV <<
" GeV" << G4endl;
228 out <<
"Momentum: " << std::setprecision(pre) << def.
momentum/CLHEP::GeV <<
" GeV" << G4endl;
229 out <<
"Gamma: " << std::setprecision(pre) << def.
gamma << G4endl;
230 out <<
"Beta: " << std::setprecision(pre) << def.
beta << G4endl;
231 out <<
"Rigidity (Brho): " << std::setprecision(pre) << def.
brho/(CLHEP::tesla*CLHEP::m) <<
" T*m" << G4endl;
239 catch (
const std::domain_error&)
240 {
throw BDSException(__METHOD_NAME__,
"Total energy insufficient to include mass or particle.");}
251 brho *= CLHEP::tesla*CLHEP::m;
259 beta = std::sqrt(1 - (1./std::pow(
gamma,2)) );
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.
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())