Garfield 0.3
Toolkit for the detailed simulation of particle detectors based on ionization 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 <array>
5#include <string>
6#include <utility>
7#include <vector>
8
10
11namespace Garfield {
12
13class Sensor;
14class ViewDrift;
15class Medium;
19 public:
21 AvalancheMC() : AvalancheMC(nullptr) {}
23 AvalancheMC(Sensor* sensor);
26
28 void SetSensor(Sensor* s);
29
31 bool DriftElectron(const double x, const double y, const double z,
32 const double t, const size_t w = 1);
34 bool DriftHole(const double x, const double y, const double z,
35 const double t, const size_t w = 1);
37 bool DriftIon(const double x, const double y, const double z,
38 const double t, const size_t w = 1);
40 bool DriftNegativeIon(const double x, const double y, const double z,
41 const double t, const size_t w = 1);
47 bool AvalancheElectron(const double x, const double y, const double z,
48 const double t, const bool hole = false,
49 const size_t w = 1);
51 bool AvalancheHole(const double x, const double y, const double z,
52 const double t, const bool electron = false,
53 const size_t w = 1);
55 bool AvalancheElectronHole(const double x, const double y, const double z,
56 const double t, const size_t w = 1);
57
59 void AddElectron(const double x, const double y, const double z,
60 const double t, const size_t w = 1);
62 void AddHole(const double x, const double y, const double z,
63 const double t, const size_t w = 1);
65 void AddIon(const double x, const double y, const double z,
66 const double t, const size_t w = 1);
68 void AddNegativeIon(const double x, const double y, const double z,
69 const double t, const size_t w = 1);
71 bool ResumeAvalanche(const bool electron = true, const bool hole = true);
72
73 struct Point {
74 double x, y, z;
75 double t;
76 };
77
78 struct EndPoint {
79 int status;
80 std::vector<Point> path;
81 size_t weight;
82 };
83
84 struct Seed {
87 size_t w = 1;
88 };
89
90 const std::vector<EndPoint>& GetElectrons() const { return m_electrons; }
91 const std::vector<EndPoint>& GetHoles() const { return m_holes; }
92 const std::vector<EndPoint>& GetIons() const { return m_ions; }
93 const std::vector<EndPoint>& GetNegativeIons() const {
94 return m_negativeIons;
95 }
96
99 size_t GetNumberOfElectronEndpoints() const { return m_electrons.size(); }
101 size_t GetNumberOfIonEndpoints() const { return m_ions.size(); }
102
110 void GetElectronEndpoint(const size_t i, double& x0, double& y0, double& z0,
111 double& t0, double& x1, double& y1, double& z1,
112 double& t1, int& status) const;
113 void GetIonEndpoint(const size_t i, double& x0, double& y0, double& z0,
114 double& t0, double& x1, double& y1, double& z1,
115 double& t1, int& status) const;
116 void GetNegativeIonEndpoint(const size_t i, double& x0, double& y0,
117 double& z0, double& t0, double& x1, double& y1,
118 double& z1, double& t1, int& status) const;
119
123 void DisablePlotting() { m_viewer = nullptr; }
124
126 void EnableDriftLines(const bool on = true) { m_storeDriftLines = on; }
127
129 void EnableSignalCalculation(const bool on = true) { m_doSignal = on; }
134 void SetSignalAveragingOrder(const unsigned int navg) { m_navg = navg; }
137 void UseWeightingPotential(const bool on = true) {
139 }
140
142 void EnableInducedChargeCalculation(const bool on = true) {
144 }
145
148 void EnableRKFSteps(const bool on = true) { m_doRKF = on; }
149
152 void EnableProjectedPathIntegration(const bool on = true) {
154 }
155
160
166 void EnableMultiplication(const bool on) { m_useMultiplication = on; }
167
169 void EnableTownsendMap(const bool on = true) { m_useTownsendMap = on; }
171 void EnableAttachmentMap(const bool on = true) { m_useAttachmentMap = on; }
173 void EnableMobilityMap(const bool on = true) { m_useMobilityMap = on; }
175 void EnableVelocityMap(const bool on = true) { m_useVelocityMap = on; }
176
179 void EnableAvalancheSizeLimit(const unsigned int size) { m_sizeCut = size; }
183 int GetAvalancheSizeLimit() const { return m_sizeCut; }
184
186 void SetTimeSteps(const double d = 0.02);
188 void SetDistanceSteps(const double d = 0.001);
191 void SetCollisionSteps(const unsigned int n = 100);
193 void SetStepDistanceFunction(double (*f)(double x, double y, double z));
194
196 void SetTimeWindow(const double t0, const double t1);
199
201 void SetElectronSignalScalingFactor(const double scale) { m_scaleE = scale; }
203 void SetHoleSignalScalingFactor(const double scale) { m_scaleH = scale; }
205 void SetIonSignalScalingFactor(const double scale) { m_scaleI = scale; }
206
208 void GetAvalancheSize(unsigned int& ne, unsigned int& ni) const {
209 ne = m_nElectrons;
210 ni = std::max(m_nIons, m_nHoles);
211 }
212
213 std::pair<unsigned int, unsigned int> GetAvalancheSize() const {
214 return std::make_pair(m_nElectrons, std::max(m_nIons, m_nHoles));
215 }
216
217 void EnableDebugging(const bool on = true) { m_debug = on; }
218
219 private:
220 std::string m_className = "AvalancheMC";
221
222 Sensor* m_sensor = nullptr;
223
230
232
234 double m_tMc = 0.02;
236 double m_dMc = 0.001;
238 int m_nMc = 100;
240 double (*m_fStep)(double x, double y, double z) = nullptr;
241
243 bool m_hasTimeWindow = false;
245 double m_tMin = 0.;
247 double m_tMax = 0.;
248
250 unsigned int m_sizeCut = 0;
251
253 unsigned int m_nElectrons = 0;
255 unsigned int m_nHoles = 0;
257 unsigned int m_nIons = 0;
259 unsigned int m_nNegativeIons = 0;
260
263 std::vector<EndPoint> m_electrons;
266 std::vector<EndPoint> m_holes;
268 std::vector<EndPoint> m_ions;
270 std::vector<EndPoint> m_negativeIons;
271
272 ViewDrift* m_viewer = nullptr;
273
274 bool m_storeDriftLines = false;
275 bool m_doSignal = true;
276 unsigned int m_navg = 1;
278 bool m_doInducedCharge = false;
279 bool m_doEquilibration = true;
280 bool m_doRKF = false;
281 bool m_useDiffusion = true;
282 bool m_useAttachment = true;
285 double m_scaleE = 1.;
287 double m_scaleH = 1.;
289 double m_scaleI = 1.;
290
292 bool m_useTownsendMap = false;
294 bool m_useAttachmentMap = false;
296 bool m_useMobilityMap = false;
298 bool m_useVelocityMap = false;
299
300 bool m_debug = false;
301
303 int DriftLine(const Seed& seed, std::vector<Point>& path,
304 std::vector<Seed>& secondaries,
305 const bool aval, const bool signal) const;
307 bool TransportParticles(std::vector<Seed>& stack,
308 const bool withElectrons, const bool withHoles,
309 const bool aval);
310
312 int GetField(const std::array<double, 3>& x, std::array<double, 3>& e,
313 std::array<double, 3>& b, Medium*& medium) const;
315 double GetMobility(const Particle particle, Medium* medium,
316 const std::array<double, 3>& x) const;
318 bool GetVelocity(const Particle particle, Medium* medium,
319 const std::array<double, 3>& x,
320 const std::array<double, 3>& e,
321 const std::array<double, 3>& b,
322 std::array<double, 3>& v) const;
324 bool GetDiffusion(const Particle particle, Medium* medium,
325 const std::array<double, 3>& e,
326 const std::array<double, 3>& b, double& dl,
327 double& dt) const;
329 double GetAttachment(const Particle particle, Medium* medium,
330 const std::array<double, 3>& x,
331 const std::array<double, 3>& e,
332 const std::array<double, 3>& b) const;
334 double GetTownsend(const Particle particle, Medium* medium,
335 const std::array<double, 3>& x,
336 const std::array<double, 3>& e,
337 const std::array<double, 3>& b) const;
339 void StepRKF(const Particle particle, const std::array<double, 3>& x0,
340 const std::array<double, 3>& v0, const double dt,
341 std::array<double, 3>& xf, std::array<double, 3>& vf,
342 int& status) const;
344 void AddDiffusion(const double step, const double dl, const double dt,
345 std::array<double, 3>& x,
346 const std::array<double, 3>& v) const;
348 void Terminate(const std::array<double, 3>& x0, const double t0,
349 std::array<double, 3>& x, double& t) const;
351 bool ComputeGainLoss(const Particle ptype, const size_t w,
352 std::vector<Point>& path, int& status,
353 std::vector<Seed>& secondaries,
354 const bool semiconductor = false) const;
356 bool ComputeAlphaEta(const Particle ptype, std::vector<Point>& path,
357 std::vector<double>& alphas,
358 std::vector<double>& etas) const;
359 bool Equilibrate(std::vector<double>& alphas) const;
361 void ComputeSignal(const double q, const std::vector<Point>& path) const;
363 void ComputeInducedCharge(const double q,
364 const std::vector<Point>& path) const;
365 void PrintError(const std::string& fcn, const std::string& par,
366 const Particle particle,
367 const std::array<double, 3>& x) const;
368};
369} // namespace Garfield
370
371#endif
void AddIon(const double x, const double y, const double z, const double t, const size_t w=1)
Add an ion to the list of particles to be transported.
std::vector< EndPoint > m_holes
Start/end points of all holes in the avalanche (including captured ones).
bool m_hasTimeWindow
Flag whether a time window should be used.
size_t GetNumberOfIonEndpoints() const
Return the number of ion trajectories.
double m_tMax
Upper limit of the time window.
int DriftLine(const Seed &seed, std::vector< Point > &path, std::vector< Seed > &secondaries, const bool aval, const bool signal) const
Compute a single drift line.
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
bool TransportParticles(std::vector< Seed > &stack, const bool withElectrons, const bool withHoles, const bool aval)
Compute an avalanche.
void DisableAvalancheSizeLimit()
Do not limit the maximum avalanche size.
double GetMobility(const Particle particle, Medium *medium, const std::array< double, 3 > &x) const
Retrieve the low-field mobility.
unsigned int m_sizeCut
Max. avalanche size.
void PrintError(const std::string &fcn, const std::string &par, const Particle particle, const std::array< double, 3 > &x) const
void SetTimeSteps(const double d=0.02)
Use fixed-time steps (default 20 ps).
void EnableDebugging(const bool on=true)
Switch debugging messages on/off (default: off).
bool ComputeGainLoss(const Particle ptype, const size_t w, std::vector< Point > &path, int &status, std::vector< Seed > &secondaries, const bool semiconductor=false) const
Compute multiplication and losses along the current drift line.
void EnableSignalCalculation(const bool on=true)
Switch calculation of induced currents on or off (default: enabled).
void EnableMobilityMap(const bool on=true)
Retrieve the (low-field) mobility from the component.
const std::vector< EndPoint > & GetHoles() const
void AddHole(const double x, const double y, const double z, const double t, const size_t w=1)
Add a hole to the list of particles to be transported.
void DisablePlotting()
Switch off drift line plotting.
std::pair< unsigned int, unsigned int > GetAvalancheSize() const
Return the number of electrons and ions/holes in the avalanche.
const std::vector< EndPoint > & GetElectrons() const
void SetIonSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by ions.
bool DriftIon(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of an ion from a given starting point.
bool m_useMobilityMap
Take mobility coefficients from the component.
void SetTimeWindow(const double t0, const double t1)
Define a time interval (only carriers inside the interval are drifted).
int m_nMc
Sample step size according to collision time.
void UseWeightingPotential(const bool on=true)
Use the weighting potential (as opposed to the weighting field) for calculating the induced signal.
bool GetDiffusion(const Particle particle, Medium *medium, const std::array< double, 3 > &e, const std::array< double, 3 > &b, double &dl, double &dt) const
Compute the diffusion coefficients.
bool m_useAttachmentMap
Take attachment coefficients from the component.
void EnableMultiplication(const bool on)
Switch multiplication on/off.
bool ResumeAvalanche(const bool electron=true, const bool hole=true)
Resume the simulation from the current set of charge carriers.
void GetIonEndpoint(const size_t i, double &x0, double &y0, double &z0, double &t0, double &x1, double &y1, double &z1, double &t1, int &status) const
void UnsetTimeWindow()
Do not limit the time interval within which carriers are drifted.
AvalancheMC(Sensor *sensor)
Constructor.
const std::vector< EndPoint > & GetNegativeIons() const
bool AvalancheElectron(const double x, const double y, const double z, const double t, const bool hole=false, const size_t w=1)
Simulate an avalanche initiated by an electron at a given starting point.
std::vector< EndPoint > m_ions
Start/end points of all positive ions in the avalanche.
unsigned int m_nElectrons
Number of electrons produced.
bool AvalancheHole(const double x, const double y, const double z, const double t, const bool electron=false, const size_t w=1)
Simulate an avalanche initiated by a hole at a given starting point.
void GetAvalancheSize(unsigned int &ne, unsigned int &ni) const
Return the number of electrons and ions/holes in the avalanche.
void AddNegativeIon(const double x, const double y, const double z, const double t, const size_t w=1)
Add an negative ion to the list of particles to be transported.
bool m_useTownsendMap
Take Townsend coefficients from the component.
void AddDiffusion(const double step, const double dl, const double dt, std::array< double, 3 > &x, const std::array< double, 3 > &v) const
Add a diffusion step.
void EnableRKFSteps(const bool on=true)
Switch on Runge-Kutta-Fehlberg stepping (as opposed to simple straight-line steps.
void Terminate(const std::array< double, 3 > &x0, const double t0, std::array< double, 3 > &x, double &t) const
Terminate a drift line close to the boundary.
~AvalancheMC()
Destructor.
int GetField(const std::array< double, 3 > &x, std::array< double, 3 > &e, std::array< double, 3 > &b, Medium *&medium) const
Compute electric and magnetic field at a given position.
void EnableVelocityMap(const bool on=true)
Retrieve the drift velocity from the component.
AvalancheMC()
Default constructor.
void GetNegativeIonEndpoint(const size_t i, double &x0, double &y0, double &z0, double &t0, double &x1, double &y1, double &z1, double &t1, int &status) const
unsigned int m_nNegativeIons
Number of negative ions produced.
void SetSensor(Sensor *s)
Set the sensor.
void AddElectron(const double x, const double y, const double z, const double t, const size_t w=1)
Add an electron to the list of particles to be transported.
void ComputeSignal(const double q, const std::vector< Point > &path) const
Compute the induced signal for the current drift line.
StepModel m_stepModel
Step size model.
void StepRKF(const Particle particle, const std::array< double, 3 > &x0, const std::array< double, 3 > &v0, const double dt, std::array< double, 3 > &xf, std::array< double, 3 > &vf, int &status) const
Compute end point and effective velocity for a step.
bool m_useVelocityMap
Take the drift velocities from the component.
void DisableAttachment()
Switch off attachment and multiplication.
unsigned int m_nIons
Number of ions produced.
double m_scaleE
Scaling factor for electron signals.
double GetTownsend(const Particle particle, Medium *medium, const std::array< double, 3 > &x, const std::array< double, 3 > &e, const std::array< double, 3 > &b) const
Compute the Townsend coefficient.
size_t GetNumberOfElectronEndpoints() const
Return the number of electron trajectories in the last simulated avalanche (including captured electr...
const std::vector< EndPoint > & GetIons() const
void EnableDiffusion()
Switch on diffusion (default: enabled).
void EnableAttachmentMap(const bool on=true)
Retrieve the attachment coefficient from the component.
void SetStepDistanceFunction(double(*f)(double x, double y, double z))
Retrieve the step distance from a user-supplied function.
void SetElectronSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by electrons.
void GetElectronEndpoint(const size_t i, double &x0, double &y0, double &z0, double &t0, double &x1, double &y1, double &z1, double &t1, int &status) const
Return the coordinates and time of start and end point of a given electron drift line.
void DisableDiffusion()
Switch off diffusion.
void SetHoleSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by holes.
double m_tMc
Fixed time step.
void EnableDriftLines(const bool on=true)
Switch on storage of drift lines (default: off).
bool DriftNegativeIon(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of a negative ion from a given starting point.
bool Equilibrate(std::vector< double > &alphas) const
int GetAvalancheSizeLimit() const
Return the currently set avalanche size limit.
double m_dMc
Fixed distance step.
unsigned int m_nHoles
Number of holes produced.
std::vector< EndPoint > m_electrons
Start/end points of all electrons in the avalanche (including captured ones).
void EnableAvalancheSizeLimit(const unsigned int size)
Set a maximum avalanche size (ignore further multiplication once this size has been reached).
double GetAttachment(const Particle particle, Medium *medium, const std::array< double, 3 > &x, const std::array< double, 3 > &e, const std::array< double, 3 > &b) const
Compute the attachment coefficient.
void SetCollisionSteps(const unsigned int n=100)
Use exponentially distributed time steps with mean equal to the specified multiple of the collision t...
void EnableAttachment()
Switch on attachment (default: enabled).
bool GetVelocity(const Particle particle, Medium *medium, const std::array< double, 3 > &x, const std::array< double, 3 > &e, const std::array< double, 3 > &b, std::array< double, 3 > &v) const
Compute the drift velocity.
bool DriftElectron(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of an electron from a given starting point.
double m_scaleI
Scaling factor for ion signals.
void EnableTownsendMap(const bool on=true)
Retrieve the Townsend coefficient from the component.
bool ComputeAlphaEta(const Particle ptype, std::vector< Point > &path, std::vector< double > &alphas, std::vector< double > &etas) const
Compute Townsend and attachment coefficients along the current drift line.
void ComputeInducedCharge(const double q, const std::vector< Point > &path) const
Compute the induced charge for the current drift line.
void EnableInducedChargeCalculation(const bool on=true)
Switch on calculation of induced charge (default: disabled).
void SetSignalAveragingOrder(const unsigned int navg)
Set the number of points to be used when averaging the signal vector over a time bin in the Sensor cl...
std::vector< EndPoint > m_negativeIons
Start/end points of all negative ions in the avalanche.
double m_tMin
Lower limit of the time window.
void SetDistanceSteps(const double d=0.001)
Use fixed distance steps (default 10 um).
double(* m_fStep)(double x, double y, double z)
User function returning the step size.
double m_scaleH
Scaling factor for hole signals.
void EnableProjectedPathIntegration(const bool on=true)
Switch on equilibration of multiplication and attachment over the drift line (default: enabled).
bool DriftHole(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of a hole from a given starting point.
bool AvalancheElectronHole(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate an avalanche initiated by an electron-hole pair.
Visualize drift lines and tracks.
Definition ViewDrift.hh:18
std::vector< Point > path
Drift line.
Particle type
Particle type.
Point pt
Starting point.
size_t w
Multiplicity.