22 const std::shared_ptr<GLogger> &logger) :
GBase(logger),
26 gsystem::ERR_GWRONGNUMBEROFPARS,
27 "Incorrect number of material parameters for %1. Expected %2 but we got %3", pars[0],
28 gsystem::GMATERIALNUMBEROFPARS, pars.size());
33 name = gutilities::removeAllSpacesFromString(pars[i++]);
34 density = stod(gutilities::removeAllSpacesFromString(pars[i++]));
37 setComponentsFromString(pars[i++]);
40 description = pars[i++];
43 getMaterialPropertyFromString(pars[i++],
"photonEnergy");
44 getMaterialPropertyFromString(pars[i++],
"indexOfRefraction");
45 getMaterialPropertyFromString(pars[i++],
"absorptionLength");
46 getMaterialPropertyFromString(pars[i++],
"reflectivity");
47 getMaterialPropertyFromString(pars[i++],
"efficiency");
50 getMaterialPropertyFromString(pars[i++],
"fastcomponent");
51 getMaterialPropertyFromString(pars[i++],
"slowcomponent");
54 scintillationyieldSet = assign_if_set(pars, i, scintillationyield);
55 resolutionscaleSet = assign_if_set(pars, i, resolutionscale);
56 fasttimeconstantSet = assign_if_set(pars, i, fasttimeconstant);
57 slowtimeconstantSet = assign_if_set(pars, i, slowtimeconstant);
58 yieldratioSet = assign_if_set(pars, i, yieldratio);
59 birksConstantSet = assign_if_set(pars, i, birksConstant);
62 getMaterialPropertyFromString(pars[i++],
"rayleigh");
69 stream <<
" - Material: " << gMat.name <<
" in system " << gMat.system <<
": " << std::endl;
70 stream <<
" Density: " << gMat.density << std::endl;
71 if (!gMat.components.empty()) {
72 stream <<
" Composition: " << std::endl;
73 for (
unsigned m = 0; m < gMat.components.size(); m++) {
74 std::string quantity = gMat.amounts[m] > 1 ?
" atoms " :
" fractional mass";
75 stream <<
" ・ " << gMat.components[m] << quantity <<
" " << gMat.amounts[m] << std::endl;
78 stream <<
" Description: " << gMat.description << std::endl;
86void GMaterial::setComponentsFromString(
const std::string &composition) {
90 for (
unsigned e = 0; e < allComponents.size() / 2; e++) {
91 components.push_back(allComponents[e * 2]);
92 amounts.push_back(stod(allComponents[e * 2 + 1]));
98void GMaterial::getMaterialPropertyFromString(
const std::string ¶meter,
const std::string &propertyName) {
105 std::stringstream parameterComponents(parameter);
107 while (!parameterComponents.eof()) {
108 std::string component;
109 parameterComponents >> component;
116 if (propertyName ==
"photonEnergy") {
118 }
else if (propertyName ==
"indexOfRefraction") {
120 }
else if (propertyName ==
"absorptionLength") {
122 }
else if (propertyName ==
"reflectivity") {
124 }
else if (propertyName ==
"efficiency") {
126 }
else if (propertyName ==
"fastcomponent") {
128 }
else if (propertyName ==
"slowcomponent") {
132 else if (propertyName ==
"scintillationyield") {
134 }
else if (propertyName ==
"resolutionscale") {
136 }
else if (propertyName ==
"fasttimeconstant") {
138 }
else if (propertyName ==
"slowtimeconstant") {
140 }
else if (propertyName ==
"yieldratio") {
142 }
else if (propertyName ==
"rayleigh") {
151 if (propertyName ==
"rayleigh") {
157 unsigned long photonEnergyVectorSize = photonEnergy.size();
159 if (!indexOfRefraction.empty() && indexOfRefraction.size() != photonEnergyVectorSize) {
162 "indexOfRefraction size %1 mismatch: photonEnergy has size %2", indexOfRefraction.size(),
163 photonEnergyVectorSize);
165 if (!absorptionLength.empty() && absorptionLength.size() != photonEnergyVectorSize) {
168 "absorptionLength size %1 mismatch: photonEnergy has size %2", absorptionLength.size(),
169 photonEnergyVectorSize);
171 if (!reflectivity.empty() && reflectivity.size() != photonEnergyVectorSize) {
174 "reflectivity size %1 mismatch: photonEnergy has size %2", reflectivity.size(),
175 photonEnergyVectorSize);
177 if (!efficiency.empty() && efficiency.size() != photonEnergyVectorSize) {
180 "efficiency size %1 mismatch: photonEnergy has size %2", efficiency.size(),
181 photonEnergyVectorSize);
183 if (!fastcomponent.empty() && fastcomponent.size() != photonEnergyVectorSize) {
186 "fastcomponent size %1 mismatch: photonEnergy has size %2", fastcomponent.size(),
187 photonEnergyVectorSize);
189 if (!slowcomponent.empty() && slowcomponent.size() != photonEnergyVectorSize) {
192 "slowcomponent size %1 mismatch: photonEnergy has size %2", slowcomponent.size(),
193 photonEnergyVectorSize);
195 if (!rayleigh.empty() && rayleigh.size() != photonEnergyVectorSize) {
198 "rayleigh size %1 mismatch: photonEnergy has size %2", rayleigh.size(), photonEnergyVectorSize);
204bool GMaterial::assign_if_set(
const std::vector<std::string> &pars,
size_t &i,
double &out) {
205 if (i >= pars.size())
return false;
207 const std::string trimmed =
210 std::string_view sv(trimmed);
214 out = std::stod(trimmed);
216 }
catch (
const std::exception &) {
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
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.
constexpr int ERR_GMATERIALOPTICALPROPERTYMISMATCH
constexpr int GMATERIALNUMBEROFPARS
Number of database parameters defining a gmaterial entry.
double getG4Number(const string &v, bool warnIfNotUnit=false)
bool is_unset(std::string_view s)
string removeLeadingAndTrailingSpacesFromString(const std::string &input)
vector< std::string > getStringVectorFromString(const std::string &input)