37 #include <Geant4/G4Element.hh>
38 #include <Geant4/G4Isotope.hh>
39 #include <Geant4/G4Material.hh>
40 #include <Geant4/G4MaterialPropertiesTable.hh>
41 #include <Geant4/G4PhysicalConstants.hh>
42 #include <Geant4/G4PhysicsFreeVector.hh>
43 #include <Geant4/G4SystemOfUnits.hh>
60 xercesc::DOMElement* atomElement =
NewElement(
"atom");
61 atomElement->setAttributeNode(
NewAttribute(
"unit",
"g/mole"));
62 atomElement->setAttributeNode(
NewAttribute(
"value", a * mole /
g));
63 element->appendChild(atomElement);
69 xercesc::DOMElement* DElement =
NewElement(
"D");
70 DElement->setAttributeNode(
NewAttribute(
"unit",
"g/cm3"));
72 element->appendChild(DElement);
78 xercesc::DOMElement* PElement =
NewElement(
"P");
79 PElement->setAttributeNode(
NewAttribute(
"unit",
"pascal"));
80 PElement->setAttributeNode(
NewAttribute(
"value", P / hep_pascal));
81 element->appendChild(PElement);
87 xercesc::DOMElement* TElement =
NewElement(
"T");
89 TElement->setAttributeNode(
NewAttribute(
"value", T / kelvin));
90 element->appendChild(TElement);
96 xercesc::DOMElement* PElement =
NewElement(
"MEE");
98 PElement->setAttributeNode(
NewAttribute(
"value", MEE / electronvolt));
99 element->appendChild(PElement);
107 xercesc::DOMElement* isotopeElement =
NewElement(
"isotope");
108 isotopeElement->setAttributeNode(
NewAttribute(
"name", name));
109 isotopeElement->setAttributeNode(
NewAttribute(
"N", isotopePtr->GetN()));
110 isotopeElement->setAttributeNode(
NewAttribute(
"Z", isotopePtr->GetZ()));
112 AtomWrite(isotopeElement, isotopePtr->GetA());
119 xercesc::DOMElement* elementElement =
NewElement(
"element");
120 elementElement->setAttributeNode(
NewAttribute(
"name", name));
122 const size_t NumberOfIsotopes = elementPtr->GetNumberOfIsotopes();
124 if (NumberOfIsotopes > 0)
126 const G4double* RelativeAbundanceVector =
127 elementPtr->GetRelativeAbundanceVector();
128 for (
size_t i = 0;
i < NumberOfIsotopes;
i++)
130 G4String fractionref =
GenerateName(elementPtr->GetIsotope(
i)->GetName(),
131 elementPtr->GetIsotope(
i));
132 xercesc::DOMElement* fractionElement =
NewElement(
"fraction");
134 RelativeAbundanceVector[
i]));
135 fractionElement->setAttributeNode(
NewAttribute(
"ref", fractionref));
136 elementElement->appendChild(fractionElement);
142 elementElement->setAttributeNode(
NewAttribute(
"Z", elementPtr->GetZ()));
143 AtomWrite(elementElement, elementPtr->GetA());
152 G4String state_str(
"undefined");
153 const G4State
state = materialPtr->GetState();
154 if (state == kStateSolid)
158 else if (state == kStateLiquid)
160 state_str =
"liquid";
162 else if (state == kStateGas)
169 xercesc::DOMElement* materialElement =
NewElement(
"material");
170 materialElement->setAttributeNode(
NewAttribute(
"name", name));
171 materialElement->setAttributeNode(
NewAttribute(
"state", state_str));
175 if (materialPtr->GetMaterialPropertiesTable())
180 if (materialPtr->GetTemperature() != STP_Temperature)
182 TWrite(materialElement, materialPtr->GetTemperature());
184 if (materialPtr->GetPressure() != STP_Pressure)
186 PWrite(materialElement, materialPtr->GetPressure());
190 MEEWrite(materialElement, materialPtr->GetIonisation()->GetMeanExcitationEnergy());
192 DWrite(materialElement, materialPtr->GetDensity());
194 const size_t NumberOfElements = materialPtr->GetNumberOfElements();
196 if ((NumberOfElements > 1) || (materialPtr->GetElement(0) && materialPtr->GetElement(0)->GetNumberOfIsotopes() > 1))
198 const G4double* MassFractionVector = materialPtr->GetFractionVector();
200 for (
size_t i = 0;
i < NumberOfElements;
i++)
202 const G4String fractionref =
204 materialPtr->GetElement(
i));
205 xercesc::DOMElement* fractionElement =
NewElement(
"fraction");
207 MassFractionVector[
i]));
208 fractionElement->setAttributeNode(
NewAttribute(
"ref", fractionref));
209 materialElement->appendChild(fractionElement);
215 materialElement->setAttributeNode(
NewAttribute(
"Z", materialPtr->GetZ()));
216 AtomWrite(materialElement, materialPtr->GetA());
224 #if G4VERSION_NUMBER >= 1100
227 void PHG4GDMLWriteMaterials::PropertyConstWrite(
228 const G4String& key,
const G4double pval,
229 const G4MaterialPropertiesTable* ptable)
232 xercesc::DOMElement* matrixElement =
NewElement(
"matrix");
233 matrixElement->setAttributeNode(
NewAttribute(
"name", matrixref));
234 matrixElement->setAttributeNode(
NewAttribute(
"coldim",
"1"));
235 std::ostringstream pvalues;
238 matrixElement->setAttributeNode(
NewAttribute(
"values", pvalues.str()));
244 const G4String& key,
const G4PhysicsFreeVector*
const pvec)
256 xercesc::DOMElement* matrixElement =
NewElement(
"matrix");
257 matrixElement->setAttributeNode(
NewAttribute(
"name", matrixref));
258 matrixElement->setAttributeNode(
NewAttribute(
"coldim",
"2"));
259 std::ostringstream pvalues;
260 for (std::size_t
i = 0;
i < pvec->GetVectorLength(); ++
i)
266 pvalues << pvec->Energy(
i) <<
" " << (*pvec)[
i];
268 matrixElement->setAttributeNode(
NewAttribute(
"values", pvalues.str()));
274 const G4Material*
const mat)
276 xercesc::DOMElement* propElement;
277 G4MaterialPropertiesTable* ptable = mat->GetMaterialPropertiesTable();
279 auto pvec = ptable->GetProperties();
280 auto cvec = ptable->GetConstProperties();
282 for (
size_t i = 0;
i < pvec.size(); ++
i)
284 if (pvec[
i] !=
nullptr)
287 propElement->setAttributeNode(
288 NewAttribute(
"name", ptable->GetMaterialPropertyNames()[
i]));
294 matElement->appendChild(propElement);
298 for (
size_t i = 0;
i < cvec.size(); ++
i)
300 if (cvec[
i].second ==
true)
304 "name", ptable->GetMaterialConstPropertyNames()[
i]));
306 "ref",
GenerateName(ptable->GetMaterialConstPropertyNames()[
i],
308 PropertyConstWrite(ptable->GetMaterialConstPropertyNames()[
i],
309 cvec[
i].first, ptable);
310 matElement->appendChild(propElement);
315 #else // #if G4VERSION_NUMBER >= 1100
317 const G4PhysicsOrderedFreeVector*
const pvec)
320 xercesc::DOMElement* matrixElement =
NewElement(
"matrix");
321 matrixElement->setAttributeNode(
NewAttribute(
"name", matrixref));
322 matrixElement->setAttributeNode(
NewAttribute(
"coldim",
"2"));
323 std::ostringstream pvalues;
324 for (
size_t i = 0;
i < pvec->GetVectorLength();
i++)
330 pvalues << pvec->Energy(
i) <<
" " << (*pvec)[
i];
332 matrixElement->setAttributeNode(
NewAttribute(
"values", pvalues.str()));
338 const G4Material*
const mat)
340 xercesc::DOMElement* propElement;
341 G4MaterialPropertiesTable* ptable = mat->GetMaterialPropertiesTable();
343 const std::map<G4int, G4PhysicsOrderedFreeVector*,
344 std::less<G4int> >* pmap = ptable->GetPropertyMap();
345 const std::map<G4int, G4double,
346 std::less<G4int> >* cmap = ptable->GetConstPropertyMap();
347 std::map<G4int, G4PhysicsOrderedFreeVector*,
348 std::less<G4int> >::const_iterator mpos;
349 std::map<G4int, G4double,
350 std::less<G4int> >::const_iterator cpos;
352 for (mpos = pmap->begin(); mpos != pmap->end(); ++mpos)
356 ptable->GetMaterialPropertyNames()[mpos->first]));
358 GenerateName(ptable->GetMaterialPropertyNames()[mpos->first],
364 matElement->appendChild(propElement);
368 G4String warn_message =
"Null pointer for material property -" + ptable->GetMaterialPropertyNames()[mpos->first] +
"- of material -" + mat->GetName() +
"- !";
369 G4Exception(
"G4GDMLWriteMaterials::PropertyWrite()",
"NullPointer",
370 JustWarning, warn_message);
375 for (cpos = cmap->begin(); cpos != cmap->end(); ++cpos)
379 ptable->GetMaterialConstPropertyNames()[cpos->first]));
381 ptable->GetMaterialConstPropertyNames()[cpos->first]));
382 xercesc::DOMElement* constElement =
NewElement(
"constant");
384 ptable->GetMaterialConstPropertyNames()[cpos->first]));
385 constElement->setAttributeNode(
NewAttribute(
"value", cpos->second));
387 matElement->appendChild(propElement);
390 #endif // #if G4VERSION_NUMBER >= 1100
394 std::cout <<
"G4GDML: Writing materials..." << std::endl;