Garfield++ 4.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 bool IsGas() const override { return true; }
23
24 /// Set the gas mixture.
25 bool SetComposition(const std::string& gas1, const double f1 = 1.,
26 const std::string& gas2 = "", const double f2 = 0.,
27 const std::string& gas3 = "", const double f3 = 0.,
28 const std::string& gas4 = "", const double f4 = 0.,
29 const std::string& gas5 = "", const double f5 = 0.,
30 const std::string& gas6 = "", const double f6 = 0.);
31 /// Retrieve the gas mixture.
32 void GetComposition(std::string& gas1, double& f1, std::string& gas2,
33 double& f2, std::string& gas3, double& f3,
34 std::string& gas4, double& f4, std::string& gas5,
35 double& f5, std::string& gas6, double& f6);
36 void GetComponent(const unsigned int i, std::string& label,
37 double& f) override;
38
39 void SetAtomicNumber(const double z) override;
40 double GetAtomicNumber() const override;
41 void SetAtomicWeight(const double a) override;
42 double GetAtomicWeight() const override;
43 void SetNumberDensity(const double n) override;
44 double GetNumberDensity() const override;
45 void SetMassDensity(const double rho) override;
46 double GetMassDensity() const override;
47
48 /// Read table of gas properties (transport parameters) from file.
49 bool LoadGasFile(const std::string& filename);
50 /// Save the present table of gas properties (transport parameters) to a file.
51 bool WriteGasFile(const std::string& filename);
52 /// Read table of gas properties from and merge with the existing dataset.
53 bool MergeGasFile(const std::string& filename, const bool replaceOld);
54
55 /** Switch on simulation of Penning transfers by means of
56 * transfer probabilities, for all excitation levels in the mixture.
57 * \param r transfer probability [0, 1]
58 * \param lambda parameter for sampling the distance of the Penning electron
59 with respect to the excitation.
60 */
61 virtual bool EnablePenningTransfer(const double r, const double lambda);
62 /// Switch on simulation of Penning transfers by means of
63 /// transfer probabilities, for all excitations of a given component.
64 virtual bool EnablePenningTransfer(const double r, const double lambda,
65 std::string gasname);
66 /// Switch the simulation of Penning transfers off globally.
67 virtual void DisablePenningTransfer();
68 /// Switch the simulation of Penning transfers off for a given component.
69 virtual bool DisablePenningTransfer(std::string gasname);
70
71 /// Print information about the present gas mixture and available data.
72 virtual void PrintGas();
73
74 /// Read a table of ion mobilities as function of electric field from file.
75 bool LoadIonMobility(const std::string& filename);
76
77 /// Adjust the Townsend coefficient using the excitation and ionisation
78 /// rates stored in the gas table and the Penning transfer probabilities.
80
81 void ResetTables() override;
82
83 void SetExtrapolationMethodExcitationRates(const std::string& low,
84 const std::string& high) {
85 SetExtrapolationMethod(low, high, m_extrExc, "ExcitationRates");
86 }
87 void SetExtrapolationMethodIonisationRates(const std::string& low,
88 const std::string& high) {
89 SetExtrapolationMethod(low, high, m_extrIon, "IonisationRates");
90 }
91 void SetInterpolationMethodExcitationRates(const unsigned int intrp) {
92 if (intrp > 0) m_intpExc = intrp;
93 }
94 void SetInterpolationMethodIonisationRates(const unsigned int intrp) {
95 if (intrp > 0) m_intpIon = intrp;
96 }
97
98 // Scaling laws.
99 // TODO: cache scaling factors.
100 double ScaleElectricField(const double e) const override {
101 return e * m_pressureTable / m_pressure;
102 }
103 double UnScaleElectricField(const double e) const override {
104 return e * m_pressure / m_pressureTable;
105 }
106 double ScaleDiffusion(const double d) const override {
107 return d * sqrt(m_pressureTable / m_pressure);
108 }
109 double ScaleDiffusionTensor(const double d) const override {
110 return d * m_pressureTable / m_pressure;
111 }
112 double ScaleTownsend(const double alpha) const override {
113 return alpha * m_pressure / m_pressureTable;
114 }
115 double ScaleAttachment(const double eta) const override {
116 return eta * m_pressure / m_pressureTable;
117 }
118 double ScaleLorentzAngle(const double lor) const override {
119 return lor * m_pressure / m_pressureTable;
120 }
121
122 bool GetPhotoAbsorptionCrossSection(const double e, double& sigma,
123 const unsigned int i) override;
124
125 protected:
126 static constexpr unsigned int m_nMaxGases = 6;
127
128 // Gas mixture
129 std::array<std::string, m_nMaxGases> m_gas;
130 std::array<double, m_nMaxGases> m_fraction;
131 std::array<double, m_nMaxGases> m_atWeight;
132 std::array<double, m_nMaxGases> m_atNum;
133
134 // Penning transfer
135 // Flag enabling/disabling Penning transfer
136 bool m_usePenning = false;
137 // Penning transfer probability
138 double m_rPenningGlobal = 0.;
139 // Mean distance of Penning ionisation
141 // Penning transfer probability per component
142 std::array<double, m_nMaxGases> m_rPenningGas;
143 // Penning transfer distance per component
144 std::array<double, m_nMaxGases> m_lambdaPenningGas;
145
146 // Pressure at which the transport parameter table was calculated
148 // Temperature at which the transport parameter table was calculated
150
151 // Table of Townsend coefficients without Penning transfer
152 std::vector<std::vector<std::vector<double> > > m_eAlp0;
153
154 // Tables for excitation and ionisation rates
155 std::vector<std::vector<std::vector<std::vector<double> > > > m_excRates;
156 std::vector<std::vector<std::vector<std::vector<double> > > > m_ionRates;
157
158 // Store excitation and ionization information
159 struct ExcLevel {
160 std::string label;
161 double energy;
162 double prob;
163 double rms;
164 double dt;
165 };
166 std::vector<ExcLevel> m_excLevels;
167
168 struct IonLevel {
169 std::string label;
170 double energy;
171 };
172 std::vector<IonLevel> m_ionLevels;
173
174 // Extrapolation/interpolation for excitation and ionisation rates.
175 std::pair<unsigned int, unsigned int> m_extrExc = {0, 1};
176 std::pair<unsigned int, unsigned int> m_extrIon = {0, 1};
177 unsigned int m_intpExc = 2;
178 unsigned int m_intpIon = 2;
179
180 bool ReadHeader(std::ifstream& gasfile, int& version,
181 std::bitset<20>& gasok, bool& is3d,
182 std::vector<double>& mixture,
183 std::vector<double>& efields, std::vector<double>& bfields,
184 std::vector<double>& angles, std::vector<ExcLevel>& excLevels,
185 std::vector<IonLevel>& ionLevels);
186 void ReadFooter(std::ifstream& gasfile,
187 std::array<unsigned int, 13>& extrapH,
188 std::array<unsigned int, 13>& extrapL,
189 std::array<unsigned int, 13>& interp,
190 unsigned int& thrAlp, unsigned int& thrAtt,
191 unsigned int& thrDis,
192 double& ionDiffL, double& ionDiffT,
193 double& pgas, double& tgas);
194 void ReadRecord3D(std::ifstream& gasfile, double& ve, double& vb, double& vx,
195 double& dl, double& dt, double& alpha, double& alpha0,
196 double& eta, double& mu, double& lor,
197 double& dis, std::array<double, 6>& dif,
198 std::vector<double>& rexc, std::vector<double>& rion);
199 void ReadRecord1D(std::ifstream& gasfile, double& ve, double& vb, double& vx,
200 double& dl, double& dt, double& alpha, double& alpha0,
201 double& eta, double& mu, double& lor,
202 double& dis, std::array<double, 6>& dif,
203 std::vector<double>& rexc, std::vector<double>& rion);
204 void InsertE(const int ie, const int ne, const int nb, const int na);
205 void InsertB(const int ib, const int ne, const int nb, const int na);
206 void InsertA(const int ia, const int ne, const int nb, const int na);
207 void ZeroRowE(const int ie, const int nb, const int na);
208 void ZeroRowB(const int ib, const int ne, const int na);
209 void ZeroRowA(const int ia, const int ne, const int nb);
210 bool GetMixture(const std::vector<double>& mixture, const int version,
211 std::vector<std::string>& gasnames,
212 std::vector<double>& percentages) const;
213 void GetGasBits(std::bitset<20>& gasok) const;
214
215 bool GetGasInfo(const std::string& gasname, double& a, double& z) const;
216 std::string GetGasName(const int gasnumber, const int version) const;
217 std::string GetGasName(std::string input) const;
218 int GetGasNumberGasFile(const std::string& input) const;
219};
220}
221
222#endif
Base class for gas media.
Definition: MediumGas.hh:15
double GetMassDensity() const override
Get the mass density [g/cm3].
Definition: MediumGas.cc:299
double GetNumberDensity() const override
Get the number density [cm-3].
Definition: MediumGas.cc:293
void SetExtrapolationMethodExcitationRates(const std::string &low, const std::string &high)
Definition: MediumGas.hh:83
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:755
bool AdjustTownsendCoefficient()
Definition: MediumGas.cc:2486
double ScaleElectricField(const double e) const override
Definition: MediumGas.hh:100
std::pair< unsigned int, unsigned int > m_extrIon
Definition: MediumGas.hh:176
void SetInterpolationMethodExcitationRates(const unsigned int intrp)
Definition: MediumGas.hh:91
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)
Retrieve the gas mixture.
Definition: MediumGas.cc:229
void SetAtomicNumber(const double z) override
Set the effective atomic number.
Definition: MediumGas.cc:260
bool GetGasInfo(const std::string &gasname, double &a, double &z) const
Definition: MediumGas.cc:2552
double ScaleDiffusion(const double d) const override
Definition: MediumGas.hh:106
static constexpr unsigned int m_nMaxGases
Definition: MediumGas.hh:126
std::vector< std::vector< std::vector< std::vector< double > > > > m_excRates
Definition: MediumGas.hh:155
void InsertB(const int ib, const int ne, const int nb, const int na)
Definition: MediumGas.cc:1646
double m_lambdaPenningGlobal
Definition: MediumGas.hh:140
void SetExtrapolationMethodIonisationRates(const std::string &low, const std::string &high)
Definition: MediumGas.hh:87
unsigned int m_intpIon
Definition: MediumGas.hh:178
std::vector< IonLevel > m_ionLevels
Definition: MediumGas.hh:172
std::array< double, m_nMaxGases > m_rPenningGas
Definition: MediumGas.hh:142
bool LoadIonMobility(const std::string &filename)
Read a table of ion mobilities as function of electric field from file.
Definition: MediumGas.cc:2215
double GetAtomicNumber() const override
Get the effective atomic number.
Definition: MediumGas.cc:303
std::array< double, m_nMaxGases > m_atNum
Definition: MediumGas.hh:132
void GetGasBits(std::bitset< 20 > &gasok) const
Definition: MediumGas.cc:2052
std::vector< std::vector< std::vector< std::vector< double > > > > m_ionRates
Definition: MediumGas.hh:156
void ZeroRowA(const int ia, const int ne, const int nb)
Definition: MediumGas.cc:1752
void ResetTables() override
Reset all tables of transport parameters.
Definition: MediumGas.cc:2292
std::vector< ExcLevel > m_excLevels
Definition: MediumGas.hh:166
void ZeroRowB(const int ib, const int ne, const int na)
Definition: MediumGas.cc:1744
MediumGas()
Constructor.
Definition: MediumGas.cc:112
double ScaleDiffusionTensor(const double d) const override
Definition: MediumGas.hh:109
int GetGasNumberGasFile(const std::string &input) const
Definition: MediumGas.cc:3055
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:813
double m_temperatureTable
Definition: MediumGas.hh:149
virtual void PrintGas()
Print information about the present gas mixture and available data.
Definition: MediumGas.cc:2072
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:789
std::array< double, m_nMaxGases > m_atWeight
Definition: MediumGas.hh:131
double ScaleTownsend(const double alpha) const override
Definition: MediumGas.hh:112
void GetComponent(const unsigned int i, std::string &label, double &f) override
Get the name and fraction of a given component.
Definition: MediumGas.cc:247
double UnScaleElectricField(const double e) const override
Definition: MediumGas.hh:103
bool WriteGasFile(const std::string &filename)
Save the present table of gas properties (transport parameters) to a file.
Definition: MediumGas.cc:1760
void SetInterpolationMethodIonisationRates(const unsigned int intrp)
Definition: MediumGas.hh:94
bool GetMixture(const std::vector< double > &mixture, const int version, std::vector< std::string > &gasnames, std::vector< double > &percentages) const
Definition: MediumGas.cc:895
std::array< double, m_nMaxGases > m_lambdaPenningGas
Definition: MediumGas.hh:144
std::pair< unsigned int, unsigned int > m_extrExc
Definition: MediumGas.hh:175
bool GetPhotoAbsorptionCrossSection(const double e, double &sigma, const unsigned int i) override
Definition: MediumGas.cc:3205
bool MergeGasFile(const std::string &filename, const bool replaceOld)
Read table of gas properties from and merge with the existing dataset.
Definition: MediumGas.cc:932
virtual void DisablePenningTransfer()
Switch the simulation of Penning transfers off globally.
Definition: MediumGas.cc:2431
std::string GetGasName(const int gasnumber, const int version) const
Definition: MediumGas.cc:2718
double GetAtomicWeight() const override
Get the effective atomic weight.
Definition: MediumGas.cc:284
void SetNumberDensity(const double n) override
Set the number density [cm-3].
Definition: MediumGas.cc:272
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:135
void ZeroRowE(const int ie, const int nb, const int na)
Definition: MediumGas.cc:1736
double ScaleLorentzAngle(const double lor) const override
Definition: MediumGas.hh:118
bool IsGas() const override
Is this medium a gas?
Definition: MediumGas.hh:22
double ScaleAttachment(const double eta) const override
Definition: MediumGas.hh:115
void SetMassDensity(const double rho) override
Set the mass density [g/cm3].
Definition: MediumGas.cc:278
virtual ~MediumGas()
Destructor.
Definition: MediumGas.hh:20
virtual bool EnablePenningTransfer(const double r, const double lambda)
Definition: MediumGas.cc:2302
std::vector< std::vector< std::vector< double > > > m_eAlp0
Definition: MediumGas.hh:152
void InsertA(const int ia, const int ne, const int nb, const int na)
Definition: MediumGas.cc:1694
bool LoadGasFile(const std::string &filename)
Read table of gas properties (transport parameters) from file.
Definition: MediumGas.cc:312
void InsertE(const int ie, const int ne, const int nb, const int na)
Definition: MediumGas.cc:1604
std::array< std::string, m_nMaxGases > m_gas
Definition: MediumGas.hh:129
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:579
void SetAtomicWeight(const double a) override
Set the effective atomic weight.
Definition: MediumGas.cc:266
unsigned int m_intpExc
Definition: MediumGas.hh:177
std::array< double, m_nMaxGases > m_fraction
Definition: MediumGas.hh:130
Abstract base class for media.
Definition: Medium.hh:13
double m_pressure
Definition: Medium.hh:506
void SetExtrapolationMethod(const std::string &low, const std::string &high, std::pair< unsigned int, unsigned int > &extr, const std::string &fcn)
Definition: Medium.cc:1100