77 #ifndef __FileDoesNotExistException_h 98 inline std::vector<double>
logspace(
const double &a,
104 for (
int i = 0; i < k; i++)
106 logspace.push_back(pow(10, i * (b - a) / (k - 1)));
158 std::vector<std::string> p_supported_scintillator_material_set;
160 p_supported_scintillator_material_set.push_back(
"Cesium iodine");
161 p_supported_scintillator_material_set.push_back(
"Cadmium tungstate");
162 p_supported_scintillator_material_set.push_back(
"Yttrium oxyde");
163 p_supported_scintillator_material_set.push_back(
"Gadolinum oxyde");
164 p_supported_scintillator_material_set.push_back(
"Yttrium gadolinum oxyde");
165 p_supported_scintillator_material_set.push_back(
"Gadolinum silicate");
166 p_supported_scintillator_material_set.push_back(
"Gadox");
167 p_supported_scintillator_material_set.push_back(
"Gadox DRZ-Plus");
168 p_supported_scintillator_material_set.push_back(
"Sodium iodine");
169 p_supported_scintillator_material_set.push_back(
"Lanthanum hafnate");
170 p_supported_scintillator_material_set.push_back(
"Gadolinium gallium garnet");
171 p_supported_scintillator_material_set.push_back(
"Yttrium aluminium garnate");
173 return p_supported_scintillator_material_set;
218 std::vector<std::pair<RATIONAL_NUMBER, RATIONAL_NUMBER> > p_energy_response;
222 if (aMaterial.size() > 0 && aThickness > 1 *
um)
229 std::vector<double> energy_range =
logspace(0., 2.48, 1000);
233 for (std::vector<double>::const_iterator ite_energy = energy_range.begin();
234 ite_energy != energy_range.end();
238 double energy = *ite_energy *
keV;
240 double response = 0.0;
244 double mu_rho = CS_Total_CP(compound.c_str(), energy /
keV, 0);
247 double mu_en_rho = CS_Energy_CP(compound.c_str(), energy /
keV, 0);
253 double mu = mu_rho * density;
256 double mu_en = mu_en_rho * density;
259 double thickness = aThickness /
cm;
262 response = energy * (mu_en / mu) * (1.0 - exp(-mu * thickness));
264 p_energy_response.push_back(std::pair<RATIONAL_NUMBER, RATIONAL_NUMBER>(energy, response));
268 return p_energy_response;
277 if (aMaterial ==
"CsI" || aMaterial ==
"Cesium iodine")
279 return 4.52 *
g /
cm3;
282 else if (aMaterial ==
"CdWO4" || aMaterial ==
"CWO" || aMaterial ==
"Cadmium tungstate")
284 return 7.9 *
g /
cm3;
287 else if (aMaterial ==
"Y2O3" || aMaterial ==
"Yttrium oxyde")
289 return 5.01 *
g /
cm3;
292 else if (aMaterial ==
"Gd2O3" || aMaterial ==
"Gadolinum oxyde")
294 return 7.55 *
g /
cm3;
297 else if (aMaterial ==
"(Y,Gd)2O3" || aMaterial ==
"YGO" || aMaterial ==
"Yttrium gadolinum oxyde")
299 return 5.9 *
g /
cm3;
302 else if (aMaterial ==
"Gd2O2S" || aMaterial ==
"Gadox" || aMaterial ==
"Gadolinum silicate" || aMaterial ==
"GOS")
304 return 7.34 *
g /
cm3;
307 else if (aMaterial ==
"Gd2O2S DRZ-Plus" || aMaterial ==
"Gadox DRZ-Plus")
309 return 4.76 *
g /
cm3;
312 else if (aMaterial ==
"NaI" || aMaterial ==
"Sodium iodine")
314 return 3.67 *
g /
cm3;
317 else if (aMaterial ==
"La2HfO7" || aMaterial ==
"Lanthanum hafnate")
319 return 7.9 *
g /
cm3;
322 else if (aMaterial ==
"Gd3Ga5O12" || aMaterial ==
"Gadolinium gallium garnet")
324 return 7.09 *
g /
cm3;
327 else if (aMaterial ==
"Y3Al5O12" || aMaterial ==
"Yttrium aluminium garnate" || aMaterial ==
"YAG")
329 return 4.55 *
g /
cm3;
333 throw Exception(__FILE__, __FUNCTION__, __LINE__,
334 std::string(
"This material (") + aMaterial +
") is not supported. Contact Franck Vidal if you think it should be added.");
344 if (aMaterial ==
"CsI" || aMaterial ==
"Cesium iodine")
349 else if (aMaterial ==
"CdWO4" || aMaterial ==
"CWO" || aMaterial ==
"Cadmium tungstate")
354 else if (aMaterial ==
"Y2O3" || aMaterial ==
"Yttrium oxyde")
359 else if (aMaterial ==
"Gd2O3" || aMaterial ==
"Gadolinum oxyde")
364 else if (aMaterial ==
"(Y,Gd)2O3" || aMaterial ==
"YGO" || aMaterial ==
"Yttrium gadolinum oxyde")
369 else if (aMaterial ==
"Gd2O2S" || aMaterial ==
"Gadox" || aMaterial ==
"Gadolinum silicate" || aMaterial ==
"GOS")
374 else if (aMaterial ==
"Gd2O2S DRZ-Plus" || aMaterial ==
"Gadox DRZ-Plus")
379 else if (aMaterial ==
"NaI" || aMaterial ==
"Sodium iodine")
384 else if (aMaterial ==
"La2HfO7" || aMaterial ==
"Lanthanum hafnate")
389 else if (aMaterial ==
"Gd3Ga5O12" || aMaterial ==
"Gadolinium gallium garnet")
394 else if (aMaterial ==
"Y3Al5O12" || aMaterial ==
"Yttrium aluminium garnate" || aMaterial ==
"YAG")
400 throw Exception(__FILE__, __FUNCTION__, __LINE__,
401 std::string(
"This material (") + aMaterial +
") is not supported. Contact Franck Vidal if you think it should be added.");
415 std::ifstream energy_response_input_stream(aFileName.c_str());
418 if (!energy_response_input_stream.is_open())
425 double output_energy;
426 while (energy_response_input_stream >> input_energy >> output_energy)
429 if (!energy_response_input_stream.eof())
431 input_energy *= aUnitOfEnergy;
432 output_energy *= aUnitOfEnergy;
434 m_p_energy_response.push_back(std::pair<RATIONAL_NUMBER, RATIONAL_NUMBER>(input_energy, output_energy));
466 for (std::vector<std::pair<double, double> >::const_iterator ite = anEnergyResponse.begin();
467 ite != anEnergyResponse.end();
470 m_p_energy_response.push_back(std::pair<RATIONAL_NUMBER, RATIONAL_NUMBER>(ite->first, ite->second));
480 if (!m_p_energy_response.size())
486 if (m_p_energy_response.front().first >= anEnergy)
return m_p_energy_response.front().second;
487 if (m_p_energy_response.back().first <= anEnergy)
return m_p_energy_response.back().second;
490 int nearest_energy_idx = findNearestEnergyIdx(anEnergy);
494 m_p_energy_response[nearest_energy_idx + 1].first,
496 m_p_energy_response[nearest_energy_idx].second,
497 m_p_energy_response[nearest_energy_idx + 1].second);
499 return corrected_energy;
508 if (!m_p_energy_response.size())
513 if (m_p_energy_response.front().first >= anEnergy)
return 0;
514 if (m_p_energy_response.back().first <= anEnergy)
return (m_p_energy_response.size() - 1);
516 for (
int i = 0; i < m_p_energy_response.size() - 1; ++i)
518 if (m_p_energy_response[i].first <= anEnergy && anEnergy <= m_p_energy_response[i + 1].first)
return i;
521 return (m_p_energy_response.size() - 1);
RATIONAL_NUMBER m_thickness
static RATIONAL_NUMBER getDensity(const std::string &aMaterial)
int findNearestEnergyIdx(const RATIONAL_NUMBER &anEnergy) const
Find the index of the closest input energy in the energy response.
static std::vector< std::string > getSupportedScintillatorMaterials()
Accessor on the list of scintillator materials currently supported.
const double cm3
cubic centimeter
void setMaterial(const std::string &aMaterial)
RATIONAL_NUMBER getThickness()
FileDoesNotExistException is a class to handle exceptions when trying to open a read-only file that i...
Exception is a class to handle exceptions.
Class to handle exceptions when trying to open a read-only file that is not accessible.
#define EPSILON
Smallest value that can be stored with a real number.
Generic class to handle exceptions.
const std::string & getMaterial() const
~Scintillator()
Destructor.
const double um
micrometre
float RATIONAL_NUMBER
Type of data used to store real numbers.
const double keV
kiloelectron volt
Some utility functions that do not fit anywhere else.
RATIONAL_NUMBER m_density
const double cm
centimeter
std::vector< std::pair< RATIONAL_NUMBER, RATIONAL_NUMBER > > m_p_energy_response
Energy response. The keys of the map are the input energies.
static std::string getCompound(const std::string &aMaterial)
Units, such as meters, etc.
std::vector< std::pair< RATIONAL_NUMBER, RATIONAL_NUMBER > > getEnergyResponse() const
void setEnergyResponse(const std::vector< std::pair< float, float > > &anEnergyResponse)
std::vector< double > logspace(const double &a, const double &b, const int &k)
void release()
Release the data.
void loadEnergyResponse(const std::string &aFileName, const RATIONAL_NUMBER &aUnitOfEnergy)
Load the energy response of the detector from a TSV file.
Scintillator()
Default constructor.
void setThickness(const RATIONAL_NUMBER &aThickness)
double interpolate(const double &a_low, const double &a_high, const double &a0, const double &b_low, const double &b_high)
RATIONAL_NUMBER applyEnergyResponse(const RATIONAL_NUMBER &anEnergy) const
Apply the energy response if any.