22 const std::shared_ptr<GLogger> &logger) :
GBase(logger),
26 "Incorrect number of material parameters for ", pars[0],
". Expected ",
36 setComponentsFromString(pars[i++]);
39 description = pars[i++];
42 getMaterialPropertyFromString(pars[i++],
"photonEnergy");
43 getMaterialPropertyFromString(pars[i++],
"indexOfRefraction");
44 getMaterialPropertyFromString(pars[i++],
"absorptionLength");
45 getMaterialPropertyFromString(pars[i++],
"reflectivity");
46 getMaterialPropertyFromString(pars[i++],
"efficiency");
49 getMaterialPropertyFromString(pars[i++],
"fastcomponent");
50 getMaterialPropertyFromString(pars[i++],
"slowcomponent");
53 scintillationyieldSet = assign_if_set(pars, i, scintillationyield);
54 resolutionscaleSet = assign_if_set(pars, i, resolutionscale);
55 fasttimeconstantSet = assign_if_set(pars, i, fasttimeconstant);
56 slowtimeconstantSet = assign_if_set(pars, i, slowtimeconstant);
57 yieldratioSet = assign_if_set(pars, i, yieldratio);
58 birksConstantSet = assign_if_set(pars, i, birksConstant);
61 getMaterialPropertyFromString(pars[i++],
"rayleigh");
68 stream <<
" - Material: " << gMat.name <<
" in system " << gMat.system <<
": " << std::endl;
69 stream <<
" Density: " << gMat.density << std::endl;
70 if (!gMat.components.empty()) {
71 stream <<
" Composition: " << std::endl;
72 for (
unsigned m = 0; m < gMat.components.size(); m++) {
73 std::string quantity = gMat.amounts[m] > 1 ?
" atoms " :
" fractional mass";
74 stream <<
" ・ " << gMat.components[m] << quantity <<
" " << gMat.amounts[m] << std::endl;
77 stream <<
" Description: " << gMat.description << std::endl;
85void GMaterial::setComponentsFromString(
const std::string &composition) {
89 for (
unsigned e = 0; e < allComponents.size() / 2; e++) {
90 components.push_back(allComponents[e * 2]);
91 amounts.push_back(stod(allComponents[e * 2 + 1]));
97void GMaterial::getMaterialPropertyFromString(
const std::string ¶meter,
const std::string &propertyName) {
102 std::stringstream parameterComponents(parameter);
104 while (!parameterComponents.eof()) {
105 std::string component;
106 parameterComponents >> component;
113 if (propertyName ==
"photonEnergy") {
115 }
else if (propertyName ==
"indexOfRefraction") {
117 }
else if (propertyName ==
"absorptionLength") {
119 }
else if (propertyName ==
"reflectivity") {
121 }
else if (propertyName ==
"efficiency") {
123 }
else if (propertyName ==
"fastcomponent") {
125 }
else if (propertyName ==
"slowcomponent") {
129 else if (propertyName ==
"scintillationyield") {
131 }
else if (propertyName ==
"resolutionscale") {
133 }
else if (propertyName ==
"fasttimeconstant") {
135 }
else if (propertyName ==
"slowtimeconstant") {
137 }
else if (propertyName ==
"yieldratio") {
139 }
else if (propertyName ==
"birkConstant") {
141 }
else if (propertyName ==
"rayleigh") {
146 if (propertyName ==
"rayleigh") {
152 unsigned long photonEnergyVectorSize = photonEnergy.size();
154 if (!indexOfRefraction.empty() && indexOfRefraction.size() != photonEnergyVectorSize) {
156 "indexOfRefraction size ", indexOfRefraction.size(),
" mismatch: photonEnergy has size ",
157 photonEnergyVectorSize);
159 if (!absorptionLength.empty() && absorptionLength.size() != photonEnergyVectorSize) {
161 "absorptionLength size ", absorptionLength.size(),
" mismatch: photonEnergy has size ",
162 photonEnergyVectorSize);
164 if (!reflectivity.empty() && reflectivity.size() != photonEnergyVectorSize) {
166 "reflectivity size ", reflectivity.size(),
" mismatch: photonEnergy has size ",
167 photonEnergyVectorSize);
169 if (!efficiency.empty() && efficiency.size() != photonEnergyVectorSize) {
171 "efficiency size ", efficiency.size(),
" mismatch: photonEnergy has size ",
172 photonEnergyVectorSize);
174 if (!fastcomponent.empty() && fastcomponent.size() != photonEnergyVectorSize) {
176 "fastcomponent size ", fastcomponent.size(),
" mismatch: photonEnergy has size ",
177 photonEnergyVectorSize);
179 if (!slowcomponent.empty() && slowcomponent.size() != photonEnergyVectorSize) {
181 "slowcomponent size ", slowcomponent.size(),
" mismatch: photonEnergy has size ",
182 photonEnergyVectorSize);
184 if (!rayleigh.empty() && rayleigh.size() != photonEnergyVectorSize) {
186 "rayleigh size ", rayleigh.size(),
" mismatch: photonEnergy has size ",
187 photonEnergyVectorSize);
194bool GMaterial::assign_if_set(
const std::vector<std::string> &pars,
size_t &i,
double &out) {
195 if (i >= pars.size())
return false;
197 const std::string trimmed =
200 std::string_view sv(trimmed);
204 out = std::stod(trimmed);
206 }
catch (
const std::exception &) {
std::shared_ptr< GLogger > log
void error(int exit_code, Args &&... args) const
Material definition belonging to a detector system.
GMaterial(const std::string &system, std::vector< std::string > pars, const std::shared_ptr< GLogger > &logger)
Construct a material from a serialized parameter list.
std::ostream & operator<<(std::ostream &stream, const GMaterial &gMat)
Conventions and shared constants for the detector-system module.
#define GMATERIALNUMBEROFPARS
Number of database parameters defining a gmaterial entry.
#define ERR_GMATERIALOPTICALPROPERTYMISMATCH
#define ERR_GWRONGNUMBEROFPARS
double getG4Number(const string &v, bool warnIfNotUnit=false)
string removeAllSpacesFromString(const std::string &str)
bool is_unset(std::string_view s)
string removeLeadingAndTrailingSpacesFromString(const std::string &input)
vector< std::string > getStringVectorFromString(const std::string &input)