Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
TrackSimple.cc
Go to the documentation of this file.
1#include <iostream>
2
3#include "Sensor.hh"
4#include "TrackSimple.hh"
7#include "Random.hh"
8
9namespace Garfield {
10
12 : m_isReady(false),
13 m_x(0.),
14 m_y(0.),
15 m_z(0.),
16 m_t(0.),
17 m_dx(0.),
18 m_dy(0.),
19 m_dz(1.),
20 m_mfp(0.04),
21 m_eloss(2530.),
22 m_useEqualSpacing(false) {
23
24 m_className = "TrackSimple";
25}
26
27void TrackSimple::SetClusterDensity(const double d) {
28
29 if (d < Small) {
30 std::cerr << m_className << "::SetClusterDensity:\n"
31 << " Cluster density (number of clusters per cm)"
32 << " must be positive.\n";
33 return;
34 }
35
36 m_mfp = 1. / d;
37}
38
39double TrackSimple::GetClusterDensity() { return 1. / m_mfp; }
40
41void TrackSimple::SetStoppingPower(const double dedx) {
42
43 if (dedx < Small) {
44 std::cerr << m_className << "::SetStoppingPower:\n"
45 << " Stopping power (average energy loss [eV] per cm)"
46 << " must be positive.\n";
47 return;
48 }
49
50 m_eloss = dedx;
51}
52
54
55bool TrackSimple::NewTrack(const double x0, const double y0, const double z0,
56 const double t0, const double dx0, const double dy0,
57 const double dz0) {
58
59 // Check if a sensor has been defined
60 if (!m_sensor) {
61 std::cerr << m_className << "::NewTrack:\n"
62 << " Sensor is not defined.\n";
63 m_isReady = false;
64 return false;
65 }
66
67 // Make sure we are inside a medium
68 Medium* medium = NULL;
69 if (!m_sensor->GetMedium(x0, y0, z0, medium)) {
70 std::cerr << m_className << "::NewTrack:\n";
71 std::cerr << " No medium at initial position.\n";
72 m_isReady = false;
73 return false;
74 }
75
76 m_isReady = true;
77
78 m_x = x0;
79 m_y = y0;
80 m_z = z0;
81 m_t = t0;
82
83 // Normalise the direction.
84 const double d = sqrt(dx0 * dx0 + dy0 * dy0 + dz0 * dz0);
85 if (d < Small) {
86 // Choose random direction.
88 } else {
89 m_dx = dx0 / d;
90 m_dy = dy0 / d;
91 m_dz = dz0 / d;
92 }
93 return true;
94}
95
96bool TrackSimple::GetCluster(double& xcls, double& ycls, double& zcls,
97 double& tcls, int& n, double& e, double& extra) {
98
99 extra = 0.;
100 if (!m_isReady) return false;
101
102 if (m_useEqualSpacing) {
103 m_x += m_dx * m_mfp;
104 m_y += m_dy * m_mfp;
105 m_z += m_dz * m_mfp;
106 } else {
107 const double d = -m_mfp * log(RndmUniformPos());
108 m_x += m_dx * d;
109 m_y += m_dy * d;
110 m_z += m_dz * d;
111 }
112
113 xcls = m_x;
114 ycls = m_y;
115 zcls = m_z;
116 tcls = m_t;
117
118 n = 1;
119 e = m_eloss * m_mfp;
120
121 Medium* medium = NULL;
122 if (!m_sensor->GetMedium(m_x, m_y, m_z, medium)) {
123 m_isReady = false;
124 if (m_debug) {
125 std::cout << m_className << "::GetCluster: Particle left the medium.\n";
126 }
127 return false;
128 }
129
130 return true;
131}
132}
Abstract base class for media.
Definition: Medium.hh:11
bool GetMedium(const double x, const double y, const double z, Medium *&medium)
Get the medium at (x, y, z).
Definition: Sensor.cc:150
void SetStoppingPower(const double dedx)
Set the stopping power (dE/dx).
Definition: TrackSimple.cc:41
virtual double GetClusterDensity()
Definition: TrackSimple.cc:39
virtual bool GetCluster(double &xcls, double &ycls, double &zcls, double &tcls, int &n, double &e, double &extra)
Definition: TrackSimple.cc:96
virtual double GetStoppingPower()
Get the stopping power (mean energy loss [eV] per cm).
Definition: TrackSimple.cc:53
void SetClusterDensity(const double d)
Set the cluster density (inverse mean free path).
Definition: TrackSimple.cc:27
TrackSimple()
Constructor.
Definition: TrackSimple.cc:11
virtual bool NewTrack(const double x0, const double y0, const double z0, const double t0, const double dx0, const double dy0, const double dz0)
Definition: TrackSimple.cc:55
Sensor * m_sensor
Definition: Track.hh:90
bool m_debug
Definition: Track.hh:97
std::string m_className
Definition: Track.hh:80
void RndmDirection(double &dx, double &dy, double &dz, const double length=1.)
Draw a random (isotropic) direction vector.
Definition: Random.hh:106
double RndmUniformPos()
Draw a random number uniformly distributed in the range (0, 1).
Definition: Random.hh:17