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