Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
MediumGas.hh
Go to the documentation of this file.
1#ifndef G_MEDIUM_GAS_H
2#define G_MEDIUM_GAS_H
3
4#include <array>
5#include <cmath>
6#include <vector>
7#include <bitset>
8
9#include "Medium.hh"
10
11namespace Garfield {
12
13/// Base class for gas media.
14
15class MediumGas : public Medium {
16 public:
17 /// Constructor
18 MediumGas();
19 /// Destructor
20 virtual ~MediumGas() {}
21
22 /// Set the gas mixture.
23 bool SetComposition(const std::string& gas1, const double f1 = 1.,
24 const std::string& gas2 = "", const double f2 = 0.,
25 const std::string& gas3 = "", const double f3 = 0.,
26 const std::string& gas4 = "", const double f4 = 0.,
27 const std::string& gas5 = "", const double f5 = 0.,
28 const std::string& gas6 = "", const double f6 = 0.);
29 /// Retrieve the gas mixture.
30 void GetComposition(std::string& gas1, double& f1,
31 std::string& gas2, double& f2,
32 std::string& gas3, double& f3,
33 std::string& gas4, double& f4,
34 std::string& gas5, double& f5,
35 std::string& gas6, double& f6) const;
36
37 /// Read table of gas properties (transport parameters) from file.
38 bool LoadGasFile(const std::string& filename, const bool quiet = false);
39 /// Save the present table of gas properties (transport parameters) to a file.
40 bool WriteGasFile(const std::string& filename);
41 /// Read table of gas properties from and merge with the existing dataset.
42 bool MergeGasFile(const std::string& filename, const bool replaceOld);
43
44 /// Switch on simulation of Penning transfers, using pre-implemented
45 /// parameterisations of the transfer probability (if available).
46 virtual bool EnablePenningTransfer();
47 /** Switch on simulation of Penning transfers by means of
48 * transfer probabilities, for all excitation levels in the mixture.
49 * \param r transfer probability [0, 1]
50 * \param lambda parameter for sampling the distance of the Penning electron
51 with respect to the excitation.
52 */
53 virtual bool EnablePenningTransfer(const double r, const double lambda);
54 /// Switch on simulation of Penning transfers by means of
55 /// transfer probabilities, for all excitations of a given component.
56 virtual bool EnablePenningTransfer(const double r, const double lambda,
57 std::string gasname);
58 /// Switch the simulation of Penning transfers off globally.
59 virtual void DisablePenningTransfer();
60 /// Switch the simulation of Penning transfers off for a given component.
61 virtual bool DisablePenningTransfer(std::string gasname);
62
63 /// Retrieve the Penning transfer probability and distance for a
64 /// specific component.
65 bool GetPenningTransfer(const std::string& gasname,
66 double& r, double& lambda);
67
68 /// Print information about the present gas mixture and available data.
69 virtual void PrintGas();
70 /// Print a list of all available gases.
71 static void PrintGases();
72
73 /// Read a table of (positive) ion mobilities vs. electric field from file.
74 bool LoadIonMobility(const std::string& filename, const bool quiet = false);
75 /// Read a table of negative ion mobilities vs. electric field from file.
76 bool LoadNegativeIonMobility(const std::string& filename,
77 const bool quiet = false);
78
79 /// Adjust the Townsend coefficient using the excitation and ionisation
80 /// rates stored in the gas table and the Penning transfer probabilities.
82
83 /// Return the number of ionisation levels in the table.
84 size_t GetNumberOfIonisationLevels() const { return m_ionLevels.size(); }
85 /// Return the number of excitation levels in the table.
86 size_t GetNumberOfExcitationLevels() const { return m_excLevels.size(); }
87 /// Return the identifier and threshold of an ionisation level.
88 void GetIonisationLevel(const size_t level, std::string& label,
89 double& energy) const;
90 /// Return the identifier and energy of an excitation level.
91 void GetExcitationLevel(const size_t level, std::string& label,
92 double& energy) const;
93 /// Get an entry in the table of ionisation rates.
94 bool GetElectronIonisationRate(const size_t level,
95 const size_t ie, const size_t ib,
96 const size_t ia, double& f) const;
97 /// Get an entry in the table of excitation rates.
98 bool GetElectronExcitationRate(const size_t level,
99 const size_t ie, const size_t ib,
100 const size_t ia, double& f) const;
101
102 bool IsGas() const override { return true; }
103
104 void GetComponent(const unsigned int i, std::string& label,
105 double& f) override;
106
107 void SetAtomicNumber(const double z) override;
108 double GetAtomicNumber() const override;
109 void SetAtomicWeight(const double a) override;
110 double GetAtomicWeight() const override;
111 void SetNumberDensity(const double n) override;
112 double GetNumberDensity() const override;
113 void SetMassDensity(const double rho) override;
114 double GetMassDensity() const override;
115
116 void ResetTables() override;
117
118 void SetExtrapolationMethodExcitationRates(const std::string& low,
119 const std::string& high) {
120 SetExtrapolationMethod(low, high, m_extrExc, "ExcitationRates");
121 }
122 void SetExtrapolationMethodIonisationRates(const std::string& low,
123 const std::string& high) {
124 SetExtrapolationMethod(low, high, m_extrIon, "IonisationRates");
125 }
126 void SetInterpolationMethodExcitationRates(const unsigned int intrp) {
127 if (intrp > 0) m_intpExc = intrp;
128 }
129 void SetInterpolationMethodIonisationRates(const unsigned int intrp) {
130 if (intrp > 0) m_intpIon = intrp;
131 }
132
133 // Scaling laws.
134 // TODO: cache scaling factors.
135 double ScaleElectricField(const double e) const override {
136 return e * m_pressureTable / m_pressure;
137 }
138 double UnScaleElectricField(const double e) const override {
139 return e * m_pressure / m_pressureTable;
140 }
141 double ScaleDiffusion(const double d) const override {
142 return d * sqrt(m_pressureTable / m_pressure);
143 }
144 double ScaleDiffusionTensor(const double d) const override {
145 return d * m_pressureTable / m_pressure;
146 }
147 double ScaleTownsend(const double alpha) const override {
148 return alpha * m_pressure / m_pressureTable;
149 }
150 double ScaleAttachment(const double eta) const override {
151 return eta * m_pressure / m_pressureTable;
152 }
153 double ScaleLorentzAngle(const double lor) const override {
154 return lor * m_pressure / m_pressureTable;
155 }
156
157 bool GetPhotoAbsorptionCrossSection(const double e, double& sigma,
158 const unsigned int i) override;
159
160 protected:
161 static constexpr unsigned int m_nMaxGases = 6;
162
163 // Gas mixture
164 std::array<std::string, m_nMaxGases> m_gas;
165 std::array<double, m_nMaxGases> m_fraction;
166 std::array<double, m_nMaxGases> m_atWeight;
167 std::array<double, m_nMaxGases> m_atNum;
168
169 // Penning transfer
170 // Flag enabling/disabling Penning transfer
171 bool m_usePenning = false;
172 // Penning transfer probability
173 double m_rPenningGlobal = 0.;
174 // Mean distance of Penning ionisation
176 // Penning transfer probability per component
177 std::array<double, m_nMaxGases> m_rPenningGas;
178 // Penning transfer distance per component
179 std::array<double, m_nMaxGases> m_lambdaPenningGas;
180
181 // Pressure at which the transport parameter table was calculated
183 // Temperature at which the transport parameter table was calculated
185
186 // Table of Townsend coefficients without Penning transfer
187 std::vector<std::vector<std::vector<double> > > m_eAlp0;
188
189 // Tables for excitation and ionisation rates
190 std::vector<std::vector<std::vector<std::vector<double> > > > m_excRates;
191 std::vector<std::vector<std::vector<std::vector<double> > > > m_ionRates;
192
193 // Store excitation and ionization information
194 struct ExcLevel {
195 std::string label;
196 double energy;
197 double prob;
198 double rms;
199 double dt;
200 };
201 std::vector<ExcLevel> m_excLevels;
202
203 struct IonLevel {
204 std::string label;
205 double energy;
206 };
207 std::vector<IonLevel> m_ionLevels;
208
209 // Extrapolation/interpolation for excitation and ionisation rates.
210 std::pair<unsigned int, unsigned int> m_extrExc = {0, 1};
211 std::pair<unsigned int, unsigned int> m_extrIon = {0, 1};
212 unsigned int m_intpExc = 2;
213 unsigned int m_intpIon = 2;
214
215 bool LoadMobility(const std::string& filename, const bool quiet,
216 const bool negative);
217 bool ReadHeader(std::ifstream& gasfile, int& version,
218 std::bitset<20>& gasok, bool& is3d,
219 std::vector<double>& mixture,
220 std::vector<double>& efields, std::vector<double>& bfields,
221 std::vector<double>& angles, std::vector<ExcLevel>& excLevels,
222 std::vector<IonLevel>& ionLevels);
223 void ReadFooter(std::ifstream& gasfile,
224 std::array<unsigned int, 13>& extrapH,
225 std::array<unsigned int, 13>& extrapL,
226 std::array<unsigned int, 13>& interp,
227 unsigned int& thrAlp, unsigned int& thrAtt,
228 unsigned int& thrDis,
229 double& ionDiffL, double& ionDiffT,
230 double& pgas, double& tgas);
231 void ReadRecord3D(std::ifstream& gasfile, double& ve, double& vb, double& vx,
232 double& dl, double& dt, double& alpha, double& alpha0,
233 double& eta, double& mu, double& lor,
234 double& dis, std::array<double, 6>& dif,
235 std::vector<double>& rexc, std::vector<double>& rion);
236 void ReadRecord1D(std::ifstream& gasfile, double& ve, double& vb, double& vx,
237 double& dl, double& dt, double& alpha, double& alpha0,
238 double& eta, double& mu, double& lor,
239 double& dis, std::array<double, 6>& dif,
240 std::vector<double>& rexc, std::vector<double>& rion);
241 void InsertE(const int ie, const int ne, const int nb, const int na);
242 void InsertB(const int ib, const int ne, const int nb, const int na);
243 void InsertA(const int ia, const int ne, const int nb, const int na);
244 void ZeroRowE(const int ie, const int nb, const int na);
245 void ZeroRowB(const int ib, const int ne, const int na);
246 void ZeroRowA(const int ia, const int ne, const int nb);
247 bool GetMixture(const std::vector<double>& mixture, const int version,
248 std::vector<std::string>& gasnames,
249 std::vector<double>& percentages) const;
250 void GetGasBits(std::bitset<20>& gasok) const;
251
252 static bool GetGasInfo(const std::string& gasname,
253 double& a, double& z, double& w, double& f);
254 static std::string GetGasName(const int gasnumber, const int version);
255 static std::string GetGasName(std::string input);
256 static int GetGasNumberGasFile(const std::string& input);
257 static const std::vector<std::string> GetAliases(const std::string& gas);
258
259};
260}
261
262#endif
double GetMassDensity() const override
Get the mass density [g/cm3].
Definition MediumGas.cc:310
double GetNumberDensity() const override
Get the number density [cm-3].
Definition MediumGas.cc:304
void SetExtrapolationMethodExcitationRates(const std::string &low, const std::string &high)
Definition MediumGas.hh:118
void ReadRecord3D(std::ifstream &gasfile, double &ve, double &vb, double &vx, double &dl, double &dt, double &alpha, double &alpha0, double &eta, double &mu, double &lor, double &dis, std::array< double, 6 > &dif, std::vector< double > &rexc, std::vector< double > &rion)
Definition MediumGas.cc:778
bool LoadGasFile(const std::string &filename, const bool quiet=false)
Read table of gas properties (transport parameters) from file.
Definition MediumGas.cc:323
bool AdjustTownsendCoefficient()
double ScaleElectricField(const double e) const override
Definition MediumGas.hh:135
bool GetElectronIonisationRate(const size_t level, const size_t ie, const size_t ib, const size_t ia, double &f) const
Get an entry in the table of ionisation rates.
void GetIonisationLevel(const size_t level, std::string &label, double &energy) const
Return the identifier and threshold of an ionisation level.
std::pair< unsigned int, unsigned int > m_extrIon
Definition MediumGas.hh:211
bool GetPenningTransfer(const std::string &gasname, double &r, double &lambda)
void SetInterpolationMethodExcitationRates(const unsigned int intrp)
Definition MediumGas.hh:126
void SetAtomicNumber(const double z) override
Set the effective atomic number.
Definition MediumGas.cc:271
bool LoadNegativeIonMobility(const std::string &filename, const bool quiet=false)
Read a table of negative ion mobilities vs. electric field from file.
double ScaleDiffusion(const double d) const override
Definition MediumGas.hh:141
virtual bool EnablePenningTransfer()
static constexpr unsigned int m_nMaxGases
Definition MediumGas.hh:161
std::vector< std::vector< std::vector< std::vector< double > > > > m_excRates
Definition MediumGas.hh:190
void InsertB(const int ib, const int ne, const int nb, const int na)
size_t GetNumberOfExcitationLevels() const
Return the number of excitation levels in the table.
Definition MediumGas.hh:86
double m_lambdaPenningGlobal
Definition MediumGas.hh:175
void SetExtrapolationMethodIonisationRates(const std::string &low, const std::string &high)
Definition MediumGas.hh:122
unsigned int m_intpIon
Definition MediumGas.hh:213
std::vector< IonLevel > m_ionLevels
Definition MediumGas.hh:207
std::array< double, m_nMaxGases > m_rPenningGas
Definition MediumGas.hh:177
void GetComposition(std::string &gas1, double &f1, std::string &gas2, double &f2, std::string &gas3, double &f3, std::string &gas4, double &f4, std::string &gas5, double &f5, std::string &gas6, double &f6) const
Retrieve the gas mixture.
Definition MediumGas.cc:240
double GetAtomicNumber() const override
Get the effective atomic number.
Definition MediumGas.cc:314
std::array< double, m_nMaxGases > m_atNum
Definition MediumGas.hh:167
static void PrintGases()
Print a list of all available gases.
void GetGasBits(std::bitset< 20 > &gasok) const
static const std::vector< std::string > GetAliases(const std::string &gas)
std::vector< std::vector< std::vector< std::vector< double > > > > m_ionRates
Definition MediumGas.hh:191
void ZeroRowA(const int ia, const int ne, const int nb)
void ResetTables() override
Reset all tables of transport parameters.
bool LoadMobility(const std::string &filename, const bool quiet, const bool negative)
std::vector< ExcLevel > m_excLevels
Definition MediumGas.hh:201
void ZeroRowB(const int ib, const int ne, const int na)
MediumGas()
Constructor.
Definition MediumGas.cc:115
bool GetElectronExcitationRate(const size_t level, const size_t ie, const size_t ib, const size_t ia, double &f) const
Get an entry in the table of excitation rates.
double ScaleDiffusionTensor(const double d) const override
Definition MediumGas.hh:144
void ReadFooter(std::ifstream &gasfile, std::array< unsigned int, 13 > &extrapH, std::array< unsigned int, 13 > &extrapL, std::array< unsigned int, 13 > &interp, unsigned int &thrAlp, unsigned int &thrAtt, unsigned int &thrDis, double &ionDiffL, double &ionDiffT, double &pgas, double &tgas)
Definition MediumGas.cc:836
bool LoadIonMobility(const std::string &filename, const bool quiet=false)
Read a table of (positive) ion mobilities vs. electric field from file.
static int GetGasNumberGasFile(const std::string &input)
virtual void PrintGas()
Print information about the present gas mixture and available data.
void ReadRecord1D(std::ifstream &gasfile, double &ve, double &vb, double &vx, double &dl, double &dt, double &alpha, double &alpha0, double &eta, double &mu, double &lor, double &dis, std::array< double, 6 > &dif, std::vector< double > &rexc, std::vector< double > &rion)
Definition MediumGas.cc:812
static bool GetGasInfo(const std::string &gasname, double &a, double &z, double &w, double &f)
std::array< double, m_nMaxGases > m_atWeight
Definition MediumGas.hh:166
double ScaleTownsend(const double alpha) const override
Definition MediumGas.hh:147
static std::string GetGasName(const int gasnumber, const int version)
void GetComponent(const unsigned int i, std::string &label, double &f) override
Get the name and fraction of a given component.
Definition MediumGas.cc:258
double UnScaleElectricField(const double e) const override
Definition MediumGas.hh:138
bool WriteGasFile(const std::string &filename)
Save the present table of gas properties (transport parameters) to a file.
void SetInterpolationMethodIonisationRates(const unsigned int intrp)
Definition MediumGas.hh:129
bool GetMixture(const std::vector< double > &mixture, const int version, std::vector< std::string > &gasnames, std::vector< double > &percentages) const
Definition MediumGas.cc:918
std::array< double, m_nMaxGases > m_lambdaPenningGas
Definition MediumGas.hh:179
std::pair< unsigned int, unsigned int > m_extrExc
Definition MediumGas.hh:210
bool GetPhotoAbsorptionCrossSection(const double e, double &sigma, const unsigned int i) override
bool MergeGasFile(const std::string &filename, const bool replaceOld)
Read table of gas properties from and merge with the existing dataset.
Definition MediumGas.cc:955
virtual void DisablePenningTransfer()
Switch the simulation of Penning transfers off globally.
double GetAtomicWeight() const override
Get the effective atomic weight.
Definition MediumGas.cc:295
void SetNumberDensity(const double n) override
Set the number density [cm-3].
Definition MediumGas.cc:283
bool SetComposition(const std::string &gas1, const double f1=1., const std::string &gas2="", const double f2=0., const std::string &gas3="", const double f3=0., const std::string &gas4="", const double f4=0., const std::string &gas5="", const double f5=0., const std::string &gas6="", const double f6=0.)
Set the gas mixture.
Definition MediumGas.cc:138
void ZeroRowE(const int ie, const int nb, const int na)
double ScaleLorentzAngle(const double lor) const override
Definition MediumGas.hh:153
bool IsGas() const override
Is this medium a gas?
Definition MediumGas.hh:102
double ScaleAttachment(const double eta) const override
Definition MediumGas.hh:150
void SetMassDensity(const double rho) override
Set the mass density [g/cm3].
Definition MediumGas.cc:289
virtual ~MediumGas()
Destructor.
Definition MediumGas.hh:20
std::vector< std::vector< std::vector< double > > > m_eAlp0
Definition MediumGas.hh:187
void GetExcitationLevel(const size_t level, std::string &label, double &energy) const
Return the identifier and energy of an excitation level.
void InsertA(const int ia, const int ne, const int nb, const int na)
void InsertE(const int ie, const int ne, const int nb, const int na)
std::array< std::string, m_nMaxGases > m_gas
Definition MediumGas.hh:164
bool ReadHeader(std::ifstream &gasfile, int &version, std::bitset< 20 > &gasok, bool &is3d, std::vector< double > &mixture, std::vector< double > &efields, std::vector< double > &bfields, std::vector< double > &angles, std::vector< ExcLevel > &excLevels, std::vector< IonLevel > &ionLevels)
Definition MediumGas.cc:597
void SetAtomicWeight(const double a) override
Set the effective atomic weight.
Definition MediumGas.cc:277
size_t GetNumberOfIonisationLevels() const
Return the number of ionisation levels in the table.
Definition MediumGas.hh:84
unsigned int m_intpExc
Definition MediumGas.hh:212
std::array< double, m_nMaxGases > m_fraction
Definition MediumGas.hh:165
double m_pressure
Definition Medium.hh:542
Medium()
Constructor.
Definition Medium.cc:61
void SetExtrapolationMethod(const std::string &low, const std::string &high, std::pair< unsigned int, unsigned int > &extr, const std::string &fcn)
Definition Medium.cc:1215