1#ifndef G_AVALANCHE_MC_H
2#define G_AVALANCHE_MC_H
42 m_useWeightingPotential = on;
47 m_doInducedCharge = on;
57 m_doEquilibration = on;
113 ni = std::max(m_nIons, m_nHoles);
125 return m_endpointsElectrons.size();
130 return m_endpointsHoles.size();
134 return m_endpointsIons.size();
145 double& z0,
double& t0,
double& x1,
double& y1,
146 double& z1,
double& t1,
int& status)
const;
147 void GetHoleEndpoint(
const unsigned int i,
double& x0,
double& y0,
double& z0,
148 double& t0,
double& x1,
double& y1,
double& z1,
149 double& t1,
int& status)
const;
150 void GetIonEndpoint(
const unsigned int i,
double& x0,
double& y0,
double& z0,
151 double& t0,
double& x1,
double& y1,
double& z1,
152 double& t1,
int& status)
const;
155 bool DriftElectron(
const double x0,
const double y0,
const double z0,
158 bool DriftHole(
const double x0,
const double y0,
const double z0,
161 bool DriftIon(
const double x0,
const double y0,
const double z0,
168 const double t0,
const bool hole =
false);
170 bool AvalancheHole(
const double x0,
const double y0,
const double z0,
171 const double t0,
const bool electron =
false);
175 bool ResumeAvalanche(
const bool electron =
true,
const bool hole =
true);
181 std::string m_className =
"AvalancheMC";
183 Sensor* m_sensor =
nullptr;
185 enum class Particle { Electron = 0, Ion, Hole };
188 std::array<double, 3> x;
194 std::vector<DriftPoint> m_drift;
196 enum class StepModel {
203 StepModel m_stepModel = StepModel::CollisionTime;
208 double m_dMc = 0.001;
212 double (*m_fStep)(
double x,
double y,
double z) =
nullptr;
215 bool m_hasTimeWindow =
false;
222 unsigned int m_sizeCut = 0;
225 unsigned int m_nElectrons = 0;
227 unsigned int m_nHoles = 0;
229 unsigned int m_nIons = 0;
232 std::array<double, 3> x0;
233 std::array<double, 3> x1;
238 std::vector<EndPoint> m_endpointsElectrons;
240 std::vector<EndPoint> m_endpointsHoles;
242 std::vector<EndPoint> m_endpointsIons;
244 ViewDrift* m_viewer =
nullptr;
246 bool m_doSignal =
false;
247 unsigned int m_navg = 1;
248 bool m_useWeightingPotential =
true;
249 bool m_doInducedCharge =
false;
250 bool m_doEquilibration =
true;
251 bool m_doRKF =
false;
252 bool m_useDiffusion =
true;
253 bool m_useAttachment =
true;
254 bool m_useBfield =
false;
256 double m_scaleE = 1.;
258 double m_scaleH = 1.;
260 double m_scaleI = 1.;
263 bool m_useAttachmentMap =
false;
265 bool m_useVelocityMap =
false;
267 bool m_debug =
false;
270 bool DriftLine(
const std::array<double, 3>& x0,
const double t0,
271 const Particle particle,
272 std::vector<DriftPoint>& secondaries,
273 const bool aval =
false);
275 bool Avalanche(std::vector<DriftPoint>& aval,
276 const bool withElectrons,
const bool withHoles);
278 void AddPoint(
const std::array<double, 3>& x,
const double t,
279 const Particle particle,
const unsigned int n,
280 std::vector<DriftPoint>& points) {
284 point.particle = particle;
286 points.push_back(std::move(point));
288 void AddEndPoint(
const std::array<double, 3>& x0,
const double t0,
289 const std::array<double, 3>& x1,
const double t1,
290 const int status,
const Particle particle) {
296 endPoint.status = status;
297 if (particle == Particle::Electron) {
298 m_endpointsElectrons.push_back(std::move(endPoint));
299 }
else if (particle == Particle::Hole) {
300 m_endpointsHoles.push_back(std::move(endPoint));
301 }
else if (particle == Particle::Ion) {
302 m_endpointsIons.push_back(std::move(endPoint));
307 int GetField(
const std::array<double, 3>& x, std::array<double, 3>& e,
308 std::array<double, 3>& b, Medium*& medium)
const;
310 double GetMobility(
const Particle particle, Medium* medium)
const;
312 bool GetVelocity(
const Particle particle, Medium* medium,
313 const std::array<double, 3>& x,
314 const std::array<double, 3>& e,
315 const std::array<double, 3>& b,
316 std::array<double, 3>& v)
const;
318 bool GetDiffusion(
const Particle particle, Medium* medium,
319 const std::array<double, 3>& e,
320 const std::array<double, 3>& b,
double& dl,
323 double GetAttachment(
const Particle particle, Medium* medium,
324 const std::array<double, 3>& x,
325 const std::array<double, 3>& e,
326 const std::array<double, 3>& b)
const;
328 void StepRKF(
const Particle particle,
const std::array<double, 3>& x0,
329 const std::array<double, 3>& v0,
const double dt,
330 std::array<double, 3>& xf, std::array<double, 3>& vf,
333 void AddDiffusion(
const double step,
const double dl,
const double dt,
334 std::array<double, 3>& x,
335 const std::array<double, 3>& v)
const;
337 void Terminate(
const std::array<double, 3>& x0,
const double t0,
338 std::array<double, 3>& x,
double& t)
const;
340 bool ComputeGainLoss(
const Particle particle,
341 std::vector<DriftPoint>& driftLine,
int& status,
342 std::vector<DriftPoint>& secondaries,
343 const bool semiconductor =
false);
345 bool ComputeAlphaEta(
const Particle particle,
346 const std::vector<DriftPoint>& driftLine,
347 std::vector<double>& alphas,
348 std::vector<double>& etas)
const;
349 bool Equilibrate(std::vector<double>& alphas)
const;
351 void ComputeSignal(
const Particle particle,
const double q,
352 const std::vector<DriftPoint>& driftLine)
const;
354 void ComputeInducedCharge(
const double q,
355 const std::vector<DriftPoint>& driftLine)
const;
356 void PrintError(
const std::string& fcn,
const std::string& par,
357 const Particle particle,
358 const std::array<double, 3>& x)
const;
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.
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
void DisableAvalancheSizeLimit()
Do not limit the maximum avalanche size.
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 AvalancheElectronHole(const double x0, const double y0, const double z0, const double t0)
Simulate an avalanche initiated by an electron-hole pair.
void EnableSignalCalculation(const bool on=true)
Switch on calculation of induced currents (default: disabled).
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.
unsigned int GetNumberOfIonEndpoints() const
Return the number of ion trajectories.
void DisablePlotting()
Switch off drift line plotting.
void SetIonSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by ions.
void SetTimeWindow(const double t0, const double t1)
Define a time interval (only carriers inside the interval are drifted).
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
void UseWeightingPotential(const bool on=true)
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.
bool ResumeAvalanche(const bool electron=true, const bool hole=true)
void UnsetTimeWindow()
Do not limit the time interval within which carriers are drifted.
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
void GetAvalancheSize(unsigned int &ne, unsigned int &ni) const
Return the number of electrons and ions/holes in the avalanche.
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
void EnableRKFSteps(const bool on=true)
~AvalancheMC()
Destructor.
void EnableVelocityMap(const bool on=true)
Retrieve the drift velocity from the component.
AvalancheMC()
Constructor.
void EnableMagneticField(const bool on=true)
Enable use of magnetic field in stepping algorithm.
void SetSensor(Sensor *s)
Set the sensor.
void DisableAttachment()
Switch off attachment and multiplication.
void EnableDiffusion()
Switch on diffusion (default: enabled).
unsigned int GetNumberOfHoleEndpoints() const
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 DisableDiffusion()
Switch off diffusion.
void SetHoleSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by holes.
int GetAvalancheSizeLimit() const
Return the currently set avalanche size limit.
void EnableAvalancheSizeLimit(const unsigned int size)
void SetCollisionSteps(const unsigned int n=100)
unsigned int GetNumberOfDriftLinePoints() const
Return the number of points along the last simulated drift line.
unsigned int GetNumberOfElectronEndpoints() const
bool AvalancheElectron(const double x0, const double y0, const double z0, const double t0, const bool hole=false)
void EnableInducedChargeCalculation(const bool on=true)
Switch on calculation of induced charge (default: disabled).
void SetSignalAveragingOrder(const unsigned int navg)
void SetDistanceSteps(const double d=0.001)
Use fixed distance steps (default 10 um).
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.
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.
void EnableProjectedPathIntegration(const bool on=true)
Visualize drift lines and tracks.