REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestAxionXrayWindow.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
96
97#include "TRestAxionXrayWindow.h"
98using namespace std;
99
100#include "TRestSystemOfUnits.h"
101using namespace REST_Units;
102
103ClassImp(TRestAxionXrayWindow);
104
109
124TRestAxionXrayWindow::TRestAxionXrayWindow(const char* cfgFileName, string name)
125 : TRestMetadata(cfgFileName) {
126 RESTDebug << "Entering TRestAxionXrayWindow constructor( cfgFileName, name )" << RESTendl;
127
128 Initialize();
129
131}
132
137
142 SetSectionName(this->ClassName());
143 SetLibraryVersion(LIBRARY_VERSION);
144
145 fEnergy.clear();
146 fTransmission.clear();
147
148 /*
149if (fWindowType != "foil" && fPatternGap == 0) {
150 RESTError << "TRestAxionXrayWindow::Initialize. fPatternGap cannot be zero!" << RESTendl;
151 fPatternGap = 1;
152}
153
154if (fPatternGap < 0) fPatternGap = -fPatternGap;
155 */
156}
157
164 std::string materialFileName = SearchFile(fMaterial + ".sol");
165
166 RESTDebug << "TRestAxionXrayWindow::ReadMaterial. Reading file : " << materialFileName << RESTendl;
167
168 if (!TRestTools::fileExists(materialFileName)) {
169 RESTError << "TRestAxionXrayWindow::ReadMaterial( )" << RESTendl;
170 RESTError << "Material file not found : " << materialFileName << RESTendl;
171 exit(1);
172 }
173
174 FILE* fin = fopen(materialFileName.c_str(), "rt");
175
176 fEnergy.clear();
177 fTransmission.clear();
178 double en, value;
179 while (fscanf(fin, "%lf\t%lf\n", &en, &value) != EOF) {
180 RESTDebug << "Energy : " << en << "eV -- Abs : " << value << RESTendl;
181
182 fEnergy.push_back(en / 1000.);
183 fTransmission.push_back(TMath::Power(value, fThickness * units("um")));
184 }
185
186 RESTDebug << "Items read : " << fEnergy.size() << RESTendl;
187
188 fclose(fin);
189}
190
198Double_t TRestAxionXrayWindow::GetTransmission(Double_t energy, Double_t x, Double_t y) {
199 if (fMaterial != "Vacuum" && fEnergy.size() == 0) ReadMaterial();
200
201 if (fMask && x * x + y * y > fMask->GetMaskRadius() * fMask->GetMaskRadius()) return 0;
202
203 if (fMask && !fMask->HitsPattern(x, y)) return 1.;
204
205 // This line must be after all previous cuts to make sure mask limits do an effect
206 if (fMaterial == "Vacuum") return 1;
207
208 Double_t energyIndex = GetEnergyIndex(energy);
209
210 if (energyIndex < 0) {
211 RESTWarning << "Energy : " << energy << " keV is out of range!" << RESTendl;
212 return 0;
213 }
214
215 // Transmission
216 double y2 = fTransmission[energyIndex + 1];
217 double y1 = fTransmission[energyIndex];
218
219 // Normalized field
220 double x2 = fEnergy[energyIndex + 1];
221 double x1 = fEnergy[energyIndex];
222
223 double m = (y2 - y1) / (x2 - x1);
224 double n = y1 - m * x1;
225
226 if (m * energy + n < 0) {
227 RESTError << "TRestAxionXrayWindow::GetAbsorptionCoefficient. Negative coefficient!" << RESTendl;
228 cout << "y2 : " << y2 << " y1 : " << y1 << endl;
229 cout << "x2 : " << x2 << " x1 : " << x1 << endl;
230 cout << "m : " << m << " n : " << n << endl;
231 cout << "E : " << energy << " bin : " << energyIndex << endl;
232 return 0;
233 }
234
235 return (m * energy + n);
236}
237
241Bool_t TRestAxionXrayWindow::HitsPattern(Double_t x, Double_t y) {
242 if (fMask) return fMask->HitsPattern(x, y);
243
244 /*
245if (fWindowType == "stripped") {
246 Double_t xEval = fPatternWidth / 2. + x - fPatternOffset;
247
248 if (xEval > 0) {
249 while (xEval > fPatternGap) xEval -= fPatternGap;
250 } else {
251 while (xEval < 0) xEval += fPatternGap;
252 }
253
254 if (xEval > fPatternWidth) {
255 return false;
256 }
257} else if (fWindowType == "grid") {
258 Double_t xEval = fPatternWidth / 2. + x - fPatternOffset;
259
260 if (xEval > 0) {
261 while (xEval > fPatternGap) xEval -= fPatternGap;
262 } else {
263 while (xEval < 0) xEval += fPatternGap;
264 }
265
266 if (xEval < fPatternWidth) return true;
267
268 Double_t yEval = fPatternWidth / 2. + y - fPatternOffset;
269
270 if (yEval > 0) {
271 while (yEval > fPatternGap) yEval -= fPatternGap;
272 } else {
273 while (yEval < 0) yEval += fPatternGap;
274 }
275
276 if (yEval < fPatternWidth) return true;
277 return false;
278}
279 */
280
281 return true;
282}
283
288 for (unsigned int n = 0; n < fEnergy.size(); n++)
289 if (energy < fEnergy[n]) return n - 1;
290 return -1;
291}
292
298 if (fEnergy.size() == 0) ReadMaterial();
299 for (unsigned int n = 0; n < fEnergy.size(); n++)
300 cout << "Energy : " << fEnergy[n] << " Transmission : " << fTransmission[n] << endl;
301}
302
308
309 if (fMask) {
310 delete fMask;
311 fMask = nullptr;
312 }
314
315 if (!fMask) {
316 RESTWarning << "TRestAxionXrayWindow. Name : " << this->GetName() << RESTendl;
317 RESTWarning << "No mask pattern was defined for the X-ray window!" << RESTendl;
318 }
319}
320
326
327 RESTMetadata << "Thickness: " << fThickness * units("um") << " um" << RESTendl;
328 RESTMetadata << "Material: " << fMaterial << RESTendl;
329 RESTMetadata << "----" << RESTendl;
330 if (fMask) {
331 fMask->Print();
332 } else {
333 RESTMetadata << " - Pattern type: foil" << RESTendl;
334 }
335
336 RESTMetadata << "+++++++++++++++++++++++++++++++++++++++++++++++++" << RESTendl;
337}
A metadata class to create x-ray transmission window definitions.
Double_t GetTransmission(Double_t energy, Double_t x, Double_t y)
It returns the window transmission probability for the given energy (in keV) and window position,...
void PrintTransmissionData()
Prints out the transmission probability curve loaded in memory. for debugging pourposes.
Bool_t HitsPattern(Double_t x, Double_t y)
It returns true if the window pattern is hitted. False otherwise.
void Initialize()
Initialization of TRestAxionXrayWindow members. It removes all gases.
Int_t GetEnergyIndex(Double_t energy)
It returns the vector element index, from fEnergy, that is just below the given input energy.
std::vector< Double_t > fTransmission
A vector with the transmission already renormalized using the material thickness. Not stored in disk.
void PrintMetadata()
Prints on screen the information about the metadata members of TRestAxionXrayWindow.
TRestPatternMask * fMask
A mask defining a pattern where the transmission will be effective.
TRestAxionXrayWindow()
Default constructor.
~TRestAxionXrayWindow()
Default destructor.
std::string fMaterial
Window material name.
void InitFromConfigFile()
To make settings from rml file. This method must be implemented in the derived class.
void ReadMaterial()
It reads the data files from the corresponding material that needs to be found in the axiolib databas...
Double_t fThickness
Thicknesss of window material in mm.
std::vector< Double_t > fEnergy
A vector with the energies loaded from the material file. Not stored in disk.
A base class for any REST metadata class.
Definition: TRestMetadata.h:74
virtual void PrintMetadata()
Implemented it in the derived metadata class to print out specific metadata information.
endl_t RESTendl
Termination flag object for TRestStringOutput.
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
TRestMetadata * InstantiateChildMetadata(int index, std::string pattern="")
This method will retrieve a new TRestMetadata instance of a child element of the present TRestMetadat...
virtual void InitFromConfigFile()
To make settings from rml file. This method must be implemented in the derived class.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void Print()
Implementing TObject::Print() method.
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string SearchFile(std::string filename)
Search files in current directory and directories specified in "searchPath" section.
std::string fConfigFileName
Full name of the rml file.
An abstract class used to encapsulate different mask pattern class definitions.
Double_t GetMaskRadius()
It returns the mask radius.
Bool_t HitsPattern(Double_t x, Double_t y)
Returns true if the pattern was hit. If (x,y) it is inside a region then, the pattern was not hit by ...
static bool fileExists(const std::string &filename)
Returns true if the file (or directory) with path filename exists.
Definition: TRestTools.cxx:728
This namespace defines the unit conversion for different units which are understood by REST.