21GMaterial::GMaterial(
const std::string& s, std::vector<std::string> pars,
const std::shared_ptr<GLogger>& logger) :
26 "Incorrect number of material parameters for ", pars[0],
". Expected ",
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");
53 assign_if_set(pars, i, scintillationyield);
54 assign_if_set(pars, i, resolutionscale);
55 assign_if_set(pars, i, fasttimeconstant);
56 assign_if_set(pars, i, slowtimeconstant);
57 assign_if_set(pars, i, yieldratio);
58 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& parameter,
const std::string& propertyName) {
102 std::stringstream parameterComponents(parameter);
104 while (!parameterComponents.eof()) {
105 std::string component;
106 parameterComponents >> component;
113 else if (propertyName ==
"indexOfRefraction") {
116 else if (propertyName ==
"absorptionLength") {
119 else if (propertyName ==
"reflectivity") { reflectivity.push_back(
gutilities::getG4Number(trimmedComponent)); }
121 else if (propertyName ==
"fastcomponent") {
124 else if (propertyName ==
"slowcomponent") {
128 else if (propertyName ==
"scintillationyield") {
139 if (propertyName ==
"rayleigh") {
145 unsigned long photonEnergyVectorSize = photonEnergy.size();
147 if (!indexOfRefraction.empty() && indexOfRefraction.size() != photonEnergyVectorSize) {
149 "indexOfRefraction size ", indexOfRefraction.size(),
" mismatch: photonEnergy has size ",
150 photonEnergyVectorSize);
152 if (!absorptionLength.empty() && absorptionLength.size() != photonEnergyVectorSize) {
154 "absorptionLength size ", absorptionLength.size(),
" mismatch: photonEnergy has size ",
155 photonEnergyVectorSize);
157 if (!reflectivity.empty() && reflectivity.size() != photonEnergyVectorSize) {
159 "reflectivity size ", reflectivity.size(),
" mismatch: photonEnergy has size ",
160 photonEnergyVectorSize);
162 if (!efficiency.empty() && efficiency.size() != photonEnergyVectorSize) {
164 "efficiency size ", efficiency.size(),
" mismatch: photonEnergy has size ",
165 photonEnergyVectorSize);
167 if (!fastcomponent.empty() && fastcomponent.size() != photonEnergyVectorSize) {
169 "fastcomponent size ", fastcomponent.size(),
" mismatch: photonEnergy has size ",
170 photonEnergyVectorSize);
172 if (!slowcomponent.empty() && slowcomponent.size() != photonEnergyVectorSize) {
174 "slowcomponent size ", slowcomponent.size(),
" mismatch: photonEnergy has size ",
175 photonEnergyVectorSize);
177 if (!rayleigh.empty() && rayleigh.size() != photonEnergyVectorSize) {
179 "rayleigh size ", rayleigh.size(),
" mismatch: photonEnergy has size ",
180 photonEnergyVectorSize);
187bool GMaterial::assign_if_set(
const std::vector<std::string>& pars,
size_t& i,
double& out) {
188 if (i >= pars.size())
return false;
190 const std::string trimmed =
193 std::string_view sv(trimmed);
197 out = std::stod(trimmed);
200 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)