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