Garfield 0.3
Toolkit for the detailed simulation of particle detectors based on ionization measurement in gases and semiconductors
Loading...
Searching...
No Matches
DriftLineRKF.hh
Go to the documentation of this file.
1#ifndef G_DRIFTLINE_RKF_H
2#define G_DRIFTLINE_RKF_H
3
4#include <array>
5#include <string>
6#include <utility>
7#include <vector>
8
10
11namespace Garfield {
12
13class Sensor;
14class ViewDrift;
15class Medium;
19 public:
21 DriftLineRKF() : DriftLineRKF(nullptr) {}
23 DriftLineRKF(Sensor* sensor);
26
28 void SetSensor(Sensor* s);
29
34
36 void EnableSignalCalculation(const bool on = true) { m_doSignal = on; }
41 void SetSignalAveragingOrder(const unsigned int navg) { m_navg = navg; }
45 void UseWeightingPotential(const bool on = true) {
47 }
48
50 void SetIntegrationAccuracy(const double eps);
52 void SetMaximumStepSize(const double ms);
60 void RejectKinks(const bool on = true) { m_rejectKinks = on; }
61
63 void SetElectronSignalScalingFactor(const double scale) { m_scaleE = scale; }
65 void SetHoleSignalScalingFactor(const double scale) { m_scaleH = scale; }
67 void SetIonSignalScalingFactor(const double scale) { m_scaleI = scale; }
68
70 void EnableAvalanche(const bool on = true) { m_doAvalanche = on; }
72 void EnableIonTail(const bool on = true) {
73 m_doIonTail = on;
74 m_doIonTailAuto = false;
75 }
76
77 void EnableNegativeIonTail(const bool on = true) { m_doNegativeIonTail = on; }
79 void SetGainFluctuationsFixed(const double gain = -1.);
82 void SetGainFluctuationsPolya(const double theta, const double mean = -1.,
83 const bool quiet = false);
84
86 void EnableTownsendMap(const bool on = true) { m_useTownsendMap = on; }
88 void EnableVelocityMap(const bool on = true) { m_useVelocityMap = on; }
89
91 bool DriftElectron(const double x, const double y, const double z,
92 const double t, const size_t w = 1);
94 bool DriftHole(const double x, const double y, const double z,
95 const double t, const size_t w = 1);
97 bool DriftIon(const double x, const double y, const double z,
98 const double t, const size_t w = 1);
101 bool DriftPositron(const double x, const double y, const double z,
102 const double t, const size_t w = 1);
105 bool DriftNegativeIon(const double x, const double y, const double z,
106 const double t, const size_t w = 1);
107
109 void PrintDriftLine() const;
111 void GetEndPoint(double& x, double& y, double& z, double& t, int& st) const;
113 size_t GetNumberOfDriftLinePoints() const { return m_x.size(); }
115 void GetDriftLinePoint(const size_t i, double& x, double& y, double& z,
116 double& t) const;
117
120 double GetArrivalTimeSpread(const double eps = 1.e-4) const;
122 double GetGain(const double eps = 1.e-4) const;
124 double GetLoss(const double eps = 1.e-4) const;
126 double GetDriftTime() const {
127 return m_t.empty() ? 0. : m_t.back() - m_t.front();
128 }
129
130 double GetPathLength() const;
131
133 void GetAvalancheSize(double& ne, double& ni) const {
134 ne = m_nE;
135 ni = m_nI;
136 }
137
138 std::pair<double, double> GetAvalancheSize() const {
139 return std::make_pair(m_nE, m_nI);
140 }
141
147 bool FieldLine(const double xi, const double yi, const double zi,
148 std::vector<std::array<float, 3> >& xl,
149 const bool electron = true) const;
150
152 void EnableDebugging(const bool on = true) { m_debug = on; }
153
154 private:
155 std::string m_className = "DriftLineRKF";
156
157 // Pointer to sensor.
158 Sensor* m_sensor = nullptr;
159
160 // Particle type of the most recent drift line.
162
163 // Maximum allowed step size.
164 double m_maxStepSize = 0.;
165 // Precision of the stepping algorithm.
166 double m_accuracy = 1.e-8;
167 // Flag to reject bends > 90 degrees or not.
168 bool m_rejectKinks = true;
169 // Flag to apply a cut on the maximum allowed step size or not.
170 bool m_useStepSizeLimit = false;
171
172 // Pointer to the drift viewer.
173 ViewDrift* m_view = nullptr;
174
175 // Points along the current drift line.
176 std::vector<std::array<double, 3> > m_x;
177 // Times corresponding to the points along the current drift line.
178 std::vector<double> m_t;
179 // Status flag of the current drift line.
180 int m_status = 0;
181
182 // Flag whether to calculate induced signals or not.
183 bool m_doSignal = true;
184 // Averaging order used when projecting the signal on the time bins.
185 unsigned int m_navg = 2;
186 // Use weighting potential or weighting field for calculating the signal.
188
189 // Scaling factor for electron signals.
190 double m_scaleE = 1.;
191 // Scaling factor for hole signals.
192 double m_scaleH = 1.;
193 // Scaling factor for ion signals.
194 double m_scaleI = 1.;
195
196 // Use drift velocity maps?
197 bool m_useVelocityMap = false;
198 // Use maps for the Townsend coefficient?
199 bool m_useTownsendMap = false;
200
201 // Flag wether to simulate electron multiplication or not.
202 bool m_doAvalanche = true;
203 enum class GainFluctuations { None = 0, Polya };
204 // Model to be used for randomizing the avalanche size.
206 // Polya shape parameter.
207 double m_theta = 0.;
208 // Mean avalanche size (only used if > 1).
209 double m_gain = -1.;
210
211 // Flag whether to simulate the ion tail or not.
212 bool m_doIonTail = true;
213 // Simulate the ion tail automatically if the medium has mobility data?
214 bool m_doIonTailAuto = true;
215 // Flag whether to simulate the negative ion tail or not.
217 // Avalanche size.
218 double m_nE = 0., m_nI = 0.;
219
220 // Debug flag.
221 bool m_debug = false;
222
223 // Calculate a drift line starting at a given position.
224 bool DriftLine(const std::array<double, 3>& x0, const double t0,
225 const Particle particle, std::vector<double>& ts,
226 std::vector<std::array<double, 3> >& xs, int& status) const;
227 // Calculate the number of electrons and ions at each point along a
228 // drift line.
229 bool Avalanche(const Particle particle,
230 const std::vector<std::array<double, 3> >& xs,
231 std::vector<double>& ne, std::vector<double>& ni,
232 std::vector<double>& nn, double& scale) const;
233 // Calculate drift lines and induced signals of the positive ions
234 // produced in an avalanche.
235 bool AddIonTail(const std::vector<double>& te,
236 const std::vector<std::array<double, 3> >& xe,
237 const std::vector<double>& ni, const double scale) const;
238 // Calculate drift lines and induced signals of the negative ions
239 // produced by electron attachment.
240 bool AddNegativeIonTail(const std::vector<double>& te,
241 const std::vector<std::array<double, 3> >& xe,
242 const std::vector<double>& nn,
243 const double scale) const;
244 // Compute electric and magnetic field at a given position.
245 int GetField(const std::array<double, 3>& x, double& ex, double& ey,
246 double& ez, double& bx, double& by, double& bz,
247 Medium*& medium) const;
248 // Calculate transport parameters for a given point and particle type.
249 std::array<double, 3> GetVelocity(const std::array<double, 3>& x,
250 const Particle particle, int& status) const;
251 bool GetDiffusion(const std::array<double, 3>& x, const Particle particle,
252 double& dl, double& dt) const;
253 double GetVar(const std::array<double, 3>& x, const Particle particle) const;
254 double GetAlpha(const std::array<double, 3>& x,
255 const Particle particle) const;
256 double GetEta(const std::array<double, 3>& x, const Particle particle) const;
257
258 // Terminate a drift line at the edge of a boundary.
259 bool Terminate(const std::array<double, 3>& xx0,
260 const std::array<double, 3>& xx1, const Particle particle,
261 std::vector<double>& ts,
262 std::vector<std::array<double, 3> >& xs) const;
263
264 // Drift a particle to a wire
265 bool DriftToWire(const double xw, const double yw, const double rw,
266 const Particle particle, std::vector<double>& ts,
267 std::vector<std::array<double, 3> >& xs, int& stat) const;
268 // Compute the arrival time spread along a drift line.
269 double ComputeSigma(const std::vector<std::array<double, 3> >& x,
270 const Particle particle, const double eps) const;
271 // Compute the gain factor along a drift line.
272 double ComputeGain(const std::vector<std::array<double, 3> >& x,
273 const Particle particle, const double eps) const;
274 // Compute the loss factor along a drift line.
275 double ComputeLoss(const std::vector<std::array<double, 3> >& x,
276 const Particle particle, const double eps) const;
277 // Integrate the longitudinal diffusion over a step.
278 double IntegrateDiffusion(const std::array<double, 3>& xi,
279 const std::array<double, 3>& xe,
280 const Particle particle, const double tol) const;
281 // Integrate the Townsend coefficient over a step.
282 double IntegrateAlpha(const std::array<double, 3>& xi,
283 const std::array<double, 3>& xe,
284 const Particle particle, const double tol) const;
285 // Integrate the attachment coefficient over a step.
286 double IntegrateEta(const std::array<double, 3>& xi,
287 const std::array<double, 3>& xe, const Particle particle,
288 const double tol) const;
289
290 // Calculate the signal for a given drift line.
291 void ComputeSignal(const Particle particle, const double scale,
292 const std::vector<double>& ts,
293 const std::vector<std::array<double, 3> >& xs,
294 const std::vector<double>& ne) const;
295
296 // Terminate a field line.
297 void Terminate(const std::array<double, 3>& xx0,
298 const std::array<double, 3>& xx1,
299 std::vector<std::array<float, 3> >& xs) const;
300
301 static double Charge(const Particle particle) {
302 if (particle == Particle::Electron || particle == Particle::NegativeIon) {
303 return -1.;
304 }
305 return 1.;
306 }
307};
308} // namespace Garfield
309
310#endif
double ComputeSigma(const std::vector< std::array< double, 3 > > &x, const Particle particle, const double eps) const
double GetEta(const std::array< double, 3 > &x, const Particle particle) const
void EnableVelocityMap(const bool on=true)
Retrieve the drift velocity from the component.
bool FieldLine(const double xi, const double yi, const double zi, std::vector< std::array< float, 3 > > &xl, const bool electron=true) const
Compute an electric field line.
double GetAlpha(const std::array< double, 3 > &x, const Particle particle) const
void EnableDebugging(const bool on=true)
Switch debugging messages on/off (default: off).
void SetIonSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by ions.
void SetSignalAveragingOrder(const unsigned int navg)
Set the number of points to be used when averaging the delayed signal vector over a time bin in the S...
void EnableSignalCalculation(const bool on=true)
Switch calculation of induced currents on or off (default: enabled).
void SetMaximumStepSize()
Try to set an upper limit to the allowable step size based on the feature size of the sensor.
bool DriftIon(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of an ion with a given starting point.
void SetGainFluctuationsPolya(const double theta, const double mean=-1., const bool quiet=false)
Sample the avalanche size from a Polya distribution with shape parameter theta.
void DisablePlotting()
Switch off drift line plotting.
bool Avalanche(const Particle particle, const std::vector< std::array< double, 3 > > &xs, std::vector< double > &ne, std::vector< double > &ni, std::vector< double > &nn, double &scale) const
double IntegrateAlpha(const std::array< double, 3 > &xi, const std::array< double, 3 > &xe, const Particle particle, const double tol) const
bool DriftToWire(const double xw, const double yw, const double rw, const Particle particle, std::vector< double > &ts, std::vector< std::array< double, 3 > > &xs, int &stat) const
double ComputeLoss(const std::vector< std::array< double, 3 > > &x, const Particle particle, const double eps) const
bool AddIonTail(const std::vector< double > &te, const std::vector< std::array< double, 3 > > &xe, const std::vector< double > &ni, const double scale) const
double IntegrateDiffusion(const std::array< double, 3 > &xi, const std::array< double, 3 > &xe, const Particle particle, const double tol) const
double GetPathLength() const
Get the cumulative path length.
double GetArrivalTimeSpread(const double eps=1.e-4) const
Compute the sigma of the arrival time distribution for the current drift line by integrating the long...
void UseWeightingPotential(const bool on=true)
Use the weighting potential (as opposed to the weighting field) for calculating the induced signal.
void EnableNegativeIonTail(const bool on=true)
Enable/disable simulation of the negative ion tail (default: off).
bool DriftElectron(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of an electron with a given starting point.
void SetSensor(Sensor *s)
Set the sensor.
void GetDriftLinePoint(const size_t i, double &x, double &y, double &z, double &t) const
Get the coordinates and time of a point along the most recent drift line.
void UnsetMaximumStepSize()
Do not apply an upper limit to the allowable step size.
void SetIntegrationAccuracy(const double eps)
Set the accuracy of the Runge Kutta Fehlberg drift line integration.
std::vector< std::array< double, 3 > > m_x
double ComputeGain(const std::vector< std::array< double, 3 > > &x, const Particle particle, const double eps) const
void SetGainFluctuationsFixed(const double gain=-1.)
Do not randomize the avalanche size.
static double Charge(const Particle particle)
bool AddNegativeIonTail(const std::vector< double > &te, const std::vector< std::array< double, 3 > > &xe, const std::vector< double > &nn, const double scale) const
void RejectKinks(const bool on=true)
Request (or not) the drift line calculation to be aborted if the drift line makes a bend sharper than...
bool Terminate(const std::array< double, 3 > &xx0, const std::array< double, 3 > &xx1, const Particle particle, std::vector< double > &ts, std::vector< std::array< double, 3 > > &xs) const
bool DriftNegativeIon(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of an ion with a given starting point, assuming that it has negative charge.
bool DriftPositron(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of an electron with a given starting point, assuming that it has positive cha...
~DriftLineRKF()
Destructor.
GainFluctuations m_gainFluctuations
void PrintDriftLine() const
Print the trajectory of the most recent drift line.
double IntegrateEta(const std::array< double, 3 > &xi, const std::array< double, 3 > &xe, const Particle particle, const double tol) const
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
double GetVar(const std::array< double, 3 > &x, const Particle particle) const
double GetGain(const double eps=1.e-4) const
Compute the multiplication factor for the current drift line.
void Terminate(const std::array< double, 3 > &xx0, const std::array< double, 3 > &xx1, std::vector< std::array< float, 3 > > &xs) const
DriftLineRKF()
Default constructor.
double GetDriftTime() const
Get the cumulative drift time.
DriftLineRKF(Sensor *sensor)
Constructor.
double GetLoss(const double eps=1.e-4) const
Compute the attachment loss factor for the current drift line.
void EnableTownsendMap(const bool on=true)
Retrieve the Townsend coefficient from the component.
bool DriftLine(const std::array< double, 3 > &x0, const double t0, const Particle particle, std::vector< double > &ts, std::vector< std::array< double, 3 > > &xs, int &status) const
void GetAvalancheSize(double &ne, double &ni) const
Return the number of electrons and ions in the avalanche.
void GetEndPoint(double &x, double &y, double &z, double &t, int &st) const
Get the end point and status flag of the most recent drift line.
int GetField(const std::array< double, 3 > &x, double &ex, double &ey, double &ez, double &bx, double &by, double &bz, Medium *&medium) const
std::array< double, 3 > GetVelocity(const std::array< double, 3 > &x, const Particle particle, int &status) const
bool GetDiffusion(const std::array< double, 3 > &x, const Particle particle, double &dl, double &dt) const
void ComputeSignal(const Particle particle, const double scale, const std::vector< double > &ts, const std::vector< std::array< double, 3 > > &xs, const std::vector< double > &ne) const
size_t GetNumberOfDriftLinePoints() const
Get the number of points of the most recent drift line.
std::vector< double > m_t
std::pair< double, double > GetAvalancheSize() const
Return the number of electrons and ions in the avalanche.
void SetHoleSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by holes.
void EnableAvalanche(const bool on=true)
Enable/disable simulation electron multiplication (default: on).
void SetMaximumStepSize(const double ms)
Set (explicitly) the maximum step size that is allowed.
void EnableIonTail(const bool on=true)
Enable/disable simulation of the ion tail (default: on).
void SetElectronSignalScalingFactor(const double scale)
Set multiplication factor for the signal induced by electrons.
bool DriftHole(const double x, const double y, const double z, const double t, const size_t w=1)
Simulate the drift line of a hole with a given starting point.
Visualize drift lines and tracks.
Definition ViewDrift.hh:18