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 <", materialName,
"> already exists in G4NistManager");
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 <", componentName,
">, needed by ", materialName,
", not found yet");
31 }
else {
log->info(2,
"Element <", componentName,
"> needed by ", materialName,
" now found"); }
33 if (NISTman->FindOrBuildMaterial(componentName) ==
nullptr) {
34 log->info(2,
"Material <", componentName,
">, needed by ", materialName,
", not found yet");
36 }
else {
log->info(2,
"Material <", componentName,
"> needed by ", materialName,
" now found"); }
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 <", materialName,
"> with components:");
47 for (
size_t i = 0; i < components.size(); i++) {
48 log->info(2,
"element <", components[i],
"> with amount: ", 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 <", materialName,
"> with components:");
57 for (
size_t i = 0; i < components.size(); i++) {
58 log->info(2,
"material <", components[i],
"> with fractional mass: ", 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()) {
77 "material <", materialName,
"> optical property <", propertyName,
"> has ",
78 values.size(),
" entries but photonEnergy has ", photonEnergy.size());
80 materialPropertiesTable->AddProperty(propertyName, photonEnergy, values);
81 hasOpticalProperties =
true;
84 auto addConstantProperty = [&](
const char *propertyName,
double value,
bool isSet) {
85 if (!isSet) {
return; }
86 materialPropertiesTable->AddConstProperty(propertyName, value);
87 hasOpticalProperties =
true;
91 addProperty(
"RINDEX", gmaterial->getIndexOfRefraction());
92 addProperty(
"ABSLENGTH", gmaterial->getAbsorptionLength());
93 addProperty(
"REFLECTIVITY", gmaterial->getReflectivity());
94 addProperty(
"EFFICIENCY", gmaterial->getEfficiency());
96 addProperty(
"SCINTILLATIONCOMPONENT1", gmaterial->getFastComponent());
97 addProperty(
"SCINTILLATIONCOMPONENT2", gmaterial->getSlowComponent());
100 addConstantProperty(
"SCINTILLATIONYIELD", gmaterial->getScintillationYield(),
101 gmaterial->hasScintillationYield());
102 addConstantProperty(
"RESOLUTIONSCALE", gmaterial->getResolutionScale(),
103 gmaterial->hasResolutionScale());
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());
112 double getBirksConstant = gmaterial->getBirksConstant();
113 if (gmaterial->hasBirksConstant()) {
114 g4materialsMap[materialName]->GetIonisation()->SetBirksConstant(getBirksConstant);
115 hasOpticalProperties =
true;
119 addProperty(
"RAYLEIGH", gmaterial->getRayleigh());
121 if (hasOpticalProperties) {
122 g4materialsMap[materialName]->SetMaterialPropertiesTable(materialPropertiesTable);
123 log->info(2,
"Attached optical material properties table to material <", materialName,
">");
124 }
else {
delete materialPropertiesTable; }
131void G4World::buildDefaultMaterialsElementsAndIsotopes() {
142 a = 1.01 * CLHEP::g / CLHEP::mole;
143 d = 0.00275 * CLHEP::g / CLHEP::cm3;
144 T = 50.0 * CLHEP::kelvin;
161 a = 2.0141018 * CLHEP::g / CLHEP::mole;
166 Deuterium->AddIsotope(Deuteron, 1);
172 d = 0.000452 * CLHEP::g / CLHEP::cm3;
173 T = 294.25 * CLHEP::kelvin;
182 "> created with density <", d,
">");
186 d = 0.169 * CLHEP::g / CLHEP::cm3;
187 T = 22.0 * CLHEP::kelvin;
201 a = 14.01 * CLHEP::g / CLHEP::mole;
202 d = 1.007 * CLHEP::g / CLHEP::cm3;
203 T = 1.0 * CLHEP::kelvin;
221 a = 3.0160293 * CLHEP::g / CLHEP::mole;
226 Helium3->AddIsotope(Helion, 1);
233 d = 0.1650 * CLHEP::mg / CLHEP::cm3;
234 T = 294.25 * CLHEP::kelvin;
251 a = 3.0160492 * CLHEP::g / CLHEP::mole;
255 Tritium->AddIsotope(Triton, 1);
261 d = 0.0034 * CLHEP::g / CLHEP::cm3;
262 T = 40.0 * CLHEP::kelvin;
277 auto NISTman = G4NistManager::Instance();
278 d = 1.29 * CLHEP::mg / CLHEP::cm3;
281 70 * CLHEP::perCent);
283 30 * CLHEP::perCent);
285 std::vector<G4double> photonEnergy = {2.034 * CLHEP::eV, 4.136 * CLHEP::eV};
286 std::vector<G4double> refractiveIndex = {1.00, 1.00};
287 auto airOpticalMPT =
new G4MaterialPropertiesTable();
288 airOpticalMPT->AddProperty(
"RINDEX", photonEnergy, refractiveIndex);
298 d = 1.0e-8 * CLHEP::mg / CLHEP::cm3;
301 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