BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSParticleDefinition.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSPARTICLEDEFINITION_H
20#define BDSPARTICLEDEFINITION_H
21#include "BDSIonDefinition.hh"
22
23#include "CLHEP/Units/PhysicalConstants.h"
24
25#include "globals.hh"
26
27#include <ostream>
28
29class G4ParticleDefinition;
30
43{
44public:
51 BDSParticleDefinition(G4ParticleDefinition* particleIn,
52 G4double totalEnergyIn,
53 G4double kineticEnergyIn,
54 G4double momentumIn,
55 G4double ffact,
56 BDSIonDefinition* ionDefinitionIn = nullptr,
57 G4int ionPDGID = 0);
58
64 BDSParticleDefinition(const G4String& nameIn,
65 G4double massIn,
66 G4double chargeIn,
67 G4double totalEnergyIn,
68 G4double kineticEnergyIn,
69 G4double momentumIn,
70 G4double ffact,
71 BDSIonDefinition* ionDefinitionIn = nullptr,
72 G4int ionPDGID = 0);
73
79
81
85 void SetEnergies(G4double totalEnergyIn,
86 G4double kineticEnergyIn,
87 G4double momentumIn);
88
91 void UpdateG4ParticleDefinition(G4ParticleDefinition* particleIn) {particle = particleIn;}
92
93
95 void ApplyChangeInKineticEnergy(G4double dEk);
96
98 inline G4ParticleDefinition* ParticleDefinition() const {return particle;}
100 inline G4String Name() const {return name;}
101 inline G4double Mass() const {return mass;}
102 inline G4double Charge() const {return charge;}
103 inline G4double TotalEnergy() const {return totalEnergy;}
104 inline G4double KineticEnergy() const {return kineticEnergy;}
105 inline G4double Momentum() const {return momentum;}
106 inline G4double Gamma() const {return gamma;}
107 inline G4double Beta() const {return beta;}
108 inline G4double BRho() const {return brho;}
109 inline G4double FFact() const {return ffact;}
110 inline G4bool IsAnIon() const {return ionDefinition != nullptr;}
111 inline G4bool NElectrons() const {return ionDefinition != nullptr ? ionDefinition->NElectrons() : 0;}
112 inline G4double Velocity() const {return Beta() * CLHEP::c_light;}
113 inline G4bool Forwards() const {return forwards;}
115
119 G4int PDGID() const;
120
122 friend std::ostream& operator<< (std::ostream& out, BDSParticleDefinition const& def);
123
124private:
127
129 void CalculateMomentum();
130
132 void CalculateRigidity(const G4double& ffactIn);
133
136
137 G4ParticleDefinition* particle;
139 G4int ionPDGID;
140
141 G4String name;
142 G4double mass;
143 G4double charge;
144 G4double totalEnergy;
145 G4double kineticEnergy;
146 G4double momentum;
147 G4double gamma;
148 G4double beta;
149 G4double brho;
150 G4double ffact;
151 G4bool forwards;
152};
153
154#endif
Class to parse an ion particle definition.
G4int NElectrons() const
Accessor.
Wrapper for particle definition.
void CalculateRigidity(const G4double &ffactIn)
Calculate and set rigidity based on charge and momentum.
G4String Name() const
Accessor.
G4double Mass() const
Accessor.
G4bool NElectrons() const
Accessor.
G4double beta
Relativistic beta.
G4double Momentum() const
Accessor.
G4double Charge() const
Accessor.
G4double totalEnergy
Particle total energy.
G4double KineticEnergy() const
Accessor.
G4ParticleDefinition * ParticleDefinition() const
Accessor.
G4double FFact() const
Accessor.
G4double BRho() const
Accessor.
void CalculateLorentzFactors()
Calculate and set lorentz factors.
G4double gamma
Relativistic gamma.
void SetEnergies(G4double totalEnergyIn, G4double kineticEnergyIn, G4double momentumIn)
G4double momentum
Particle momentum.
G4double Beta() const
Accessor.
G4bool Forwards() const
Accessor.
BDSIonDefinition * ionDefinition
Optional ion definition. Does own.
G4double charge
Particle charge.
BDSParticleDefinition()=delete
No default constructor.
friend std::ostream & operator<<(std::ostream &out, BDSParticleDefinition const &def)
Output stream operator implementation.
G4double Velocity() const
Accessor.
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 Gamma() const
Accessor.
BDSIonDefinition * IonDefinition() const
Accessor.
G4double brho
Particle rigidity.
G4int ionPDGID
Cache this for ions only.
G4double TotalEnergy() const
Accessor.
G4ParticleDefinition * particle
Does not own.
void CalculateMomentum()
Calculate and set momentum based on totalEnergy and mass.
G4double kineticEnergy
Particle kinetic energy.
G4bool IsAnIon() const
Accessor.
void UpdateG4ParticleDefinition(G4ParticleDefinition *particleIn)