4#include "G4Material.hh"
9bool G4World::createG4Material(
const std::shared_ptr<GMaterial> &gmaterial) {
10 auto NISTman = G4NistManager::Instance();
11 auto materialName = gmaterial->getName();
14 auto g4material = NISTman->FindMaterial(materialName);
15 if (g4material !=
nullptr) {
16 log->info(2,
"Material <%1> already exists in G4NistManager", materialName);
20 auto components = gmaterial->getComponents();
21 auto amounts = gmaterial->getAmounts();
22 bool isChemical = gmaterial->isChemicalFormula();
26 for (
auto &componentName: components) {
28 if (NISTman->FindOrBuildElement(componentName) ==
nullptr) {
29 log->info(2,
"Element <%1>, needed by %2, not found yet", componentName, materialName);
31 }
else {
log->info(2,
"Element <%1> needed by %2 now found", componentName, materialName); }
33 if (NISTman->FindOrBuildMaterial(componentName) ==
nullptr) {
34 log->info(2,
"Material <%1>, needed by %2, not found yet", componentName, materialName);
36 }
else {
log->info(2,
"Material <%1> needed by %2 now found", componentName, materialName); }
41 auto density = gmaterial->getDensity();
42 g4materialsMap[materialName] =
new G4Material(materialName, density * CLHEP::g / CLHEP::cm3,
43 static_cast<G4int
>(components.size()));
46 log->info(2,
"Building material <%1> with components:", materialName);
47 for (
size_t i = 0; i < components.size(); i++) {
48 log->info(2,
"element <%1> with amount: %2", components[i], amounts[i]);
51 for (
size_t i = 0; i < components.size(); i++) {
52 auto element = NISTman->FindOrBuildElement(components[i]);
53 g4materialsMap[materialName]->AddElement(element,
static_cast<G4int
>(amounts[i]));
56 log->info(2,
"Building material <%1> with components:", materialName);
57 for (
size_t i = 0; i < components.size(); i++) {
58 log->info(2,
"material <%1> with fractional mass: %2", components[i], amounts[i]);
61 for (
size_t i = 0; i < components.size(); i++) {
62 auto material = NISTman->FindOrBuildMaterial(components[i]);
63 g4materialsMap[materialName]->AddMaterial(material, amounts[i]);
68 auto photonEnergy = gmaterial->getPhotonEnergy();
69 if (!photonEnergy.empty()) {
70 auto *materialPropertiesTable =
new G4MaterialPropertiesTable();
71 bool hasOpticalProperties =
false;
73 auto addProperty = [&](
const char *propertyName,
const std::vector<double> &values) {
74 if (values.empty()) {
return; }
75 if (values.size() != photonEnergy.size()) {
78 "material <%1> optical property <%2> has %3 entries but photonEnergy has %4", materialName,
79 propertyName, values.size(), photonEnergy.size());
81 materialPropertiesTable->AddProperty(propertyName, photonEnergy, values);
82 hasOpticalProperties =
true;
85 auto addConstantProperty = [&](
const char *propertyName,
double value,
bool isSet) {
86 if (!isSet) {
return; }
87 materialPropertiesTable->AddConstProperty(propertyName, value);
88 hasOpticalProperties =
true;
92 addProperty(
"RINDEX", gmaterial->getIndexOfRefraction());
93 addProperty(
"ABSLENGTH", gmaterial->getAbsorptionLength());
94 addProperty(
"REFLECTIVITY", gmaterial->getReflectivity());
95 addProperty(
"EFFICIENCY", gmaterial->getEfficiency());
97 addProperty(
"SCINTILLATIONCOMPONENT1", gmaterial->getFastComponent());
98 addProperty(
"SCINTILLATIONCOMPONENT2", gmaterial->getSlowComponent());
101 addConstantProperty(
"SCINTILLATIONYIELD", gmaterial->getScintillationYield(),
102 gmaterial->hasScintillationYield());
103 addConstantProperty(
"RESOLUTIONSCALE", gmaterial->getResolutionScale(),
104 gmaterial->hasResolutionScale());
106 addConstantProperty(
"SCINTILLATIONTIMECONSTANT1", gmaterial->getFasttimeConstant() * CLHEP::ns,
107 gmaterial->hasFasttimeConstant());
108 addConstantProperty(
"SCINTILLATIONTIMECONSTANT2", gmaterial->getSlowtimeConstant() * CLHEP::ns,
109 gmaterial->hasSlowtimeConstant());
110 addConstantProperty(
"SCINTILLATIONYIELD1", gmaterial->getYieldratio(),
111 gmaterial->hasYieldratio());
113 double getBirksConstant = gmaterial->getBirksConstant();
114 if (gmaterial->hasBirksConstant()) {
115 g4materialsMap[materialName]->GetIonisation()->SetBirksConstant(getBirksConstant);
116 hasOpticalProperties =
true;
120 addProperty(
"RAYLEIGH", gmaterial->getRayleigh());
122 if (hasOpticalProperties) {
123 g4materialsMap[materialName]->SetMaterialPropertiesTable(materialPropertiesTable);
124 log->info(2,
"Attached optical material properties table to material <%1>", materialName);
125 }
else {
delete materialPropertiesTable; }
132void G4World::buildDefaultMaterialsElementsAndIsotopes() {
143 a = 1.01 * CLHEP::g / CLHEP::mole;
144 d = 0.00275 * CLHEP::g / CLHEP::cm3;
145 T = 50.0 * CLHEP::kelvin;
162 a = 2.0141018 * CLHEP::g / CLHEP::mole;
167 Deuterium->AddIsotope(Deuteron, 1);
173 d = 0.000452 * CLHEP::g / CLHEP::cm3;
174 T = 294.25 * CLHEP::kelvin;
188 d = 0.169 * CLHEP::g / CLHEP::cm3;
189 T = 22.0 * CLHEP::kelvin;
203 a = 14.01 * CLHEP::g / CLHEP::mole;
204 d = 1.007 * CLHEP::g / CLHEP::cm3;
205 T = 1.0 * CLHEP::kelvin;
223 a = 3.0160293 * CLHEP::g / CLHEP::mole;
228 Helium3->AddIsotope(Helion, 1);
235 d = 0.1650 * CLHEP::mg / CLHEP::cm3;
236 T = 294.25 * CLHEP::kelvin;
253 a = 3.0160492 * CLHEP::g / CLHEP::mole;
257 Tritium->AddIsotope(Triton, 1);
263 d = 0.0034 * CLHEP::g / CLHEP::cm3;
264 T = 40.0 * CLHEP::kelvin;
279 auto NISTman = G4NistManager::Instance();
280 d = 1.29 * CLHEP::mg / CLHEP::cm3;
283 70 * CLHEP::perCent);
285 30 * CLHEP::perCent);
287 std::vector<G4double> photonEnergy = {2.034 * CLHEP::eV, 4.136 * CLHEP::eV};
288 std::vector<G4double> refractiveIndex = {1.00, 1.00};
289 auto airOpticalMPT =
new G4MaterialPropertiesTable();
290 airOpticalMPT->AddProperty(
"RINDEX", photonEnergy, refractiveIndex);
300 d = 1.0e-8 * CLHEP::mg / CLHEP::cm3;
303 G4NistManager::Instance()->FindOrBuildMaterial(
"G4_Ar"), 100 * CLHEP::perCent);
std::shared_ptr< GLogger > log
High-level builder that turns a GEMC world description into Geant4 geometry.
constexpr char LD2_MATERIAL[]
constexpr char TRITON_ISOTOPE[]
constexpr char HELIUM3_ELEMENT[]
constexpr char ND3_MATERIAL[]
constexpr char HGAS_MATERIAL[]
constexpr char DEUTERIUM_ELEMENT[]
constexpr char DEUTERON_ISOTOPE[]
constexpr char AIROPTICAL_MATERIAL[]
constexpr char TRITIUM_ELEMENT[]
constexpr char NITRO_ELEMENT[]
constexpr char TRITIUMGAS_MATERIAL[]
constexpr char KRYPTONITE_MATERIAL[]
constexpr char HELIUM3GAS_MATERIAL[]
constexpr char DEUTERIUMGAS_MATERIAL[]
constexpr char HYDROGEN_ELEMENT[]
constexpr char HELION_ISOTOPE[]
constexpr int ERR_GMATERIALOPTICALPROPERTYMISMATCH