Garfield 0.3
Toolkit for the detailed simulation of particle detectors based on ionization 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 <array>
5#include <cmath>
6#include <string>
7#include <vector>
8
9namespace Garfield {
10
11class Sensor;
14
17 public:
21 AvalancheGrid(Sensor *sensor);
23 ~AvalancheGrid() = default;
24
26 void SetSensor(Sensor *sensor) { m_sensor = sensor; }
27
31 void SetElectronVelocity(const double vx, const double vy, const double vz) {
32 double vel = std::sqrt(vx * vx + vy * vy + vz * vz);
33 if (vel != std::abs(vx) && vel != std::abs(vy) && vel != std::abs(vz))
34 return;
35 int nx = (int)vx / vel;
36 int ny = (int)vy / vel;
37 int nz = (int)vz / vel;
38 m_velNormal = {nx, ny, nz};
39 m_Velocity = -std::abs(vel);
40 }
41
42 void SetElectronTownsend(const double town) { m_Townsend = town; }
44 void SetElectronAttachment(const double att) { m_Attachment = att; }
46 void SetMaxAvalancheSize(const double size) { m_MaxSize = size; }
47
56 void AddElectron(const double x, const double y, const double z,
57 const double t = 0, const int n = 1);
60
70 void SetGrid(const double xmin, const double xmax, const int xsteps,
71 const double ymin, const double ymax, const int ysteps,
72 const double zmin, const double zmax, const int zsteps);
73
77 int GetAvalancheSize() { return m_nTotal; }
78
79 void EnableDebugging() { m_debug = true; }
80
81 void Reset();
82
83 private:
84 bool m_debug = false;
85
86 double m_Townsend = -1; // [1/cm]
87
88 double m_Attachment = -1; // [1/cm]
89
90 double m_Velocity = 0.; // [cm/ns]
91
92 std::vector<int> m_velNormal = {0, 0, 0};
93
94 double m_MaxSize = 1.6e7; // Saturations size
95 // Check if avalanche has reached maximum size
96 bool m_Saturated = false;
97 // Time when the avalanche has reached maximum size
98 double m_SaturationTime = -1.;
99
100 int m_nestart = 0.;
101
102 std::vector<double> m_nLayer;
103
104 std::string m_className = "AvalancheGrid";
105
106 Sensor *m_sensor = nullptr;
107
108 bool m_printPar = false;
109
110 std::vector<double> m_zgrid;
111 double m_zStepSize = 0.;
112
113 std::vector<double> m_ygrid;
114 double m_yStepSize = 0.;
115
116 std::vector<double> m_xgrid;
117 double m_xStepSize = 0.;
118
119 bool m_gridset = false;
120 int m_nTotal = 0;
121 double m_time = 0;
122 bool m_run = true;
123
124 struct Path {
125 std::vector<double> ts = {};
126 std::vector<std::array<double, 3> > xs = {};
127 std::vector<double> qs = {};
128 };
129
131 double ix = 0;
132 double iy = 0;
133 double iz = 0;
134
135 int n = 1;
136
137 int layer = 0;
138
139 double townsend = 0;
140 double attachment = 0;
141 double velocity = 0;
142
143 double stepSize = 0;
144 std::vector<int> velNormal = {0, 0, 0};
145
146 double time = 0.;
147 double dt = -1.;
148
149 bool active = true;
150
152 };
153
154 std::vector<AvalancheNode> m_activeNodes = {};
155
156 // Assign electron to the closest grid point.
157 bool SnapToGrid(const double x, const double y, const double z,
158 const double v, const int n = 1);
159 // Go to next time step.
161 // Obtain the Townsend coef., Attachment coef. and velocity vector from
162 // sensor class.
164
166};
167} // namespace Garfield
168
169#endif
~AvalancheGrid()=default
Destructor.
std::vector< AvalancheNode > m_activeNodes
void SetMaxAvalancheSize(const double size)
Set the maximum avalanche size (1e7 by default).
double m_yStepSize
Distance between the grid points.
void SetSensor(Sensor *sensor)
Set the sensor.
std::vector< double > m_nLayer
int m_nTotal
Total amount of charge.
bool m_gridset
Keeps track if the grid has been defined.
void DeactivateNode(AvalancheNode &node)
void SetElectronTownsend(const double town)
Set the electron Townsend coefficient (in 1 / cm).
double m_xStepSize
Distance between the grid points.
int GetAmountOfStartingElectrons()
Returns the initial number of electrons in the avalanche.
void StartGridAvalanche()
Start grid based avalanche simulation.
std::vector< double > m_ygrid
Grid points of y-coordinate.
double m_zStepSize
Distance between the grid points.
void SetElectronAttachment(const double att)
Set the electron attachment coefficient (in 1 / cm).
AvalancheGrid()
Default constructor.
bool GetParameters(AvalancheNode &node)
bool m_run
Tracking if the charges are still in the drift gap.
void SetElectronVelocity(const double vx, const double vy, const double vz)
Set the electron drift velocity (in cm / ns).
void AddElectron(const double x, const double y, const double z, const double t=0, const int n=1)
Add an electron to the initial configuration.
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)
Set the grid.
int GetAvalancheSize()
Returns the final number of electrons in the avalanche.
std::vector< int > m_velNormal
std::vector< double > m_zgrid
Grid points of z-coordinate.
void AddElectrons(AvalancheMicroscopic *avmc)
Import electrons from AvalancheMicroscopic object.
std::vector< double > m_xgrid
Grid points of x-coordinate.
bool SnapToGrid(const double x, const double y, const double z, const double v, const int n=1)
AvalancheGrid(Sensor *sensor)
Constructor.
Calculate electron drift lines and avalanches using microscopic tracking.
Component for parallel-plate geometries.
std::vector< std::array< double, 3 > > xs