-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functionality for setting nuclei targets abundances in mol (volume) and as chemical compound #11
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e53037c
Adding functionality for defining target material with abundance in m…
AlvaroEzq 0bdf8a7
pre-commit fixes
AlvaroEzq d4e130f
Improving documentation
AlvaroEzq d3d3dd4
Fixing bug TRestWimpUtils::ParseChemicalCompound
AlvaroEzq de30ed9
Fixing nested subcompound in ParseChemicalCompound()
AlvaroEzq 4620d30
Merge branch 'master' into alvaroezq_Volume
AlvaroEzq 93039e3
Making energy spectra range wide enough
AlvaroEzq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<wimp> | ||
<TRestWimpSensitivity name="WIMPSensitivity" title="WIMP Sensitivity" verboseLevel="info"> | ||
<addElement nucleusName="Ar" anum="39.948" znum="18" abundanceInMol="0.99"/> | ||
<addCompound compoundName="C4H10" abundanceInMol="0.01"> | ||
<addElement nucleusName="C" anum="12.0107" znum="6" /> | ||
<addElement nucleusName="H" anum="1.00784" znum="1" /> | ||
</addCompound> | ||
<parameter name="wimpDensity" value="0.3"/> | ||
<parameter name="labVelocity" value="232"/> | ||
<parameter name="rmsVelocity" value="220"/> | ||
<parameter name="escapeVelocity" value="544"/> | ||
<parameter name="exposure" value="116.8"/> | ||
<parameter name="background" value="100"/> | ||
<parameter name="energySpectra" value="(0,8)"/> | ||
<parameter name="energySpectraStep" value="0.01"/> | ||
<parameter name="energyRange" value="(0.05,1.05)"/> | ||
<parameter name="useQuenchingFactor" value="true"/> | ||
</TRestWimpSensitivity> | ||
</wimp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<wimp> | ||
<TRestWimpSensitivity name="WIMPSensitivity" title="WIMP Sensitivity" verboseLevel="info"> | ||
<addCompound compoundName="Ar99(C4H10)1" abundanceInMol="1"> | ||
<addElement nucleusName="Ar" anum="39.948" znum="18"/> | ||
<addElement nucleusName="C" anum="12.0107" znum="6" /> | ||
<addElement nucleusName="H" anum="1.00784" znum="1" /> | ||
</addCompound> | ||
<parameter name="wimpDensity" value="0.3"/> | ||
<parameter name="labVelocity" value="232"/> | ||
<parameter name="rmsVelocity" value="220"/> | ||
<parameter name="escapeVelocity" value="544"/> | ||
<parameter name="exposure" value="116.8"/> | ||
<parameter name="background" value="100"/> | ||
<parameter name="energySpectra" value="(0,8)"/> | ||
<parameter name="energySpectraStep" value="0.01"/> | ||
<parameter name="energyRange" value="(0.05,1.05)"/> | ||
<parameter name="useQuenchingFactor" value="true"/> | ||
</TRestWimpSensitivity> | ||
</wimp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ | |
/// - *anum* : Atomic number of the nucleus | ||
/// - *znum* : Number of protons in the nucleus | ||
/// - *abundance* : Mass percentage of the nucleus in the target material. | ||
/// - *abundanceInMol* : Mol (or volume) percentage of the nucleus in the | ||
/// target material. | ||
/// - *wimpDensity* : WIMP density in the DM halo in GeV/cm3 | ||
/// - *labVelocity* : WIMP velocity in the lab (Earth) frame reference | ||
/// in km/s | ||
|
@@ -68,6 +70,12 @@ | |
/// <parameter name="useQuenchingFactor" value="true"/> | ||
/// </TRestWimpSensitivity> | ||
/// \endcode | ||
/// Other ways to define the target material is through the use of | ||
/// compounds. Also, the abundances can be given in mol (or volume) using | ||
/// the parameter *abundanceInMol* instead of *abundance*. Examples for an | ||
/// Ar+Isobutane mixture at 99% in volume can be found inside the files | ||
/// 'REST_PATH/source/libraries/wimp/examples/WIMP_compound_1.rml' and | ||
/// 'REST_PATH/source/libraries/wimp/examples/WIMP_compound_2.rml'. | ||
/// | ||
/// Besides target material elements, the other parameters are optional, | ||
/// and if not provided they will take their default values. | ||
|
@@ -161,23 +169,123 @@ void TRestWimpSensitivity::InitFromConfigFile() { | |
/// | ||
void TRestWimpSensitivity::ReadNuclei() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it would be better to move this function inside |
||
fNuclei.clear(); | ||
bool anyAbundanceGivenInMol = false; | ||
|
||
// Read nuclei (standalone given) elements | ||
TiXmlElement* ElementDef = GetElement("addElement"); | ||
while (ElementDef) { | ||
TRestWimpNucleus nucleus; | ||
nucleus.fNucleusName = GetFieldValue("nucleusName", ElementDef); | ||
nucleus.fAnum = StringToDouble(GetFieldValue("anum", ElementDef)); | ||
nucleus.fZnum = StringToInteger(GetFieldValue("znum", ElementDef)); | ||
nucleus.fAbundance = StringToDouble(GetFieldValue("abundance", ElementDef)); | ||
|
||
std::string el = | ||
!ElementDef->Attribute("abundance") ? "Not defined" : ElementDef->Attribute("abundance"); | ||
if (!(el.empty() || el == "Not defined")) nucleus.fAbundance = StringToDouble(el); | ||
|
||
el = !ElementDef->Attribute("abundanceInMol") ? "Not defined" | ||
: ElementDef->Attribute("abundanceInMol"); | ||
if (!(el.empty() || el == "Not defined")) { | ||
nucleus.fAbundanceMol = StringToDouble(el); | ||
anyAbundanceGivenInMol = true; | ||
} | ||
|
||
if (nucleus.fAbundance == 0 || nucleus.fAbundanceMol == 0) { | ||
if (nucleus.fAbundance == 0) | ||
nucleus.fAbundance = nucleus.fAbundanceMol * nucleus.fAnum; | ||
else if (nucleus.fAbundanceMol == 0) | ||
nucleus.fAbundanceMol = nucleus.fAbundance / nucleus.fAnum; | ||
else | ||
RESTError << "abundance or abundanceInMol not defined for nucleus " << nucleus.fNucleusName | ||
<< RESTendl; | ||
} | ||
fNuclei.emplace_back(nucleus); | ||
ElementDef = GetNextElement(ElementDef); | ||
} | ||
|
||
// Read nuclei (compound form given) elements | ||
TiXmlElement* CompoundDef = GetElement("addCompound"); | ||
while (CompoundDef) { | ||
bool compoundAbundanceGivenInMol = false; | ||
std::string compoundName = GetFieldValue("compoundName", CompoundDef); | ||
double compoundAbundance = 0, compoundAbundanceInMol = 0; | ||
double totalMolMass = 0; | ||
|
||
std::string el = | ||
!CompoundDef->Attribute("abundance") ? "Not defined" : CompoundDef->Attribute("abundance"); | ||
if (!(el.empty() || el == "Not defined")) compoundAbundance = StringToDouble(el); | ||
|
||
el = !CompoundDef->Attribute("abundanceInMol") ? "Not defined" | ||
: CompoundDef->Attribute("abundanceInMol"); | ||
if (!(el.empty() || el == "Not defined")) { | ||
compoundAbundanceInMol = StringToDouble(el); | ||
compoundAbundanceGivenInMol = true; | ||
anyAbundanceGivenInMol = true; | ||
} | ||
|
||
if (compoundAbundance == 0 && compoundAbundanceInMol == 0) { | ||
RESTWarning << "abundance or abundanceInMol not defined for compound " << compoundName | ||
<< ". Setting its abundanceInMol to 1 " << RESTendl; | ||
compoundAbundanceInMol = 1; | ||
} | ||
|
||
// Read nuclei (inside compound) elements | ||
TiXmlElement* ElementDef = GetElement("addElement", CompoundDef); | ||
int i = 0; | ||
while (ElementDef) { | ||
i++; | ||
TRestWimpNucleus nucleus; | ||
nucleus.fNucleusName = GetFieldValue("nucleusName", ElementDef); | ||
nucleus.fAnum = StringToDouble(GetFieldValue("anum", ElementDef)); | ||
nucleus.fZnum = StringToInteger(GetFieldValue("znum", ElementDef)); | ||
totalMolMass += nucleus.fAnum * nucleus.GetStechiometricFactorFromCompound(compoundName); | ||
|
||
fNuclei.emplace_back(nucleus); | ||
ElementDef = GetNextElement(ElementDef); | ||
} | ||
if (compoundAbundanceGivenInMol) | ||
compoundAbundance = compoundAbundanceInMol * totalMolMass; | ||
else | ||
compoundAbundanceInMol = compoundAbundance / totalMolMass; | ||
// Set the compound abundance to all nuclei elements inside the compound | ||
for (auto it = fNuclei.end() - i; it != fNuclei.end(); it++) { | ||
auto& nucleus = *it; | ||
int stechiometricFactor = nucleus.GetStechiometricFactorFromCompound(compoundName); | ||
nucleus.fAbundanceMol = compoundAbundanceInMol * stechiometricFactor; | ||
nucleus.fAbundance = nucleus.fAbundanceMol * nucleus.fAnum; | ||
} | ||
|
||
CompoundDef = GetNextElement(CompoundDef); | ||
} | ||
|
||
// Merge the repeated nuclei (same name, anum and znum) by summing their abundances | ||
std::map<std::tuple<TString, Double_t, Int_t>, TRestWimpNucleus> uniqueNucleiMap; | ||
for (const auto& nucleus : fNuclei) { | ||
auto key = std::make_tuple(nucleus.fNucleusName, nucleus.fAnum, nucleus.fZnum); | ||
if (uniqueNucleiMap.find(key) != uniqueNucleiMap.end()) { | ||
uniqueNucleiMap[key].fAbundance += nucleus.fAbundance; | ||
uniqueNucleiMap[key].fAbundanceMol += nucleus.fAbundanceMol; | ||
} else | ||
uniqueNucleiMap[key] = nucleus; | ||
} | ||
fNuclei.clear(); | ||
for (const auto& entry : uniqueNucleiMap) fNuclei.push_back(entry.second); | ||
|
||
// normalize fAbundance (in mass only) if anyAbundanceGivenInMol | ||
if (anyAbundanceGivenInMol) { | ||
double sumMass = 0; | ||
for (auto& nucl : fNuclei) sumMass += nucl.fAbundance; | ||
for (auto& nucl : fNuclei) nucl.fAbundance /= sumMass; | ||
} | ||
|
||
for (auto& nucl : fNuclei) nucl.PrintNucleus(); | ||
} | ||
|
||
/////////////////////////////////////////////// | ||
/// \brief Get recoil spectra for a given WIMP | ||
/// mass and cross section | ||
/// Better performance version | ||
/// Better performance version (velocity integral | ||
/// is done only once for all recoil energies). | ||
/// | ||
std::map<std::string, TH1D*> TRestWimpSensitivity::GetRecoilSpectra(const double wimpMass, | ||
const double crossSection) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general is a better practise to initialize these variables in the header.