22 const std::shared_ptr<GLogger> &logger) :
GBase(logger),
27 gsystem::ERR_GWRONGNUMBEROFPARS,
28 "Incorrect number of material parameters for %1. Expected %2 but we got %3", pars[0],
29 gsystem::GMATERIALNUMBEROFPARS, pars.size());
34 name = gutilities::removeAllSpacesFromString(pars[i++]);
35 density = stod(gutilities::removeAllSpacesFromString(pars[i++]));
38 setComponentsFromString(pars[i++]);
41 description = pars[i++];
44 getMaterialPropertyFromString(pars[i++],
"photonEnergy");
45 getMaterialPropertyFromString(pars[i++],
"indexOfRefraction");
46 getMaterialPropertyFromString(pars[i++],
"absorptionLength");
47 getMaterialPropertyFromString(pars[i++],
"reflectivity");
48 getMaterialPropertyFromString(pars[i++],
"efficiency");
51 getMaterialPropertyFromString(pars[i++],
"fastcomponent");
52 getMaterialPropertyFromString(pars[i++],
"slowcomponent");
55 scintillationyieldSet = assign_if_set(pars, i, scintillationyield);
56 resolutionscaleSet = assign_if_set(pars, i, resolutionscale);
57 fasttimeconstantSet = assign_if_set(pars, i, fasttimeconstant);
58 slowtimeconstantSet = assign_if_set(pars, i, slowtimeconstant);
59 yieldratioSet = assign_if_set(pars, i, yieldratio);
60 birksConstantSet = assign_if_set(pars, i, birksConstant);
63 getMaterialPropertyFromString(pars[i++],
"rayleigh");
64 if (i < pars.size()) {
65 getMaterialPropertyFromString(pars[i++],
"mie");
66 mieforwardSet = assign_if_set(pars, i, mieforward);
67 miebackwardSet = assign_if_set(pars, i, miebackward);
68 mieratioSet = assign_if_set(pars, i, mieratio);
76 stream <<
" - Material: " << gMat.name <<
" in system " << gMat.system <<
": " << std::endl;
77 stream <<
" Density: " << gMat.density << std::endl;
78 if (!gMat.components.empty()) {
79 stream <<
" Composition: " << std::endl;
80 for (
unsigned m = 0; m < gMat.components.size(); m++) {
81 std::string quantity = gMat.amounts[m] > 1 ?
" atoms " :
" fractional mass";
82 stream <<
" ・ " << gMat.components[m] << quantity <<
" " << gMat.amounts[m] << std::endl;
85 stream <<
" Description: " << gMat.description << std::endl;
93void GMaterial::setComponentsFromString(
const std::string &composition) {
97 for (
unsigned e = 0; e < allComponents.size() / 2; e++) {
98 components.push_back(allComponents[e * 2]);
99 amounts.push_back(stod(allComponents[e * 2 + 1]));
105void GMaterial::getMaterialPropertyFromString(
const std::string ¶meter,
const std::string &propertyName) {
112 std::stringstream parameterComponents(parameter);
114 while (!parameterComponents.eof()) {
115 std::string component;
116 parameterComponents >> component;
123 if (propertyName ==
"photonEnergy") {
125 }
else if (propertyName ==
"indexOfRefraction") {
127 }
else if (propertyName ==
"absorptionLength") {
129 }
else if (propertyName ==
"reflectivity") {
131 }
else if (propertyName ==
"efficiency") {
133 }
else if (propertyName ==
"fastcomponent") {
135 }
else if (propertyName ==
"slowcomponent") {
139 else if (propertyName ==
"scintillationyield") {
141 }
else if (propertyName ==
"resolutionscale") {
143 }
else if (propertyName ==
"fasttimeconstant") {
145 }
else if (propertyName ==
"slowtimeconstant") {
147 }
else if (propertyName ==
"yieldratio") {
149 }
else if (propertyName ==
"mie") {
151 }
else if (propertyName ==
"rayleigh") {
160 if (propertyName ==
"rayleigh" || propertyName ==
"mie") {
166 unsigned long photonEnergyVectorSize = photonEnergy.size();
168 if (!indexOfRefraction.empty() && indexOfRefraction.size() != photonEnergyVectorSize) {
171 "indexOfRefraction size %1 mismatch: photonEnergy has size %2", indexOfRefraction.size(),
172 photonEnergyVectorSize);
174 if (!absorptionLength.empty() && absorptionLength.size() != photonEnergyVectorSize) {
177 "absorptionLength size %1 mismatch: photonEnergy has size %2", absorptionLength.size(),
178 photonEnergyVectorSize);
180 if (!reflectivity.empty() && reflectivity.size() != photonEnergyVectorSize) {
183 "reflectivity size %1 mismatch: photonEnergy has size %2", reflectivity.size(),
184 photonEnergyVectorSize);
186 if (!efficiency.empty() && efficiency.size() != photonEnergyVectorSize) {
189 "efficiency size %1 mismatch: photonEnergy has size %2", efficiency.size(),
190 photonEnergyVectorSize);
192 if (!fastcomponent.empty() && fastcomponent.size() != photonEnergyVectorSize) {
195 "fastcomponent size %1 mismatch: photonEnergy has size %2", fastcomponent.size(),
196 photonEnergyVectorSize);
198 if (!slowcomponent.empty() && slowcomponent.size() != photonEnergyVectorSize) {
201 "slowcomponent size %1 mismatch: photonEnergy has size %2", slowcomponent.size(),
202 photonEnergyVectorSize);
204 if (!mie.empty() && mie.size() != photonEnergyVectorSize) {
206 "Mie size %1 mismatch: photonEnergy has size %2", mie.size(), photonEnergyVectorSize);
208 if (!rayleigh.empty() && rayleigh.size() != photonEnergyVectorSize) {
211 "rayleigh size %1 mismatch: photonEnergy has size %2", rayleigh.size(), photonEnergyVectorSize);
217bool GMaterial::assign_if_set(
const std::vector<std::string> &pars,
size_t &i,
double &out) {
218 if (i >= pars.size())
return false;
220 const std::string trimmed =
223 std::string_view sv(trimmed);
227 out = std::stod(trimmed);
229 }
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)