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) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef BDSOUTPUTROOTPARTICLEDATA_H
19#define BDSOUTPUTROOTPARTICLEDATA_H
20
21#include "Rtypes.h"
22#include "TObject.h"
23
24#ifndef __ROOTBUILD__
25#include "globals.hh"
26#endif
27
28#include <cstdlib> // for std::abs(int)
29#include <cmath>
30#include <map>
31#include <limits>
32#include <string>
33
39class BDSOutputROOTParticleData: public TObject
40{
41public:
42 // structs up front
45 {
46 std::string name;
47 int charge;
48 double mass;
49
50 double rigidity(const double totalEnergy) const
51 {
52 if (!(std::abs(charge) > std::numeric_limits<double>::epsilon()))
53 {return 0;} // not finite charge, so rigidity 0
54 if (totalEnergy <= mass)
55 {return 0;} // invalid - just return 0
56 // calculation reproduced from BDSParticleDefinition but with hard coded constants
57 // for units here and to ensure no Geant4 linkage for output structures
58 // p = sqrt(E^2 - m^2) in GeV
59 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
60 double brho = momentum / 0.29979245799999998 / charge;
61 return brho;
62 }
63 double rigidity(const double totalEnergy, const double chargeIn) const
64 {
65 if (!(std::abs(chargeIn) > std::numeric_limits<double>::epsilon()))
66 {return 0;} // not finite charge, so rigidity 0
67 if (totalEnergy <= mass)
68 {return 0;} // invalid - just return 0
69 // calculation reproduced from BDSParticleDefinition but with hard coded constants
70 // for units here and to ensure no Geant4 linkage for output structures
71 // p = sqrt(E^2 - m^2) in GeV
72 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
73 double brho = momentum / 0.29979245799999998 / chargeIn;
74 return brho;
75 }
76 };
77
79 struct IonInfo
80 {
81 std::string name;
82 int charge;
83 double mass;
84 int a;
85 int z;
86
87 double rigidity(const double totalEnergy) const
88 {
89 if (!(std::abs(charge) > std::numeric_limits<double>::epsilon()))
90 {return 0;} // not finite charge, so rigidity 0
91 if (totalEnergy <= mass)
92 {return 0;} // invalid - just return 0
93 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
94 double brho = momentum / 0.29979245799999998 / charge;
95 return brho;
96 }
97 double rigidity(const double totalEnergy, const double chargeIn) const
98 {
99 if (!(std::abs(chargeIn) > std::numeric_limits<double>::epsilon()))
100 {return 0;} // not finite charge, so rigidity 0
101 if (totalEnergy <= mass)
102 {return 0;} // invalid - just return 0
103 double momentum = std::sqrt(std::pow(totalEnergy,2) - std::pow(mass,2));
104 double brho = momentum / 0.29979245799999998 / chargeIn;
105 return brho;
106 }
107 };
108
110 virtual ~BDSOutputROOTParticleData(){;}
111
113 virtual void Flush();
114
115 const ParticleInfo GetParticleInfo(const int& pdgID) const;
116 const IonInfo GetIonInfo(const int& pdgID) const;
117 int Charge(const int& pdgID) const;
118 double Mass(const int& pdgID) const;
119
121 double Rigidity(const int& pdgID,
122 const double& totalEnergy) const;
123
125 double KineticEnergy(const int& pdgID,
126 const double& totalEnergy) const;
127
128 std::string Name(const int& pdgID) const;
129 int IonA(const int& pdgID) const;
130 int IonZ(const int& pdgID) const;
131
133 inline bool IsIon(const int& pdgID) const {return pdgID > 1000000000;}
134
135#ifndef __ROOTBUILD__
137 void Fill(G4bool fillIons);
138#endif
139
140 std::map<int, ParticleInfo> particles;
141 std::map<int, IonInfo> ions;
142
143 ClassDef(BDSOutputROOTParticleData, 1);
144};
145
146#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.