Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
DriftLineRKF.hh
Go to the documentation of this file.
1#ifndef G_DRIFTLINE_RKF_H
2#define G_DRIFTLINE_RKF_H
3
4#include <string>
5#include <vector>
6#include <array>
7
8#include "Medium.hh"
9#include "Sensor.hh"
10#include "ViewDrift.hh"
11
12namespace Garfield {
13
14/// Calculation of drift lines based on macroscopic transport coefficients
15/// using Runge-Kutta-Fehlberg integration.
16
18 public:
19 /// Constructor
21 /// Destructor
23
24 /// Set the sensor.
25 void SetSensor(Sensor* s);
26
27 /// Switch on drift line plotting.
28 void EnablePlotting(ViewDrift* view);
29 /// Switch off drift line plotting.
30 void DisablePlotting();
31
32 /// Switch on/off calculation of induced currents (default: enabled).
33 void EnableSignalCalculation(const bool on = true) { m_doSignal = on; }
34 /// Set the number of points to be used when averaging the delayed
35 /// signal vector over a time bin in the Sensor class.
36 /// The averaging is done with a \f$2\times navg + 1\f$ point
37 /// Newton-Raphson integration. Default: 2.
38 void SetSignalAveragingOrder(const unsigned int navg) { m_navg = navg; }
39
40 /// Set the accuracy of the Runge Kutta Fehlberg drift line integration.
41 void SetIntegrationAccuracy(const double eps);
42 /// Set the maximum step size that is allowed. By default, there is no limit.
43 void SetMaximumStepSize(const double ms);
44 /// Do not apply an upper limit to the step size that is allowed.
45 void UnsetMaximumStepSize() { m_useStepSizeLimit = false; }
46 /// Request (or not) the drift line calculation to be aborted if the
47 /// drift line makes a bend sharper than 90 degrees.
48 void RejectKinks(const bool on = true) { m_rejectKinks = on; }
49
50 /// Set multiplication factor for the signal induced by electrons.
51 void SetElectronSignalScalingFactor(const double scale) { m_scaleE = scale; }
52 /// Set multiplication factor for the signal induced by holes.
53 void SetHoleSignalScalingFactor(const double scale) { m_scaleH = scale; }
54 /// Set multiplication factor for the signal induced by ions.
55 void SetIonSignalScalingFactor(const double scale) { m_scaleI = scale; }
56
57 /// Enable/disable simulation electron multiplication (default: on).
58 void EnableAvalanche(const bool on = true) { m_doAvalanche = on; }
59 /// Enable/disable simulation of the ion tail (default: off).
60 void EnableIonTail(const bool on = true) { m_doIonTail = on; }
61 /// Do not randomize the avalanche size.
62 void SetGainFluctuationsFixed(const double gain = -1.);
63 /// Sample the avalanche size from a Polya distribution with
64 /// shape parameter theta.
65 void SetGainFluctuationsPolya(const double theta, const double mean = -1.);
66
67 /// Simulate the drift line of an electron with a given starting point.
68 bool DriftElectron(const double x0, const double y0, const double z0,
69 const double t0);
70 /// Simulate the drift line of a hole with a given starting point.
71 bool DriftHole(const double x0, const double y0, const double z0,
72 const double t0);
73 /// Simulate the drift line of an ion with a given starting point.
74 bool DriftIon(const double x0, const double y0, const double z0,
75 const double t0);
76 /// Simulate the drift line of an electron with a given starting point,
77 /// assuming that it has positive charge.
78 bool DriftPositron(const double x0, const double y0, const double z0,
79 const double t0);
80 /// Simulate the drift line of an ion with a given starting point,
81 /// assuming that it has negative charge.
82 bool DriftNegativeIon(const double x0, const double y0, const double z0,
83 const double t0);
84
85 /// Print the trajectory of the most recent drift line.
86 void PrintDriftLine() const;
87 /// Get the end point and status flag of the most recent drift line.
88 void GetEndPoint(double& x, double& y, double& z, double& t, int& st) const;
89 /// Get the number of points of the most recent drift line.
90 unsigned int GetNumberOfDriftLinePoints() const { return m_x.size(); }
91 /// Get the coordinates and time of a point along the most recent drift line.
92 void GetDriftLinePoint(const unsigned int i, double& x, double& y, double& z,
93 double& t) const;
94
95 /// Compute the sigma of the arrival time distribution for the current
96 /// drift line by integrating the longitudinal diffusion coefficient.
97 double GetArrivalTimeSpread(const double eps = 1.e-4);
98 /// Compute the multiplication factor for the current drift line.
99 double GetGain(const double eps = 1.e-4);
100 /// Compute the attachment loss factor for the current drift line.
101 double GetLoss(const double eps = 1.e-4);
102 double GetDriftTime() const { return m_t.empty() ? 0. : m_t.back(); }
103
104 void GetAvalancheSize(double& ne, double& ni) const { ne = m_nE; ni = m_nI; }
105
106 /** Compute an electric field line.
107 * \param xi,yi,zi starting point
108 * \param xl points along the field line
109 * \param electron flag to set the direction in which to follow the field
110 */
111 bool FieldLine(const double xi, const double yi, const double zi,
112 std::vector<std::array<float, 3> >& xl,
113 const bool electron = true);
114
115 void EnableDebugging() { m_debug = true; }
116 void DisableDebugging() { m_debug = false; }
117
118 private:
119 std::string m_className = "DriftLineRKF";
120
121 // Pointer to sensor.
122 Sensor* m_sensor = nullptr;
123
124 enum class Particle { Electron = 0, Ion, Hole, Positron, NegativeIon };
125 // Type of particle (of the most current drift line).
126 Particle m_particle = Particle::Electron;
127
128 // Maximum allowed step size.
129 double m_maxStepSize = 0.;
130 // Precision of the stepping algorithm.
131 double m_accuracy = 1.e-8;
132 // Flag to reject bends > 90 degrees or not.
133 bool m_rejectKinks = true;
134 // Flag to apply a cut on the maximum allowed step size or not.
135 bool m_useStepSizeLimit = false;
136
137 // Pointer to the drift viewer.
138 ViewDrift* m_view = nullptr;
139
140 // Points along the current drift line.
141 std::vector<std::array<double, 3> > m_x;
142 // Times corresponding to the points along the current drift line.
143 std::vector<double> m_t;
144 // Status flag of the current drift line.
145 int m_status = 0;
146
147 // Flag whether to calculate induced signals or not.
148 bool m_doSignal = true;
149 // Averaging order used when projecting the signal on the time bins.
150 unsigned int m_navg = 2;
151
152 // Scaling factor for electron signals.
153 double m_scaleE = 1.;
154 // Scaling factor for hole signals.
155 double m_scaleH = 1.;
156 // Scaling factor for ion signals.
157 double m_scaleI = 1.;
158
159 // Flag wether to simulate electron multiplication or not.
160 bool m_doAvalanche = true;
161 enum class GainFluctuations { None = 0, Polya };
162 // Model to be used for randomizing the avalanche size.
163 GainFluctuations m_gainFluctuations = GainFluctuations::None;
164 // Polya shape parameter.
165 double m_theta = 0.;
166 // Mean avalanche size (only used if < 1).
167 double m_gain = -1.;
168
169 // Flag whether to simulate the ion tail or not.
170 bool m_doIonTail = false;
171 // Avalanche size.
172 double m_nE = 0., m_nI = 0.;
173
174 bool m_debug = false;
175
176 // Calculate a drift line starting at a given position.
177 bool DriftLine(const double x0, const double y0, const double z0,
178 const double t0, const Particle particle,
179 std::vector<double>& ts,
180 std::vector<std::array<double, 3> >& xs, int& status);
181 bool Avalanche(const Particle particle,
182 const std::vector<std::array<double, 3> >& xs,
183 std::vector<double>& ne, std::vector<double>& ni,
184 double& scale);
185 bool AddIonTail(const std::vector<double>& te,
186 const std::vector<std::array<double, 3> >& xe,
187 const std::vector<double>& ni, const double scale);
188 // Compute electric and magnetic field at a given position.
189 int GetField(const std::array<double, 3>& x,
190 double& ex, double& ey, double& ez,
191 double& bx, double& by, double& bz,
192 Medium*& medium) const;
193 // Calculate transport parameters for the respective particle type.
194 bool GetVelocity(const std::array<double, 3>& x, const Particle particle,
195 std::array<double, 3>& v, int& status) const;
196 bool GetVelocity(const double ex, const double ey, const double ez,
197 const double bx, const double by, const double bz,
198 Medium* medium, const Particle particle,
199 std::array<double, 3>& v) const;
200 bool GetDiffusion(const double ex, const double ey, const double ez,
201 const double bx, const double by, const double bz,
202 Medium* medium, const Particle particle,
203 double& dl, double& dt) const;
204 bool GetAlpha(const double ex, const double ey, const double ez,
205 const double bx, const double by, const double bz,
206 Medium* medium, const Particle particle, double& alpha) const;
207 bool GetEta(const double ex, const double ey, const double ez,
208 const double bx, const double by, const double bz,
209 Medium* medium, const Particle particle, double& eta) const;
210
211 // Terminate a drift line at the edge of a boundary.
212 bool Terminate(const std::array<double, 3>& xx0,
213 const std::array<double, 3>& xx1,
214 const Particle particle,
215 std::vector<double>& ts,
216 std::vector<std::array<double, 3> >& xs);
217
218 // Drift a particle to a wire
219 bool DriftToWire(const double xw, const double yw, const double rw,
220 const Particle particle,
221 std::vector<double>& ts,
222 std::vector<std::array<double, 3> >& xs, int& stat);
223
224 // Integrate the longitudinal diffusion over a step.
225 double IntegrateDiffusion(const std::array<double, 3>& xi,
226 const std::array<double, 3>& xe,
227 const Particle particle, const double tol);
228 // Integrate the Townsend coefficient over a step.
229 double IntegrateAlpha(const std::array<double, 3>& xi,
230 const std::array<double, 3>& xe,
231 const Particle particle, const double tol);
232 // Integrate the attachment coefficient over a step.
233 double IntegrateEta(const std::array<double, 3>& xi,
234 const std::array<double, 3>& xe,
235 const Particle particle, const double tol);
236
237 // Calculate the signal for the current drift line.
238 void ComputeSignal(const Particle particle, const double scale,
239 const std::vector<double>& ts,
240 const std::vector<std::array<double, 3> >& xs,
241 const std::vector<double>& ne) const;
242
243 // Terminate a field line.
244 void Terminate(const std::array<double, 3>& xx0,
245 const std::array<double, 3>& xx1,
246 std::vector<std::array<float, 3> >& xs);
247};
248}
249
250#endif
void SetIonSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by ions.
Definition: DriftLineRKF.hh:55
void SetSignalAveragingOrder(const unsigned int navg)
Definition: DriftLineRKF.hh:38
void EnableSignalCalculation(const bool on=true)
Switch on/off calculation of induced currents (default: enabled).
Definition: DriftLineRKF.hh:33
void DisablePlotting()
Switch off drift line plotting.
Definition: DriftLineRKF.cc:90
bool DriftNegativeIon(const double x0, const double y0, const double z0, const double t0)
double GetLoss(const double eps=1.e-4)
Compute the attachment loss factor for the current drift line.
bool DriftHole(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of a hole with a given starting point.
bool DriftIon(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of an ion with a given starting point.
void SetSensor(Sensor *s)
Set the sensor.
Definition: DriftLineRKF.cc:55
void UnsetMaximumStepSize()
Do not apply an upper limit to the step size that is allowed.
Definition: DriftLineRKF.hh:45
void SetIntegrationAccuracy(const double eps)
Set the accuracy of the Runge Kutta Fehlberg drift line integration.
Definition: DriftLineRKF.cc:63
unsigned int GetNumberOfDriftLinePoints() const
Get the number of points of the most recent drift line.
Definition: DriftLineRKF.hh:90
bool DriftElectron(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of an electron with a given starting point.
void SetGainFluctuationsPolya(const double theta, const double mean=-1.)
double GetGain(const double eps=1.e-4)
Compute the multiplication factor for the current drift line.
void SetGainFluctuationsFixed(const double gain=-1.)
Do not randomize the avalanche size.
Definition: DriftLineRKF.cc:92
void RejectKinks(const bool on=true)
Definition: DriftLineRKF.hh:48
bool DriftPositron(const double x0, const double y0, const double z0, const double t0)
void GetDriftLinePoint(const unsigned int i, double &x, double &y, double &z, double &t) const
Get the coordinates and time of a point along the most recent drift line.
~DriftLineRKF()
Destructor.
Definition: DriftLineRKF.hh:22
void PrintDriftLine() const
Print the trajectory of the most recent drift line.
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
Definition: DriftLineRKF.cc:82
DriftLineRKF()
Constructor.
Definition: DriftLineRKF.cc:50
double GetDriftTime() const
double GetArrivalTimeSpread(const double eps=1.e-4)
void GetAvalancheSize(double &ne, double &ni) const
void GetEndPoint(double &x, double &y, double &z, double &t, int &st) const
Get the end point and status flag of the most recent drift line.
bool FieldLine(const double xi, const double yi, const double zi, std::vector< std::array< float, 3 > > &xl, const bool electron=true)
void SetHoleSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by holes.
Definition: DriftLineRKF.hh:53
void EnableAvalanche(const bool on=true)
Enable/disable simulation electron multiplication (default: on).
Definition: DriftLineRKF.hh:58
void SetMaximumStepSize(const double ms)
Set the maximum step size that is allowed. By default, there is no limit.
Definition: DriftLineRKF.cc:72
void EnableIonTail(const bool on=true)
Enable/disable simulation of the ion tail (default: off).
Definition: DriftLineRKF.hh:60
void SetElectronSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by electrons.
Definition: DriftLineRKF.hh:51
Visualize drift lines and tracks.
Definition: ViewDrift.hh:18