Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Track.cc
Go to the documentation of this file.
1#include <iostream>
2#include <algorithm>
3#include <cctype>
4
7#include "Garfield/Sensor.hh"
8#include "Garfield/Track.hh"
10
11namespace Garfield {
12
13Track::Track() : m_mass(MuonMass) { SetBetaGamma(3.); }
14
15void Track::SetParticle(const std::string& part) {
16 std::string id = part;
17 std::transform(id.begin(), id.end(), id.begin(),
18 [](unsigned char c) -> unsigned char {
19 return std::toupper(c);
20 });
21 m_isElectron = false;
22 if (id == "ELECTRON" || id == "E-") {
23 m_q = -1;
24 m_mass = ElectronMass;
25 m_spin = 1;
26 m_isElectron = true;
27 m_particleName = "e-";
28 } else if (id == "POSITRON" || id == "E+") {
29 m_q = 1;
30 m_mass = ElectronMass;
31 m_spin = 1;
32 m_particleName = "e+";
33 } else if (id == "MUON" || id == "MU" || id == "MU-") {
34 m_q = -1;
35 m_mass = MuonMass;
36 m_spin = 1;
37 m_particleName = "mu-";
38 } else if (id == "MU+") {
39 m_q = 1;
40 m_mass = MuonMass;
41 m_spin = 1;
42 m_particleName = "mu+";
43 } else if (id == "PION" || id == "PI" || id == "PI-") {
44 m_q = -1;
45 m_mass = 139.57018e6;
46 m_spin = 0;
47 m_particleName = "pi-";
48 } else if (id == "PI+") {
49 m_q = 1;
50 m_mass = 139.57018e6;
51 m_spin = 0;
52 m_particleName = "pi+";
53 } else if (id == "KAON" || id == "K" || id == "K-") {
54 m_q = -1;
55 m_mass = 493.677e6;
56 m_spin = 0;
57 m_particleName = "K-";
58 } else if (id == "K+") {
59 m_q = 1;
60 m_mass = 493.677e6;
61 m_spin = 0;
62 m_particleName = "K+";
63 } else if (id == "PROTON" || id == "P") {
64 m_q = 1;
65 m_mass = ProtonMass;
66 m_spin = 1;
67 m_particleName = "p";
68 } else if (id == "ANTI-PROTON" || id == "ANTIPROTON" ||
69 id == "P-BAR" || id == "PBAR") {
70 m_q = -1;
71 m_mass = ProtonMass;
72 m_spin = 1;
73 m_particleName = "pbar";
74 } else if (id == "DEUTERON" || id == "D") {
75 m_q = 1;
76 m_mass = 1875.612793e6;
77 m_spin = 2;
78 m_particleName = "d";
79 } else if (id == "ALPHA") {
80 m_q = 2;
81 m_mass = 3.727379240e9;
82 m_spin = 0;
83 m_particleName = "alpha";
84 } else {
85 std::cerr << m_className << "::SetParticle:\n"
86 << " Particle " << part << " is not defined.\n";
87 }
88}
89
90void Track::SetEnergy(const double e) {
91 if (e <= m_mass) {
92 std::cerr << m_className << "::SetEnergy:\n"
93 << " Particle energy must be greater than the mass.\n";
94 return;
95 }
96
97 m_energy = e;
98 const double gamma = m_energy / m_mass;
99 m_beta2 = 1. - 1. / (gamma * gamma);
100 m_isChanged = true;
101}
102
103void Track::SetBetaGamma(const double bg) {
104 if (bg <= 0.) {
105 std::cerr << m_className << "::SetBetaGamma:\n"
106 << " Particle speed must be greater than zero.\n";
107 return;
108 }
109
110 const double bg2 = bg * bg;
111 m_energy = m_mass * sqrt(1. + bg2);
112 m_beta2 = bg2 / (1. + bg2);
113 m_isChanged = true;
114}
115
116void Track::SetBeta(const double beta) {
117 if (beta <= 0. || beta >= 1.) {
118 std::cerr << m_className << "::SetBeta:\n"
119 << " Beta must be between zero and one.\n";
120 return;
121 }
122
123 m_beta2 = beta * beta;
124 m_energy = m_mass * sqrt(1. / (1. - m_beta2));
125 m_isChanged = true;
126}
127
128void Track::SetGamma(const double gamma) {
129 if (gamma <= 1.) {
130 std::cerr << m_className << "::SetGamma:\n"
131 << " Gamma must be greater than one.\n";
132 return;
133 }
134
135 m_energy = m_mass * gamma;
136 m_beta2 = 1. - 1. / (gamma * gamma);
137 m_isChanged = true;
138}
139
140void Track::SetMomentum(const double p) {
141 if (p <= 0.) {
142 std::cerr << m_className << "::SetMomentum:\n"
143 << " Particle momentum must be greater than zero.\n";
144 return;
145 }
146
147 m_energy = sqrt(m_mass * m_mass + p * p);
148 const double bg = p / m_mass;
149 m_beta2 = bg * bg / (1. + bg * bg);
150 m_isChanged = true;
151}
152
153void Track::SetKineticEnergy(const double ekin) {
154 if (ekin <= 0.) {
155 std::cerr << m_className << "::SetKineticEnergy:\n"
156 << " Kinetic energy must be greater than zero.\n";
157 return;
158 }
159
160 m_energy = m_mass + ekin;
161 const double gamma = 1. + ekin / m_mass;
162 m_beta2 = 1. - 1. / (gamma * gamma);
163 m_isChanged = true;
164}
165
167 if (!s) {
168 std::cerr << m_className << "::SetSensor: Null pointer.\n";
169 return;
170 }
171
172 m_sensor = s;
173}
174
176 if (!view) {
177 std::cerr << m_className << "::EnablePlotting: Null pointer.\n";
178 return;
179 }
180 m_viewer = view;
181}
182
184 m_viewer = nullptr;
185}
186
187void Track::PlotNewTrack(const double x0, const double y0, const double z0) {
188 if (!m_viewer) return;
190}
191
192void Track::PlotCluster(const double x0, const double y0, const double z0) {
193 if (m_viewer) m_viewer->AddTrackPoint(m_plotId, x0, y0, z0);
194}
195}
size_t m_plotId
Definition: Track.hh:120
void DisablePlotting()
Switch off plotting.
Definition: Track.cc:183
void EnablePlotting(ViewDrift *viewer)
Switch on plotting.
Definition: Track.cc:175
Sensor * m_sensor
Definition: Track.hh:112
void SetBetaGamma(const double bg)
Set the relative momentum of the particle.
Definition: Track.cc:103
void SetSensor(Sensor *s)
Set the sensor through which to transport the particle.
Definition: Track.cc:166
bool m_isElectron
Definition: Track.hh:109
bool m_isChanged
Definition: Track.hh:114
void SetKineticEnergy(const double ekin)
Set the kinetic energy of the particle.
Definition: Track.cc:153
void SetMomentum(const double p)
Set the particle momentum.
Definition: Track.cc:140
virtual void SetParticle(const std::string &part)
Definition: Track.cc:15
double m_q
Definition: Track.hh:104
ViewDrift * m_viewer
Definition: Track.hh:116
std::string m_particleName
Definition: Track.hh:110
void PlotCluster(const double x0, const double y0, const double z0)
Definition: Track.cc:192
double m_beta2
Definition: Track.hh:108
std::string m_className
Definition: Track.hh:102
void SetEnergy(const double e)
Set the particle energy.
Definition: Track.cc:90
void SetGamma(const double gamma)
Set the Lorentz factor of the particle.
Definition: Track.cc:128
double m_mass
Definition: Track.hh:106
void SetBeta(const double beta)
Set the speed ( ) of the particle.
Definition: Track.cc:116
Track()
Constructor.
Definition: Track.cc:13
double m_energy
Definition: Track.hh:107
void PlotNewTrack(const double x0, const double y0, const double z0)
Definition: Track.cc:187
Visualize drift lines and tracks.
Definition: ViewDrift.hh:18
void AddTrackPoint(const size_t iL, const float x, const float y, const float z)
Definition: ViewDrift.cc:156
void NewChargedParticleTrack(const size_t np, size_t &id, const float x0, const float y0, const float z0)
Definition: ViewDrift.cc:111