Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
AvalancheMC.hh
Go to the documentation of this file.
1#ifndef G_AVALANCHE_MC_H
2#define G_AVALANCHE_MC_H
3
4#include <string>
5#include <vector>
6#include <array>
7
9#include "Sensor.hh"
10#include "ViewDrift.hh"
11
12namespace Garfield {
13
14/// Calculate drift lines and avalanches based on macroscopic transport
15/// coefficients, using Monte Carlo 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() { m_viewer = nullptr; }
31
32 /// Switch on calculation of induced currents (default: disabled).
33 void EnableSignalCalculation(const bool on = true) { m_doSignal = on; }
34 /// Set the number of points to be used when averaging the
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: 1.
38 void SetSignalAveragingOrder(const unsigned int navg) { m_navg = navg; }
39 /// Use the weighting potential (as opposed to the weighting field)
40 /// for calculating the induced signal.
41 void UseWeightingPotential(const bool on = true) {
42 m_useWeightingPotential = on;
43 }
44
45 /// Switch on calculation of induced charge (default: disabled).
46 void EnableInducedChargeCalculation(const bool on = true) {
47 m_doInducedCharge = on;
48 }
49
50 /** Switch on Runge-Kutta-Fehlberg stepping (as opposed to simple
51 * straight-line steps. */
52 void EnableRKFSteps(const bool on = true) { m_doRKF = on; }
53
54 /** Switch on equilibration of multiplication and attachment
55 * over the drift line (default: enabled). */
56 void EnableProjectedPathIntegration(const bool on = true) {
57 m_doEquilibration = on;
58 }
59
60 /// Switch on diffusion (default: enabled).
61 void EnableDiffusion() { m_useDiffusion = true; }
62 /// Switch off diffusion.
63 void DisableDiffusion() { m_useDiffusion = false; }
64
65 /** Switch on attachment (and multiplication) for drift line calculation
66 * (default: enabled). For avalanches the flag is ignored. */
67 void EnableAttachment() { m_useAttachment = true; }
68 /// Switch off attachment and multiplication.
69 void DisableAttachment() { m_useAttachment = false; }
70
71 /// Switch on calculating trapping with TCAD traps.
72 void EnableTcadTraps(const bool on = true) { m_useTcadTrapping = on; }
73 /// Switch on TCAD velocity maps
74 void EnableTcadVelocity(const bool on = true) { m_useTcadVelocity = on; }
75
76 /// Enable use of magnetic field in stepping algorithm.
77 void EnableMagneticField(const bool on = true) { m_useBfield = on; }
78
79 /** Set a maximum avalanche size (ignore further multiplication
80 once this size has been reached). */
81 void EnableAvalancheSizeLimit(const unsigned int size) { m_sizeCut = size; }
82 /// Do not limit the maximum avalanche size.
83 void DisableAvalancheSizeLimit() { m_sizeCut = 0; }
84 /// Return the currently set avalanche size limit.
85 int GetAvalancheSizeLimit() const { return m_sizeCut; }
86
87 /// Use fixed-time steps (default 20 ps).
88 void SetTimeSteps(const double d = 0.02);
89 /// Use fixed distance steps (default 10 um).
90 void SetDistanceSteps(const double d = 0.001);
91 /** Use exponentially distributed time steps with mean equal
92 * to the specified multiple of the collision time (default model).*/
93 void SetCollisionSteps(const unsigned int n = 100);
94 /// Retrieve the step distance from a user-supplied function.
95 void SetStepDistanceFunction(double (*f)(double x, double y, double z));
96
97 /// Define a time interval (only carriers inside the interval are drifted).
98 void SetTimeWindow(const double t0, const double t1);
99 /// Do not limit the time interval within which carriers are drifted.
100 void UnsetTimeWindow() { m_hasTimeWindow = false; }
101
102 /// Set multiplication factor for the signal induced by electrons.
103 void SetElectronSignalScalingFactor(const double scale) { m_scaleE = scale; }
104 /// Set multiplication factor for the signal induced by holes.
105 void SetHoleSignalScalingFactor(const double scale) { m_scaleH = scale; }
106 /// Set multiplication factor for the signal induced by ions.
107 void SetIonSignalScalingFactor(const double scale) { m_scaleI = scale; }
108
109 /// Return the number of electrons and ions/holes in the avalanche.
110 void GetAvalancheSize(unsigned int& ne, unsigned int& ni) const {
111 ne = m_nElectrons;
112 ni = m_nIons;
113 }
114
115 /// Return the number of points along the last simulated drift line.
116 unsigned int GetNumberOfDriftLinePoints() const { return m_drift.size(); }
117 /// Return the coordinates and time of a point along the last drift line.
118 void GetDriftLinePoint(const unsigned int i, double& x, double& y, double& z,
119 double& t) const;
120
121 /** Return the number of electron trajectories in the last
122 * simulated avalanche (including captured electrons). */
123 unsigned int GetNumberOfElectronEndpoints() const {
124 return m_endpointsElectrons.size();
125 }
126 /** Return the number of hole trajectories in the last
127 * simulated avalanche (including captured holes). */
128 unsigned int GetNumberOfHoleEndpoints() const {
129 return m_endpointsHoles.size();
130 }
131 /// Return the number of ion trajectories.
132 unsigned int GetNumberOfIonEndpoints() const {
133 return m_endpointsIons.size();
134 }
135
136 /** Return the coordinates and time of start and end point of a given
137 * electron drift line.
138 * \param i index of the drift line
139 * \param x0,y0,z0,t0 coordinates and time of the starting point
140 * \param x1,y1,z1,t1 coordinates and time of the end point
141 * \param status status code (see GarfieldConstants.hh)
142 */
143 void GetElectronEndpoint(const unsigned int i, double& x0, double& y0,
144 double& z0, double& t0, double& x1, double& y1,
145 double& z1, double& t1, int& status) const;
146 void GetHoleEndpoint(const unsigned int i, double& x0, double& y0, double& z0,
147 double& t0, double& x1, double& y1, double& z1,
148 double& t1, int& status) const;
149 void GetIonEndpoint(const unsigned int i, double& x0, double& y0, double& z0,
150 double& t0, double& x1, double& y1, double& z1,
151 double& t1, int& status) const;
152
153 /// Simulate the drift line of an electron from a given starting point.
154 bool DriftElectron(const double x0, const double y0, const double z0,
155 const double t0);
156 /// Simulate the drift line of a hole from a given starting point.
157 bool DriftHole(const double x0, const double y0, const double z0,
158 const double t0);
159 /// Simulate the drift line of an ion from a given starting point.
160 bool DriftIon(const double x0, const double y0, const double z0,
161 const double t0);
162 /// Simulate an avalanche initiated by an electron at a given starting point.
163 bool AvalancheElectron(const double x0, const double y0, const double z0,
164 const double t0, const bool hole = false);
165 /// Simulate an avalanche initiated by a hole at a given starting point.
166 bool AvalancheHole(const double x0, const double y0, const double z0,
167 const double t0, const bool electron = false);
168 bool AvalancheElectronHole(const double x0, const double y0, const double z0,
169 const double t0);
170
171 /// Switch on debugging messages (default: off).
172 void EnableDebugging() { m_debug = true; }
173 /// Switch off debugging messages.
174 void DisableDebugging() { m_debug = false; }
175
176 private:
177 std::string m_className = "AvalancheMC";
178
179 Sensor* m_sensor = nullptr;
180
181 enum class Particle { Electron = 0, Ion, Hole };
182
183 struct DriftPoint {
184 std::array<double, 3> x; //< Position.
185 double t; //< Time.
186 unsigned int ne, nh, ni; //< Number of secondaries produced at this point.
187 };
188 /// Current drift line
189 std::vector<DriftPoint> m_drift;
190
191 enum class StepModel { FixedTime, FixedDistance, CollisionTime, UserDistance};
192 /// Step size model.
193 StepModel m_stepModel = StepModel::CollisionTime;
194
195 /// Fixed time step
196 double m_tMc = 0.02;
197 /// Fixed distance step
198 double m_dMc = 0.001;
199 /// Sample step size according to collision time
200 int m_nMc = 100;
201 /// User function returning the step size
202 double (*m_fStep)(double x, double y, double z) = nullptr;
203
204 /// Flag whether a time window should be used.
205 bool m_hasTimeWindow = false;
206 /// Lower limit of the time window.
207 double m_tMin = 0.;
208 /// Upper limit of the time window.
209 double m_tMax = 0.;
210
211 /// Max. avalanche size.
212 unsigned int m_sizeCut = 0;
213
214 /// Number of electrons produced
215 unsigned int m_nElectrons = 0;
216 /// Number of holes produced
217 unsigned int m_nHoles = 0;
218 /// Number of ions produced
219 unsigned int m_nIons = 0;
220
221 struct EndPoint {
222 std::array<double, 3> x0; //< Starting point.
223 std::array<double, 3> x1; //< End point.
224 double t0, t1; //< Start and end time.
225 int status; //< Status flag at the end point.
226 };
227 /// Endpoints of all electrons in the avalanche (including captured ones)
228 std::vector<EndPoint> m_endpointsElectrons;
229 /// Endpoints of all holes in the avalanche (including captured ones)
230 std::vector<EndPoint> m_endpointsHoles;
231 /// Endpoints of all ions in the avalanche
232 std::vector<EndPoint> m_endpointsIons;
233
234 ViewDrift* m_viewer = nullptr;
235
236 bool m_doSignal = false;
237 unsigned int m_navg = 1;
238 bool m_useWeightingPotential = true;
239 bool m_doInducedCharge = false;
240 bool m_doEquilibration = true;
241 bool m_doRKF = false;
242 bool m_useDiffusion = true;
243 bool m_useAttachment = true;
244 bool m_useBfield = false;
245 /// Scaling factor for electron signals.
246 double m_scaleE = 1.;
247 /// Scaling factor for hole signals.
248 double m_scaleH = 1.;
249 /// Scaling factor for ion signals.
250 double m_scaleI = 1.;
251
252 /// Use traps from the field component (TCAD).
253 bool m_useTcadTrapping = false;
254 /// Take the velocity from the field component (TCAD).
255 bool m_useTcadVelocity = false;
256
257 bool m_debug = false;
258
259 /// Compute a drift line with starting point (x0, y0, z0).
260 bool DriftLine(const double x0, const double y0, const double z0,
261 const double t0, const Particle particle,
262 const bool aval = false);
263 /// Compute an avalanche with starting point (x0, y0, z0).
264 bool Avalanche(const double x0, const double y0, const double z0,
265 const double t0, const unsigned int ne, const unsigned int nh,
266 const unsigned int ni, const bool withElectrons,
267 const bool withHoles);
268
269 void AddPoint(const std::array<double, 3>& x, const double t,
270 const unsigned int ne, const unsigned int nh,
271 const unsigned int ni, std::vector<DriftPoint>& points) {
272 DriftPoint point;
273 point.x = x;
274 point.t = t;
275 point.ne = ne;
276 point.nh = nh;
277 point.ni = ni;
278 points.push_back(std::move(point));
279 }
280
281 /// Compute electric and magnetic field at a given position.
282 int GetField(const std::array<double, 3>& x,
283 std::array<double, 3>& e, std::array<double, 3>& b,
284 Medium*& medium) const;
285 /// Retrieve the low-field mobility.
286 double GetMobility(const Particle particle, Medium* medium) const;
287 /// Compute the drift velocity.
288 bool GetVelocity(const Particle particle, Medium* medium,
289 const std::array<double, 3>& x,
290 const std::array<double, 3>& e,
291 const std::array<double, 3>& b,
292 std::array<double, 3>& v) const;
293 /// Compute the diffusion coefficients.
294 bool GetDiffusion(const Particle particle, Medium* medium,
295 const std::array<double, 3>& e,
296 const std::array<double, 3>& b,
297 double& dl, double& dt) const;
298 /// Compute the attachment coefficient.
299 double GetAttachment(const Particle particle, Medium* medium,
300 const std::array<double, 3>& x,
301 const std::array<double, 3>& e,
302 const std::array<double, 3>& b) const;
303 /// Compute end point and effective velocity for a step.
304 void StepRKF(const Particle particle, const std::array<double, 3>& x0,
305 const std::array<double, 3>& v0, const double dt,
306 std::array<double, 3>& xf, std::array<double, 3>& vf,
307 int& status) const;
308 /// Add a diffusion step.
309 void AddDiffusion(const double step, const double dl, const double dt,
310 std::array<double, 3>& x,
311 const std::array<double, 3>& v) const;
312 /// Terminate a drift line close to the boundary.
313 void Terminate(const std::array<double, 3>& x0, const double t0,
314 std::array<double, 3>& x, double& t) const;
315 /// Compute multiplication and losses along the current drift line.
316 bool ComputeGainLoss(const Particle particle,
317 std::vector<DriftPoint>& driftLine, int& status,
318 const bool semiconductor = false);
319 /// Compute Townsend and attachment coefficients along the current drift line.
320 bool ComputeAlphaEta(const Particle particle,
321 const std::vector<DriftPoint>& driftLine,
322 std::vector<double>& alphas,
323 std::vector<double>& etas) const;
324 bool Equilibrate(std::vector<double>& alphas) const;
325 /// Compute the induced signal for the current drift line.
326 void ComputeSignal(const Particle particle, const double q,
327 const std::vector<DriftPoint>& driftLine) const;
328 /// Compute the induced charge for the current drift line.
329 void ComputeInducedCharge(const double q,
330 const std::vector<DriftPoint>& driftLine) const;
331 void PrintError(const std::string& fcn, const std::string& par,
332 const Particle particle,
333 const std::array<double, 3>& x) const;
334
335};
336}
337
338#endif
void GetDriftLinePoint(const unsigned int i, double &x, double &y, double &z, double &t) const
Return the coordinates and time of a point along the last drift line.
Definition: AvalancheMC.cc:117
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
Definition: AvalancheMC.cc:40
void DisableAvalancheSizeLimit()
Do not limit the maximum avalanche size.
Definition: AvalancheMC.hh:83
void EnableDebugging()
Switch on debugging messages (default: off).
Definition: AvalancheMC.hh:172
void SetTimeSteps(const double d=0.02)
Use fixed-time steps (default 20 ps).
Definition: AvalancheMC.cc:49
bool AvalancheElectronHole(const double x0, const double y0, const double z0, const double t0)
Definition: AvalancheMC.cc:535
void EnableSignalCalculation(const bool on=true)
Switch on calculation of induced currents (default: disabled).
Definition: AvalancheMC.hh:33
bool DriftIon(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of an ion from a given starting point.
Definition: AvalancheMC.cc:225
unsigned int GetNumberOfIonEndpoints() const
Return the number of ion trajectories.
Definition: AvalancheMC.hh:132
void DisablePlotting()
Switch off drift line plotting.
Definition: AvalancheMC.hh:30
void SetIonSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by ions.
Definition: AvalancheMC.hh:107
void EnableTcadVelocity(const bool on=true)
Switch on TCAD velocity maps.
Definition: AvalancheMC.hh:74
void SetTimeWindow(const double t0, const double t1)
Define a time interval (only carriers inside the interval are drifted).
Definition: AvalancheMC.cc:105
void GetIonEndpoint(const unsigned int i, double &x0, double &y0, double &z0, double &t0, double &x1, double &y1, double &z1, double &t1, int &status) const
Definition: AvalancheMC.cc:150
void UseWeightingPotential(const bool on=true)
Definition: AvalancheMC.hh:41
bool DriftElectron(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of an electron from a given starting point.
Definition: AvalancheMC.cc:189
void UnsetTimeWindow()
Do not limit the time interval within which carriers are drifted.
Definition: AvalancheMC.hh:100
void EnableTcadTraps(const bool on=true)
Switch on calculating trapping with TCAD traps.
Definition: AvalancheMC.hh:72
void GetElectronEndpoint(const unsigned int i, double &x0, double &y0, double &z0, double &t0, double &x1, double &y1, double &z1, double &t1, int &status) const
Definition: AvalancheMC.cc:169
void GetAvalancheSize(unsigned int &ne, unsigned int &ni) const
Return the number of electrons and ions/holes in the avalanche.
Definition: AvalancheMC.hh:110
void GetHoleEndpoint(const unsigned int i, double &x0, double &y0, double &z0, double &t0, double &x1, double &y1, double &z1, double &t1, int &status) const
Definition: AvalancheMC.cc:130
void EnableRKFSteps(const bool on=true)
Definition: AvalancheMC.hh:52
~AvalancheMC()
Destructor.
Definition: AvalancheMC.hh:22
AvalancheMC()
Constructor.
Definition: AvalancheMC.cc:29
void DisableDebugging()
Switch off debugging messages.
Definition: AvalancheMC.hh:174
void EnableMagneticField(const bool on=true)
Enable use of magnetic field in stepping algorithm.
Definition: AvalancheMC.hh:77
void SetSensor(Sensor *s)
Set the sensor.
Definition: AvalancheMC.cc:31
void DisableAttachment()
Switch off attachment and multiplication.
Definition: AvalancheMC.hh:69
void EnableDiffusion()
Switch on diffusion (default: enabled).
Definition: AvalancheMC.hh:61
unsigned int GetNumberOfHoleEndpoints() const
Definition: AvalancheMC.hh:128
void SetStepDistanceFunction(double(*f)(double x, double y, double z))
Retrieve the step distance from a user-supplied function.
Definition: AvalancheMC.cc:94
void SetElectronSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by electrons.
Definition: AvalancheMC.hh:103
void DisableDiffusion()
Switch off diffusion.
Definition: AvalancheMC.hh:63
void SetHoleSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by holes.
Definition: AvalancheMC.hh:105
int GetAvalancheSizeLimit() const
Return the currently set avalanche size limit.
Definition: AvalancheMC.hh:85
void EnableAvalancheSizeLimit(const unsigned int size)
Definition: AvalancheMC.hh:81
void SetCollisionSteps(const unsigned int n=100)
Definition: AvalancheMC.cc:79
unsigned int GetNumberOfDriftLinePoints() const
Return the number of points along the last simulated drift line.
Definition: AvalancheMC.hh:116
unsigned int GetNumberOfElectronEndpoints() const
Definition: AvalancheMC.hh:123
bool AvalancheElectron(const double x0, const double y0, const double z0, const double t0, const bool hole=false)
Simulate an avalanche initiated by an electron at a given starting point.
Definition: AvalancheMC.cc:523
void EnableInducedChargeCalculation(const bool on=true)
Switch on calculation of induced charge (default: disabled).
Definition: AvalancheMC.hh:46
void SetSignalAveragingOrder(const unsigned int navg)
Definition: AvalancheMC.hh:38
void SetDistanceSteps(const double d=0.001)
Use fixed distance steps (default 10 um).
Definition: AvalancheMC.cc:64
bool AvalancheHole(const double x0, const double y0, const double z0, const double t0, const bool electron=false)
Simulate an avalanche initiated by a hole at a given starting point.
Definition: AvalancheMC.cc:529
bool DriftHole(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of a hole from a given starting point.
Definition: AvalancheMC.cc:207
void EnableProjectedPathIntegration(const bool on=true)
Definition: AvalancheMC.hh:56
Visualize drift lines and tracks.
Definition: ViewDrift.hh:19