Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
AvalancheGrid.hh
Go to the documentation of this file.
1#ifndef G_AVALANCHE_GRID_H
2#define G_AVALANCHE_GRID_H
3
4#include <iostream>
5#include <string>
6#include <vector>
7
10#include "Sensor.hh"
11
12namespace Garfield {
13
14/// Calculate avalanches in a uniform electric field using avalanche
15/// statistics.
16
18 public:
19 /// Constructor
21 /// Destructor
23 /// Set the sensor.
24 void SetSensor(Sensor* sensor) { m_sensor = sensor; }
25 /// Set the AvalancheMicroscopic.
26 void SetAvalancheMicroscopic(AvalancheMicroscopic* avmc) { m_avmc = avmc; }
27
28 /** Start grid based avalanche simulation.
29 *
30 * \param zmin,zmax z-coordinate range of grid [cm].
31 * \param zsteps amount of z-coordinate points in grid.
32 * \param xmin,xmax x-coordinate range of grid [cm].
33 * \param xsteps amount of x-coordinate points in grid.
34 */
35 void StartGridAvalanche();
36 /// Set the electron drift velocity (in cm / ns).
37 void SetElectronVelocity(const double vx, const double vy, const double vz) {
38 double vel = sqrt(vx * vx + vy * vy + vz * vz);
39 if (vel != std::abs(vx) && vel != std::abs(vy) && vel != std::abs(vz)) return;
40 int nx = (int)vx / vel;
41 int ny = (int)vy / vel;
42 int nz = (int)vz / vel;
43 m_velNormal = {nx, ny, nz};
44 m_Velocity = -std::abs(vel);
45 }
46 /// Set the electron Townsend coefficient (in 1 / cm).
47 void SetElectronTownsend(const double town) { m_Townsend = town; }
48 /// Set the electron attachment coefficient (in 1 / cm).
49 void SetElectronAttachment(const double att) { m_Attachment = att; }
50 /// Set the maximum avalanche size (1e7 by default).
51 void SetMaxAvalancheSize(const double size) { m_MaxSize = size; }
52 /// Enable transverse diffusion of electrons with transverse diffusion
53 /// coefficients (in √cm).
54 void EnableDiffusion(const double diffSigma) {
55 m_diffusion = true;
56 m_DiffSigma = diffSigma;
57 }
58 /** Setting the starting point of an electron that .
59 *
60 * \param z z-coordinate of initial electron.
61 * \param x x-coordinate of initial electron.
62 * \param v speed of initial electron.
63 * \param t starting time of avalanche.
64 */
65 void CreateAvalanche(const double x, const double y, const double z,
66 const double t = 0, const int n = 1);
67 /// Import electron data from AvalancheMicroscopic class
69
70 /// Import electron data from AvalancheMicroscopic class
71 void SetGrid(const double xmin, const double xmax, const int xsteps,
72 const double ymin, const double ymax, const int ysteps,
73 const double zmin, const double zmax, const int zsteps);
74 int GetAmountOfStartingElectrons() { return m_nestart; }
75
76 void EnableDebugging() { m_debug = true; }
77
78 void Reset();
79
80 private:
81 bool m_debug = false;
82
83 double m_Townsend = -1; // [1/cm]
84
85 double m_Attachment = -1; // [1/cm]
86
87 double m_Velocity = 0.; // [cm/ns]
88
89 std::vector<int> m_velNormal = {0, 0, -1};
90
91 double m_MaxSize = 1.6e7; // Saturations size
92
93 bool m_Saturated = false; // Check if avalanche has reached maximum size
94
95 double m_SaturationTime =
96 -1.; // Time when the avalanche has reached maximum size
97
98 bool m_diffusion = false; // Check if transverse diffusion is enabled.
99
100 double m_DiffSigma = 0.; // Transverse diffusion coefficients (in √cm).
101
102 int m_nestart = 0.;
103
104 bool m_driftAvalanche = false;
105 bool m_importAvalanche = false;
106 bool m_SensorParameters = false;
107
108 std::string m_className = "AvalancheGrid";
109
110 Sensor* m_sensor = nullptr;
111
112 AvalancheMicroscopic* m_avmc = nullptr;
113
114 struct Grid {
115 std::vector<double> zgrid; ///< Grid points of z-coordinate.
116 int zsteps = 0; ///< Amount of grid points.
117 double zStepSize =
118 0.; ///< Distance between the grid points of z-coordinate.
119
120 std::vector<double> ygrid; ///< Grid points of y-coordinate.
121 double yStepSize = 0.; ///< Amount of grid points.
122 int ysteps = 0.; ///< Distance between the grid points of y-coordinate.
123
124 std::vector<double> xgrid; ///< Grid points of x-coordinate.
125 double xStepSize = 0.; ///< Amount of grid points.
126 int xsteps = 0.; ///< Distance between the grid points of x-coordinate.
127
128 std::vector<std::vector<int>> gridPosition = {
129 {}, {}, {}}; ///< Tracking of active z-coordinate grid points.
130
131 bool gridset = false; ///< Keeps track if the grid has been defined.
132
133 std::vector<std::vector<std::vector<int>>>
134 n; ///< Grid based representation of space-charge. [z,y,x];
135 int N = 0; ///< Total amount of charge.
136
137 std::vector<double>
138 transverseDiffusion; ///< Factors of the charge that go to horizontally
139 ///< neighboring grid points.
140
141 double velocity = 0; ///< Velocity of electrons.
142 double time = 0; ///< Clock.
143
144 bool run = true; ///< Tracking if the charges are still in the drift gap.
145 };
146
147 Grid m_avgrid;
148 // Setting z-coordinate grid.
149 void SetZGrid(Grid& av, const double top, const double bottom,
150 const int steps);
151 // Setting y-coordinate grid.
152 void SetYGrid(Grid& av, const double top, const double bottom,
153 const int steps);
154 // Setting x-coordinate grid.
155 void SetXGrid(Grid& av, const double top, const double bottom,
156 const int steps);
157 // Get size of avalanche when going from z to z-dz.
158 int GetAvalancheSize(double dz, const int nsize, const double alpha,
159 const double eta);
160 // Assign electron to the closest grid point.
161 bool SnapToGrid(Grid& av, const double x, const double y, const double z,
162 const double v, const int n = 1);
163 // Go to next time step.
164 void NextAvalancheGridPoint(Grid& av);
165 // Compute the factor of the charge that go to neighboring points through
166 // transverse diffusion.
167 void DiffusionFactors(Grid& av);
168 // Obtain the Townsend coef., Attachment coef. and velocity vector from
169 // sensor class.
170 void GetParametersFromSensor();
171
172 void SortPositionVector();
173};
174} // namespace Garfield
175
176#endif
void SetMaxAvalancheSize(const double size)
Set the maximum avalanche size (1e7 by default).
void GetElectronsFromAvalancheMicroscopic()
Import electron data from AvalancheMicroscopic class.
void SetSensor(Sensor *sensor)
Set the sensor.
void SetElectronTownsend(const double town)
Set the electron Townsend coefficient (in 1 / cm).
void SetElectronAttachment(const double att)
Set the electron attachment coefficient (in 1 / cm).
AvalancheGrid()
Constructor.
void SetAvalancheMicroscopic(AvalancheMicroscopic *avmc)
Set the AvalancheMicroscopic.
void SetElectronVelocity(const double vx, const double vy, const double vz)
Set the electron drift velocity (in cm / ns).
void EnableDiffusion(const double diffSigma)
void SetGrid(const double xmin, const double xmax, const int xsteps, const double ymin, const double ymax, const int ysteps, const double zmin, const double zmax, const int zsteps)
Import electron data from AvalancheMicroscopic class.
void CreateAvalanche(const double x, const double y, const double z, const double t=0, const int n=1)
~AvalancheGrid()
Destructor.
Calculate electron drift lines and avalanches using microscopic tracking.