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)
84 const G4MultiUnion*
const)
86 G4Exception(
"PHG4GDMLWriteSolids::MultiUnionWrite()",
87 "InvalidSetup", FatalException,
88 "Installation with USolids primitives required!");
94 const G4MultiUnion*
const munionSolid)
96 G4int numSolids=munionSolid->GetNumberOfSolids();
97 G4String tag(
"multiUnion");
100 G4Transform3D* transform;
102 const G4String& name =
GenerateName(munionSolid->GetName(),munionSolid);
103 xercesc::DOMElement* multiUnionElement =
NewElement(tag);
104 multiUnionElement->setAttributeNode(
NewAttribute(
"name",name));
106 for (G4int i=0; i<numSolids; ++i)
108 solid = munionSolid->GetSolid(i);
109 transform = munionSolid->GetTransformation(i);
111 HepGeom::Rotate3D rot3d;
112 HepGeom::Translate3D transl ;
113 HepGeom::Scale3D scale;
114 transform->getDecomposition(scale,rot3d,transl);
116 G4ThreeVector pos = transl.getTranslation();
118 rotm(CLHEP::HepRep3x3(rot3d.xx(), rot3d.xy(), rot3d.xz(),
119 rot3d.yx(), rot3d.yy(), rot3d.yz(),
120 rot3d.zx(), rot3d.zy(), rot3d.zz()));
124 const G4String& solidref =
GenerateName(solid->GetName(),solid);
125 std::ostringstream os; os << i+1;
126 const G4String& nodeName =
"Node-" + G4String(os.str());
127 xercesc::DOMElement* solidElement =
NewElement(
"solid");
128 solidElement->setAttributeNode(
NewAttribute(
"ref",solidref));
129 xercesc::DOMElement* multiUnionNodeElement =
NewElement(
"multiUnionNode");
130 multiUnionNodeElement->setAttributeNode(
NewAttribute(
"name", nodeName));
131 multiUnionNodeElement->appendChild(solidElement);
144 multiUnionElement->appendChild(multiUnionNodeElement);
147 solElement->appendChild(multiUnionElement);
154 const G4BooleanSolid*
const boolean)
158 G4String tag(
"undefined");
159 if (
dynamic_cast<const G4IntersectionSolid*
>(
boolean))
160 { tag =
"intersection"; }
else
161 if (
dynamic_cast<const G4SubtractionSolid*
>(
boolean))
162 { tag =
"subtraction"; }
else
163 if (
dynamic_cast<const G4UnionSolid*
>(
boolean))
166 G4VSolid* firstPtr =
const_cast<G4VSolid*
>(
boolean->GetConstituentSolid(0));
167 G4VSolid* secondPtr =
const_cast<G4VSolid*
>(
boolean->GetConstituentSolid(1));
169 G4ThreeVector firstpos,firstrot,pos,rot;
177 G4String ErrorMessage =
"The referenced solid '"
178 + firstPtr->GetName() +
179 +
"in the Boolean shape '" +
180 +
boolean->GetName() +
181 +
"' was displaced too many times!";
182 G4Exception(
"PHG4GDMLWriteSolids::BooleanWrite()",
183 "InvalidSetup", FatalException, ErrorMessage);
186 if (G4DisplacedSolid* disp =
dynamic_cast<G4DisplacedSolid*
>(firstPtr))
188 firstpos += disp->GetObjectTranslation();
189 firstrot +=
GetAngles(disp->GetObjectRotation());
190 firstPtr = disp->GetConstituentMovedSolid();
201 G4String ErrorMessage =
"The referenced solid '"
202 + secondPtr->GetName() +
203 +
"in the Boolean shape '" +
204 +
boolean->GetName() +
205 +
"' was displaced too many times!";
206 G4Exception(
"PHG4GDMLWriteSolids::BooleanWrite()",
207 "InvalidSetup", FatalException, ErrorMessage);
210 if (G4DisplacedSolid* disp =
dynamic_cast<G4DisplacedSolid*
>(secondPtr))
212 pos += disp->GetObjectTranslation();
213 rot +=
GetAngles(disp->GetObjectRotation());
214 secondPtr = disp->GetConstituentMovedSolid();
224 const G4String& name =
GenerateName(boolean->GetName(),
boolean);
225 const G4String& firstref =
GenerateName(firstPtr->GetName(),firstPtr);
226 const G4String& secondref =
GenerateName(secondPtr->GetName(),secondPtr);
228 xercesc::DOMElement* booleanElement =
NewElement(tag);
229 booleanElement->setAttributeNode(
NewAttribute(
"name",name));
230 xercesc::DOMElement* firstElement =
NewElement(
"first");
231 firstElement->setAttributeNode(
NewAttribute(
"ref",firstref));
232 booleanElement->appendChild(firstElement);
233 xercesc::DOMElement* secondElement =
NewElement(
"second");
234 secondElement->setAttributeNode(
NewAttribute(
"ref",secondref));
235 booleanElement->appendChild(secondElement);
236 solElement->appendChild(booleanElement);
269 BoxWrite(xercesc::DOMElement* solElement,
const G4Box*
const box)
271 const G4String& name =
GenerateName(box->GetName(),box);
273 xercesc::DOMElement* boxElement =
NewElement(
"box");
274 boxElement->setAttributeNode(
NewAttribute(
"name",name));
275 boxElement->setAttributeNode(
NewAttribute(
"x",2.0*box->GetXHalfLength()/mm));
276 boxElement->setAttributeNode(
NewAttribute(
"y",2.0*box->GetYHalfLength()/mm));
277 boxElement->setAttributeNode(
NewAttribute(
"z",2.0*box->GetZHalfLength()/mm));
278 boxElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
279 solElement->appendChild(boxElement);
283 ConeWrite(xercesc::DOMElement* solElement,
const G4Cons*
const cone)
285 const G4String& name =
GenerateName(cone->GetName(),cone);
287 xercesc::DOMElement* coneElement =
NewElement(
"cone");
288 coneElement->setAttributeNode(
NewAttribute(
"name",name));
290 setAttributeNode(
NewAttribute(
"rmin1",cone->GetInnerRadiusMinusZ()/mm));
292 setAttributeNode(
NewAttribute(
"rmax1",cone->GetOuterRadiusMinusZ()/mm));
294 setAttributeNode(
NewAttribute(
"rmin2",cone->GetInnerRadiusPlusZ()/mm));
296 setAttributeNode(
NewAttribute(
"rmax2",cone->GetOuterRadiusPlusZ()/mm));
298 setAttributeNode(
NewAttribute(
"z",2.0*cone->GetZHalfLength()/mm));
300 setAttributeNode(
NewAttribute(
"startphi",cone->GetStartPhiAngle()/degree));
302 setAttributeNode(
NewAttribute(
"deltaphi",cone->GetDeltaPhiAngle()/degree));
303 coneElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
304 coneElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
305 solElement->appendChild(coneElement);
310 const G4EllipticalCone*
const elcone)
312 const G4String& name =
GenerateName(elcone->GetName(),elcone);
314 xercesc::DOMElement* elconeElement =
NewElement(
"elcone");
315 elconeElement->setAttributeNode(
NewAttribute(
"name",name));
316 elconeElement->setAttributeNode(
NewAttribute(
"dx",elcone->GetSemiAxisX()/mm));
317 elconeElement->setAttributeNode(
NewAttribute(
"dy",elcone->GetSemiAxisY()/mm));
318 elconeElement->setAttributeNode(
NewAttribute(
"zmax",elcone->GetZMax()/mm));
319 elconeElement->setAttributeNode(
NewAttribute(
"zcut",elcone->GetZTopCut()/mm));
320 elconeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
321 solElement->appendChild(elconeElement);
326 const G4Ellipsoid*
const ellipsoid)
328 const G4String& name =
GenerateName(ellipsoid->GetName(),ellipsoid);
330 xercesc::DOMElement* ellipsoidElement =
NewElement(
"ellipsoid");
331 ellipsoidElement->setAttributeNode(
NewAttribute(
"name",name));
333 setAttributeNode(
NewAttribute(
"ax",ellipsoid->GetSemiAxisMax(0)/mm));
335 setAttributeNode(
NewAttribute(
"by",ellipsoid->GetSemiAxisMax(1)/mm));
337 setAttributeNode(
NewAttribute(
"cz",ellipsoid->GetSemiAxisMax(2)/mm));
339 setAttributeNode(
NewAttribute(
"zcut1",ellipsoid->GetZBottomCut()/mm));
341 setAttributeNode(
NewAttribute(
"zcut2",ellipsoid->GetZTopCut()/mm));
344 solElement->appendChild(ellipsoidElement);
349 const G4EllipticalTube*
const eltube)
351 const G4String& name =
GenerateName(eltube->GetName(),eltube);
353 xercesc::DOMElement* eltubeElement =
NewElement(
"eltube");
354 eltubeElement->setAttributeNode(
NewAttribute(
"name",name));
355 eltubeElement->setAttributeNode(
NewAttribute(
"dx",eltube->GetDx()/mm));
356 eltubeElement->setAttributeNode(
NewAttribute(
"dy",eltube->GetDy()/mm));
357 eltubeElement->setAttributeNode(
NewAttribute(
"dz",eltube->GetDz()/mm));
358 eltubeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
359 solElement->appendChild(eltubeElement);
363 XtruWrite(xercesc::DOMElement* solElement,
364 const G4ExtrudedSolid*
const xtru)
366 const G4String& name =
GenerateName(xtru->GetName(),xtru);
368 xercesc::DOMElement* xtruElement =
NewElement(
"xtru");
369 xtruElement->setAttributeNode(
NewAttribute(
"name",name));
370 xtruElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
371 solElement->appendChild(xtruElement);
373 const G4int NumVertex = xtru->GetNofVertices();
375 for (G4int i=0;i<NumVertex;i++)
377 xercesc::DOMElement* twoDimVertexElement =
NewElement(
"twoDimVertex");
378 xtruElement->appendChild(twoDimVertexElement);
380 const G4TwoVector& vertex = xtru->GetVertex(i);
382 twoDimVertexElement->setAttributeNode(
NewAttribute(
"x",vertex.x()/mm));
383 twoDimVertexElement->setAttributeNode(
NewAttribute(
"y",vertex.y()/mm));
386 const G4int NumSection = xtru->GetNofZSections();
388 for (G4int i=0;i<NumSection;i++)
390 xercesc::DOMElement* sectionElement =
NewElement(
"section");
391 xtruElement->appendChild(sectionElement);
393 const G4ExtrudedSolid::ZSection section = xtru->GetZSection(i);
395 sectionElement->setAttributeNode(
NewAttribute(
"zOrder",i));
396 sectionElement->setAttributeNode(
NewAttribute(
"zPosition",section.fZ/mm));
398 setAttributeNode(
NewAttribute(
"xOffset",section.fOffset.x()/mm));
400 setAttributeNode(
NewAttribute(
"yOffset",section.fOffset.y()/mm));
402 setAttributeNode(
NewAttribute(
"scalingFactor",section.fScale));
407 HypeWrite(xercesc::DOMElement* solElement,
const G4Hype*
const hype)
409 const G4String& name =
GenerateName(hype->GetName(),hype);
411 xercesc::DOMElement* hypeElement =
NewElement(
"hype");
412 hypeElement->setAttributeNode(
NewAttribute(
"name",name));
414 hype->GetInnerRadius()/mm));
416 hype->GetOuterRadius()/mm));
418 hype->GetInnerStereo()/degree));
420 hype->GetOuterStereo()/degree));
422 2.0*hype->GetZHalfLength()/mm));
423 hypeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
424 hypeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
425 solElement->appendChild(hypeElement);
429 OrbWrite(xercesc::DOMElement* solElement,
const G4Orb*
const orb)
431 const G4String& name =
GenerateName(orb->GetName(),orb);
433 xercesc::DOMElement* orbElement =
NewElement(
"orb");
434 orbElement->setAttributeNode(
NewAttribute(
"name",name));
435 orbElement->setAttributeNode(
NewAttribute(
"r",orb->GetRadius()/mm));
436 orbElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
437 solElement->appendChild(orbElement);
441 ParaWrite(xercesc::DOMElement* solElement,
const G4Para*
const para)
443 const G4String& name =
GenerateName(para->GetName(),para);
445 const G4ThreeVector simaxis = para->GetSymAxis();
446 const G4double alpha = std::atan(para->GetTanAlpha());
447 const G4double phi = simaxis.phi();
448 const G4double theta = simaxis.theta();
450 xercesc::DOMElement* paraElement =
NewElement(
"para");
451 paraElement->setAttributeNode(
NewAttribute(
"name",name));
453 2.0*para->GetXHalfLength()/mm));
455 2.0*para->GetYHalfLength()/mm));
457 2.0*para->GetZHalfLength()/mm));
458 paraElement->setAttributeNode(
NewAttribute(
"alpha",alpha/degree));
459 paraElement->setAttributeNode(
NewAttribute(
"theta",theta/degree));
460 paraElement->setAttributeNode(
NewAttribute(
"phi",phi/degree));
461 paraElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
462 paraElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
463 solElement->appendChild(paraElement);
468 const G4Paraboloid*
const paraboloid)
470 const G4String& name =
GenerateName(paraboloid->GetName(),paraboloid);
472 xercesc::DOMElement* paraboloidElement =
NewElement(
"paraboloid");
473 paraboloidElement->setAttributeNode(
NewAttribute(
"name",name));
475 paraboloid->GetRadiusMinusZ()/mm));
477 paraboloid->GetRadiusPlusZ()/mm));
479 paraboloid->GetZHalfLength()/mm));
480 paraboloidElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
481 solElement->appendChild(paraboloidElement);
485 const G4Polycone*
const polycone)
487 const G4String& name =
GenerateName(polycone->GetName(),polycone);
489 xercesc::DOMElement* polyconeElement =
NewElement(
"polycone");
490 polyconeElement->setAttributeNode(
NewAttribute(
"name",name));
491 polyconeElement->setAttributeNode(
NewAttribute(
"startphi",
492 polycone->GetOriginalParameters()->Start_angle/degree));
493 polyconeElement->setAttributeNode(
NewAttribute(
"deltaphi",
494 polycone->GetOriginalParameters()->Opening_angle/degree));
495 polyconeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
496 polyconeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
497 solElement->appendChild(polyconeElement);
499 const size_t num_zplanes = polycone->GetOriginalParameters()->Num_z_planes;
500 const G4double* z_array = polycone->GetOriginalParameters()->Z_values;
501 const G4double* rmin_array = polycone->GetOriginalParameters()->Rmin;
502 const G4double* rmax_array = polycone->GetOriginalParameters()->Rmax;
504 for (
size_t i=0; i<num_zplanes; i++)
506 ZplaneWrite(polyconeElement,z_array[i],rmin_array[i],rmax_array[i]);
514 const G4GenericPolycone*
const polycone)
516 const G4String& name =
GenerateName(polycone->GetName(),polycone);
517 xercesc::DOMElement* polyconeElement =
NewElement(
"genericPolycone");
518 const G4double startPhi=polycone->GetStartPhi();
519 polyconeElement->setAttributeNode(
NewAttribute(
"name",name));
520 polyconeElement->setAttributeNode(
NewAttribute(
"startphi",
522 polyconeElement->setAttributeNode(
NewAttribute(
"deltaphi",
523 (polycone->GetEndPhi()-startPhi)/degree));
524 polyconeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
525 polyconeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
526 solElement->appendChild(polyconeElement);
528 const size_t num_rzpoints = polycone->GetNumRZCorner();
529 for (
size_t i=0; i<num_rzpoints; i++)
531 const G4double r_point=polycone->GetCorner(i).r;
532 const G4double z_point=polycone->GetCorner(i).z;
540 const G4Polyhedra*
const polyhedra)
542 const G4String& name =
GenerateName(polyhedra->GetName(),polyhedra);
543 if(polyhedra->IsGeneric() ==
false){
544 xercesc::DOMElement* polyhedraElement =
NewElement(
"polyhedra");
545 polyhedraElement->setAttributeNode(
NewAttribute(
"name",name));
546 polyhedraElement->setAttributeNode(
NewAttribute(
"startphi",
547 polyhedra->GetOriginalParameters()->Start_angle/degree));
548 polyhedraElement->setAttributeNode(
NewAttribute(
"deltaphi",
549 polyhedra->GetOriginalParameters()->Opening_angle/degree));
550 polyhedraElement->setAttributeNode(
NewAttribute(
"numsides",
551 polyhedra->GetOriginalParameters()->numSide));
552 polyhedraElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
553 polyhedraElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
554 solElement->appendChild(polyhedraElement);
556 const size_t num_zplanes = polyhedra->GetOriginalParameters()->Num_z_planes;
557 const G4double* z_array = polyhedra->GetOriginalParameters()->Z_values;
558 const G4double* rmin_array = polyhedra->GetOriginalParameters()->Rmin;
559 const G4double* rmax_array = polyhedra->GetOriginalParameters()->Rmax;
561 const G4double convertRad =
562 std::cos(0.5*polyhedra->GetOriginalParameters()->Opening_angle
563 / polyhedra->GetOriginalParameters()->numSide);
565 for (
size_t i=0;i<num_zplanes;i++)
568 rmin_array[i]*convertRad, rmax_array[i]*convertRad);
572 xercesc::DOMElement* polyhedraElement =
NewElement(
"genericPolyhedra");
573 polyhedraElement->setAttributeNode(
NewAttribute(
"name",name));
574 polyhedraElement->setAttributeNode(
NewAttribute(
"startphi",
575 polyhedra->GetOriginalParameters()->Start_angle/degree));
576 polyhedraElement->setAttributeNode(
NewAttribute(
"deltaphi",
577 polyhedra->GetOriginalParameters()->Opening_angle/degree));
578 polyhedraElement->setAttributeNode(
NewAttribute(
"numsides",
579 polyhedra->GetOriginalParameters()->numSide));
580 polyhedraElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
581 polyhedraElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
582 solElement->appendChild(polyhedraElement);
584 const size_t num_rzpoints = polyhedra->GetNumRZCorner();
586 for (
size_t i=0;i<num_rzpoints;i++)
588 const G4double r_point = polyhedra->GetCorner(i).r;
589 const G4double z_point = polyhedra->GetCorner(i).z;
596 SphereWrite(xercesc::DOMElement* solElement,
const G4Sphere*
const sphere)
598 const G4String& name =
GenerateName(sphere->GetName(),sphere);
600 xercesc::DOMElement* sphereElement =
NewElement(
"sphere");
601 sphereElement->setAttributeNode(
NewAttribute(
"name",name));
603 sphere->GetInnerRadius()/mm));
605 sphere->GetOuterRadius()/mm));
606 sphereElement->setAttributeNode(
NewAttribute(
"startphi",
607 sphere->GetStartPhiAngle()/degree));
608 sphereElement->setAttributeNode(
NewAttribute(
"deltaphi",
609 sphere->GetDeltaPhiAngle()/degree));
610 sphereElement->setAttributeNode(
NewAttribute(
"starttheta",
611 sphere->GetStartThetaAngle()/degree));
612 sphereElement->setAttributeNode(
NewAttribute(
"deltatheta",
613 sphere->GetDeltaThetaAngle()/degree));
614 sphereElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
615 sphereElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
616 solElement->appendChild(sphereElement);
621 const G4TessellatedSolid*
const tessellated)
623 const G4String& solid_name = tessellated->GetName();
624 const G4String& name =
GenerateName(solid_name, tessellated);
626 xercesc::DOMElement* tessellatedElement =
NewElement(
"tessellated");
627 tessellatedElement->setAttributeNode(
NewAttribute(
"name",name));
628 tessellatedElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
629 tessellatedElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
630 solElement->appendChild(tessellatedElement);
632 std::map<G4ThreeVector, G4String, G4ThreeVectorCompare> vertexMap;
634 const size_t NumFacets = tessellated->GetNumberOfFacets();
635 size_t NumVertex = 0;
637 for (
size_t i=0;i<NumFacets;i++)
639 const G4VFacet* facet = tessellated->GetFacet(i);
640 const size_t NumVertexPerFacet = facet->GetNumberOfVertices();
644 if (NumVertexPerFacet==3) { FacetTag=
"triangular"; }
else
645 if (NumVertexPerFacet==4) { FacetTag=
"quadrangular"; }
648 G4Exception(
"PHG4GDMLWriteSolids::TessellatedWrite()",
"InvalidSetup",
649 FatalException,
"Facet should contain 3 or 4 vertices!");
652 xercesc::DOMElement* facetElement =
NewElement(FacetTag);
653 tessellatedElement->appendChild(facetElement);
655 for (
size_t j=0; j<NumVertexPerFacet; j++)
657 std::stringstream name_stream;
658 std::stringstream ref_stream;
660 name_stream <<
"vertex" << (j+1);
661 ref_stream << solid_name <<
"_v" << NumVertex;
663 const G4String& fname = name_stream.str();
664 G4String ref = ref_stream.str();
672 const G4ThreeVector& vertex = facet->GetVertex(j);
674 if(vertexMap.find(vertex) != vertexMap.end())
676 ref = vertexMap[vertex];
680 vertexMap.insert(std::make_pair(vertex,ref));
687 facetElement->setAttributeNode(
NewAttribute(fname,ref));
693 TetWrite(xercesc::DOMElement* solElement,
const G4Tet*
const tet)
695 const G4String& solid_name = tet->GetName();
698 std::vector<G4ThreeVector> vertexList = tet->GetVertices();
700 xercesc::DOMElement* tetElement =
NewElement(
"tet");
701 tetElement->setAttributeNode(
NewAttribute(
"name",name));
702 tetElement->setAttributeNode(
NewAttribute(
"vertex1",solid_name+
"_v1"));
703 tetElement->setAttributeNode(
NewAttribute(
"vertex2",solid_name+
"_v2"));
704 tetElement->setAttributeNode(
NewAttribute(
"vertex3",solid_name+
"_v3"));
705 tetElement->setAttributeNode(
NewAttribute(
"vertex4",solid_name+
"_v4"));
706 tetElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
707 solElement->appendChild(tetElement);
716 TorusWrite(xercesc::DOMElement* solElement,
const G4Torus*
const torus)
718 const G4String& name =
GenerateName(torus->GetName(),torus);
720 xercesc::DOMElement* torusElement =
NewElement(
"torus");
721 torusElement->setAttributeNode(
NewAttribute(
"name",name));
722 torusElement->setAttributeNode(
NewAttribute(
"rmin",torus->GetRmin()/mm));
723 torusElement->setAttributeNode(
NewAttribute(
"rmax",torus->GetRmax()/mm));
724 torusElement->setAttributeNode(
NewAttribute(
"rtor",torus->GetRtor()/mm));
726 setAttributeNode(
NewAttribute(
"startphi",torus->GetSPhi()/degree));
728 setAttributeNode(
NewAttribute(
"deltaphi",torus->GetDPhi()/degree));
729 torusElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
730 torusElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
731 solElement->appendChild(torusElement);
736 const G4GenericTrap*
const gtrap)
738 const G4String& name =
GenerateName(gtrap->GetName(),gtrap);
740 std::vector<G4TwoVector> vertices = gtrap->GetVertices();
742 xercesc::DOMElement* gtrapElement =
NewElement(
"arb8");
743 gtrapElement->setAttributeNode(
NewAttribute(
"name",name));
745 gtrap->GetZHalfLength()/mm));
746 gtrapElement->setAttributeNode(
NewAttribute(
"v1x", vertices[0].x()));
747 gtrapElement->setAttributeNode(
NewAttribute(
"v1y", vertices[0].y()));
748 gtrapElement->setAttributeNode(
NewAttribute(
"v2x", vertices[1].x()));
749 gtrapElement->setAttributeNode(
NewAttribute(
"v2y", vertices[1].y()));
750 gtrapElement->setAttributeNode(
NewAttribute(
"v3x", vertices[2].x()));
751 gtrapElement->setAttributeNode(
NewAttribute(
"v3y", vertices[2].y()));
752 gtrapElement->setAttributeNode(
NewAttribute(
"v4x", vertices[3].x()));
753 gtrapElement->setAttributeNode(
NewAttribute(
"v4y", vertices[3].y()));
754 gtrapElement->setAttributeNode(
NewAttribute(
"v5x", vertices[4].x()));
755 gtrapElement->setAttributeNode(
NewAttribute(
"v5y", vertices[4].y()));
756 gtrapElement->setAttributeNode(
NewAttribute(
"v6x", vertices[5].x()));
757 gtrapElement->setAttributeNode(
NewAttribute(
"v6y", vertices[5].y()));
758 gtrapElement->setAttributeNode(
NewAttribute(
"v7x", vertices[6].x()));
759 gtrapElement->setAttributeNode(
NewAttribute(
"v7y", vertices[6].y()));
760 gtrapElement->setAttributeNode(
NewAttribute(
"v8x", vertices[7].x()));
761 gtrapElement->setAttributeNode(
NewAttribute(
"v8y", vertices[7].y()));
762 gtrapElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
763 solElement->appendChild(gtrapElement);
767 TrapWrite(xercesc::DOMElement* solElement,
const G4Trap*
const trap)
769 const G4String& name =
GenerateName(trap->GetName(),trap);
771 const G4ThreeVector& simaxis = trap->GetSymAxis();
772 const G4double phi = simaxis.phi();
773 const G4double theta = simaxis.theta();
774 const G4double alpha1 = std::atan(trap->GetTanAlpha1());
775 const G4double alpha2 = std::atan(trap->GetTanAlpha2());
777 xercesc::DOMElement* trapElement =
NewElement(
"trap");
778 trapElement->setAttributeNode(
NewAttribute(
"name",name));
780 2.0*trap->GetZHalfLength()/mm));
781 trapElement->setAttributeNode(
NewAttribute(
"theta",theta/degree));
782 trapElement->setAttributeNode(
NewAttribute(
"phi",phi/degree));
784 2.0*trap->GetYHalfLength1()/mm));
786 2.0*trap->GetXHalfLength1()/mm));
788 2.0*trap->GetXHalfLength2()/mm));
789 trapElement->setAttributeNode(
NewAttribute(
"alpha1",alpha1/degree));
791 2.0*trap->GetYHalfLength2()/mm));
793 2.0*trap->GetXHalfLength3()/mm));
795 2.0*trap->GetXHalfLength4()/mm));
796 trapElement->setAttributeNode(
NewAttribute(
"alpha2",alpha2/degree));
797 trapElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
798 trapElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
799 solElement->appendChild(trapElement);
803 TrdWrite(xercesc::DOMElement* solElement,
const G4Trd*
const trd)
805 const G4String& name =
GenerateName(trd->GetName(),trd);
807 xercesc::DOMElement* trdElement =
NewElement(
"trd");
808 trdElement->setAttributeNode(
NewAttribute(
"name",name));
810 2.0*trd->GetXHalfLength1()/mm));
812 2.0*trd->GetXHalfLength2()/mm));
814 2.0*trd->GetYHalfLength1()/mm));
816 2.0*trd->GetYHalfLength2()/mm));
818 2.0*trd->GetZHalfLength()/mm));
819 trdElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
820 solElement->appendChild(trdElement);
824 TubeWrite(xercesc::DOMElement* solElement,
const G4Tubs*
const tube)
826 const G4String& name =
GenerateName(tube->GetName(),tube);
828 xercesc::DOMElement* tubeElement =
NewElement(
"tube");
829 tubeElement->setAttributeNode(
NewAttribute(
"name",name));
831 tube->GetInnerRadius()/mm));
833 tube->GetOuterRadius()/mm));
835 2.0*tube->GetZHalfLength()/mm));
837 tube->GetStartPhiAngle()/degree));
839 tube->GetDeltaPhiAngle()/degree));
840 tubeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
841 tubeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
842 solElement->appendChild(tubeElement);
846 CutTubeWrite(xercesc::DOMElement* solElement,
const G4CutTubs*
const cuttube)
848 const G4String& name =
GenerateName(cuttube->GetName(),cuttube);
850 xercesc::DOMElement* cuttubeElement =
NewElement(
"cutTube");
851 cuttubeElement->setAttributeNode(
NewAttribute(
"name",name));
853 cuttube->GetInnerRadius()/mm));
855 cuttube->GetOuterRadius()/mm));
857 2.0*cuttube->GetZHalfLength()/mm));
858 cuttubeElement->setAttributeNode(
NewAttribute(
"startphi",
859 cuttube->GetStartPhiAngle()/degree));
860 cuttubeElement->setAttributeNode(
NewAttribute(
"deltaphi",
861 cuttube->GetDeltaPhiAngle()/degree));
863 cuttube->GetLowNorm().getX()/mm));
865 cuttube->GetLowNorm().getY()/mm));
867 cuttube->GetLowNorm().getZ()/mm));
869 cuttube->GetHighNorm().getX()/mm));
871 cuttube->GetHighNorm().getY()/mm));
873 cuttube->GetHighNorm().getZ()/mm));
874 cuttubeElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
875 cuttubeElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
876 solElement->appendChild(cuttubeElement);
881 const G4TwistedBox*
const twistedbox)
883 const G4String& name =
GenerateName(twistedbox->GetName(),twistedbox);
885 xercesc::DOMElement* twistedboxElement =
NewElement(
"twistedbox");
886 twistedboxElement->setAttributeNode(
NewAttribute(
"name",name));
888 2.0*twistedbox->GetXHalfLength()/mm));
890 2.0*twistedbox->GetYHalfLength()/mm));
892 2.0*twistedbox->GetZHalfLength()/mm));
893 twistedboxElement->setAttributeNode(
NewAttribute(
"PhiTwist",
894 twistedbox->GetPhiTwist()/degree));
895 twistedboxElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
896 twistedboxElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
897 solElement->appendChild(twistedboxElement);
902 const G4TwistedTrap*
const twistedtrap)
904 const G4String& name =
GenerateName(twistedtrap->GetName(),twistedtrap);
906 xercesc::DOMElement* twistedtrapElement =
NewElement(
"twistedtrap");
907 twistedtrapElement->setAttributeNode(
NewAttribute(
"name",name));
909 2.0*twistedtrap->GetY1HalfLength()/mm));
911 2.0*twistedtrap->GetX1HalfLength()/mm));
913 2.0*twistedtrap->GetX2HalfLength()/mm));
915 2.0*twistedtrap->GetY2HalfLength()/mm));
917 2.0*twistedtrap->GetX3HalfLength()/mm));
919 2.0*twistedtrap->GetX4HalfLength()/mm));
921 2.0*twistedtrap->GetZHalfLength()/mm));
922 twistedtrapElement->setAttributeNode(
NewAttribute(
"Alph",
923 twistedtrap->GetTiltAngleAlpha()/degree));
924 twistedtrapElement->setAttributeNode(
NewAttribute(
"Theta",
925 twistedtrap->GetPolarAngleTheta()/degree));
926 twistedtrapElement->setAttributeNode(
NewAttribute(
"Phi",
927 twistedtrap->GetAzimuthalAnglePhi()/degree));
928 twistedtrapElement->setAttributeNode(
NewAttribute(
"PhiTwist",
929 twistedtrap->GetPhiTwist()/degree));
930 twistedtrapElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
931 twistedtrapElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
933 solElement->appendChild(twistedtrapElement);
938 const G4TwistedTrd*
const twistedtrd)
940 const G4String& name =
GenerateName(twistedtrd->GetName(),twistedtrd);
942 xercesc::DOMElement* twistedtrdElement =
NewElement(
"twistedtrd");
943 twistedtrdElement->setAttributeNode(
NewAttribute(
"name",name));
945 2.0*twistedtrd->GetX1HalfLength()/mm));
947 2.0*twistedtrd->GetX2HalfLength()/mm));
949 2.0*twistedtrd->GetY1HalfLength()/mm));
951 2.0*twistedtrd->GetY2HalfLength()/mm));
953 2.0*twistedtrd->GetZHalfLength()/mm));
954 twistedtrdElement->setAttributeNode(
NewAttribute(
"PhiTwist",
955 twistedtrd->GetPhiTwist()/degree));
956 twistedtrdElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
957 twistedtrdElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
958 solElement->appendChild(twistedtrdElement);
963 const G4TwistedTubs*
const twistedtubs)
965 const G4String& name =
GenerateName(twistedtubs->GetName(),twistedtubs);
967 xercesc::DOMElement* twistedtubsElement =
NewElement(
"twistedtubs");
968 twistedtubsElement->setAttributeNode(
NewAttribute(
"name",name));
969 twistedtubsElement->setAttributeNode(
NewAttribute(
"twistedangle",
970 twistedtubs->GetPhiTwist()/degree));
971 twistedtubsElement->setAttributeNode(
NewAttribute(
"endinnerrad",
972 twistedtubs->GetInnerRadius()/mm));
973 twistedtubsElement->setAttributeNode(
NewAttribute(
"endouterrad",
974 twistedtubs->GetOuterRadius()/mm));
975 twistedtubsElement->setAttributeNode(
NewAttribute(
"zlen",
976 2.0*twistedtubs->GetZHalfLength()/mm));
977 twistedtubsElement->setAttributeNode(
NewAttribute(
"phi",
978 twistedtubs->GetDPhi()/degree));
979 twistedtubsElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
980 twistedtubsElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
981 solElement->appendChild(twistedtubsElement);
985 ZplaneWrite(xercesc::DOMElement* element,
const G4double& z,
986 const G4double& rmin,
const G4double& rmax)
988 xercesc::DOMElement* zplaneElement =
NewElement(
"zplane");
989 zplaneElement->setAttributeNode(
NewAttribute(
"z",z/mm));
990 zplaneElement->setAttributeNode(
NewAttribute(
"rmin",rmin/mm));
991 zplaneElement->setAttributeNode(
NewAttribute(
"rmax",rmax/mm));
992 element->appendChild(zplaneElement);
996 RZPointWrite(xercesc::DOMElement* element,
const G4double& r,
999 xercesc::DOMElement* rzpointElement =
NewElement(
"rzpoint");
1000 rzpointElement->setAttributeNode(
NewAttribute(
"r",r/mm));
1001 rzpointElement->setAttributeNode(
NewAttribute(
"z",z/mm));
1002 element->appendChild(rzpointElement);
1007 const G4OpticalSurface*
const surf)
1009 xercesc::DOMElement* optElement =
NewElement(
"opticalsurface");
1010 G4OpticalSurfaceModel smodel = surf->GetModel();
1011 G4double sval = (smodel==glisur) ? surf->GetPolish() : surf->GetSigmaAlpha();
1013 optElement->setAttributeNode(
NewAttribute(
"name", surf->GetName()));
1014 optElement->setAttributeNode(
NewAttribute(
"model", smodel));
1015 optElement->setAttributeNode(
NewAttribute(
"finish", surf->GetFinish()));
1016 optElement->setAttributeNode(
NewAttribute(
"type", surf->GetType()));
1017 optElement->setAttributeNode(
NewAttribute(
"value", sval));
1019 solElement->appendChild(optElement);
1024 G4cout <<
"PHG4GDML: Writing solids..." << G4endl;
1034 for (
size_t i=0; i<
solidList.size(); i++)
1036 if (
solidList[i] == solidPtr) {
return; }
1041 if (
const G4BooleanSolid*
const booleanPtr
1042 =
dynamic_cast<const G4BooleanSolid*
>(solidPtr))
1044 if (solidPtr->GetEntityType()==
"G4MultiUnion")
1045 {
const G4MultiUnion*
const munionPtr
1046 =
static_cast<const G4MultiUnion*
>(solidPtr);
1048 if (solidPtr->GetEntityType()==
"G4Box")
1049 {
const G4Box*
const boxPtr
1050 =
static_cast<const G4Box*
>(solidPtr);
1052 if (solidPtr->GetEntityType()==
"G4Cons")
1053 {
const G4Cons*
const conePtr
1054 =
static_cast<const G4Cons*
>(solidPtr);
1056 if (solidPtr->GetEntityType()==
"G4EllipticalCone")
1057 {
const G4EllipticalCone*
const elconePtr
1058 =
static_cast<const G4EllipticalCone*
>(solidPtr);
1060 if (solidPtr->GetEntityType()==
"G4Ellipsoid")
1061 {
const G4Ellipsoid*
const ellipsoidPtr
1062 =
static_cast<const G4Ellipsoid*
>(solidPtr);
1064 if (solidPtr->GetEntityType()==
"G4EllipticalTube")
1065 {
const G4EllipticalTube*
const eltubePtr
1066 =
static_cast<const G4EllipticalTube*
>(solidPtr);
1068 if (solidPtr->GetEntityType()==
"G4ExtrudedSolid")
1069 {
const G4ExtrudedSolid*
const xtruPtr
1070 =
static_cast<const G4ExtrudedSolid*
>(solidPtr);
1072 if (solidPtr->GetEntityType()==
"G4Hype")
1073 {
const G4Hype*
const hypePtr
1074 =
static_cast<const G4Hype*
>(solidPtr);
1076 if (solidPtr->GetEntityType()==
"G4Orb")
1077 {
const G4Orb*
const orbPtr
1078 =
static_cast<const G4Orb*
>(solidPtr);
1080 if (solidPtr->GetEntityType()==
"G4Para")
1081 {
const G4Para*
const paraPtr
1082 =
static_cast<const G4Para*
>(solidPtr);
1084 if (solidPtr->GetEntityType()==
"G4Paraboloid")
1085 {
const G4Paraboloid*
const paraboloidPtr
1086 =
static_cast<const G4Paraboloid*
>(solidPtr);
1088 if (solidPtr->GetEntityType()==
"G4Polycone")
1089 {
const G4Polycone*
const polyconePtr
1090 =
static_cast<const G4Polycone*
>(solidPtr);
1092 if (solidPtr->GetEntityType()==
"G4GenericPolycone")
1093 {
const G4GenericPolycone*
const genpolyconePtr
1094 =
static_cast<const G4GenericPolycone*
>(solidPtr);
1096 if (solidPtr->GetEntityType()==
"G4Polyhedra")
1097 {
const G4Polyhedra*
const polyhedraPtr
1098 =
static_cast<const G4Polyhedra*
>(solidPtr);
1100 if (solidPtr->GetEntityType()==
"G4Sphere")
1101 {
const G4Sphere*
const spherePtr
1102 =
static_cast<const G4Sphere*
>(solidPtr);
1104 if (solidPtr->GetEntityType()==
"G4TessellatedSolid")
1105 {
const G4TessellatedSolid*
const tessellatedPtr
1106 =
static_cast<const G4TessellatedSolid*
>(solidPtr);
1108 if (solidPtr->GetEntityType()==
"G4Tet")
1109 {
const G4Tet*
const tetPtr
1110 =
static_cast<const G4Tet*
>(solidPtr);
1112 if (solidPtr->GetEntityType()==
"G4Torus")
1113 {
const G4Torus*
const torusPtr
1114 =
static_cast<const G4Torus*
>(solidPtr);
1116 if (solidPtr->GetEntityType()==
"G4GenericTrap")
1117 {
const G4GenericTrap*
const gtrapPtr
1118 =
static_cast<const G4GenericTrap*
>(solidPtr);
1120 if (solidPtr->GetEntityType()==
"G4Trap")
1121 {
const G4Trap*
const trapPtr
1122 =
static_cast<const G4Trap*
>(solidPtr);
1124 if (solidPtr->GetEntityType()==
"G4Trd")
1125 {
const G4Trd*
const trdPtr
1126 =
static_cast<const G4Trd*
>(solidPtr);
1128 if (solidPtr->GetEntityType()==
"G4Tubs")
1129 {
const G4Tubs*
const tubePtr
1130 =
static_cast<const G4Tubs*
>(solidPtr);
1132 if (solidPtr->GetEntityType()==
"G4CutTubs")
1133 {
const G4CutTubs*
const cuttubePtr
1134 =
static_cast<const G4CutTubs*
>(solidPtr);
1136 if (solidPtr->GetEntityType()==
"G4TwistedBox")
1137 {
const G4TwistedBox*
const twistedboxPtr
1138 =
static_cast<const G4TwistedBox*
>(solidPtr);
1140 if (solidPtr->GetEntityType()==
"G4TwistedTrap")
1141 {
const G4TwistedTrap*
const twistedtrapPtr
1142 =
static_cast<const G4TwistedTrap*
>(solidPtr);
1144 if (solidPtr->GetEntityType()==
"G4TwistedTrd")
1145 {
const G4TwistedTrd*
const twistedtrdPtr
1146 =
static_cast<const G4TwistedTrd*
>(solidPtr);
1148 if (solidPtr->GetEntityType()==
"G4TwistedTubs")
1149 {
const G4TwistedTubs*
const twistedtubsPtr
1150 =
static_cast<const G4TwistedTubs*
>(solidPtr);
1154 G4String error_msg =
"Unknown solid: " + solidPtr->GetName()
1155 +
"; Type: " + solidPtr->GetEntityType();
1156 G4Exception(
"PHG4GDMLWriteSolids::AddSolid()",
"WriteError",
1157 FatalException, error_msg);
void PositionWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &pos)
void AddPosition(const G4String &name, const G4ThreeVector &pos)
G4ThreeVector GetAngles(const G4RotationMatrix &)
void RotationWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &rot)
static const G4double kAngularPrecision
void FirstpositionWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &pos)
static const G4double kLinearPrecision
void FirstrotationWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &rot)
void TwistedtrdWrite(xercesc::DOMElement *, const G4TwistedTrd *const)
xercesc::DOMElement * solidsElement
void MultiUnionWrite(xercesc::DOMElement *solElement, const G4MultiUnion *const)
void EllipsoidWrite(xercesc::DOMElement *, const G4Ellipsoid *const)
void TessellatedWrite(xercesc::DOMElement *, const G4TessellatedSolid *const)
void TwistedboxWrite(xercesc::DOMElement *, const G4TwistedBox *const)
void ZplaneWrite(xercesc::DOMElement *, const G4double &, const G4double &, const G4double &)
void OrbWrite(xercesc::DOMElement *, const G4Orb *const)
static const G4int maxTransforms
void ParaWrite(xercesc::DOMElement *, const G4Para *const)
void TubeWrite(xercesc::DOMElement *, const G4Tubs *const)
void TwistedtubsWrite(xercesc::DOMElement *, const G4TwistedTubs *const)
void XtruWrite(xercesc::DOMElement *, const G4ExtrudedSolid *const)
void TorusWrite(xercesc::DOMElement *, const G4Torus *const)
void ParaboloidWrite(xercesc::DOMElement *, const G4Paraboloid *const)
void SphereWrite(xercesc::DOMElement *, const G4Sphere *const)
void RZPointWrite(xercesc::DOMElement *, const G4double &, const G4double &)
void TrapWrite(xercesc::DOMElement *, const G4Trap *const)
void ElconeWrite(xercesc::DOMElement *, const G4EllipticalCone *const)
void TwistedtrapWrite(xercesc::DOMElement *, const G4TwistedTrap *const)
void GenTrapWrite(xercesc::DOMElement *, const G4GenericTrap *const)
virtual void SolidsWrite(xercesc::DOMElement *)
void GenericPolyconeWrite(xercesc::DOMElement *, const G4GenericPolycone *const)
void EltubeWrite(xercesc::DOMElement *, const G4EllipticalTube *const)
void HypeWrite(xercesc::DOMElement *, const G4Hype *const)
void TetWrite(xercesc::DOMElement *, const G4Tet *const)
virtual ~PHG4GDMLWriteSolids()
void BooleanWrite(xercesc::DOMElement *, const G4BooleanSolid *const)
void PolyhedraWrite(xercesc::DOMElement *, const G4Polyhedra *const)
void BoxWrite(xercesc::DOMElement *, const G4Box *const)
virtual void AddSolid(const G4VSolid *const)
void TrdWrite(xercesc::DOMElement *, const G4Trd *const)
void OpticalSurfaceWrite(xercesc::DOMElement *, const G4OpticalSurface *const)
void ConeWrite(xercesc::DOMElement *, const G4Cons *const)
void PolyconeWrite(xercesc::DOMElement *, const G4Polycone *const)
std::vector< const G4VSolid * > solidList
void CutTubeWrite(xercesc::DOMElement *, const G4CutTubs *const)
G4String GenerateName(const G4String &, const void *const)
xercesc::DOMElement * NewElement(const G4String &)
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)