Garfield++ v2r0
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
3#include "Sensor.hh"
4#include "ViewDrift.hh"
5#include "Track.hh"
8
9namespace Garfield {
10
12 : m_className("Track"),
13 m_q(-1.),
14 m_spin(1),
15 m_mass(MuonMass),
16 m_energy(0.),
17 m_isElectron(false),
18 m_particleName("mu-"),
19 m_sensor(NULL),
20 m_isChanged(true),
21 m_usePlotting(false),
22 m_viewer(NULL),
23 m_debug(false),
24 m_plotId(-1) {
25
26 SetBetaGamma(3.);
27}
28
29void Track::SetParticle(const std::string& part) {
30
31 m_isElectron = false;
32 if (part == "electron" || part == "Electron" || part == "e-") {
33 m_q = -1;
34 m_mass = ElectronMass;
35 m_spin = 1;
36 m_isElectron = true;
37 m_particleName = "e-";
38 } else if (part == "positron" || part == "Positron" || part == "e+") {
39 m_q = 1;
40 m_mass = ElectronMass;
41 m_spin = 1;
42 m_particleName = "e+";
43 } else if (part == "muon" || part == "Muon" || part == "mu" ||
44 part == "mu-") {
45 m_q = -1;
46 m_mass = MuonMass;
47 m_spin = 1;
48 m_particleName = "mu-";
49 } else if (part == "mu+") {
50 m_q = 1;
51 m_mass = MuonMass;
52 m_spin = 1;
53 m_particleName = "mu+";
54 } else if (part == "pion" || part == "Pion" || part == "pi" ||
55 part == "pi-") {
56 m_q = -1;
57 m_mass = 139.57018e6;
58 m_spin = 0;
59 m_particleName = "pi-";
60 } else if (part == "pi+") {
61 m_q = 1;
62 m_mass = 139.57018e6;
63 m_spin = 0;
64 m_particleName = "pi+";
65 } else if (part == "kaon" || part == "Kaon" || part == "K" || part == "K-") {
66 m_q = -1;
67 m_mass = 493.677e6;
68 m_spin = 0;
69 m_particleName = "K-";
70 } else if (part == "K+") {
71 m_q = 1;
72 m_mass = 493.677e6;
73 m_spin = 0;
74 m_particleName = "K+";
75 } else if (part == "proton" || part == "Proton" || part == "p") {
76 m_q = 1;
77 m_mass = ProtonMass;
78 m_spin = 1;
79 m_particleName = "p";
80 } else if (part == "anti-proton" || part == "Anti-Proton" ||
81 part == "antiproton" || part == "Antiproton" || part == "p-bar") {
82 m_q = -1;
83 m_mass = ProtonMass;
84 m_spin = 1;
85 m_particleName = "pbar";
86 } else if (part == "deuteron" || part == "Deuteron" || part == "d") {
87 m_q = 1;
88 m_mass = 1875.612793e6;
89 m_spin = 2;
90 m_particleName = "d";
91 } else if (part == "alpha" || part == "Alpha") {
92 m_q = 2;
93 m_mass = 3.727379240e9;
94 m_spin = 0;
95 m_particleName = "alpha";
96 } else {
97 std::cerr << m_className << "::SetParticle:\n"
98 << " Particle " << part << " is not defined.\n";
99 }
100}
101
102void Track::SetEnergy(const double e) {
103
104 if (e <= m_mass) {
105 std::cerr << m_className << "::SetEnergy:\n"
106 << " Particle energy must be greater than the mass.\n";
107 return;
108 }
109
110 m_energy = e;
111 const double gamma = m_energy / m_mass;
112 m_beta2 = 1. - 1. / (gamma * gamma);
113 m_isChanged = true;
114}
115
116void Track::SetBetaGamma(const double bg) {
117
118 if (bg <= 0.) {
119 std::cerr << m_className << "::SetBetaGamma:\n"
120 << " Particle speed must be greater than zero.\n";
121 return;
122 }
123
124 const double bg2 = bg * bg;
125 m_energy = m_mass * sqrt(1. + bg2);
126 m_beta2 = bg2 / (1. + bg2);
127 m_isChanged = true;
128}
129
130void Track::SetBeta(const double beta) {
131
132 if (beta <= 0. && beta >= 1.) {
133 std::cerr << m_className << "::SetBeta:\n";
134 std::cerr << " Particle speed must be between zero"
135 << " and speed of light.\n";
136 return;
137 }
138
139 m_beta2 = beta * beta;
140 m_energy = m_mass * sqrt(1. / (1. - m_beta2));
141 m_isChanged = true;
142}
143
144void Track::SetGamma(const double gamma) {
145
146 if (gamma <= 1.) {
147 std::cerr << m_className << "::SetGamma:\n";
148 std::cerr << " Particle speed must be greater than zero.\n";
149 return;
150 }
151
152 m_energy = m_mass * gamma;
153 m_beta2 = 1. - 1. / (gamma * gamma);
154 m_isChanged = true;
155}
156
157void Track::SetMomentum(const double p) {
158
159 if (p <= 0.) {
160 std::cerr << m_className << "::SetMomentum:\n";
161 std::cerr << " Particle momentum must be greater than zero.\n";
162 return;
163 }
164
165 m_energy = sqrt(m_mass * m_mass + p * p);
166 const double bg = p / m_mass;
167 m_beta2 = bg * bg / (1. + bg * bg);
168 m_isChanged = true;
169}
170
171void Track::SetKineticEnergy(const double ekin) {
172
173 if (ekin <= 0.) {
174 std::cerr << m_className << "::SetKineticEnergy:\n";
175 std::cerr << " Kinetic energy must be greater than zero.\n";
176 return;
177 }
178
179 m_energy = m_mass + ekin;
180 const double gamma = 1. + ekin / m_mass;
181 m_beta2 = 1. - 1. / (gamma * gamma);
182 m_isChanged = true;
183}
184
186
187 if (!s) {
188 std::cerr << m_className << "::SetSensor:\n";
189 std::cerr << " Sensor pointer is null.\n";
190 return;
191 }
192
193 m_sensor = s;
194}
195
197
198 if (!view) {
199 std::cerr << m_className << "::EnablePlotting:\n";
200 std::cerr << " Pointer is null.\n";
201 return;
202 }
203
204 m_viewer = view;
205 m_usePlotting = true;
206}
207
209
210 m_usePlotting = false;
211 m_viewer = NULL;
212}
213
214void Track::PlotNewTrack(const double x0, const double y0, const double z0) {
215
216 if (!m_usePlotting || !m_viewer) return;
217
219}
220
221void Track::PlotCluster(const double x0, const double y0, const double z0) {
222
223 if (m_plotId < 0 || !m_usePlotting || !m_viewer) {
224 std::cerr << m_className << "::PlotCluster:\n";
225 std::cerr << " No track set. Program bug!\n";
226 return;
227 }
228 m_viewer->AddTrackPoint(m_plotId, x0, y0, z0);
229}
230}
void DisablePlotting()
Definition: Track.cc:208
void EnablePlotting(ViewDrift *viewer)
Definition: Track.cc:196
Sensor * m_sensor
Definition: Track.hh:90
void SetBetaGamma(const double bg)
Set the relative momentum of the particle.
Definition: Track.cc:116
void SetSensor(Sensor *s)
Definition: Track.cc:185
bool m_isElectron
Definition: Track.hh:87
bool m_isChanged
Definition: Track.hh:92
void SetKineticEnergy(const double ekin)
Set the kinetic energy of the particle.
Definition: Track.cc:171
void SetMomentum(const double p)
Set the particle momentum.
Definition: Track.cc:157
virtual void SetParticle(const std::string &part)
Set the type of particle.
Definition: Track.cc:29
double m_q
Definition: Track.hh:82
ViewDrift * m_viewer
Definition: Track.hh:95
std::string m_particleName
Definition: Track.hh:88
void PlotCluster(const double x0, const double y0, const double z0)
Definition: Track.cc:221
double m_beta2
Definition: Track.hh:86
std::string m_className
Definition: Track.hh:80
int m_plotId
Definition: Track.hh:99
bool m_usePlotting
Definition: Track.hh:94
void SetEnergy(const double e)
Set the particle energy.
Definition: Track.cc:102
void SetGamma(const double gamma)
Set the Lorentz factor of the particle.
Definition: Track.cc:144
double m_mass
Definition: Track.hh:84
void SetBeta(const double beta)
Set the speed ( ) of the particle.
Definition: Track.cc:130
Track()
Constructor.
Definition: Track.cc:11
double m_energy
Definition: Track.hh:85
void PlotNewTrack(const double x0, const double y0, const double z0)
Definition: Track.cc:214
Visualize drift lines and tracks.
Definition: ViewDrift.hh:15
void AddTrackPoint(const unsigned int iL, const double x, const double y, const double z)
Definition: ViewDrift.cc:269
void NewChargedParticleTrack(const unsigned int np, int &id, const double x0, const double y0, const double z0)
Definition: ViewDrift.cc:216