Garfield++ 3.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 std::cerr << " Particle speed must be between zero"
120 << " and speed of light.\n";
121 return;
122 }
123
124 m_beta2 = beta * beta;
125 m_energy = m_mass * sqrt(1. / (1. - m_beta2));
126 m_isChanged = true;
127}
128
129void Track::SetGamma(const double gamma) {
130 if (gamma <= 1.) {
131 std::cerr << m_className << "::SetGamma:\n";
132 std::cerr << " Particle speed must be greater than zero.\n";
133 return;
134 }
135
136 m_energy = m_mass * gamma;
137 m_beta2 = 1. - 1. / (gamma * gamma);
138 m_isChanged = true;
139}
140
141void Track::SetMomentum(const double p) {
142 if (p <= 0.) {
143 std::cerr << m_className << "::SetMomentum:\n";
144 std::cerr << " Particle momentum must be greater than zero.\n";
145 return;
146 }
147
148 m_energy = sqrt(m_mass * m_mass + p * p);
149 const double bg = p / m_mass;
150 m_beta2 = bg * bg / (1. + bg * bg);
151 m_isChanged = true;
152}
153
154void Track::SetKineticEnergy(const double ekin) {
155 if (ekin <= 0.) {
156 std::cerr << m_className << "::SetKineticEnergy:\n";
157 std::cerr << " Kinetic energy must be greater than zero.\n";
158 return;
159 }
160
161 m_energy = m_mass + ekin;
162 const double gamma = 1. + ekin / m_mass;
163 m_beta2 = 1. - 1. / (gamma * gamma);
164 m_isChanged = true;
165}
166
168 if (!s) {
169 std::cerr << m_className << "::SetSensor:\n";
170 std::cerr << " Sensor pointer is null.\n";
171 return;
172 }
173
174 m_sensor = s;
175}
176
178 if (!view) {
179 std::cerr << m_className << "::EnablePlotting:\n";
180 std::cerr << " Pointer is null.\n";
181 return;
182 }
183
184 m_viewer = view;
185 m_usePlotting = true;
186}
187
189 m_usePlotting = false;
190 m_viewer = NULL;
191}
192
193void Track::PlotNewTrack(const double x0, const double y0, const double z0) {
194 if (!m_usePlotting || !m_viewer) return;
195
197}
198
199void Track::PlotCluster(const double x0, const double y0, const double z0) {
200 if (m_plotId < 0 || !m_usePlotting || !m_viewer) {
201 std::cerr << m_className << "::PlotCluster:\n";
202 std::cerr << " No track set. Program bug!\n";
203 return;
204 }
205 m_viewer->AddTrackPoint(m_plotId, x0, y0, z0);
206}
207}
void DisablePlotting()
Switch off plotting.
Definition: Track.cc:188
void EnablePlotting(ViewDrift *viewer)
Switch on plotting.
Definition: Track.cc:177
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:167
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:154
void SetMomentum(const double p)
Set the particle momentum.
Definition: Track.cc:141
virtual void SetParticle(const std::string &part)
Definition: Track.cc:15
double m_q
Definition: Track.hh:104
ViewDrift * m_viewer
Definition: Track.hh:117
std::string m_particleName
Definition: Track.hh:110
void PlotCluster(const double x0, const double y0, const double z0)
Definition: Track.cc:199
double m_beta2
Definition: Track.hh:108
std::string m_className
Definition: Track.hh:102
bool m_usePlotting
Definition: Track.hh:116
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:129
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:193
Visualize drift lines and tracks.
Definition: ViewDrift.hh:19
void AddTrackPoint(const unsigned int iL, const double x, const double y, const double z)
Definition: ViewDrift.cc:198
void NewChargedParticleTrack(const unsigned int np, int &id, const double x0, const double y0, const double z0)
Definition: ViewDrift.cc:149