1#ifndef G_AVALANCHE_MC_H
2#define G_AVALANCHE_MC_H
31 bool DriftElectron(
const double x,
const double y,
const double z,
34 bool DriftHole(
const double x,
const double y,
const double z,
37 bool DriftIon(
const double x,
const double y,
const double z,
47 const double t,
const bool hole =
false);
49 bool AvalancheHole(
const double x,
const double y,
const double z,
50 const double t,
const bool electron =
false);
56 void AddElectron(
const double x,
const double y,
const double z,
59 void AddHole(
const double x,
const double y,
const double z,
const double t);
61 void AddIon(
const double x,
const double y,
const double z,
const double t);
63 bool ResumeAvalanche(
const bool electron =
true,
const bool hole =
true);
75 const std::vector<EndPoint>&
GetElectrons()
const {
return m_electrons; }
76 const std::vector<EndPoint>&
GetHoles()
const {
return m_holes; }
77 const std::vector<EndPoint>&
GetIons()
const {
return m_ions; }
79 return m_negativeIons;
99 double& z0,
double& t0,
double& x1,
double& y1,
100 double& z1,
double& t1,
int& status)
const;
101 void GetHoleEndpoint(
const size_t i,
double& x0,
double& y0,
double& z0,
102 double& t0,
double& x1,
double& y1,
double& z1,
103 double& t1,
int& status)
const;
104 void GetIonEndpoint(
const size_t i,
double& x0,
double& y0,
double& z0,
105 double& t0,
double& x1,
double& y1,
double& z1,
106 double& t1,
int& status)
const;
126 m_useWeightingPotential = on;
131 m_doInducedCharge = on;
141 m_doEquilibration = on;
195 ni = std::max(m_nIons, m_nHoles);
202 std::string m_className =
"AvalancheMC";
204 Sensor* m_sensor =
nullptr;
206 enum class StepModel {
213 StepModel m_stepModel = StepModel::CollisionTime;
218 double m_dMc = 0.001;
222 double (*m_fStep)(
double x,
double y,
double z) =
nullptr;
225 bool m_hasTimeWindow =
false;
232 unsigned int m_sizeCut = 0;
235 unsigned int m_nElectrons = 0;
237 unsigned int m_nHoles = 0;
239 unsigned int m_nIons = 0;
243 std::vector<EndPoint> m_electrons;
246 std::vector<EndPoint> m_holes;
248 std::vector<EndPoint> m_ions;
250 std::vector<EndPoint> m_negativeIons;
252 ViewDrift* m_viewer =
nullptr;
254 bool m_storeDriftLines =
false;
255 bool m_doSignal =
true;
256 unsigned int m_navg = 1;
257 bool m_useWeightingPotential =
true;
258 bool m_doInducedCharge =
false;
259 bool m_doEquilibration =
true;
260 bool m_doRKF =
false;
261 bool m_useDiffusion =
true;
262 bool m_useAttachment =
true;
264 double m_scaleE = 1.;
266 double m_scaleH = 1.;
268 double m_scaleI = 1.;
271 bool m_useTownsendMap =
false;
273 bool m_useAttachmentMap =
false;
275 bool m_useVelocityMap =
false;
277 bool m_debug =
false;
280 int DriftLine(
const Point& p0,
const Particle particle,
281 std::vector<Point>& path,
282 std::vector<std::pair<Point, Particle> >& secondaries,
283 const bool aval,
const bool signal);
285 bool TransportParticles(std::vector<std::pair<Point, Particle> >& particles,
286 const bool withElectrons,
const bool withHoles,
290 int GetField(
const std::array<double, 3>& x, std::array<double, 3>& e,
291 std::array<double, 3>& b, Medium*& medium)
const;
293 double GetMobility(
const Particle particle, Medium* medium)
const;
295 bool GetVelocity(
const Particle particle, Medium* medium,
296 const std::array<double, 3>& x,
297 const std::array<double, 3>& e,
298 const std::array<double, 3>& b,
299 std::array<double, 3>& v)
const;
301 bool GetDiffusion(
const Particle particle, Medium* medium,
302 const std::array<double, 3>& e,
303 const std::array<double, 3>& b,
double& dl,
306 double GetAttachment(
const Particle particle, Medium* medium,
307 const std::array<double, 3>& x,
308 const std::array<double, 3>& e,
309 const std::array<double, 3>& b)
const;
311 double GetTownsend(
const Particle particle, Medium* medium,
312 const std::array<double, 3>& x,
313 const std::array<double, 3>& e,
314 const std::array<double, 3>& b)
const;
316 void StepRKF(
const Particle particle,
const std::array<double, 3>& x0,
317 const std::array<double, 3>& v0,
const double dt,
318 std::array<double, 3>& xf, std::array<double, 3>& vf,
321 void AddDiffusion(
const double step,
const double dl,
const double dt,
322 std::array<double, 3>& x,
323 const std::array<double, 3>& v)
const;
325 void Terminate(
const std::array<double, 3>& x0,
const double t0,
326 std::array<double, 3>& x,
double& t)
const;
328 bool ComputeGainLoss(
const Particle particle,
329 std::vector<Point>& path,
int& status,
330 std::vector<std::pair<Point, Particle> > & secondaries,
331 const bool semiconductor =
false);
333 bool ComputeAlphaEta(
const Particle particle,
334 std::vector<Point>& path,
335 std::vector<double>& alphas,
336 std::vector<double>& etas)
const;
337 bool Equilibrate(std::vector<double>& alphas)
const;
339 void ComputeSignal(
const Particle particle,
const double q,
340 const std::vector<Point>& path)
const;
342 void ComputeInducedCharge(
const double q,
343 const std::vector<Point>& path)
const;
344 void PrintError(
const std::string& fcn,
const std::string& par,
346 const std::array<double, 3>& x)
const;
size_t GetNumberOfIonEndpoints() const
Return the number of ion trajectories.
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
void DisableAvalancheSizeLimit()
Do not limit the maximum avalanche size.
bool AvalancheHole(const double x, const double y, const double z, const double t, const bool electron=false)
Simulate an avalanche initiated by a hole at a given starting point.
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).
void EnableSignalCalculation(const bool on=true)
Switch calculation of induced currents on or off (default: enabled).
const std::vector< EndPoint > & GetHoles() const
void GetHoleEndpoint(const size_t i, double &x0, double &y0, double &z0, double &t0, double &x1, double &y1, double &z1, double &t1, int &status) const
size_t GetNumberOfHoleEndpoints() const
void DisablePlotting()
Switch off drift line plotting.
const std::vector< EndPoint > & GetElectrons() const
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 AddHole(const double x, const double y, const double z, const double t)
Add a hole to the list of particles to be transported.
bool DriftNegativeIon(const double x, const double y, const double z, const double t)
Simulate the drift line of a negative ion from a given starting point.
void UseWeightingPotential(const bool on=true)
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.
const std::vector< EndPoint > & GetNegativeIons() const
bool DriftIon(const double x, const double y, const double z, const double t)
Simulate the drift line of an ion from 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 AddElectron(const double x, const double y, const double z, const double t)
Add an electron to the list of particles to be transported.
void EnableRKFSteps(const bool on=true)
~AvalancheMC()
Destructor.
void EnableVelocityMap(const bool on=true)
Retrieve the drift velocity from the component.
AvalancheMC()
Default constructor.
bool AvalancheElectron(const double x, const double y, const double z, const double t, const bool hole=false)
void SetSensor(Sensor *s)
Set the sensor.
void DisableAttachment()
Switch off attachment and multiplication.
size_t GetNumberOfElectronEndpoints() const
bool DriftHole(const double x, const double y, const double z, const double t)
Simulate the drift line of a hole from a given starting point.
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
void DisableDiffusion()
Switch off diffusion.
void SetHoleSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by holes.
void EnableDriftLines(const bool on=true)
Switch on storage of drift lines (default: off).
int GetAvalancheSizeLimit() const
Return the currently set avalanche size limit.
void EnableAvalancheSizeLimit(const unsigned int size)
void SetCollisionSteps(const unsigned int n=100)
bool AvalancheElectronHole(const double x, const double y, const double z, const double t)
Simulate an avalanche initiated by an electron-hole pair.
bool DriftElectron(const double x, const double y, const double z, const double t)
Simulate the drift line of an electron from a given starting point.
void EnableTownsendMap(const bool on=true)
Retrieve the Townsend coefficient from the component.
void EnableInducedChargeCalculation(const bool on=true)
Switch on calculation of induced charge (default: disabled).
void SetSignalAveragingOrder(const unsigned int navg)
void AddIon(const double x, const double y, const double z, const double t)
Add an ion to the list of particles to be transported.
void SetDistanceSteps(const double d=0.001)
Use fixed distance steps (default 10 um).
void EnableProjectedPathIntegration(const bool on=true)
Visualize drift lines and tracks.
std::vector< Point > path
Drift line.