fisx: fisx_elements.h Source File

fisx

fisx_elements.h
Go to the documentation of this file.
1 #/*##########################################################################
2 #
3 # The fisx library for X-Ray Fluorescence
4 #
5 # Copyright (c) 2014-2022 European Synchrotron Radiation Facility
6 #
7 # This file is part of the fisx X-ray developed by V.A. Sole
8 #
9 # Permission is hereby granted, free of charge, to any person obtaining a copy
10 # of this software and associated documentation files (the "Software"), to deal
11 # in the Software without restriction, including without limitation the rights
12 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 # copies of the Software, and to permit persons to whom the Software is
14 # furnished to do so, subject to the following conditions:
15 #
16 # The above copyright notice and this permission notice shall be included in
17 # all copies or substantial portions of the Software.
18 #
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 # THE SOFTWARE.
26 #
27 #############################################################################*/
28 #ifndef FISX_ELEMENTS_H
29 #define FISX_ELEMENTS_H
30
37 #include <string>
38 #include <vector>
39 #include <map>
40 #include "fisx_simplespecfile.h"
41 #include "fisx_element.h"
42 #include "fisx_epdl97.h"
43 #include "fisx_material.h"
44
45 namespace fisx
46 {
47
56 #ifndef FISX_DATA_DIR
57 #define FISX_DATA_DIR ""
58 #endif
59
60 class Elements
61 {
62
63 public:
67 static const std::string defaultDataDir();
68
69
73 Elements(std::string dataDirectory="");
74
82 Elements(std::string dataDirectory, short pymca);
83
93 Elements(std::string dataDirectory, std::string bindingEnergiesFile, std::string crossSectionsFile="");
94
95 // Direct element handling
99 bool isElementNameDefined(const std::string & elementName) const;
100
104 const Element & getElement(const std::string & elementName) const;
105
109 Element getElementCopy(const std::string & elementName);
110
111 // function to ADD or REPLACE if already existing an element
115 void addElement(const Element & elementInstance);
116
120 std::vector<std::string> getElementNames();
121
122
129 std::map<std::string, double> getEmittedXRayLines(const std::string & elementName, \
130 const double & energy= 1000.) const;
131
132
136 const std::map<std::string, double> & getNonradiativeTransitions(const std::string & elementName, \
137 const std::string & subshell) const;
138
142 const std::map<std::string, double> & getRadiativeTransitions(const std::string & elementName, \
143 const std::string & subshell) const;
144
153 std::map<std::string, std::vector <double> >getInitialPhotoelectricVacancyDistribution(\
154 const std::string & elementName,
155 const std::vector<double> & energies) const;
156
165 std::map<std::string, double> getInitialPhotoelectricVacancyDistribution(\
166 const std::string & elementName,
167 const double & energy) const;
168
169 std::map<std::string, double> getCascadeModifiedVacancyDistribution(const std::string & elementName,
170 const std::map<std::string, \
171 double> & distribution) const;
172
187 std::map<std::string, std::map<std::string, double> >\
188 getXRayLinesFromVacancyDistribution(const std::string & elementName,
189 const std::map<std::string, double> & distribution, \
190 const int & cascade = 1,
191 const int & useFluorescenceYield = 1) const;
192
193 // shell related functions
197 std::map<std::string, double> getShellConstants(const std::string & elementName, \
198 const std::string & subshell) const;
199
203 void setShellConstantsFile(const std::string & mainShellName, const std::string & fileName);
204
209 void setShellRadiativeTransitionsFile(const std::string & mainShellName, \
210 const std::string & fileName);
211
216 void setShellNonradiativeTransitionsFile(const std::string & mainShellName, \
217 const std::string & fileName);
218
219
220
224 const std::string & getShellConstantsFile(const std::string & mainShellName) const;
225
230 const std::string & getShellRadiativeTransitionsFile(const std::string & mainShellName) const;
231
236 const std::string & getShellNonradiativeTransitionsFile(const std::string & mainShellName) const;
237
238 // mass attenuation related functions
243 void setMassAttenuationCoefficientsFile(const std::string & fileName);
244
250 void setMassAttenuationCoefficients(const std::string & elementName, \
251 const std::vector<double> & energy, \
252 const std::vector<double> & photoelectric, \
253 const std::vector<double> & coherent, \
254 const std::vector<double> & compton,\
255 const std::vector<double> & pair);
256
260 std::map<std::string, std::vector<double> > getMassAttenuationCoefficients( \
261 const std::string & elementName) const;
262
268 std::map<std::string, std::vector<double> > getMassAttenuationCoefficients( \
269 const std::string & formula,
270 const std::vector<double> & energies) const;
271
277 std::map<std::string, std::vector<double> > getMassAttenuationCoefficients(\
278 std::map<std::string, double> elementMassFractions,\
279 std::vector<double> energies) const;
280
281
288 std::map<std::string, double> getMassAttenuationCoefficients(std::string formula, double energy) const;
289
295 std::map<std::string, double> getMassAttenuationCoefficients(\
296 std::map<std::string, double> elementMassFractions,\
297 double energies) const;
298
299 // Material handling
304 Material createMaterial(const std::string & name, const double & density = 1.0,
305 const double & thickness = 1.0, const std::string & comment = "");
306
314 void setMaterialComposition(const std::string & materialName, \
315 const std::map<std::string, double> & composition);
316
322 void setMaterialComposition(const std::string & materialName, \
323 const std::vector<std::string> & names,\
324 const std::vector<double> & amounts);
325
329 const Material & getMaterial(const std::string & materialName);
330
334 std::vector<std::string> getMaterialNames();
335
339 Material getMaterialCopy(const std::string & materialName);
340
344 void addMaterial(const Material & materialInstance, const int & errorOnReplace = 1);
345
349 void addMaterial(const std::string & name, const double & density = 1.0, \
350 const double & thickness = 1.0, const std::string & comment = "", \
351 const int & errorOnReplace = 1);
352
356 void removeMaterial(const std::string & name);
357
361 void removeMaterials();
362
367 std::map<std::string, double> getCompositionFromFormula(const std::string & formula) const;
368
374 std::map<std::string, double> getComposition(const std::string & name) const;
375
382 std::map<std::string, double> getComposition(const std::string & name, \
383 const std::vector<Material> & materials) const;
384
389 std::map<std::string, double> parseFormula(const std::string & formula) const;
390
396 std::vector<std::map<std::string, std::map<std::string, double> > > getExcitationFactors( \
397 const std::string & element,
398 const std::vector<double> & energy,
399 const std::vector<double> & weights = std::vector<double>()) const;
400
406 std::map<std::string, std::map<std::string, double> > getExcitationFactors( \
407 const std::string & element,
408 const double & energy, \
409 const double & weights = 1.0) const;
410
415 std::vector<std::pair<std::string, double> > getPeakFamilies(const std::string & name, \
416 const double & energy) const;
417
418
423 std::vector<std::pair<std::string, double> > getPeakFamilies(const std::vector<std::string> & elementList, \
424 const double & energy) const;
425
426
430 const double & getAtomicMass(const std::string & name) const;
431
435 const int & getAtomicNumber(const std::string & name) const;
436
437
441 const std::map<std::string, double> & getBindingEnergies(const std::string & name) const;
442
446 double getDensity(const std::string & name) const;
447
451 std::string getLongName(const std::string & name) const;
452
456 int getColumn(const std::string & name) const;
457
461 int getRow(const std::string & name) const;
462
484 std::map<std::string, std::map<std::string, double> > getEscape(const std::map<std::string, double> & composition, \
485 const double & energy, \
486 const double & energyThreshold = 0.010, \
487 const double & intensityThreshold = 1.0e-7, \
488 const int & nThreshold = 4 , \
489 const double & alphaIn = 90.,\
490 const double & thickness = 0.0) const;
491
496 void updateEscapeCache(const std::map<std::string, double> & composition, \
497 const std::vector<double> & energy, \
498 const double & energyThreshold = 0.010, \
499 const double & intensityThreshold = 1.0e-7, \
500 const int & nThreshold = 4 , \
501 const double & alphaIn = 90.,\
502 const double & thickness = 0.0);
503
508 void setElementCascadeCacheEnabled(const std::string & elementName, const int & flag = 1);
509 int isElementCascadeCacheFilled(const std::string & elementName) const;
510 void fillElementCascadeCache(const std::string & elementName);
511 void emptyElementCascadeCache(const std::string & elementName);
512 void setEscapeCacheEnabled(const int & flag = 1){this->escapeCacheEnabled = flag;};
513 int isEscapeCacheEnabled() const {return this->escapeCacheEnabled;};
514
519 void fillCache(const std::string & elementName, const std::vector< double> & energy);
520
525 void setCacheEnabled(const std::string & elementName, const int & flag = 1);
526
531 void updateCache(const std::string & elementName, const std::vector< double> & energy);
532
536 void clearCache(const std::string & elementName);
537
541 void clearEscapeCache(void);
542
546 const int isCacheEnabled(const std::string & elementName) const;
547
551 int getCacheSize(const std::string & elementName) const;
552
556 static bool stringToDouble(const std::string & str, double& number);
557
561 static std::string toString(const double& number);
562
563 private:
564
565 void initialize(std::string, std::string);
566
567 // The EPDL97 library
568 EPDL97 epdl97;
569
570 // The map of defined elements
571 // The map has the form Element Name, Index
572 std::map<std::string , int> elementDict;
573
574 // The vector of defined elements
575 std::vector<Element> elementList;
576
577 // The vector of defined Materials
578 std::vector<Material> materialList;
579
580 // Utility function
581 const std::vector<Material>::size_type getMaterialIndexFromName(const std::string & name) const;
582
583 // The files used for configuring the library
584 std::map<std::string, std::string> shellConstantsFile;
585 std::map<std::string, std::string> shellRadiativeTransitionsFile;
586 std::map<std::string, std::string> shellNonradiativeTransitionsFile;
587
588 // A cache of escape peaks
589 std::map< double, std::map<std::string,std::map<std::string, double> > > detectorEscapeCache;
590 std::map< std::string, double> detectorCompositionUsedInCache;
591 double detectorEnergyThresholdUsedInCache;
592 double detectorIntensityThresholdUsedInCache;
593 int detectorNThresholdUsedInCache;
594 double detectorAlphaInUsedInCache;
595 double detectorThicknessUsedInCache;
596 int escapeCacheEnabled;
597 bool isEscapeCacheCompatible(\
598 const std::map<std::string, double> & composition,
599 const double & energyThreshold, \
600 const double & intensityThreshold, \
601 const int & nThreshold , \
602 const double & alphaIn , \
603 const double & thickness) const;
604
605 struct sortVectorOfExcited {
606 bool operator()(const std::pair<std::string, double> &left, const std::pair<std::string,int> &right) {
607 return left.second < right.second;
608 }
609 };
610
611 };
612
613 } // namespace fisx
614
615 #endif //FISX_ELEMENTS_H
fisx::Elements::createMaterial
Material createMaterial(const std::string &name, const double &density=1.0, const double &thickness=1.0, const std::string &comment="")
Definition: fisx_elements.cpp:1161
fisx::Elements::setCacheEnabled
void setCacheEnabled(const std::string &elementName, const int &flag=1)
Definition: fisx_elements.cpp:2175
fisx::Elements::getMaterial
const Material & getMaterial(const std::string &materialName)
Definition: fisx_elements.cpp:1239
fisx::Elements::setElementCascadeCacheEnabled
void setElementCascadeCacheEnabled(const std::string &elementName, const int &flag=1)
Definition: fisx_elements.cpp:2093
fisx::Elements::getShellConstantsFile
const std::string & getShellConstantsFile(const std::string &mainShellName) const
Definition: fisx_elements.cpp:1786
fisx::Elements::getShellNonradiativeTransitionsFile
const std::string & getShellNonradiativeTransitionsFile(const std::string &mainShellName) const
Definition: fisx_elements.cpp:1811
fisx::Elements::setMassAttenuationCoefficients
void setMassAttenuationCoefficients(const std::string &elementName, const std::vector< double > &energy, const std::vector< double > &photoelectric, const std::vector< double > &coherent, const std::vector< double > &compton, const std::vector< double > &pair)
Definition: fisx_elements.cpp:719
fisx::Elements::clearEscapeCache
void clearEscapeCache(void)
Definition: fisx_elements.cpp:2203
fisx::Elements::getBindingEnergies
const std::map< std::string, double > & getBindingEnergies(const std::string &name) const
Definition: fisx_elements.cpp:1870
fisx::Elements::defaultDataDir
static const std::string defaultDataDir()
Definition: fisx_elements.cpp:42
fisx::Elements::addMaterial
void addMaterial(const Material &materialInstance, const int &errorOnReplace=1)
Definition: fisx_elements.cpp:1282
fisx::Elements::getCompositionFromFormula
std::map< std::string, double > getCompositionFromFormula(const std::string &formula) const
Definition: fisx_elements.cpp:1466
fisx::Material
Class containing the composition of a material.
Definition: fisx_material.h:45
fisx::Elements::fillCache
void fillCache(const std::string &elementName, const std::vector< double > &energy)
Definition: fisx_elements.cpp:2146
fisx
Definition: fisx_element.cpp:34
fisx::Elements::getAtomicMass
const double & getAtomicMass(const std::string &name) const
Definition: fisx_elements.cpp:1860
fisx::Elements::setMaterialComposition
void setMaterialComposition(const std::string &materialName, const std::map< std::string, double > &composition)
Definition: fisx_elements.cpp:1224
fisx::Elements::setShellNonradiativeTransitionsFile
void setShellNonradiativeTransitionsFile(const std::string &mainShellName, const std::string &fileName)
Definition: fisx_elements.cpp:426
fisx::Elements
Class handling the physical properties.
Definition: fisx_elements.h:60
fisx::Elements::getInitialPhotoelectricVacancyDistribution
std::map< std::string, std::vector< double > > getInitialPhotoelectricVacancyDistribution(const std::string &elementName, const std::vector< double > &energies) const
Definition: fisx_elements.cpp:1529
fisx::Elements::stringToDouble
static bool stringToDouble(const std::string &str, double &number)
Definition: fisx_elements.cpp:1918
fisx::Elements::updateCache
void updateCache(const std::string &elementName, const std::vector< double > &energy)
Definition: fisx_elements.cpp:2160
fisx::EPDL97
Definition: fisx_epdl97.h:38
fisx::Elements::getExcitationFactors
std::vector< std::map< std::string, std::map< std::string, double > > > getExcitationFactors(const std::string &element, const std::vector< double > &energy, const std::vector< double > &weights=std::vector< double >()) const
Definition: fisx_elements.cpp:1504
fisx::Elements::getPeakFamilies
std::vector< std::pair< std::string, double > > getPeakFamilies(const std::string &name, const double &energy) const
Definition: fisx_elements.cpp:1895
fisx::Elements::setShellRadiativeTransitionsFile
void setShellRadiativeTransitionsFile(const std::string &mainShellName, const std::string &fileName)
Definition: fisx_elements.cpp:522
fisx::Elements::toString
static std::string toString(const double &number)
Definition: fisx_elements.cpp:1931
fisx::Elements::getMaterialCopy
Material getMaterialCopy(const std::string &materialName)
Definition: fisx_elements.cpp:1267
fisx::Elements::getElementCopy
Element getElementCopy(const std::string &elementName)
Definition: fisx_elements.cpp:296
fisx::Elements::getColumn
int getColumn(const std::string &name) const
Definition: fisx_elements.cpp:1890
fisx::Elements::getRow
int getRow(const std::string &name) const
Definition: fisx_elements.cpp:1885
fisx::Elements::setShellConstantsFile
void setShellConstantsFile(const std::string &mainShellName, const std::string &fileName)
Definition: fisx_elements.cpp:321
fisx::Elements::isElementNameDefined
bool isElementNameDefined(const std::string &elementName) const
Definition: fisx_elements.cpp:255
fisx::Elements::getCacheSize
int getCacheSize(const std::string &elementName) const
Definition: fisx_elements.cpp:2318
fisx::Elements::getElementNames
std::vector< std::string > getElementNames()
Definition: fisx_elements.cpp:268
fisx::Element
Definition: fisx_element.h:40
fisx::Elements::getRadiativeTransitions
const std::map< std::string, double > & getRadiativeTransitions(const std::string &elementName, const std::string &subshell) const
Definition: fisx_elements.cpp:1950
fisx::Elements::getMassAttenuationCoefficients
std::map< std::string, std::vector< double > > getMassAttenuationCoefficients(const std::string &elementName) const
Definition: fisx_elements.cpp:984
fisx::Elements::Elements
Elements(std::string dataDirectory="")
Definition: fisx_elements.cpp:70
fisx::Elements::updateEscapeCache
void updateEscapeCache(const std::map< std::string, double > &composition, const std::vector< double > &energy, const double &energyThreshold=0.010, const double &intensityThreshold=1.0e-7, const int &nThreshold=4, const double &alphaIn=90., const double &thickness=0.0)
Definition: fisx_elements.cpp:2261
fisx::Elements::clearCache
void clearCache(const std::string &elementName)
Definition: fisx_elements.cpp:2189
fisx::Elements::addElement
void addElement(const Element &elementInstance)
Definition: fisx_elements.cpp:304
fisx::Elements::getLongName
std::string getLongName(const std::string &name) const
Definition: fisx_elements.cpp:1880
fisx::Elements::getComposition
std::map< std::string, double > getComposition(const std::string &name) const
Definition: fisx_elements.cpp:1320
fisx::Elements::parseFormula
std::map< std::string, double > parseFormula(const std::string &formula) const
Definition: fisx_elements.cpp:1566
fisx::Elements::getMaterialNames
std::vector< std::string > getMaterialNames()
Definition: fisx_elements.cpp:1253
fisx::Elements::setMassAttenuationCoefficientsFile
void setMassAttenuationCoefficientsFile(const std::string &fileName)
Definition: fisx_elements.cpp:619
fisx::Elements::getNonradiativeTransitions
const std::map< std::string, double > & getNonradiativeTransitions(const std::string &elementName, const std::string &subshell) const
Definition: fisx_elements.cpp:1944
fisx::Elements::removeMaterials
void removeMaterials()
Definition: fisx_elements.cpp:1315
fisx::Elements::getShellConstants
std::map< std::string, double > getShellConstants(const std::string &elementName, const std::string &subshell) const
Definition: fisx_elements.cpp:1956
fisx::Elements::removeMaterial
void removeMaterial(const std::string &name)
Definition: fisx_elements.cpp:2080
fisx::Elements::getEscape
std::map< std::string, std::map< std::string, double > > getEscape(const std::map< std::string, double > &composition, const double &energy, const double &energyThreshold=0.010, const double &intensityThreshold=1.0e-7, const int &nThreshold=4, const double &alphaIn=90., const double &thickness=0.0) const
Definition: fisx_elements.cpp:1964
fisx::Elements::getAtomicNumber
const int & getAtomicNumber(const std::string &name) const
Definition: fisx_elements.cpp:1865
fisx::Elements::getShellRadiativeTransitionsFile
const std::string & getShellRadiativeTransitionsFile(const std::string &mainShellName) const
Definition: fisx_elements.cpp:1798
fisx::Elements::getElement
const Element & getElement(const std::string &elementName) const
Definition: fisx_elements.cpp:282
fisx::Elements::isCacheEnabled
const int isCacheEnabled(const std::string &elementName) const
Definition: fisx_elements.cpp:2304
fisx::Elements::getEmittedXRayLines
std::map< std::string, double > getEmittedXRayLines(const std::string &elementName, const double &energy=1000.) const
Definition: fisx_elements.cpp:1939
fisx::Elements::getDensity
double getDensity(const std::string &name) const
Definition: fisx_elements.cpp:1875