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