BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSOutputROOTParticleData.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 BDSOUTPUTROOTPARTICLEDATA_H
20#define BDSOUTPUTROOTPARTICLEDATA_H
21
22#include "Rtypes.h"
23#include "TObject.h"
24
25#ifndef __ROOTBUILD__
26#include "globals.hh"
27#endif
28
29#include <cstdlib> // for std::abs(int)
30#include <cmath>
31#include <map>
32#include <limits>
33#include <string>
34
40class BDSOutputROOTParticleData: public TObject
41{
42public:
43 // structs up front
46 {
47 std::string name;
48 int charge;
49 double mass;
50
51 double rigidity(const double totalEnergy) const
52 {
53 if (!(std::abs(charge) > std::numeric_limits<double>::epsilon()))
54 {return 0;} // not finite charge, so rigidity 0
55 if (totalEnergy <= mass)
56 {return 0;} // invalid - just return 0
57 // calculation reproduced from BDSParticleDefinition but with hard coded constants
58 // for units here and to ensure no Geant4 linkage for output structures
59 // p = sqrt(E^2 - m^2) in GeV
60 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
61 double brho = momentum / 0.29979245799999998 / charge;
62 return brho;
63 }
64 double rigidity(const double totalEnergy, const double chargeIn) const
65 {
66 if (!(std::abs(chargeIn) > std::numeric_limits<double>::epsilon()))
67 {return 0;} // not finite charge, so rigidity 0
68 if (totalEnergy <= mass)
69 {return 0;} // invalid - just return 0
70 // calculation reproduced from BDSParticleDefinition but with hard coded constants
71 // for units here and to ensure no Geant4 linkage for output structures
72 // p = sqrt(E^2 - m^2) in GeV
73 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
74 double brho = momentum / 0.29979245799999998 / chargeIn;
75 return brho;
76 }
77 };
78
80 struct IonInfo
81 {
82 std::string name;
83 int charge;
84 double mass;
85 int a;
86 int z;
87
88 double rigidity(const double totalEnergy) const
89 {
90 if (!(std::abs(charge) > std::numeric_limits<double>::epsilon()))
91 {return 0;} // not finite charge, so rigidity 0
92 if (totalEnergy <= mass)
93 {return 0;} // invalid - just return 0
94 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
95 double brho = momentum / 0.29979245799999998 / charge;
96 return brho;
97 }
98 double rigidity(const double totalEnergy, const double chargeIn) const
99 {
100 if (!(std::abs(chargeIn) > std::numeric_limits<double>::epsilon()))
101 {return 0;} // not finite charge, so rigidity 0
102 if (totalEnergy <= mass)
103 {return 0;} // invalid - just return 0
104 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
105 double brho = momentum / 0.29979245799999998 / chargeIn;
106 return brho;
107 }
108 };
109
111 virtual ~BDSOutputROOTParticleData(){;}
112
114 virtual void Flush();
115
116 const ParticleInfo GetParticleInfo(const int& pdgID) const;
117 const IonInfo GetIonInfo(const int& pdgID) const;
118 int Charge(const int& pdgID) const;
119 double Mass(const int& pdgID) const;
120
122 double Rigidity(const int& pdgID,
123 const double& totalEnergy) const;
124
126 double KineticEnergy(const int& pdgID,
127 const double& totalEnergy) const;
128
129 std::string Name(const int& pdgID) const;
130 int IonA(const int& pdgID) const;
131 int IonZ(const int& pdgID) const;
132
134 inline bool IsIon(const int& pdgID) const {return pdgID > 1000000000;}
135
136#ifndef __ROOTBUILD__
138 void Fill(G4bool fillIons);
139#endif
140
141 std::map<int, ParticleInfo> particles;
142 std::map<int, IonInfo> ions;
143
144 ClassDef(BDSOutputROOTParticleData, 1);
145};
146
147#endif
Geant4 particle data for particles used in simulation.
bool IsIon(const int &pdgID) const
This doesn't count a proton (even with electrons) as an ion.
void Fill(G4bool fillIons)
Fill maps of particle information from Geant4.
double KineticEnergy(const int &pdgID, const double &totalEnergy) const
Calculate kinetic energy of particle given PDG ID and total energy in GeV.
virtual void Flush()
Clear maps.
double Rigidity(const int &pdgID, const double &totalEnergy) const
Calculate rigidity of particle given PDG ID and total energy in GeV.
Simple particle information to be stored per ion specifically.
int z
Atomic number - number of protons in nucleus.
int a
Mass number - number of nucleons in nucleus.
Simple particle information to be stored per particle.