Garfield++ v1r0
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 : isReady(false),
13 x(0.),
14 y(0.),
15 z(0.),
16 t(0.),
17 dx(0.),
18 dy(0.),
19 dz(1.),
20 mfp(0.04),
21 eloss(2530.),
22 useEqualSpacing(false) {
23
24 className = "TrackSimple";
25}
26
27void TrackSimple::SetClusterDensity(const double d) {
28
29 if (d < Small) {
30 std::cerr << className << "::SetClusterDensity:\n";
31 std::cerr << " Cluster density (number of clusters per cm)"
32 << " must be positive.\n" << std::endl;
33 return;
34 }
35
36 mfp = 1. / d;
37}
38
39double TrackSimple::GetClusterDensity() { return 1. / mfp; }
40
41void TrackSimple::SetStoppingPower(const double dedx) {
42
43 if (dedx < Small) {
44 std::cerr << className << "::SetStoppingPower:\n";
45 std::cerr << " Stopping power (average energy loss [eV] per cm)"
46 << " must be positive.\n";
47 return;
48 }
49
50 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 (sensor == 0) {
61 std::cerr << className << "::NewTrack:\n";
62 std::cerr << " Sensor is not defined.\n";
63 isReady = false;
64 return false;
65 }
66
67 // Make sure we are inside a medium
68 Medium* medium;
69 if (!sensor->GetMedium(x0, y0, z0, medium)) {
70 std::cerr << className << "::NewTrack:\n";
71 std::cerr << " No medium at initial position.\n";
72 isReady = false;
73 return false;
74 }
75
76 isReady = true;
77
78 x = x0;
79 y = y0;
80 z = z0;
81 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
87 double phi = TwoPi * RndmUniform();
88 double ctheta = 1. - 2. * RndmUniform();
89 double stheta = sqrt(1. - ctheta * ctheta);
90 dx = cos(phi) * stheta;
91 dy = sin(phi) * stheta;
92 dz = ctheta;
93 } else {
94 dx = dx0 / d;
95 dy = dy0 / d;
96 dz = dz0 / d;
97 }
98 return true;
99}
100
101bool TrackSimple::GetCluster(double& xcls, double& ycls, double& zcls,
102 double& tcls, int& n, double& e, double& extra) {
103
104 extra = 0.;
105 if (!isReady) return false;
106
107 if (useEqualSpacing) {
108 x += dx * mfp;
109 y += dy * mfp;
110 z += dz * mfp;
111 } else {
112 const double d = -mfp * log(RndmUniformPos());
113 x += dx * d;
114 y += dy * d;
115 z += dz * d;
116 }
117
118 xcls = x;
119 ycls = y;
120 zcls = z;
121 tcls = t;
122
123 n = 1;
124 e = eloss * mfp;
125
126 Medium* medium;
127 if (!sensor->GetMedium(x, y, z, medium)) {
128 isReady = false;
129 if (debug) {
130 std::cout << className << "::GetCluster:\n";
131 std::cout << " Particle left the medium.\n";
132 }
133 return false;
134 }
135
136 return true;
137}
138}
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:431
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:383
bool GetMedium(const double x, const double y, const double z, Medium *&medium)
Definition: Sensor.cc:141
void SetStoppingPower(const double dedx)
Definition: TrackSimple.cc:41
double GetClusterDensity()
Definition: TrackSimple.cc:39
bool GetCluster(double &xcls, double &ycls, double &zcls, double &tcls, int &n, double &e, double &extra)
Definition: TrackSimple.cc:101
void SetClusterDensity(const double d)
Definition: TrackSimple.cc:27
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
std::string className
Definition: Track.hh:61
bool debug
Definition: Track.hh:78
Sensor * sensor
Definition: Track.hh:71
double RndmUniform()
Definition: Random.hh:16
double RndmUniformPos()
Definition: Random.hh:19