37 #include <Geant4/G4SystemOfUnits.hh>
38 #include <Geant4/G4BooleanSolid.hh>
39 #include <Geant4/G4Box.hh>
40 #include <Geant4/G4Cons.hh>
41 #include <Geant4/G4Ellipsoid.hh>
42 #include <Geant4/G4EllipticalCone.hh>
43 #include <Geant4/G4EllipticalTube.hh>
44 #include <Geant4/G4ExtrudedSolid.hh>
45 #include <Geant4/G4Hype.hh>
46 #include <Geant4/G4Orb.hh>
47 #include <Geant4/G4Para.hh>
48 #include <Geant4/G4Paraboloid.hh>
49 #include <Geant4/G4IntersectionSolid.hh>
50 #include <Geant4/G4Polycone.hh>
51 #include <Geant4/G4GenericPolycone.hh>
52 #include <Geant4/G4Polyhedra.hh>
53 #include <Geant4/G4ReflectedSolid.hh>
54 #include <Geant4/G4Sphere.hh>
55 #include <Geant4/G4SubtractionSolid.hh>
56 #include <Geant4/G4GenericTrap.hh>
57 #include <Geant4/G4TessellatedSolid.hh>
58 #include <Geant4/G4Tet.hh>
59 #include <Geant4/G4Torus.hh>
60 #include <Geant4/G4Trap.hh>
61 #include <Geant4/G4Trd.hh>
62 #include <Geant4/G4Tubs.hh>
63 #include <Geant4/G4CutTubs.hh>
64 #include <Geant4/G4TwistedBox.hh>
65 #include <Geant4/G4TwistedTrap.hh>
66 #include <Geant4/G4TwistedTrd.hh>
67 #include <Geant4/G4TwistedTubs.hh>
68 #include <Geant4/G4UnionSolid.hh>
69 #include <Geant4/G4OpticalSurface.hh>
70 #include <Geant4/G4SurfaceProperty.hh>
81 #if !defined(G4GEOM_USE_USOLIDS)
86 G4Exception(
"PHG4GDMLWriteSolids::MultiUnionWrite()",
88 "Installation with USolids primitives required!");
101 multiUnionElement->setAttributeNode(
NewAttribute(
"name",name));
103 for (
G4int i=0; i<numSolids; ++i)
116 rot3d.
yx(), rot3d.
yy(), rot3d.
yz(),
117 rot3d.
zx(), rot3d.
zy(), rot3d.
zz()));
122 std::ostringstream os; os << i+1;
124 xercesc::DOMElement* solidElement =
NewElement(
"solid");
125 solidElement->setAttributeNode(
NewAttribute(
"ref",solidref));
126 xercesc::DOMElement* multiUnionNodeElement =
NewElement(
"multiUnionNode");
127 multiUnionNodeElement->setAttributeNode(
NewAttribute(
"name", nodeName));
128 multiUnionNodeElement->appendChild(solidElement);
141 multiUnionElement->appendChild(multiUnionNodeElement);
144 solElement->appendChild(multiUnionElement);
156 if (dynamic_cast<const G4IntersectionSolid*>(
boolean))
157 { tag =
"intersection"; }
else
158 if (dynamic_cast<const G4SubtractionSolid*>(
boolean))
159 { tag =
"subtraction"; }
else
160 if (dynamic_cast<const G4UnionSolid*>(
boolean))
163 G4VSolid* firstPtr =
const_cast<G4VSolid*
>(
boolean->GetConstituentSolid(0));
164 G4VSolid* secondPtr =
const_cast<G4VSolid*
>(
boolean->GetConstituentSolid(1));
174 G4String ErrorMessage =
"The referenced solid '"
176 +
"in the Boolean shape '" +
177 +
boolean->GetName() +
178 +
"' was displaced too many times!";
185 firstpos += disp->GetObjectTranslation();
186 firstrot +=
GetAngles(disp->GetObjectRotation());
187 firstPtr = disp->GetConstituentMovedSolid();
198 G4String ErrorMessage =
"The referenced solid '"
200 +
"in the Boolean shape '" +
201 +
boolean->GetName() +
202 +
"' was displaced too many times!";
209 pos += disp->GetObjectTranslation();
210 rot +=
GetAngles(disp->GetObjectRotation());
211 secondPtr = disp->GetConstituentMovedSolid();
225 xercesc::DOMElement* booleanElement =
NewElement(tag);
226 booleanElement->setAttributeNode(
NewAttribute(
"name",name));
227 xercesc::DOMElement* firstElement =
NewElement(
"first");
228 firstElement->setAttributeNode(
NewAttribute(
"ref",firstref));
229 booleanElement->appendChild(firstElement);
230 xercesc::DOMElement* secondElement =
NewElement(
"second");
231 secondElement->setAttributeNode(
NewAttribute(
"ref",secondref));
232 booleanElement->appendChild(secondElement);
233 solElement->appendChild(booleanElement);
270 xercesc::DOMElement* boxElement =
NewElement(
"box");
271 boxElement->setAttributeNode(
NewAttribute(
"name",name));
275 boxElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
276 solElement->appendChild(boxElement);
284 xercesc::DOMElement* coneElement =
NewElement(
"cone");
285 coneElement->setAttributeNode(
NewAttribute(
"name",name));
300 coneElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
301 coneElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
302 solElement->appendChild(coneElement);
311 xercesc::DOMElement* elconeElement =
NewElement(
"elcone");
312 elconeElement->setAttributeNode(
NewAttribute(
"name",name));
317 elconeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
318 solElement->appendChild(elconeElement);
327 xercesc::DOMElement* ellipsoidElement =
NewElement(
"ellipsoid");
328 ellipsoidElement->setAttributeNode(
NewAttribute(
"name",name));
341 solElement->appendChild(ellipsoidElement);
350 xercesc::DOMElement* eltubeElement =
NewElement(
"eltube");
351 eltubeElement->setAttributeNode(
NewAttribute(
"name",name));
355 eltubeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
356 solElement->appendChild(eltubeElement);
365 xercesc::DOMElement* xtruElement =
NewElement(
"xtru");
366 xtruElement->setAttributeNode(
NewAttribute(
"name",name));
367 xtruElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
368 solElement->appendChild(xtruElement);
372 for (
G4int i=0;i<NumVertex;i++)
374 xercesc::DOMElement* twoDimVertexElement =
NewElement(
"twoDimVertex");
375 xtruElement->appendChild(twoDimVertexElement);
379 twoDimVertexElement->setAttributeNode(
NewAttribute(
"x",vertex.
x()/
mm));
380 twoDimVertexElement->setAttributeNode(
NewAttribute(
"y",vertex.
y()/
mm));
385 for (
G4int i=0;i<NumSection;i++)
387 xercesc::DOMElement* sectionElement =
NewElement(
"section");
388 xtruElement->appendChild(sectionElement);
392 sectionElement->setAttributeNode(
NewAttribute(
"zOrder",i));
408 xercesc::DOMElement* hypeElement =
NewElement(
"hype");
409 hypeElement->setAttributeNode(
NewAttribute(
"name",name));
420 hypeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
421 hypeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
422 solElement->appendChild(hypeElement);
430 xercesc::DOMElement* orbElement =
NewElement(
"orb");
431 orbElement->setAttributeNode(
NewAttribute(
"name",name));
433 orbElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
434 solElement->appendChild(orbElement);
447 xercesc::DOMElement* paraElement =
NewElement(
"para");
448 paraElement->setAttributeNode(
NewAttribute(
"name",name));
458 paraElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
459 paraElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
460 solElement->appendChild(paraElement);
469 xercesc::DOMElement* paraboloidElement =
NewElement(
"paraboloid");
470 paraboloidElement->setAttributeNode(
NewAttribute(
"name",name));
477 paraboloidElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
478 solElement->appendChild(paraboloidElement);
486 xercesc::DOMElement* polyconeElement =
NewElement(
"polycone");
487 polyconeElement->setAttributeNode(
NewAttribute(
"name",name));
488 polyconeElement->setAttributeNode(
NewAttribute(
"startphi",
490 polyconeElement->setAttributeNode(
NewAttribute(
"deltaphi",
492 polyconeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
493 polyconeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
494 solElement->appendChild(polyconeElement);
501 for (
size_t i=0; i<num_zplanes; i++)
503 ZplaneWrite(polyconeElement,z_array[i],rmin_array[i],rmax_array[i]);
514 xercesc::DOMElement* polyconeElement =
NewElement(
"genericPolycone");
516 polyconeElement->setAttributeNode(
NewAttribute(
"name",name));
517 polyconeElement->setAttributeNode(
NewAttribute(
"startphi",
519 polyconeElement->setAttributeNode(
NewAttribute(
"deltaphi",
521 polyconeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
522 polyconeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
523 solElement->appendChild(polyconeElement);
526 for (
size_t i=0; i<num_rzpoints; i++)
541 xercesc::DOMElement* polyhedraElement =
NewElement(
"polyhedra");
542 polyhedraElement->setAttributeNode(
NewAttribute(
"name",name));
543 polyhedraElement->setAttributeNode(
NewAttribute(
"startphi",
545 polyhedraElement->setAttributeNode(
NewAttribute(
"deltaphi",
547 polyhedraElement->setAttributeNode(
NewAttribute(
"numsides",
549 polyhedraElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
550 polyhedraElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
551 solElement->appendChild(polyhedraElement);
562 for (
size_t i=0;i<num_zplanes;i++)
565 rmin_array[i]*convertRad, rmax_array[i]*convertRad);
569 xercesc::DOMElement* polyhedraElement =
NewElement(
"genericPolyhedra");
570 polyhedraElement->setAttributeNode(
NewAttribute(
"name",name));
571 polyhedraElement->setAttributeNode(
NewAttribute(
"startphi",
573 polyhedraElement->setAttributeNode(
NewAttribute(
"deltaphi",
575 polyhedraElement->setAttributeNode(
NewAttribute(
"numsides",
577 polyhedraElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
578 polyhedraElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
579 solElement->appendChild(polyhedraElement);
583 for (
size_t i=0;i<num_rzpoints;i++)
597 xercesc::DOMElement* sphereElement =
NewElement(
"sphere");
598 sphereElement->setAttributeNode(
NewAttribute(
"name",name));
603 sphereElement->setAttributeNode(
NewAttribute(
"startphi",
605 sphereElement->setAttributeNode(
NewAttribute(
"deltaphi",
607 sphereElement->setAttributeNode(
NewAttribute(
"starttheta",
609 sphereElement->setAttributeNode(
NewAttribute(
"deltatheta",
611 sphereElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
612 sphereElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
613 solElement->appendChild(sphereElement);
623 xercesc::DOMElement* tessellatedElement =
NewElement(
"tessellated");
624 tessellatedElement->setAttributeNode(
NewAttribute(
"name",name));
625 tessellatedElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
626 tessellatedElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
627 solElement->appendChild(tessellatedElement);
629 std::map<G4ThreeVector, G4String, G4ThreeVectorCompare> vertexMap;
632 size_t NumVertex = 0;
634 for (
size_t i=0;i<NumFacets;i++)
641 if (NumVertexPerFacet==3) { FacetTag=
"triangular"; }
else
642 if (NumVertexPerFacet==4) { FacetTag=
"quadrangular"; }
645 G4Exception(
"PHG4GDMLWriteSolids::TessellatedWrite()",
"InvalidSetup",
649 xercesc::DOMElement* facetElement =
NewElement(FacetTag);
650 tessellatedElement->appendChild(facetElement);
652 for (
size_t j=0; j<NumVertexPerFacet; j++)
654 std::stringstream name_stream;
655 std::stringstream ref_stream;
657 name_stream <<
"vertex" << (j+1);
658 ref_stream << solid_name <<
"_v" << NumVertex;
671 if(vertexMap.find(vertex) != vertexMap.end())
673 ref = vertexMap[vertex];
677 vertexMap.insert(std::make_pair(vertex,ref));
684 facetElement->setAttributeNode(
NewAttribute(fname,ref));
695 std::vector<G4ThreeVector> vertexList = tet->
GetVertices();
697 xercesc::DOMElement* tetElement =
NewElement(
"tet");
698 tetElement->setAttributeNode(
NewAttribute(
"name",name));
699 tetElement->setAttributeNode(
NewAttribute(
"vertex1",solid_name+
"_v1"));
700 tetElement->setAttributeNode(
NewAttribute(
"vertex2",solid_name+
"_v2"));
701 tetElement->setAttributeNode(
NewAttribute(
"vertex3",solid_name+
"_v3"));
702 tetElement->setAttributeNode(
NewAttribute(
"vertex4",solid_name+
"_v4"));
703 tetElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
704 solElement->appendChild(tetElement);
717 xercesc::DOMElement* torusElement =
NewElement(
"torus");
718 torusElement->setAttributeNode(
NewAttribute(
"name",name));
726 torusElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
727 torusElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
728 solElement->appendChild(torusElement);
737 std::vector<G4TwoVector> vertices = gtrap->
GetVertices();
739 xercesc::DOMElement* gtrapElement =
NewElement(
"arb8");
740 gtrapElement->setAttributeNode(
NewAttribute(
"name",name));
743 gtrapElement->setAttributeNode(
NewAttribute(
"v1x", vertices[0].
x()));
744 gtrapElement->setAttributeNode(
NewAttribute(
"v1y", vertices[0].
y()));
745 gtrapElement->setAttributeNode(
NewAttribute(
"v2x", vertices[1].
x()));
746 gtrapElement->setAttributeNode(
NewAttribute(
"v2y", vertices[1].
y()));
747 gtrapElement->setAttributeNode(
NewAttribute(
"v3x", vertices[2].
x()));
748 gtrapElement->setAttributeNode(
NewAttribute(
"v3y", vertices[2].
y()));
749 gtrapElement->setAttributeNode(
NewAttribute(
"v4x", vertices[3].
x()));
750 gtrapElement->setAttributeNode(
NewAttribute(
"v4y", vertices[3].
y()));
751 gtrapElement->setAttributeNode(
NewAttribute(
"v5x", vertices[4].
x()));
752 gtrapElement->setAttributeNode(
NewAttribute(
"v5y", vertices[4].
y()));
753 gtrapElement->setAttributeNode(
NewAttribute(
"v6x", vertices[5].
x()));
754 gtrapElement->setAttributeNode(
NewAttribute(
"v6y", vertices[5].
y()));
755 gtrapElement->setAttributeNode(
NewAttribute(
"v7x", vertices[6].
x()));
756 gtrapElement->setAttributeNode(
NewAttribute(
"v7y", vertices[6].
y()));
757 gtrapElement->setAttributeNode(
NewAttribute(
"v8x", vertices[7].
x()));
758 gtrapElement->setAttributeNode(
NewAttribute(
"v8y", vertices[7].
y()));
759 gtrapElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
760 solElement->appendChild(gtrapElement);
774 xercesc::DOMElement* trapElement =
NewElement(
"trap");
775 trapElement->setAttributeNode(
NewAttribute(
"name",name));
794 trapElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
795 trapElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
796 solElement->appendChild(trapElement);
804 xercesc::DOMElement* trdElement =
NewElement(
"trd");
805 trdElement->setAttributeNode(
NewAttribute(
"name",name));
816 trdElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
817 solElement->appendChild(trdElement);
825 xercesc::DOMElement* tubeElement =
NewElement(
"tube");
826 tubeElement->setAttributeNode(
NewAttribute(
"name",name));
837 tubeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
838 tubeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
839 solElement->appendChild(tubeElement);
847 xercesc::DOMElement* cuttubeElement =
NewElement(
"cutTube");
848 cuttubeElement->setAttributeNode(
NewAttribute(
"name",name));
855 cuttubeElement->setAttributeNode(
NewAttribute(
"startphi",
857 cuttubeElement->setAttributeNode(
NewAttribute(
"deltaphi",
871 cuttubeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
872 cuttubeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
873 solElement->appendChild(cuttubeElement);
882 xercesc::DOMElement* twistedboxElement =
NewElement(
"twistedbox");
883 twistedboxElement->setAttributeNode(
NewAttribute(
"name",name));
890 twistedboxElement->setAttributeNode(
NewAttribute(
"PhiTwist",
892 twistedboxElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
893 twistedboxElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
894 solElement->appendChild(twistedboxElement);
903 xercesc::DOMElement* twistedtrapElement =
NewElement(
"twistedtrap");
904 twistedtrapElement->setAttributeNode(
NewAttribute(
"name",name));
919 twistedtrapElement->setAttributeNode(
NewAttribute(
"Alph",
921 twistedtrapElement->setAttributeNode(
NewAttribute(
"Theta",
923 twistedtrapElement->setAttributeNode(
NewAttribute(
"Phi",
925 twistedtrapElement->setAttributeNode(
NewAttribute(
"PhiTwist",
927 twistedtrapElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
928 twistedtrapElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
930 solElement->appendChild(twistedtrapElement);
939 xercesc::DOMElement* twistedtrdElement =
NewElement(
"twistedtrd");
940 twistedtrdElement->setAttributeNode(
NewAttribute(
"name",name));
951 twistedtrdElement->setAttributeNode(
NewAttribute(
"PhiTwist",
953 twistedtrdElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
954 twistedtrdElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
955 solElement->appendChild(twistedtrdElement);
964 xercesc::DOMElement* twistedtubsElement =
NewElement(
"twistedtubs");
965 twistedtubsElement->setAttributeNode(
NewAttribute(
"name",name));
966 twistedtubsElement->setAttributeNode(
NewAttribute(
"twistedangle",
968 twistedtubsElement->setAttributeNode(
NewAttribute(
"endinnerrad",
970 twistedtubsElement->setAttributeNode(
NewAttribute(
"endouterrad",
972 twistedtubsElement->setAttributeNode(
NewAttribute(
"zlen",
974 twistedtubsElement->setAttributeNode(
NewAttribute(
"phi",
976 twistedtubsElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
977 twistedtubsElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
978 solElement->appendChild(twistedtubsElement);
985 xercesc::DOMElement* zplaneElement =
NewElement(
"zplane");
989 element->appendChild(zplaneElement);
996 xercesc::DOMElement* rzpointElement =
NewElement(
"rzpoint");
999 element->appendChild(rzpointElement);
1006 xercesc::DOMElement* optElement =
NewElement(
"opticalsurface");
1011 optElement->setAttributeNode(
NewAttribute(
"model", smodel));
1014 optElement->setAttributeNode(
NewAttribute(
"value", sval));
1016 solElement->appendChild(optElement);
1021 std::cout <<
"PHG4GDML: Writing solids..." << std::endl;
1031 for (
size_t i=0; i<
solidList.size(); i++)
1033 if (
solidList[i] == solidPtr) {
return; }
1039 = dynamic_cast<const G4BooleanSolid*>(solidPtr))
1046 {
const G4Box*
const boxPtr
1047 =
static_cast<const G4Box*
>(solidPtr);
1050 {
const G4Cons*
const conePtr
1051 =
static_cast<const G4Cons*
>(solidPtr);
1070 {
const G4Hype*
const hypePtr
1071 =
static_cast<const G4Hype*
>(solidPtr);
1074 {
const G4Orb*
const orbPtr
1075 =
static_cast<const G4Orb*
>(solidPtr);
1078 {
const G4Para*
const paraPtr
1079 =
static_cast<const G4Para*
>(solidPtr);
1099 =
static_cast<const G4Sphere*
>(solidPtr);
1106 {
const G4Tet*
const tetPtr
1107 =
static_cast<const G4Tet*
>(solidPtr);
1110 {
const G4Torus*
const torusPtr
1111 =
static_cast<const G4Torus*
>(solidPtr);
1118 {
const G4Trap*
const trapPtr
1119 =
static_cast<const G4Trap*
>(solidPtr);
1122 {
const G4Trd*
const trdPtr
1123 =
static_cast<const G4Trd*
>(solidPtr);
1126 {
const G4Tubs*
const tubePtr
1127 =
static_cast<const G4Tubs*
>(solidPtr);
1131 =
static_cast<const G4CutTubs*
>(solidPtr);
1153 G4Exception(
"PHG4GDMLWriteSolids::AddSolid()",
"WriteError",