89#include "TRestAxionBufferGas.h"
92#include "TRestSystemOfUnits.h"
117 RESTDebug <<
"Entering TRestAxionBufferGas constructor( cfgFileName, name )" <<
RESTendl;
137void TRestAxionBufferGas::Clear() {
155 while (gasDefinition) {
157 if (gasName.Contains(
"+")) {
158 TString gasDensity =
GetFieldValue(
"density", gasDefinition);
161 Double_t gasDensity = GetDblParameterWithUnits(
"density", gasDefinition);
195 std::vector<string> names =
Split((
string)gasMixture,
"+");
196 std::vector<string> densities;
197 if (gasDensities ==
"0")
200 densities =
Split((
string)gasDensities,
"+");
202 if (!densities.empty() && names.size() == densities.size()) {
203 for (
unsigned int n = 0; n < names.size(); n++) {
207 }
else if (densities.empty()) {
208 for (
unsigned int n = 0; n < names.size(); n++) {
212 this->
SetError(
"SetGasMixture. Number of gases does not match the densities!");
223 RESTError <<
"TRestAxionBufferGas::GetGasDensity. Gas name : " << gasName <<
" not found!"
242 TString factorFileName =
SearchFile((
string)gasName +
".nff");
244 RESTDebug <<
"TRestAxionBufferGas::ReadGasData. Reading factor file : " << factorFileName <<
RESTendl;
247 RESTError <<
"TRestAxionBufferGas::ReadGasData( " << gasName <<
" )" <<
RESTendl;
248 RESTError <<
"Gas factor file not found : " << factorFileName <<
RESTendl;
253 FILE* fin = fopen(factorFileName.Data(),
"rt");
257 std::vector<Double_t> energyFactor;
258 std::vector<Double_t> factor;
261 while (fscanf(fin,
"%lf\t%lf\n", &en, &value) != EOF) {
262 RESTDebug <<
"Energy : " << en <<
"keV -- Factor : " << value <<
RESTendl;
264 energyFactor.push_back(en);
265 factor.push_back(value);
268 RESTDebug <<
"Items read : " << energyFactor.size() <<
RESTendl;
273 TString absFileName =
SearchFile((
string)gasName +
".abs");
275 RESTDebug <<
"TRestAxionBufferGas::ReadGasData. Reading factor file : " << absFileName <<
RESTendl;
278 RESTError <<
"TRestAxionBufferGas::ReadGasData( " << gasName <<
" )" <<
RESTendl;
279 RESTError <<
"Gas absorption file not found : " << absFileName <<
RESTendl;
284 fin = fopen(absFileName.Data(),
"rt");
286 std::vector<Double_t> energyAbs;
287 std::vector<Double_t> absorption;
290 while (fscanf(fin,
"%lf\t%lf\n", &en, &value) != EOF) {
291 RESTDebug <<
"Energy : " << en <<
"keV -- Absorption : " << value <<
RESTendl;
293 energyAbs.push_back(en);
294 absorption.push_back(value);
297 RESTDebug <<
"Items read : " << energyAbs.size() <<
RESTendl;
323 RESTDebug <<
"TRestAxionBufferGas::GetFormFactor. Gas index = " << gasIndex <<
RESTendl;
325 if (gasIndex == -1) {
330 if (gasIndex == -1) {
331 RESTError <<
"TRestAxionBufferGas::GetFormFactor. Gas: " << gasName <<
" Not Found!" <<
RESTendl;
336 RESTDebug <<
"Energy index : " << energyIndex <<
RESTendl;
338 if (energyIndex == -1) {
339 RESTError <<
"TRestAxionBufferGas::GetFormFactor. Energy (" << energy <<
" keV) out of range"
352 double m = (y2 - y1) / (x2 - x1);
353 double n = y1 - m * x1;
355 if (m * energy + n < 0) {
356 RESTError <<
"TRestAxionBufferGas::GetAbsorptionCoefficient. Negative coefficient" <<
RESTendl;
357 cout <<
"y2 : " << y2 <<
" y1 : " << y1 << endl;
358 cout <<
"x2 : " << x2 <<
" x1 : " << x1 << endl;
359 cout <<
"m : " << m <<
" n : " << n << endl;
360 cout <<
"E : " << energy <<
" bin : " << energyIndex << endl;
364 return (m * energy + n);
372 Double_t attLength = 0;
401 Double_t photonMass = 0;
404 RESTError <<
"TRestAxionBufferGas::GetDensityForMass gas has not been defined!" <<
RESTendl;
407 Double_t W_value = 0;
415 RESTError <<
"Gas name : " <<
fBufferGasName[n] <<
" is not implemented in TRestBufferGas!!"
417 RESTError <<
"W value must be defined in TRestAxionBufferGas::GetPhotonMass" <<
RESTendl;
418 RESTError <<
"This gas will not contribute to the calculation of the photon mass!" <<
RESTendl;
425 return 28.77 * TMath::Sqrt(photonMass);
439 Double_t massDensity = 0;
442 RESTError <<
"TRestAxionBufferGas::GetDensityForMass gas has not been defined!" <<
RESTendl;
445 RESTError <<
"TRestAxionBufferGas::GetDensityForMass gas this method is only for sinale gas mixtures!"
448 Double_t W_value = 0;
456 RESTError <<
"Gas name : " <<
fBufferGasName[0] <<
" is not implemented in TRestAxionBufferGas!!"
458 RESTError <<
"W value must be defined in TRestAxionBufferGas::GetDensityForMass" <<
RESTendl;
459 RESTError <<
"This gas will not contribute to the calculation of the photon mass!" <<
RESTendl;
465 return massDensity /
units(
"g/cm^3");
474 RESTDebug <<
"TRestAxionBufferGas::GetAbsorptionCoefficient. Gas index = " << gasIndex <<
RESTendl;
476 if (gasIndex == -1) {
481 if (gasIndex == -1) {
482 RESTError <<
"TRestAxionBufferGas::GetAbsorptionCoefficient. Gas: " << gasName <<
" Not Found!"
488 RESTDebug <<
"Energy index : " << energyIndex <<
RESTendl;
490 if (energyIndex == -1) {
491 RESTError <<
"TRestAxionBufferGas::GetAbsorptionCoefficient. Energy out of range" <<
RESTendl;
500 double x2 =
fAbsEnergy[gasIndex][energyIndex + 1];
501 double x1 =
fAbsEnergy[gasIndex][energyIndex];
503 double m = (y2 - y1) / (x2 - x1);
504 double n = y1 - m * x1;
506 if (m * energy + n < 0) {
507 RESTError <<
"TRestAxionBufferGas::GetAbsorptionCoefficient. Negative coeffient" <<
RESTendl;
508 cout <<
"y2 : " << y2 <<
" y1 : " << y1 << endl;
509 cout <<
"x2 : " << x2 <<
" x1 : " << x1 << endl;
510 cout <<
"m : " << m <<
" n : " << n << endl;
511 cout <<
"E : " << energy <<
" bin : " << energyIndex << endl;
515 return (m * energy + n);
522 for (
unsigned int n = 0; n < enVector.size(); n++)
523 if (energy < enVector[n])
return n - 1;
534 for (
int n = 0; n < nGases; n++)
550 for (
unsigned int n = 0; n <
fAbsEnergy[gasIndex].size(); n++)
551 cout <<
"energy : " <<
fAbsEnergy[gasIndex][n]
562 for (
unsigned int n = 0; n <
fAbsEnergy[gasIndex].size(); n++)
575 RESTMetadata <<
"Buffer medium is vacuum" <<
RESTendl;
579 RESTMetadata <<
"Buffer gases inside mixture : " <<
RESTendl;
580 RESTMetadata <<
"---------------------------" <<
RESTendl;
585 RESTMetadata <<
" Form factor energy range : ( " <<
fFactorEnergy[n][0] <<
", "
587 RESTMetadata <<
" Absorption energy range : ( " <<
fAbsEnergy[n][0] <<
", "
593 RESTMetadata <<
"+++++++++++++++++++++++++++++++++++++++++++++++++" <<
RESTendl;
A metadata class to define the gas properties used in axion search calculations.
TRestAxionBufferGas()
Default constructor.
Int_t GetNumberOfGases()
It returns the number of gases in the mixture.
void Initialize()
Initialization of TRestAxionBufferGas members. It removes all gases.
void InitFromConfigFile()
Initialization of TRestAxionBufferGas field members through a RML file.
void PrintMetadata()
Prints on screen the information about the metadata members of TRestAxionBufferGas.
Double_t cmToeV(double l_Inv)
It transforms cm-1 to eV.
std::vector< std::vector< Double_t > > fGasFormFactor
Gas form factor.
void PrintFormFactorGasData(TString gasName)
Prints out the atomic form factors as function of the energy for the given gas component,...
std::vector< std::vector< Double_t > > fGasAbsCoefficient
Gas absorption coefficient in cm2/g.
Int_t GetEnergyIndex(std::vector< Double_t > enVector, Double_t energy)
It returns the vector element index, from enVector, that is just below the given input energy.
Double_t GetPhotonMass(double en)
It returns the equivalent photon mass (in eV) for the gas mixture at the given input energy expressed...
std::vector< std::vector< Double_t > > fFactorEnergy
Energy values for gas form factor in keV.
std::vector< Double_t > fBufferGasDensity
Gas density of the corresponding gasName in g/cm3.
Double_t GetGasDensity(TString gasName)
It returns the gas density - from the chosen gasName component - in g/cm3.
void ReadGasData(TString gasName)
It reads the data files from the corresponding gas component.
Double_t GetDensityForMass(double m_gamma, double en=4.2)
It returns the equivalent gas density for a given photon mass expressed in eV and a given axion energ...
void SetGasDensity(TString gasName, Double_t density)
It adds a new gas component to the mixture. If it already exists it will update its density.
Int_t FindGasIndex(TString gName)
It returns the internal index of the gas component given by gasName.
std::vector< TString > fBufferGasName
Name of the buffer gas (He, Ne, Ar, Xe, ..., etc )
void PrintAbsorptionGasData(TString gasName)
Prints out the absorption coefficients as function of the energy for the given gas component,...
Double_t GetPhotonAbsorptionLengthIneV(Double_t energy)
It returns the inverse of the absorption lenght, for the gas mixture, in eV, for the given energy in ...
void SetGasMixture(TString gasMixture, TString gasDensities="0")
It re-initializes the gas mixture to the one provided by argument.
std::vector< std::vector< Double_t > > fAbsEnergy
Energy values for gas absorption coefficient in keV.
Double_t GetAbsorptionCoefficient(TString gasName, Double_t energy)
It returns the absorption coefficient, in cm2/g, for the given gas component and energy in keV.
Double_t GetFormFactor(TString gasName, Double_t energy)
It returns the atomic form factor of the gasName component at the given energy.
Double_t GetPhotonAbsorptionLength(Double_t energy)
It returns the inverse of the absorption lenght, for the gas mixture, in cm-1, for the given energy i...
~TRestAxionBufferGas()
Default destructor.
@ REST_Info
+show most of the information for each steps
constexpr double PhMeterIneV
A meter in eV.
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
std::vector< std::string > Split(std::string in, std::string separator, bool allowBlankString=false, bool removeWhiteSpaces=false, int startPos=-1)
Split the input string according to the given separator. Returning a vector of fragments.
This namespace defines the unit conversion for different units which are understood by REST.
Double_t GetValueInRESTUnits(std::string in)
It scales a physics measurement with its units into a REST default units value.