1#ifndef G_AVALANCHE_MC_H
2#define G_AVALANCHE_MC_H
42 m_useWeightingPotential = on;
47 m_doInducedCharge = on;
57 m_doEquilibration = on;
124 return m_endpointsElectrons.size();
129 return m_endpointsHoles.size();
133 return m_endpointsIons.size();
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;
154 bool DriftElectron(
const double x0,
const double y0,
const double z0,
157 bool DriftHole(
const double x0,
const double y0,
const double z0,
160 bool DriftIon(
const double x0,
const double y0,
const double z0,
164 const double t0,
const bool hole =
false);
166 bool AvalancheHole(
const double x0,
const double y0,
const double z0,
167 const double t0,
const bool electron =
false);
177 std::string m_className =
"AvalancheMC";
179 Sensor* m_sensor =
nullptr;
181 enum class Particle { Electron = 0, Ion, Hole };
184 std::array<double, 3> x;
186 unsigned int ne, nh, ni;
189 std::vector<DriftPoint> m_drift;
191 enum class StepModel { FixedTime, FixedDistance, CollisionTime, UserDistance};
193 StepModel m_stepModel = StepModel::CollisionTime;
198 double m_dMc = 0.001;
202 double (*m_fStep)(
double x,
double y,
double z) =
nullptr;
205 bool m_hasTimeWindow =
false;
212 unsigned int m_sizeCut = 0;
215 unsigned int m_nElectrons = 0;
217 unsigned int m_nHoles = 0;
219 unsigned int m_nIons = 0;
222 std::array<double, 3> x0;
223 std::array<double, 3> x1;
228 std::vector<EndPoint> m_endpointsElectrons;
230 std::vector<EndPoint> m_endpointsHoles;
232 std::vector<EndPoint> m_endpointsIons;
234 ViewDrift* m_viewer =
nullptr;
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;
246 double m_scaleE = 1.;
248 double m_scaleH = 1.;
250 double m_scaleI = 1.;
253 bool m_useTcadTrapping =
false;
255 bool m_useTcadVelocity =
false;
257 bool m_debug =
false;
260 bool DriftLine(
const double x0,
const double y0,
const double z0,
261 const double t0,
const Particle particle,
262 const bool aval =
false);
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);
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) {
278 points.push_back(std::move(point));
282 int GetField(
const std::array<double, 3>& x,
283 std::array<double, 3>& e, std::array<double, 3>& b,
284 Medium*& medium)
const;
286 double GetMobility(
const Particle particle, Medium* medium)
const;
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;
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;
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;
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,
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;
313 void Terminate(
const std::array<double, 3>& x0,
const double t0,
314 std::array<double, 3>& x,
double& t)
const;
316 bool ComputeGainLoss(
const Particle particle,
317 std::vector<DriftPoint>& driftLine,
int& status,
318 const bool semiconductor =
false);
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;
326 void ComputeSignal(
const Particle particle,
const double q,
327 const std::vector<DriftPoint>& driftLine)
const;
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;
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 EnableDebugging()
Switch on debugging messages (default: off).
void SetTimeSteps(const double d=0.02)
Use fixed-time steps (default 20 ps).
bool AvalancheElectronHole(const double x0, const double y0, const double z0, const double t0)
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 EnableTcadVelocity(const bool on=true)
Switch on TCAD velocity maps.
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.
void UnsetTimeWindow()
Do not limit the time interval within which carriers are drifted.
void EnableTcadTraps(const bool on=true)
Switch on calculating trapping with TCAD traps.
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.
AvalancheMC()
Constructor.
void DisableDebugging()
Switch off debugging messages.
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 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)
Simulate an avalanche initiated by an electron at a given starting point.
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.