11 #include "G4Element.hh" 12 #include "G4NistManager.hh" 13 #include "G4OpBoundaryProcess.hh" 16 #include "CLHEP/Units/PhysicalConstants.h" 17 using namespace CLHEP;
22 string hd_msg = opts.
optMap[
"LOG_MSG"].args +
" GDML Materials: >> ";
26 map<string, G4Element*> elementsMap;
27 map<string, G4Material*> materialsMap;
36 if(it->second.get_factory() !=
"GDML" )
40 cout << hd_msg <<
" Initializing " << it->second.get_factory() <<
" for detector " << it->first << endl;
42 string dname = it->first;
43 string fname = dname +
".gdml";
46 QFile gdet(fname.c_str());
50 cout << hd_msg <<
" Failed to open geometry file " << fname <<
" for system: " << dname <<
". Maybe the filename doesn't exist? Exiting." << endl;
54 QDomDocument domDocument;
56 if(!domDocument.setContent(&gdet))
58 cout << hd_msg <<
" Failed to open geometry file " << fname <<
" for system: " << dname <<
". Wrong XML syntax. Exiting." << endl;
63 QDomElement docElem = domDocument.documentElement();
64 QDomNode n = docElem.firstChild();
68 QDomElement e = n.toElement();
70 if(!e.isNull() && e.tagName().toStdString() ==
"materials")
72 QDomNode nn= e.firstChild();
76 QDomElement ee = nn.toElement();
78 if(ee.tagName().toStdString() ==
"element")
83 double molar_mass = 0;
85 QDomNode nnn= ee.firstChild();
87 while( !nnn.isNull() )
89 QDomElement eee = nnn.toElement();
91 if(eee.tagName().toStdString() ==
"atom")
94 nnn=nnn.nextSibling();
95 cout << ename <<
" Z: "<< Z <<
" molar_mass: " << molar_mass << endl;
98 elementsMap[ename] =
new G4Element(ename, ename, Z, molar_mass*g/mole);
101 if(ee.tagName().toStdString() ==
"material")
103 vector<double> fractions;
104 vector<int> composite;
109 double molar_mass = 0;
113 QDomNode nnn= ee.firstChild();
114 while( !nnn.isNull() )
116 QDomElement eee = nnn.toElement();
118 if(eee.tagName().toStdString() ==
"D")
121 if(eee.tagName().toStdString() ==
"atom")
126 if(eee.tagName().toStdString() ==
"fraction")
131 if(eee.tagName().toStdString() ==
"composite")
136 nnn=nnn.nextSibling();
139 if(fractions.size() == 0)
140 elementsMap[ename] =
new G4Element(ename, ename, Z, molar_mass*g/mole);
142 if (Z>0 && molar_mass >0)
143 materialsMap[ename]=
new G4Material(ename, Z, molar_mass*g/mole, density*g/cm3);
146 if(fractions.size() != 0)
148 cout <<
"fraction.size() " << fractions.size() << endl;
149 materialsMap[ename] =
new G4Material(ename, density*g/cm3, (
int) fractions.size());
151 for(
unsigned int i=0; i<fractions.size(); i++)
153 cout << refs[i] <<
" elementsMap : " << elementsMap[refs[i]] << endl;
154 if(fractions[i] >= 1) materialsMap[ename]->AddElement(elementsMap[refs[i]], (
int)fractions[i]);
155 else materialsMap[ename]->AddElement(elementsMap[refs[i]], fractions[i]);
map< string, G4Material * > initMaterials(runConditions, goptions)
int check_if_factory_is_needed(map< string, detectorCondition > dcon, string factory)
map< string, detectorCondition > detectorConditionsMap
void printMaterials(map< string, G4Material * > matMap)
string assignAttribute(QDomElement e, string attribute, string defaultValue)
map< string, aopt > optMap
Options map.