Skip to content

Commit 582e377

Browse files
committed
Fixed not assigning optical properties to materials when they were set to zero
1 parent 9daf872 commit 582e377

3 files changed

Lines changed: 33 additions & 18 deletions

File tree

g4system/g4materials.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ bool G4World::createG4Material(const std::shared_ptr<GMaterial> &gmaterial) {
8181
hasOpticalProperties = true;
8282
};
8383

84-
auto addConstantProperty = [&](const char *propertyName, double value) {
85-
// default values initialied to zero
86-
if (value == 0) { return; }
87-
84+
auto addConstantProperty = [&](const char *propertyName, double value, bool isSet) {
85+
if (!isSet) { return; }
8886
materialPropertiesTable->AddConstProperty(propertyName, value);
89-
9087
hasOpticalProperties = true;
9188
};
9289

@@ -100,15 +97,20 @@ bool G4World::createG4Material(const std::shared_ptr<GMaterial> &gmaterial) {
10097
addProperty("SCINTILLATIONCOMPONENT2", gmaterial->getSlowComponent());
10198

10299
// scalar properties
103-
addConstantProperty("SCINTILLATIONYIELD", gmaterial->getScintillationYield());
104-
addConstantProperty("RESOLUTIONSCALE", gmaterial->getResolutionScale());
105-
106-
addConstantProperty("SCINTILLATIONTIMECONSTANT1", gmaterial->getFasttimeConstant() * CLHEP::ns);
107-
addConstantProperty("SCINTILLATIONTIMECONSTANT2", gmaterial->getSlowtimeConstant() * CLHEP::ns);
108-
addConstantProperty("SCINTILLATIONYIELD1", gmaterial->getYieldratio());
100+
addConstantProperty("SCINTILLATIONYIELD", gmaterial->getScintillationYield(),
101+
gmaterial->hasScintillationYield());
102+
addConstantProperty("RESOLUTIONSCALE", gmaterial->getResolutionScale(),
103+
gmaterial->hasResolutionScale());
104+
105+
addConstantProperty("SCINTILLATIONTIMECONSTANT1", gmaterial->getFasttimeConstant() * CLHEP::ns,
106+
gmaterial->hasFasttimeConstant());
107+
addConstantProperty("SCINTILLATIONTIMECONSTANT2", gmaterial->getSlowtimeConstant() * CLHEP::ns,
108+
gmaterial->hasSlowtimeConstant());
109+
addConstantProperty("SCINTILLATIONYIELD1", gmaterial->getYieldratio(),
110+
gmaterial->hasYieldratio());
109111

110112
double getBirksConstant = gmaterial->getBirksConstant();
111-
if (getBirksConstant != 0) {
113+
if (gmaterial->hasBirksConstant()) {
112114
g4materialsMap[materialName]->GetIonisation()->SetBirksConstant(getBirksConstant);
113115
hasOpticalProperties = true;
114116
}

gsystem/gmaterial.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ GMaterial::GMaterial(const std::string &s, std::vector<std::string> pars,
5050
getMaterialPropertyFromString(pars[i++], "slowcomponent");
5151

5252
// assign_if_set increment index
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);
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);
5959

6060
// Other optical processes: the final vector load triggers cross-vector size validation.
6161
getMaterialPropertyFromString(pars[i++], "rayleigh");

gsystem/gmaterial.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ class GMaterial : public GBase<GMaterial> {
108108
double slowtimeconstant{}; ///< Slow scintillation time constant (time units).
109109
double yieldratio{}; ///< Fraction of total yield attributed to the fast component.
110110
double birksConstant{}; ///< Birks constant for quenching model (units depend on convention).
111+
112+
bool scintillationyieldSet{}; ///< True when the scalar was explicitly provided.
113+
bool resolutionscaleSet{}; ///< True when the scalar was explicitly provided.
114+
bool fasttimeconstantSet{}; ///< True when the scalar was explicitly provided.
115+
bool slowtimeconstantSet{}; ///< True when the scalar was explicitly provided.
116+
bool yieldratioSet{}; ///< True when the scalar was explicitly provided.
117+
bool birksConstantSet{}; ///< True when the scalar was explicitly provided.
111118
///@}
112119

113120
/**
@@ -191,6 +198,12 @@ class GMaterial : public GBase<GMaterial> {
191198
[[nodiscard]] double getSlowtimeConstant() const { return slowtimeconstant; }
192199
[[nodiscard]] double getYieldratio() const { return yieldratio; }
193200
[[nodiscard]] double getBirksConstant() const { return birksConstant; }
201+
[[nodiscard]] bool hasScintillationYield() const { return scintillationyieldSet; }
202+
[[nodiscard]] bool hasResolutionScale() const { return resolutionscaleSet; }
203+
[[nodiscard]] bool hasFasttimeConstant() const { return fasttimeconstantSet; }
204+
[[nodiscard]] bool hasSlowtimeConstant() const { return slowtimeconstantSet; }
205+
[[nodiscard]] bool hasYieldratio() const { return yieldratioSet; }
206+
[[nodiscard]] bool hasBirksConstant() const { return birksConstantSet; }
194207
///@}
195208

196209
/// \name Additional optical properties

0 commit comments

Comments
 (0)