Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GDMLWriteSolids.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4GDMLWriteSolids.cc 96133 2016-03-16 22:21:17Z gcosmo $
28 //
29 // class G4GDMLWriteSolids Implementation
30 //
31 // Original author: Zoltan Torzsok, November 2007
32 //
33 // --------------------------------------------------------------------
34 
35 #include "G4GDMLWriteSolids.hh"
36 
37 #include "G4SystemOfUnits.hh"
38 #include "G4BooleanSolid.hh"
39 #include "G4ScaledSolid.hh"
40 #include "G4Box.hh"
41 #include "G4Cons.hh"
42 #include "G4Ellipsoid.hh"
43 #include "G4EllipticalCone.hh"
44 #include "G4EllipticalTube.hh"
45 #include "G4ExtrudedSolid.hh"
46 #include "G4Hype.hh"
47 #include "G4Orb.hh"
48 #include "G4Para.hh"
49 #include "G4Paraboloid.hh"
50 #include "G4IntersectionSolid.hh"
51 #include "G4Polycone.hh"
52 #include "G4GenericPolycone.hh"
53 #include "G4Polyhedra.hh"
54 #include "G4ReflectedSolid.hh"
55 #include "G4Sphere.hh"
56 #include "G4SubtractionSolid.hh"
57 #include "G4GenericTrap.hh"
58 #include "G4TessellatedSolid.hh"
59 #include "G4Tet.hh"
60 #include "G4Torus.hh"
61 #include "G4Trap.hh"
62 #include "G4Trd.hh"
63 #include "G4Tubs.hh"
64 #include "G4CutTubs.hh"
65 #include "G4TwistedBox.hh"
66 #include "G4TwistedTrap.hh"
67 #include "G4TwistedTrd.hh"
68 #include "G4TwistedTubs.hh"
69 #include "G4UnionSolid.hh"
70 #include "G4OpticalSurface.hh"
71 #include "G4SurfaceProperty.hh"
72 
74  : G4GDMLWriteMaterials(), solidsElement(0)
75 {
76 }
77 
79 {
80 }
81 
82 #if !defined(G4GEOM_USE_USOLIDS)
84 MultiUnionWrite(xercesc::DOMElement*,
85  const G4MultiUnion* const)
86 {
87  G4Exception("G4GDMLWriteSolids::MultiUnionWrite()",
88  "InvalidSetup", FatalException,
89  "Installation with USolids primitives required!");
90  return;
91 }
92 #else
94 MultiUnionWrite(xercesc::DOMElement* solElement,
95  const G4MultiUnion* const munionSolid)
96 {
97  G4int numSolids=munionSolid->GetNumberOfSolids();
98  G4String tag("multiUnion");
99 
100  G4VSolid* solid;
101  G4Transform3D* transform;
102 
103  const G4String& name = GenerateName(munionSolid->GetName(),munionSolid);
104  xercesc::DOMElement* multiUnionElement = NewElement(tag);
105  multiUnionElement->setAttributeNode(NewAttribute("name",name));
106 
107  for (G4int i=0; i<numSolids; ++i)
108  {
109  solid = munionSolid->GetSolid(i);
110  transform = munionSolid->GetTransformation(i);
111 
112  HepGeom::Rotate3D rot3d;
113  HepGeom::Translate3D transl ;
114  HepGeom::Scale3D scale;
115  transform->getDecomposition(scale,rot3d,transl);
116 
117  G4ThreeVector pos = transl.getTranslation();
119  rotm(CLHEP::HepRep3x3(rot3d.xx(), rot3d.xy(), rot3d.xz(),
120  rot3d.yx(), rot3d.yy(), rot3d.yz(),
121  rot3d.zx(), rot3d.zy(), rot3d.zz()));
122  G4ThreeVector rot = GetAngles(rotm);
123 
124  AddSolid(solid);
125  const G4String& solidref = GenerateName(solid->GetName(),solid);
126  std::ostringstream os; os << i+1;
127  const G4String& nodeName = "Node-" + G4String(os.str());
128  xercesc::DOMElement* solidElement = NewElement("solid");
129  solidElement->setAttributeNode(NewAttribute("ref",solidref));
130  xercesc::DOMElement* multiUnionNodeElement = NewElement("multiUnionNode");
131  multiUnionNodeElement->setAttributeNode(NewAttribute("name", nodeName));
132  multiUnionNodeElement->appendChild(solidElement); // Append solid to node
133  if ( (std::fabs(pos.x()) > kLinearPrecision)
134  || (std::fabs(pos.y()) > kLinearPrecision)
135  || (std::fabs(pos.z()) > kLinearPrecision) )
136  {
137  PositionWrite(multiUnionNodeElement,name+"_pos",pos);
138  }
139  if ( (std::fabs(rot.x()) > kAngularPrecision)
140  || (std::fabs(rot.y()) > kAngularPrecision)
141  || (std::fabs(rot.z()) > kAngularPrecision) )
142  {
143  RotationWrite(multiUnionNodeElement,name+"_rot",rot);
144  }
145  multiUnionElement->appendChild(multiUnionNodeElement); // Append node
146  }
147 
148  solElement->appendChild(multiUnionElement);
149  // Add the multiUnion solid AFTER the constituent nodes!
150 }
151 #endif
152 
154 BooleanWrite(xercesc::DOMElement* solElement,
155  const G4BooleanSolid* const boolean)
156 {
157  G4int displaced=0;
158 
159  G4String tag("undefined");
160  if (dynamic_cast<const G4IntersectionSolid*>(boolean))
161  { tag = "intersection"; } else
162  if (dynamic_cast<const G4SubtractionSolid*>(boolean))
163  { tag = "subtraction"; } else
164  if (dynamic_cast<const G4UnionSolid*>(boolean))
165  { tag = "union"; }
166 
167  G4VSolid* firstPtr = const_cast<G4VSolid*>(boolean->GetConstituentSolid(0));
168  G4VSolid* secondPtr = const_cast<G4VSolid*>(boolean->GetConstituentSolid(1));
169 
170  G4ThreeVector firstpos,firstrot,pos,rot;
171 
172  // Solve possible displacement of referenced solids!
173  //
174  while (true)
175  {
176  if ( displaced>8 )
177  {
178  G4String ErrorMessage = "The referenced solid '"
179  + firstPtr->GetName() +
180  + "in the Boolean shape '" +
181  + boolean->GetName() +
182  + "' was displaced too many times!";
183  G4Exception("G4GDMLWriteSolids::BooleanWrite()",
184  "InvalidSetup", FatalException, ErrorMessage);
185  }
186 
187  if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(firstPtr))
188  {
189  firstpos += disp->GetObjectTranslation();
190  firstrot += GetAngles(disp->GetObjectRotation());
191  firstPtr = disp->GetConstituentMovedSolid();
192  displaced++;
193  continue;
194  }
195  break;
196  }
197  displaced = 0;
198  while (true)
199  {
200  if ( displaced>maxTransforms )
201  {
202  G4String ErrorMessage = "The referenced solid '"
203  + secondPtr->GetName() +
204  + "in the Boolean shape '" +
205  + boolean->GetName() +
206  + "' was displaced too many times!";
207  G4Exception("G4GDMLWriteSolids::BooleanWrite()",
208  "InvalidSetup", FatalException, ErrorMessage);
209  }
210 
211  if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(secondPtr))
212  {
213  pos += disp->GetObjectTranslation();
214  rot += GetAngles(disp->GetObjectRotation());
215  secondPtr = disp->GetConstituentMovedSolid();
216  displaced++;
217  continue;
218  }
219  break;
220  }
221 
222  AddSolid(firstPtr); // At first add the constituent solids!
223  AddSolid(secondPtr);
224 
225  const G4String& name = GenerateName(boolean->GetName(),boolean);
226  const G4String& firstref = GenerateName(firstPtr->GetName(),firstPtr);
227  const G4String& secondref = GenerateName(secondPtr->GetName(),secondPtr);
228 
229  xercesc::DOMElement* booleanElement = NewElement(tag);
230  booleanElement->setAttributeNode(NewAttribute("name",name));
231  xercesc::DOMElement* firstElement = NewElement("first");
232  firstElement->setAttributeNode(NewAttribute("ref",firstref));
233  booleanElement->appendChild(firstElement);
234  xercesc::DOMElement* secondElement = NewElement("second");
235  secondElement->setAttributeNode(NewAttribute("ref",secondref));
236  booleanElement->appendChild(secondElement);
237  solElement->appendChild(booleanElement);
238  // Add the boolean solid AFTER the constituent solids!
239 
240  if ( (std::fabs(pos.x()) > kLinearPrecision)
241  || (std::fabs(pos.y()) > kLinearPrecision)
242  || (std::fabs(pos.z()) > kLinearPrecision) )
243  {
244  PositionWrite(booleanElement,name+"_pos",pos);
245  }
246 
247  if ( (std::fabs(rot.x()) > kAngularPrecision)
248  || (std::fabs(rot.y()) > kAngularPrecision)
249  || (std::fabs(rot.z()) > kAngularPrecision) )
250  {
251  RotationWrite(booleanElement,name+"_rot",rot);
252  }
253 
254  if ( (std::fabs(firstpos.x()) > kLinearPrecision)
255  || (std::fabs(firstpos.y()) > kLinearPrecision)
256  || (std::fabs(firstpos.z()) > kLinearPrecision) )
257  {
258  FirstpositionWrite(booleanElement,name+"_fpos",firstpos);
259  }
260 
261  if ( (std::fabs(firstrot.x()) > kAngularPrecision)
262  || (std::fabs(firstrot.y()) > kAngularPrecision)
263  || (std::fabs(firstrot.z()) > kAngularPrecision) )
264  {
265  FirstrotationWrite(booleanElement,name+"_frot",firstrot);
266  }
267 }
268 
270 ScaledWrite(xercesc::DOMElement* solElement,
271  const G4ScaledSolid* const scaled)
272 {
273  G4String tag("scaledSolid");
274 
275  G4VSolid* solid = const_cast<G4VSolid*>(scaled->GetUnscaledSolid());
276  G4Scale3D scale = scaled->GetScaleTransform();
277  G4ThreeVector sclVector = G4ThreeVector(scale.xx(), scale.yy(), scale.zz());
278 
279  AddSolid(solid); // Add the constituent solid!
280 
281  const G4String& name = GenerateName(scaled->GetName(),scaled);
282  const G4String& solidref = GenerateName(solid->GetName(),solid);
283 
284  xercesc::DOMElement* scaledElement = NewElement(tag);
285  scaledElement->setAttributeNode(NewAttribute("name",name));
286 
287  xercesc::DOMElement* solidElement = NewElement("solidref");
288  solidElement->setAttributeNode(NewAttribute("ref",solidref));
289  scaledElement->appendChild(solidElement);
290 
291  if ( (std::fabs(scale.xx()) > kLinearPrecision)
292  && (std::fabs(scale.yy()) > kLinearPrecision)
293  && (std::fabs(scale.zz()) > kLinearPrecision) )
294  {
295  ScaleWrite(scaledElement, name+"_scl", sclVector);
296  }
297 
298  solElement->appendChild(scaledElement);
299  // Add the scaled solid AFTER its constituent solid!
300 }
301 
303 BoxWrite(xercesc::DOMElement* solElement, const G4Box* const box)
304 {
305  const G4String& name = GenerateName(box->GetName(),box);
306 
307  xercesc::DOMElement* boxElement = NewElement("box");
308  boxElement->setAttributeNode(NewAttribute("name",name));
309  boxElement->setAttributeNode(NewAttribute("x",2.0*box->GetXHalfLength()/mm));
310  boxElement->setAttributeNode(NewAttribute("y",2.0*box->GetYHalfLength()/mm));
311  boxElement->setAttributeNode(NewAttribute("z",2.0*box->GetZHalfLength()/mm));
312  boxElement->setAttributeNode(NewAttribute("lunit","mm"));
313  solElement->appendChild(boxElement);
314 }
315 
317 ConeWrite(xercesc::DOMElement* solElement, const G4Cons* const cone)
318 {
319  const G4String& name = GenerateName(cone->GetName(),cone);
320 
321  xercesc::DOMElement* coneElement = NewElement("cone");
322  coneElement->setAttributeNode(NewAttribute("name",name));
323  coneElement->
324  setAttributeNode(NewAttribute("rmin1",cone->GetInnerRadiusMinusZ()/mm));
325  coneElement->
326  setAttributeNode(NewAttribute("rmax1",cone->GetOuterRadiusMinusZ()/mm));
327  coneElement->
328  setAttributeNode(NewAttribute("rmin2",cone->GetInnerRadiusPlusZ()/mm));
329  coneElement->
330  setAttributeNode(NewAttribute("rmax2",cone->GetOuterRadiusPlusZ()/mm));
331  coneElement->
332  setAttributeNode(NewAttribute("z",2.0*cone->GetZHalfLength()/mm));
333  coneElement->
334  setAttributeNode(NewAttribute("startphi",cone->GetStartPhiAngle()/degree));
335  coneElement->
336  setAttributeNode(NewAttribute("deltaphi",cone->GetDeltaPhiAngle()/degree));
337  coneElement->setAttributeNode(NewAttribute("aunit","deg"));
338  coneElement->setAttributeNode(NewAttribute("lunit","mm"));
339  solElement->appendChild(coneElement);
340 }
341 
343 ElconeWrite(xercesc::DOMElement* solElement,
344  const G4EllipticalCone* const elcone)
345 {
346  const G4String& name = GenerateName(elcone->GetName(),elcone);
347 
348  xercesc::DOMElement* elconeElement = NewElement("elcone");
349  elconeElement->setAttributeNode(NewAttribute("name",name));
350  elconeElement->setAttributeNode(NewAttribute("dx",elcone->GetSemiAxisX()/mm));
351  elconeElement->setAttributeNode(NewAttribute("dy",elcone->GetSemiAxisY()/mm));
352  elconeElement->setAttributeNode(NewAttribute("zmax",elcone->GetZMax()/mm));
353  elconeElement->setAttributeNode(NewAttribute("zcut",elcone->GetZTopCut()/mm));
354  elconeElement->setAttributeNode(NewAttribute("lunit","mm"));
355  solElement->appendChild(elconeElement);
356 }
357 
359 EllipsoidWrite(xercesc::DOMElement* solElement,
360  const G4Ellipsoid* const ellipsoid)
361 {
362  const G4String& name = GenerateName(ellipsoid->GetName(),ellipsoid);
363 
364  xercesc::DOMElement* ellipsoidElement = NewElement("ellipsoid");
365  ellipsoidElement->setAttributeNode(NewAttribute("name",name));
366  ellipsoidElement->
367  setAttributeNode(NewAttribute("ax",ellipsoid->GetSemiAxisMax(0)/mm));
368  ellipsoidElement->
369  setAttributeNode(NewAttribute("by",ellipsoid->GetSemiAxisMax(1)/mm));
370  ellipsoidElement->
371  setAttributeNode(NewAttribute("cz",ellipsoid->GetSemiAxisMax(2)/mm));
372  ellipsoidElement->
373  setAttributeNode(NewAttribute("zcut1",ellipsoid->GetZBottomCut()/mm));
374  ellipsoidElement->
375  setAttributeNode(NewAttribute("zcut2",ellipsoid->GetZTopCut()/mm));
376  ellipsoidElement->
377  setAttributeNode(NewAttribute("lunit","mm"));
378  solElement->appendChild(ellipsoidElement);
379 }
380 
382 EltubeWrite(xercesc::DOMElement* solElement,
383  const G4EllipticalTube* const eltube)
384 {
385  const G4String& name = GenerateName(eltube->GetName(),eltube);
386 
387  xercesc::DOMElement* eltubeElement = NewElement("eltube");
388  eltubeElement->setAttributeNode(NewAttribute("name",name));
389  eltubeElement->setAttributeNode(NewAttribute("dx",eltube->GetDx()/mm));
390  eltubeElement->setAttributeNode(NewAttribute("dy",eltube->GetDy()/mm));
391  eltubeElement->setAttributeNode(NewAttribute("dz",eltube->GetDz()/mm));
392  eltubeElement->setAttributeNode(NewAttribute("lunit","mm"));
393  solElement->appendChild(eltubeElement);
394 }
395 
397 XtruWrite(xercesc::DOMElement* solElement,
398  const G4ExtrudedSolid* const xtru)
399 {
400  const G4String& name = GenerateName(xtru->GetName(),xtru);
401 
402  xercesc::DOMElement* xtruElement = NewElement("xtru");
403  xtruElement->setAttributeNode(NewAttribute("name",name));
404  xtruElement->setAttributeNode(NewAttribute("lunit","mm"));
405  solElement->appendChild(xtruElement);
406 
407  const G4int NumVertex = xtru->GetNofVertices();
408 
409  for (G4int i=0;i<NumVertex;i++)
410  {
411  xercesc::DOMElement* twoDimVertexElement = NewElement("twoDimVertex");
412  xtruElement->appendChild(twoDimVertexElement);
413 
414  const G4TwoVector& vertex = xtru->GetVertex(i);
415 
416  twoDimVertexElement->setAttributeNode(NewAttribute("x",vertex.x()/mm));
417  twoDimVertexElement->setAttributeNode(NewAttribute("y",vertex.y()/mm));
418  }
419 
420  const G4int NumSection = xtru->GetNofZSections();
421 
422  for (G4int i=0;i<NumSection;i++)
423  {
424  xercesc::DOMElement* sectionElement = NewElement("section");
425  xtruElement->appendChild(sectionElement);
426 
427  const G4ExtrudedSolid::ZSection section = xtru->GetZSection(i);
428 
429  sectionElement->setAttributeNode(NewAttribute("zOrder",i));
430  sectionElement->setAttributeNode(NewAttribute("zPosition",section.fZ/mm));
431  sectionElement->
432  setAttributeNode(NewAttribute("xOffset",section.fOffset.x()/mm));
433  sectionElement->
434  setAttributeNode(NewAttribute("yOffset",section.fOffset.y()/mm));
435  sectionElement->
436  setAttributeNode(NewAttribute("scalingFactor",section.fScale));
437  }
438 }
439 
441 HypeWrite(xercesc::DOMElement* solElement, const G4Hype* const hype)
442 {
443  const G4String& name = GenerateName(hype->GetName(),hype);
444 
445  xercesc::DOMElement* hypeElement = NewElement("hype");
446  hypeElement->setAttributeNode(NewAttribute("name",name));
447  hypeElement->setAttributeNode(NewAttribute("rmin",
448  hype->GetInnerRadius()/mm));
449  hypeElement->setAttributeNode(NewAttribute("rmax",
450  hype->GetOuterRadius()/mm));
451  hypeElement->setAttributeNode(NewAttribute("inst",
452  hype->GetInnerStereo()/degree));
453  hypeElement->setAttributeNode(NewAttribute("outst",
454  hype->GetOuterStereo()/degree));
455  hypeElement->setAttributeNode(NewAttribute("z",
456  2.0*hype->GetZHalfLength()/mm));
457  hypeElement->setAttributeNode(NewAttribute("aunit","deg"));
458  hypeElement->setAttributeNode(NewAttribute("lunit","mm"));
459  solElement->appendChild(hypeElement);
460 }
461 
463 OrbWrite(xercesc::DOMElement* solElement, const G4Orb* const orb)
464 {
465  const G4String& name = GenerateName(orb->GetName(),orb);
466 
467  xercesc::DOMElement* orbElement = NewElement("orb");
468  orbElement->setAttributeNode(NewAttribute("name",name));
469  orbElement->setAttributeNode(NewAttribute("r",orb->GetRadius()/mm));
470  orbElement->setAttributeNode(NewAttribute("lunit","mm"));
471  solElement->appendChild(orbElement);
472 }
473 
475 ParaWrite(xercesc::DOMElement* solElement, const G4Para* const para)
476 {
477  const G4String& name = GenerateName(para->GetName(),para);
478 
479  const G4ThreeVector simaxis = para->GetSymAxis();
480  const G4double alpha = std::atan(para->GetTanAlpha());
481  const G4double phi = simaxis.phi();
482  const G4double theta = simaxis.theta();
483 
484  xercesc::DOMElement* paraElement = NewElement("para");
485  paraElement->setAttributeNode(NewAttribute("name",name));
486  paraElement->setAttributeNode(NewAttribute("x",
487  2.0*para->GetXHalfLength()/mm));
488  paraElement->setAttributeNode(NewAttribute("y",
489  2.0*para->GetYHalfLength()/mm));
490  paraElement->setAttributeNode(NewAttribute("z",
491  2.0*para->GetZHalfLength()/mm));
492  paraElement->setAttributeNode(NewAttribute("alpha",alpha/degree));
493  paraElement->setAttributeNode(NewAttribute("theta",theta/degree));
494  paraElement->setAttributeNode(NewAttribute("phi",phi/degree));
495  paraElement->setAttributeNode(NewAttribute("aunit","deg"));
496  paraElement->setAttributeNode(NewAttribute("lunit","mm"));
497  solElement->appendChild(paraElement);
498 }
499 
501 ParaboloidWrite(xercesc::DOMElement* solElement,
502  const G4Paraboloid* const paraboloid)
503 {
504  const G4String& name = GenerateName(paraboloid->GetName(),paraboloid);
505 
506  xercesc::DOMElement* paraboloidElement = NewElement("paraboloid");
507  paraboloidElement->setAttributeNode(NewAttribute("name",name));
508  paraboloidElement->setAttributeNode(NewAttribute("rlo",
509  paraboloid->GetRadiusMinusZ()/mm));
510  paraboloidElement->setAttributeNode(NewAttribute("rhi",
511  paraboloid->GetRadiusPlusZ()/mm));
512  paraboloidElement->setAttributeNode(NewAttribute("dz",
513  paraboloid->GetZHalfLength()/mm));
514  paraboloidElement->setAttributeNode(NewAttribute("lunit","mm"));
515  solElement->appendChild(paraboloidElement);
516 }
518 PolyconeWrite(xercesc::DOMElement* solElement,
519  const G4Polycone* const polycone)
520 {
521  const G4String& name = GenerateName(polycone->GetName(),polycone);
522 
523  xercesc::DOMElement* polyconeElement = NewElement("polycone");
524  polyconeElement->setAttributeNode(NewAttribute("name",name));
525  polyconeElement->setAttributeNode(NewAttribute("startphi",
527  polyconeElement->setAttributeNode(NewAttribute("deltaphi",
529  polyconeElement->setAttributeNode(NewAttribute("aunit","deg"));
530  polyconeElement->setAttributeNode(NewAttribute("lunit","mm"));
531  solElement->appendChild(polyconeElement);
532 
533  const size_t num_zplanes = polycone->GetOriginalParameters()->Num_z_planes;
534  const G4double* z_array = polycone->GetOriginalParameters()->Z_values;
535  const G4double* rmin_array = polycone->GetOriginalParameters()->Rmin;
536  const G4double* rmax_array = polycone->GetOriginalParameters()->Rmax;
537 
538  for (size_t i=0; i<num_zplanes; i++)
539  {
540  ZplaneWrite(polyconeElement,z_array[i],rmin_array[i],rmax_array[i]);
541  }
542 
543 
544 }
545 
547 GenericPolyconeWrite(xercesc::DOMElement* solElement,
548  const G4GenericPolycone* const polycone)
549 {
550  const G4String& name = GenerateName(polycone->GetName(),polycone);
551  xercesc::DOMElement* polyconeElement = NewElement("genericPolycone");
552  const G4double startPhi=polycone->GetStartPhi();
553  polyconeElement->setAttributeNode(NewAttribute("name",name));
554  polyconeElement->setAttributeNode(NewAttribute("startphi",
555  startPhi/degree));
556  polyconeElement->setAttributeNode(NewAttribute("deltaphi",
557  (polycone->GetEndPhi()-startPhi)/degree));
558  polyconeElement->setAttributeNode(NewAttribute("aunit","deg"));
559  polyconeElement->setAttributeNode(NewAttribute("lunit","mm"));
560  solElement->appendChild(polyconeElement);
561 
562  const size_t num_rzpoints = polycone->GetNumRZCorner();
563  for (size_t i=0; i<num_rzpoints; i++)
564  {
565  const G4double r_point=polycone->GetCorner(i).r;
566  const G4double z_point=polycone->GetCorner(i).z;
567  RZPointWrite(polyconeElement,r_point,z_point);
568  }
569 
570 }
571 
573 PolyhedraWrite(xercesc::DOMElement* solElement,
574  const G4Polyhedra* const polyhedra)
575 {
576  const G4String& name = GenerateName(polyhedra->GetName(),polyhedra);
577  if(polyhedra->IsGeneric() == false){
578  xercesc::DOMElement* polyhedraElement = NewElement("polyhedra");
579  polyhedraElement->setAttributeNode(NewAttribute("name",name));
580  polyhedraElement->setAttributeNode(NewAttribute("startphi",
581  polyhedra->GetOriginalParameters()->Start_angle/degree));
582  polyhedraElement->setAttributeNode(NewAttribute("deltaphi",
584  polyhedraElement->setAttributeNode(NewAttribute("numsides",
585  polyhedra->GetOriginalParameters()->numSide));
586  polyhedraElement->setAttributeNode(NewAttribute("aunit","deg"));
587  polyhedraElement->setAttributeNode(NewAttribute("lunit","mm"));
588  solElement->appendChild(polyhedraElement);
589 
590  const size_t num_zplanes = polyhedra->GetOriginalParameters()->Num_z_planes;
591  const G4double* z_array = polyhedra->GetOriginalParameters()->Z_values;
592  const G4double* rmin_array = polyhedra->GetOriginalParameters()->Rmin;
593  const G4double* rmax_array = polyhedra->GetOriginalParameters()->Rmax;
594 
595  const G4double convertRad =
596  std::cos(0.5*polyhedra->GetOriginalParameters()->Opening_angle
597  / polyhedra->GetOriginalParameters()->numSide);
598 
599  for (size_t i=0;i<num_zplanes;i++)
600  {
601  ZplaneWrite(polyhedraElement,z_array[i],
602  rmin_array[i]*convertRad, rmax_array[i]*convertRad);
603  }
604  }else{//generic polyhedra
605 
606  xercesc::DOMElement* polyhedraElement = NewElement("genericPolyhedra");
607  polyhedraElement->setAttributeNode(NewAttribute("name",name));
608  polyhedraElement->setAttributeNode(NewAttribute("startphi",
609  polyhedra->GetOriginalParameters()->Start_angle/degree));
610  polyhedraElement->setAttributeNode(NewAttribute("deltaphi",
612  polyhedraElement->setAttributeNode(NewAttribute("numsides",
613  polyhedra->GetOriginalParameters()->numSide));
614  polyhedraElement->setAttributeNode(NewAttribute("aunit","deg"));
615  polyhedraElement->setAttributeNode(NewAttribute("lunit","mm"));
616  solElement->appendChild(polyhedraElement);
617 
618  const size_t num_rzpoints = polyhedra->GetNumRZCorner();
619 
620  for (size_t i=0;i<num_rzpoints;i++)
621  {
622  const G4double r_point = polyhedra->GetCorner(i).r;
623  const G4double z_point = polyhedra->GetCorner(i).z;
624  RZPointWrite(polyhedraElement,r_point,z_point);
625  }
626  }
627 }
628 
630 SphereWrite(xercesc::DOMElement* solElement, const G4Sphere* const sphere)
631 {
632  const G4String& name = GenerateName(sphere->GetName(),sphere);
633 
634  xercesc::DOMElement* sphereElement = NewElement("sphere");
635  sphereElement->setAttributeNode(NewAttribute("name",name));
636  sphereElement->setAttributeNode(NewAttribute("rmin",
637  sphere->GetInnerRadius()/mm));
638  sphereElement->setAttributeNode(NewAttribute("rmax",
639  sphere->GetOuterRadius()/mm));
640  sphereElement->setAttributeNode(NewAttribute("startphi",
641  sphere->GetStartPhiAngle()/degree));
642  sphereElement->setAttributeNode(NewAttribute("deltaphi",
643  sphere->GetDeltaPhiAngle()/degree));
644  sphereElement->setAttributeNode(NewAttribute("starttheta",
645  sphere->GetStartThetaAngle()/degree));
646  sphereElement->setAttributeNode(NewAttribute("deltatheta",
647  sphere->GetDeltaThetaAngle()/degree));
648  sphereElement->setAttributeNode(NewAttribute("aunit","deg"));
649  sphereElement->setAttributeNode(NewAttribute("lunit","mm"));
650  solElement->appendChild(sphereElement);
651 }
652 
654 TessellatedWrite(xercesc::DOMElement* solElement,
655  const G4TessellatedSolid* const tessellated)
656 {
657  const G4String& solid_name = tessellated->GetName();
658  const G4String& name = GenerateName(solid_name, tessellated);
659 
660  xercesc::DOMElement* tessellatedElement = NewElement("tessellated");
661  tessellatedElement->setAttributeNode(NewAttribute("name",name));
662  tessellatedElement->setAttributeNode(NewAttribute("aunit","deg"));
663  tessellatedElement->setAttributeNode(NewAttribute("lunit","mm"));
664  solElement->appendChild(tessellatedElement);
665 
666  std::map<G4ThreeVector, G4String, G4ThreeVectorCompare> vertexMap;
667 
668  const size_t NumFacets = tessellated->GetNumberOfFacets();
669  size_t NumVertex = 0;
670 
671  for (size_t i=0;i<NumFacets;i++)
672  {
673  const G4VFacet* facet = tessellated->GetFacet(i);
674  const size_t NumVertexPerFacet = facet->GetNumberOfVertices();
675 
676  G4String FacetTag;
677 
678  if (NumVertexPerFacet==3) { FacetTag="triangular"; } else
679  if (NumVertexPerFacet==4) { FacetTag="quadrangular"; }
680  else
681  {
682  G4Exception("G4GDMLWriteSolids::TessellatedWrite()", "InvalidSetup",
683  FatalException, "Facet should contain 3 or 4 vertices!");
684  }
685 
686  xercesc::DOMElement* facetElement = NewElement(FacetTag);
687  tessellatedElement->appendChild(facetElement);
688 
689  for (size_t j=0; j<NumVertexPerFacet; j++)
690  {
691  std::stringstream name_stream;
692  std::stringstream ref_stream;
693 
694  name_stream << "vertex" << (j+1);
695  ref_stream << solid_name << "_v" << NumVertex;
696 
697  const G4String& fname = name_stream.str(); // facet's tag variable
698  G4String ref = ref_stream.str(); // vertex tag to be associated
699 
700  // Now search for the existance of the current vertex in the
701  // map of cached vertices. If existing, do NOT store it as
702  // position in the GDML file, so avoiding duplication; otherwise
703  // cache it in the local map and add it as position in the
704  // "define" section of the GDML file.
705 
706  const G4ThreeVector& vertex = facet->GetVertex(j);
707 
708  if(vertexMap.find(vertex) != vertexMap.end()) // Vertex is cached
709  {
710  ref = vertexMap[vertex]; // Set the proper tag for it
711  }
712  else // Vertex not found
713  {
714  vertexMap.insert(std::make_pair(vertex,ref)); // Cache vertex and ...
715  AddPosition(ref, vertex); // ... add it to define section!
716  NumVertex++;
717  }
718 
719  // Now create association of the vertex with its facet
720  //
721  facetElement->setAttributeNode(NewAttribute(fname,ref));
722  }
723  }
724 }
725 
727 TetWrite(xercesc::DOMElement* solElement, const G4Tet* const tet)
728 {
729  const G4String& solid_name = tet->GetName();
730  const G4String& name = GenerateName(solid_name, tet);
731 
732  std::vector<G4ThreeVector> vertexList = tet->GetVertices();
733 
734  xercesc::DOMElement* tetElement = NewElement("tet");
735  tetElement->setAttributeNode(NewAttribute("name",name));
736  tetElement->setAttributeNode(NewAttribute("vertex1",solid_name+"_v1"));
737  tetElement->setAttributeNode(NewAttribute("vertex2",solid_name+"_v2"));
738  tetElement->setAttributeNode(NewAttribute("vertex3",solid_name+"_v3"));
739  tetElement->setAttributeNode(NewAttribute("vertex4",solid_name+"_v4"));
740  tetElement->setAttributeNode(NewAttribute("lunit","mm"));
741  solElement->appendChild(tetElement);
742 
743  AddPosition(solid_name+"_v1",vertexList[0]);
744  AddPosition(solid_name+"_v2",vertexList[1]);
745  AddPosition(solid_name+"_v3",vertexList[2]);
746  AddPosition(solid_name+"_v4",vertexList[3]);
747 }
748 
750 TorusWrite(xercesc::DOMElement* solElement, const G4Torus* const torus)
751 {
752  const G4String& name = GenerateName(torus->GetName(),torus);
753 
754  xercesc::DOMElement* torusElement = NewElement("torus");
755  torusElement->setAttributeNode(NewAttribute("name",name));
756  torusElement->setAttributeNode(NewAttribute("rmin",torus->GetRmin()/mm));
757  torusElement->setAttributeNode(NewAttribute("rmax",torus->GetRmax()/mm));
758  torusElement->setAttributeNode(NewAttribute("rtor",torus->GetRtor()/mm));
759  torusElement->
760  setAttributeNode(NewAttribute("startphi",torus->GetSPhi()/degree));
761  torusElement->
762  setAttributeNode(NewAttribute("deltaphi",torus->GetDPhi()/degree));
763  torusElement->setAttributeNode(NewAttribute("aunit","deg"));
764  torusElement->setAttributeNode(NewAttribute("lunit","mm"));
765  solElement->appendChild(torusElement);
766 }
767 
769 GenTrapWrite(xercesc::DOMElement* solElement,
770  const G4GenericTrap* const gtrap)
771 {
772  const G4String& name = GenerateName(gtrap->GetName(),gtrap);
773 
774  std::vector<G4TwoVector> vertices = gtrap->GetVertices();
775 
776  xercesc::DOMElement* gtrapElement = NewElement("arb8");
777  gtrapElement->setAttributeNode(NewAttribute("name",name));
778  gtrapElement->setAttributeNode(NewAttribute("dz",
779  gtrap->GetZHalfLength()/mm));
780  gtrapElement->setAttributeNode(NewAttribute("v1x", vertices[0].x()));
781  gtrapElement->setAttributeNode(NewAttribute("v1y", vertices[0].y()));
782  gtrapElement->setAttributeNode(NewAttribute("v2x", vertices[1].x()));
783  gtrapElement->setAttributeNode(NewAttribute("v2y", vertices[1].y()));
784  gtrapElement->setAttributeNode(NewAttribute("v3x", vertices[2].x()));
785  gtrapElement->setAttributeNode(NewAttribute("v3y", vertices[2].y()));
786  gtrapElement->setAttributeNode(NewAttribute("v4x", vertices[3].x()));
787  gtrapElement->setAttributeNode(NewAttribute("v4y", vertices[3].y()));
788  gtrapElement->setAttributeNode(NewAttribute("v5x", vertices[4].x()));
789  gtrapElement->setAttributeNode(NewAttribute("v5y", vertices[4].y()));
790  gtrapElement->setAttributeNode(NewAttribute("v6x", vertices[5].x()));
791  gtrapElement->setAttributeNode(NewAttribute("v6y", vertices[5].y()));
792  gtrapElement->setAttributeNode(NewAttribute("v7x", vertices[6].x()));
793  gtrapElement->setAttributeNode(NewAttribute("v7y", vertices[6].y()));
794  gtrapElement->setAttributeNode(NewAttribute("v8x", vertices[7].x()));
795  gtrapElement->setAttributeNode(NewAttribute("v8y", vertices[7].y()));
796  gtrapElement->setAttributeNode(NewAttribute("lunit","mm"));
797  solElement->appendChild(gtrapElement);
798 }
799 
801 TrapWrite(xercesc::DOMElement* solElement, const G4Trap* const trap)
802 {
803  const G4String& name = GenerateName(trap->GetName(),trap);
804 
805  const G4ThreeVector& simaxis = trap->GetSymAxis();
806  const G4double phi = simaxis.phi();
807  const G4double theta = simaxis.theta();
808  const G4double alpha1 = std::atan(trap->GetTanAlpha1());
809  const G4double alpha2 = std::atan(trap->GetTanAlpha2());
810 
811  xercesc::DOMElement* trapElement = NewElement("trap");
812  trapElement->setAttributeNode(NewAttribute("name",name));
813  trapElement->setAttributeNode(NewAttribute("z",
814  2.0*trap->GetZHalfLength()/mm));
815  trapElement->setAttributeNode(NewAttribute("theta",theta/degree));
816  trapElement->setAttributeNode(NewAttribute("phi",phi/degree));
817  trapElement->setAttributeNode(NewAttribute("y1",
818  2.0*trap->GetYHalfLength1()/mm));
819  trapElement->setAttributeNode(NewAttribute("x1",
820  2.0*trap->GetXHalfLength1()/mm));
821  trapElement->setAttributeNode(NewAttribute("x2",
822  2.0*trap->GetXHalfLength2()/mm));
823  trapElement->setAttributeNode(NewAttribute("alpha1",alpha1/degree));
824  trapElement->setAttributeNode(NewAttribute("y2",
825  2.0*trap->GetYHalfLength2()/mm));
826  trapElement->setAttributeNode(NewAttribute("x3",
827  2.0*trap->GetXHalfLength3()/mm));
828  trapElement->setAttributeNode(NewAttribute("x4",
829  2.0*trap->GetXHalfLength4()/mm));
830  trapElement->setAttributeNode(NewAttribute("alpha2",alpha2/degree));
831  trapElement->setAttributeNode(NewAttribute("aunit","deg"));
832  trapElement->setAttributeNode(NewAttribute("lunit","mm"));
833  solElement->appendChild(trapElement);
834 }
835 
837 TrdWrite(xercesc::DOMElement* solElement, const G4Trd* const trd)
838 {
839  const G4String& name = GenerateName(trd->GetName(),trd);
840 
841  xercesc::DOMElement* trdElement = NewElement("trd");
842  trdElement->setAttributeNode(NewAttribute("name",name));
843  trdElement->setAttributeNode(NewAttribute("x1",
844  2.0*trd->GetXHalfLength1()/mm));
845  trdElement->setAttributeNode(NewAttribute("x2",
846  2.0*trd->GetXHalfLength2()/mm));
847  trdElement->setAttributeNode(NewAttribute("y1",
848  2.0*trd->GetYHalfLength1()/mm));
849  trdElement->setAttributeNode(NewAttribute("y2",
850  2.0*trd->GetYHalfLength2()/mm));
851  trdElement->setAttributeNode(NewAttribute("z",
852  2.0*trd->GetZHalfLength()/mm));
853  trdElement->setAttributeNode(NewAttribute("lunit","mm"));
854  solElement->appendChild(trdElement);
855 }
856 
858 TubeWrite(xercesc::DOMElement* solElement, const G4Tubs* const tube)
859 {
860  const G4String& name = GenerateName(tube->GetName(),tube);
861 
862  xercesc::DOMElement* tubeElement = NewElement("tube");
863  tubeElement->setAttributeNode(NewAttribute("name",name));
864  tubeElement->setAttributeNode(NewAttribute("rmin",
865  tube->GetInnerRadius()/mm));
866  tubeElement->setAttributeNode(NewAttribute("rmax",
867  tube->GetOuterRadius()/mm));
868  tubeElement->setAttributeNode(NewAttribute("z",
869  2.0*tube->GetZHalfLength()/mm));
870  tubeElement->setAttributeNode(NewAttribute("startphi",
871  tube->GetStartPhiAngle()/degree));
872  tubeElement->setAttributeNode(NewAttribute("deltaphi",
873  tube->GetDeltaPhiAngle()/degree));
874  tubeElement->setAttributeNode(NewAttribute("aunit","deg"));
875  tubeElement->setAttributeNode(NewAttribute("lunit","mm"));
876  solElement->appendChild(tubeElement);
877 }
878 
880 CutTubeWrite(xercesc::DOMElement* solElement, const G4CutTubs* const cuttube)
881 {
882  const G4String& name = GenerateName(cuttube->GetName(),cuttube);
883 
884  xercesc::DOMElement* cuttubeElement = NewElement("cutTube");
885  cuttubeElement->setAttributeNode(NewAttribute("name",name));
886  cuttubeElement->setAttributeNode(NewAttribute("rmin",
887  cuttube->GetInnerRadius()/mm));
888  cuttubeElement->setAttributeNode(NewAttribute("rmax",
889  cuttube->GetOuterRadius()/mm));
890  cuttubeElement->setAttributeNode(NewAttribute("z",
891  2.0*cuttube->GetZHalfLength()/mm));
892  cuttubeElement->setAttributeNode(NewAttribute("startphi",
893  cuttube->GetStartPhiAngle()/degree));
894  cuttubeElement->setAttributeNode(NewAttribute("deltaphi",
895  cuttube->GetDeltaPhiAngle()/degree));
896  cuttubeElement->setAttributeNode(NewAttribute("lowX",
897  cuttube->GetLowNorm().getX()/mm));
898  cuttubeElement->setAttributeNode(NewAttribute("lowY",
899  cuttube->GetLowNorm().getY()/mm));
900  cuttubeElement->setAttributeNode(NewAttribute("lowZ",
901  cuttube->GetLowNorm().getZ()/mm));
902  cuttubeElement->setAttributeNode(NewAttribute("highX",
903  cuttube->GetHighNorm().getX()/mm));
904  cuttubeElement->setAttributeNode(NewAttribute("highY",
905  cuttube->GetHighNorm().getY()/mm));
906  cuttubeElement->setAttributeNode(NewAttribute("highZ",
907  cuttube->GetHighNorm().getZ()/mm));
908  cuttubeElement->setAttributeNode(NewAttribute("aunit","deg"));
909  cuttubeElement->setAttributeNode(NewAttribute("lunit","mm"));
910  solElement->appendChild(cuttubeElement);
911 }
912 
914 TwistedboxWrite(xercesc::DOMElement* solElement,
915  const G4TwistedBox* const twistedbox)
916 {
917  const G4String& name = GenerateName(twistedbox->GetName(),twistedbox);
918 
919  xercesc::DOMElement* twistedboxElement = NewElement("twistedbox");
920  twistedboxElement->setAttributeNode(NewAttribute("name",name));
921  twistedboxElement->setAttributeNode(NewAttribute("x",
922  2.0*twistedbox->GetXHalfLength()/mm));
923  twistedboxElement->setAttributeNode(NewAttribute("y",
924  2.0*twistedbox->GetYHalfLength()/mm));
925  twistedboxElement->setAttributeNode(NewAttribute("z",
926  2.0*twistedbox->GetZHalfLength()/mm));
927  twistedboxElement->setAttributeNode(NewAttribute("PhiTwist",
928  twistedbox->GetPhiTwist()/degree));
929  twistedboxElement->setAttributeNode(NewAttribute("aunit","deg"));
930  twistedboxElement->setAttributeNode(NewAttribute("lunit","mm"));
931  solElement->appendChild(twistedboxElement);
932 }
933 
935 TwistedtrapWrite(xercesc::DOMElement* solElement,
936  const G4TwistedTrap* const twistedtrap)
937 {
938  const G4String& name = GenerateName(twistedtrap->GetName(),twistedtrap);
939 
940  xercesc::DOMElement* twistedtrapElement = NewElement("twistedtrap");
941  twistedtrapElement->setAttributeNode(NewAttribute("name",name));
942  twistedtrapElement->setAttributeNode(NewAttribute("y1",
943  2.0*twistedtrap->GetY1HalfLength()/mm));
944  twistedtrapElement->setAttributeNode(NewAttribute("x1",
945  2.0*twistedtrap->GetX1HalfLength()/mm));
946  twistedtrapElement->setAttributeNode(NewAttribute("x2",
947  2.0*twistedtrap->GetX2HalfLength()/mm));
948  twistedtrapElement->setAttributeNode(NewAttribute("y2",
949  2.0*twistedtrap->GetY2HalfLength()/mm));
950  twistedtrapElement->setAttributeNode(NewAttribute("x3",
951  2.0*twistedtrap->GetX3HalfLength()/mm));
952  twistedtrapElement->setAttributeNode(NewAttribute("x4",
953  2.0*twistedtrap->GetX4HalfLength()/mm));
954  twistedtrapElement->setAttributeNode(NewAttribute("z",
955  2.0*twistedtrap->GetZHalfLength()/mm));
956  twistedtrapElement->setAttributeNode(NewAttribute("Alph",
957  twistedtrap->GetTiltAngleAlpha()/degree));
958  twistedtrapElement->setAttributeNode(NewAttribute("Theta",
959  twistedtrap->GetPolarAngleTheta()/degree));
960  twistedtrapElement->setAttributeNode(NewAttribute("Phi",
961  twistedtrap->GetAzimuthalAnglePhi()/degree));
962  twistedtrapElement->setAttributeNode(NewAttribute("PhiTwist",
963  twistedtrap->GetPhiTwist()/degree));
964  twistedtrapElement->setAttributeNode(NewAttribute("aunit","deg"));
965  twistedtrapElement->setAttributeNode(NewAttribute("lunit","mm"));
966 
967  solElement->appendChild(twistedtrapElement);
968 }
969 
971 TwistedtrdWrite(xercesc::DOMElement* solElement,
972  const G4TwistedTrd* const twistedtrd)
973 {
974  const G4String& name = GenerateName(twistedtrd->GetName(),twistedtrd);
975 
976  xercesc::DOMElement* twistedtrdElement = NewElement("twistedtrd");
977  twistedtrdElement->setAttributeNode(NewAttribute("name",name));
978  twistedtrdElement->setAttributeNode(NewAttribute("x1",
979  2.0*twistedtrd->GetX1HalfLength()/mm));
980  twistedtrdElement->setAttributeNode(NewAttribute("x2",
981  2.0*twistedtrd->GetX2HalfLength()/mm));
982  twistedtrdElement->setAttributeNode(NewAttribute("y1",
983  2.0*twistedtrd->GetY1HalfLength()/mm));
984  twistedtrdElement->setAttributeNode(NewAttribute("y2",
985  2.0*twistedtrd->GetY2HalfLength()/mm));
986  twistedtrdElement->setAttributeNode(NewAttribute("z",
987  2.0*twistedtrd->GetZHalfLength()/mm));
988  twistedtrdElement->setAttributeNode(NewAttribute("PhiTwist",
989  twistedtrd->GetPhiTwist()/degree));
990  twistedtrdElement->setAttributeNode(NewAttribute("aunit","deg"));
991  twistedtrdElement->setAttributeNode(NewAttribute("lunit","mm"));
992  solElement->appendChild(twistedtrdElement);
993 }
994 
996 TwistedtubsWrite(xercesc::DOMElement* solElement,
997  const G4TwistedTubs* const twistedtubs)
998 {
999  const G4String& name = GenerateName(twistedtubs->GetName(),twistedtubs);
1000 
1001  xercesc::DOMElement* twistedtubsElement = NewElement("twistedtubs");
1002  twistedtubsElement->setAttributeNode(NewAttribute("name",name));
1003  twistedtubsElement->setAttributeNode(NewAttribute("twistedangle",
1004  twistedtubs->GetPhiTwist()/degree));
1005  twistedtubsElement->setAttributeNode(NewAttribute("endinnerrad",
1006  twistedtubs->GetInnerRadius()/mm));
1007  twistedtubsElement->setAttributeNode(NewAttribute("endouterrad",
1008  twistedtubs->GetOuterRadius()/mm));
1009  twistedtubsElement->setAttributeNode(NewAttribute("zlen",
1010  2.0*twistedtubs->GetZHalfLength()/mm));
1011  twistedtubsElement->setAttributeNode(NewAttribute("phi",
1012  twistedtubs->GetDPhi()/degree));
1013  twistedtubsElement->setAttributeNode(NewAttribute("aunit","deg"));
1014  twistedtubsElement->setAttributeNode(NewAttribute("lunit","mm"));
1015  solElement->appendChild(twistedtubsElement);
1016 }
1017 
1019 ZplaneWrite(xercesc::DOMElement* element, const G4double& z,
1020  const G4double& rmin, const G4double& rmax)
1021 {
1022  xercesc::DOMElement* zplaneElement = NewElement("zplane");
1023  zplaneElement->setAttributeNode(NewAttribute("z",z/mm));
1024  zplaneElement->setAttributeNode(NewAttribute("rmin",rmin/mm));
1025  zplaneElement->setAttributeNode(NewAttribute("rmax",rmax/mm));
1026  element->appendChild(zplaneElement);
1027 }
1028 
1030 RZPointWrite(xercesc::DOMElement* element, const G4double& r,
1031  const G4double& z)
1032 {
1033  xercesc::DOMElement* rzpointElement = NewElement("rzpoint");
1034  rzpointElement->setAttributeNode(NewAttribute("r",r/mm));
1035  rzpointElement->setAttributeNode(NewAttribute("z",z/mm));
1036  element->appendChild(rzpointElement);
1037 }
1038 
1040 OpticalSurfaceWrite(xercesc::DOMElement* solElement,
1041  const G4OpticalSurface* const surf)
1042 {
1043  xercesc::DOMElement* optElement = NewElement("opticalsurface");
1044  G4OpticalSurfaceModel smodel = surf->GetModel();
1045  G4double sval = (smodel==glisur) ? surf->GetPolish() : surf->GetSigmaAlpha();
1046 
1047  optElement->setAttributeNode(NewAttribute("name", surf->GetName()));
1048  optElement->setAttributeNode(NewAttribute("model", smodel));
1049  optElement->setAttributeNode(NewAttribute("finish", surf->GetFinish()));
1050  optElement->setAttributeNode(NewAttribute("type", surf->GetType()));
1051  optElement->setAttributeNode(NewAttribute("value", sval));
1052 
1053  solElement->appendChild(optElement);
1054 }
1055 
1056 void G4GDMLWriteSolids::SolidsWrite(xercesc::DOMElement* gdmlElement)
1057 {
1058  G4cout << "G4GDML: Writing solids..." << G4endl;
1059 
1060  solidsElement = NewElement("solids");
1061  gdmlElement->appendChild(solidsElement);
1062 
1063  solidList.clear();
1064 }
1065 
1066 void G4GDMLWriteSolids::AddSolid(const G4VSolid* const solidPtr)
1067 {
1068  for (size_t i=0; i<solidList.size(); i++) // Check if solid is
1069  { // already in the list!
1070  if (solidList[i] == solidPtr) { return; }
1071  }
1072 
1073  solidList.push_back(solidPtr);
1074 
1075  if (const G4BooleanSolid* const booleanPtr
1076  = dynamic_cast<const G4BooleanSolid*>(solidPtr))
1077  { BooleanWrite(solidsElement,booleanPtr); } else
1078  if (const G4ScaledSolid* const scaledPtr
1079  = dynamic_cast<const G4ScaledSolid*>(solidPtr))
1080  { ScaledWrite(solidsElement,scaledPtr); } else
1081  if (solidPtr->GetEntityType()=="G4MultiUnion")
1082  { const G4MultiUnion* const munionPtr
1083  = static_cast<const G4MultiUnion*>(solidPtr);
1084  MultiUnionWrite(solidsElement,munionPtr); } else
1085  if (solidPtr->GetEntityType()=="G4Box")
1086  { const G4Box* const boxPtr
1087  = static_cast<const G4Box*>(solidPtr);
1088  BoxWrite(solidsElement,boxPtr); } else
1089  if (solidPtr->GetEntityType()=="G4Cons")
1090  { const G4Cons* const conePtr
1091  = static_cast<const G4Cons*>(solidPtr);
1092  ConeWrite(solidsElement,conePtr); } else
1093  if (solidPtr->GetEntityType()=="G4EllipticalCone")
1094  { const G4EllipticalCone* const elconePtr
1095  = static_cast<const G4EllipticalCone*>(solidPtr);
1096  ElconeWrite(solidsElement,elconePtr); } else
1097  if (solidPtr->GetEntityType()=="G4Ellipsoid")
1098  { const G4Ellipsoid* const ellipsoidPtr
1099  = static_cast<const G4Ellipsoid*>(solidPtr);
1100  EllipsoidWrite(solidsElement,ellipsoidPtr); } else
1101  if (solidPtr->GetEntityType()=="G4EllipticalTube")
1102  { const G4EllipticalTube* const eltubePtr
1103  = static_cast<const G4EllipticalTube*>(solidPtr);
1104  EltubeWrite(solidsElement,eltubePtr); } else
1105  if (solidPtr->GetEntityType()=="G4ExtrudedSolid")
1106  { const G4ExtrudedSolid* const xtruPtr
1107  = static_cast<const G4ExtrudedSolid*>(solidPtr);
1108  XtruWrite(solidsElement,xtruPtr); } else
1109  if (solidPtr->GetEntityType()=="G4Hype")
1110  { const G4Hype* const hypePtr
1111  = static_cast<const G4Hype*>(solidPtr);
1112  HypeWrite(solidsElement,hypePtr); } else
1113  if (solidPtr->GetEntityType()=="G4Orb")
1114  { const G4Orb* const orbPtr
1115  = static_cast<const G4Orb*>(solidPtr);
1116  OrbWrite(solidsElement,orbPtr); } else
1117  if (solidPtr->GetEntityType()=="G4Para")
1118  { const G4Para* const paraPtr
1119  = static_cast<const G4Para*>(solidPtr);
1120  ParaWrite(solidsElement,paraPtr); } else
1121  if (solidPtr->GetEntityType()=="G4Paraboloid")
1122  { const G4Paraboloid* const paraboloidPtr
1123  = static_cast<const G4Paraboloid*>(solidPtr);
1124  ParaboloidWrite(solidsElement,paraboloidPtr); } else
1125  if (solidPtr->GetEntityType()=="G4Polycone")
1126  { const G4Polycone* const polyconePtr
1127  = static_cast<const G4Polycone*>(solidPtr);
1128  PolyconeWrite(solidsElement,polyconePtr); } else
1129  if (solidPtr->GetEntityType()=="G4GenericPolycone")
1130  { const G4GenericPolycone* const genpolyconePtr
1131  = static_cast<const G4GenericPolycone*>(solidPtr);
1132  GenericPolyconeWrite(solidsElement,genpolyconePtr); } else
1133  if (solidPtr->GetEntityType()=="G4Polyhedra")
1134  { const G4Polyhedra* const polyhedraPtr
1135  = static_cast<const G4Polyhedra*>(solidPtr);
1136  PolyhedraWrite(solidsElement,polyhedraPtr); } else
1137  if (solidPtr->GetEntityType()=="G4Sphere")
1138  { const G4Sphere* const spherePtr
1139  = static_cast<const G4Sphere*>(solidPtr);
1140  SphereWrite(solidsElement,spherePtr); } else
1141  if (solidPtr->GetEntityType()=="G4TessellatedSolid")
1142  { const G4TessellatedSolid* const tessellatedPtr
1143  = static_cast<const G4TessellatedSolid*>(solidPtr);
1144  TessellatedWrite(solidsElement,tessellatedPtr); } else
1145  if (solidPtr->GetEntityType()=="G4Tet")
1146  { const G4Tet* const tetPtr
1147  = static_cast<const G4Tet*>(solidPtr);
1148  TetWrite(solidsElement,tetPtr); } else
1149  if (solidPtr->GetEntityType()=="G4Torus")
1150  { const G4Torus* const torusPtr
1151  = static_cast<const G4Torus*>(solidPtr);
1152  TorusWrite(solidsElement,torusPtr); } else
1153  if (solidPtr->GetEntityType()=="G4GenericTrap")
1154  { const G4GenericTrap* const gtrapPtr
1155  = static_cast<const G4GenericTrap*>(solidPtr);
1156  GenTrapWrite(solidsElement,gtrapPtr); } else
1157  if (solidPtr->GetEntityType()=="G4Trap")
1158  { const G4Trap* const trapPtr
1159  = static_cast<const G4Trap*>(solidPtr);
1160  TrapWrite(solidsElement,trapPtr); } else
1161  if (solidPtr->GetEntityType()=="G4Trd")
1162  { const G4Trd* const trdPtr
1163  = static_cast<const G4Trd*>(solidPtr);
1164  TrdWrite(solidsElement,trdPtr); } else
1165  if (solidPtr->GetEntityType()=="G4Tubs")
1166  { const G4Tubs* const tubePtr
1167  = static_cast<const G4Tubs*>(solidPtr);
1168  TubeWrite(solidsElement,tubePtr); } else
1169  if (solidPtr->GetEntityType()=="G4CutTubs")
1170  { const G4CutTubs* const cuttubePtr
1171  = static_cast<const G4CutTubs*>(solidPtr);
1172  CutTubeWrite(solidsElement,cuttubePtr); } else
1173  if (solidPtr->GetEntityType()=="G4TwistedBox")
1174  { const G4TwistedBox* const twistedboxPtr
1175  = static_cast<const G4TwistedBox*>(solidPtr);
1176  TwistedboxWrite(solidsElement,twistedboxPtr); } else
1177  if (solidPtr->GetEntityType()=="G4TwistedTrap")
1178  { const G4TwistedTrap* const twistedtrapPtr
1179  = static_cast<const G4TwistedTrap*>(solidPtr);
1180  TwistedtrapWrite(solidsElement,twistedtrapPtr); } else
1181  if (solidPtr->GetEntityType()=="G4TwistedTrd")
1182  { const G4TwistedTrd* const twistedtrdPtr
1183  = static_cast<const G4TwistedTrd*>(solidPtr);
1184  TwistedtrdWrite(solidsElement,twistedtrdPtr); } else
1185  if (solidPtr->GetEntityType()=="G4TwistedTubs")
1186  { const G4TwistedTubs* const twistedtubsPtr
1187  = static_cast<const G4TwistedTubs*>(solidPtr);
1188  TwistedtubsWrite(solidsElement,twistedtubsPtr); }
1189  else
1190  {
1191  G4String error_msg = "Unknown solid: " + solidPtr->GetName()
1192  + "; Type: " + solidPtr->GetEntityType();
1193  G4Exception("G4GDMLWriteSolids::AddSolid()", "WriteError",
1194  FatalException, error_msg);
1195  }
1196 }
G4ThreeVector GetSymAxis() const
G4double GetSPhi() const
static const G4double kAngularPrecision
G4PolyconeSideRZ GetCorner(G4int index) const
G4String GetName() const
G4double GetXHalfLength4() const
double yy() const
Definition: Transform3D.h:264
const XML_Char * name
Definition: expat.h:151
void ScaledWrite(xercesc::DOMElement *, const G4ScaledSolid *const)
double y() const
G4double GetXHalfLength() const
G4double GetOuterStereo() const
Definition: G4Para.hh:77
G4double GetX1HalfLength() const
Definition: G4TwistedTrd.hh:77
G4Scale3D GetScaleTransform() const
double x() const
G4OpticalSurfaceModel GetModel() const
static constexpr double mm
Definition: G4SIunits.hh:115
G4double GetY1HalfLength() const
Definition: G4TwistedTrd.hh:79
G4double GetPolarAngleTheta() const
G4double GetYHalfLength2() const
G4double GetYHalfLength1() const
G4double GetInnerStereo() const
G4double GetDy() const
G4double GetSemiAxisX() const
CLHEP::Hep3Vector G4ThreeVector
void BoxWrite(xercesc::DOMElement *, const G4Box *const)
G4double GetInnerRadius() const
double x() const
void PolyhedraWrite(xercesc::DOMElement *, const G4Polyhedra *const)
void TessellatedWrite(xercesc::DOMElement *, const G4TessellatedSolid *const)
double yx() const
Definition: Transform3D.h:261
Definition: G4Box.hh:64
void getDecomposition(Scale3D &scale, Rotate3D &rotation, Translate3D &translation) const
Definition: Transform3D.cc:174
G4double GetZTopCut() const
G4double GetZHalfLength() const
G4ThreeVector GetLowNorm() const
Definition: G4Tubs.hh:85
Definition: xmlparse.cc:187
G4double GetZHalfLength() const
virtual G4int GetNumberOfVertices() const =0
virtual ~G4GDMLWriteSolids()
G4double GetRmax() const
void TrdWrite(xercesc::DOMElement *, const G4Trd *const)
G4double GetZBottomCut() const
const G4String & GetName() const
void FirstpositionWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &pos)
void XtruWrite(xercesc::DOMElement *, const G4ExtrudedSolid *const)
double getY() const
const G4SurfaceType & GetType() const
tuple x
Definition: test.py:50
G4double GetZHalfLength() const
G4double GetOuterRadiusMinusZ() const
G4double GetRadiusMinusZ() const
Definition: G4Trd.hh:72
G4double GetX2HalfLength() const
Definition: G4TwistedTrd.hh:78
double zz() const
Definition: Transform3D.h:276
G4double GetInnerRadius() const
virtual G4GeometryType GetEntityType() const =0
G4double GetZHalfLength() const
void TwistedtrdWrite(xercesc::DOMElement *, const G4TwistedTrd *const)
xercesc::DOMElement * NewElement(const G4String &)
Definition: G4GDMLWrite.cc:160
G4double GetStartPhiAngle() const
G4double GetDeltaPhiAngle() const
int G4int
Definition: G4Types.hh:78
G4double GetZHalfLength() const
G4double GetSemiAxisMax(G4int i) const
G4double GetXHalfLength2() const
double z() const
G4TwoVector GetVertex(G4int index) const
G4double GetZHalfLength() const
Definition: G4TwistedTrd.hh:81
G4double GetRtor() const
G4double GetZHalfLength() const
Definition: G4TwistedBox.hh:75
void TwistedboxWrite(xercesc::DOMElement *, const G4TwistedBox *const)
G4double GetEndPhi() const
G4double GetTanAlpha2() const
G4int GetNumRZCorner() const
G4double GetPhiTwist() const
G4VFacet * GetFacet(G4int i) const
double xz() const
Definition: Transform3D.h:258
G4double GetY1HalfLength() const
void MultiUnionWrite(xercesc::DOMElement *solElement, const G4MultiUnion *const)
std::vector< G4ThreeVector > GetVertices() const
Definition: G4Tet.cc:733
G4double GetXHalfLength2() const
G4double GetRadius() const
static const G4int maxTransforms
double getX() const
void RZPointWrite(xercesc::DOMElement *, const G4double &, const G4double &)
void OrbWrite(xercesc::DOMElement *, const G4Orb *const)
void TwistedtubsWrite(xercesc::DOMElement *, const G4TwistedTubs *const)
G4double GetXHalfLength1() const
G4double GetDz() const
G4GLOB_DLL std::ostream G4cout
G4double GetDeltaPhiAngle() const
G4double GetPolish() const
G4double GetStartThetaAngle() const
G4double GetRmin() const
G4double GetXHalfLength3() const
void TrapWrite(xercesc::DOMElement *, const G4Trap *const)
static G4double tet[DIM]
void ConeWrite(xercesc::DOMElement *, const G4Cons *const)
static constexpr double degree
Definition: G4SIunits.hh:144
Definition: G4Tet.hh:66
void ElconeWrite(xercesc::DOMElement *, const G4EllipticalCone *const)
Definition: G4Hype.hh:67
G4double GetZHalfLength() const
void ParaboloidWrite(xercesc::DOMElement *, const G4Paraboloid *const)
void FirstrotationWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &rot)
void PolyconeWrite(xercesc::DOMElement *, const G4Polycone *const)
G4double GetY2HalfLength() const
Definition: G4TwistedTrd.hh:80
G4int GetNofVertices() const
void OpticalSurfaceWrite(xercesc::DOMElement *, const G4OpticalSurface *const)
G4double GetZMax() const
Definition: G4Cons.hh:83
G4double GetX3HalfLength() const
G4double GetPhiTwist() const
Definition: G4TwistedTrd.hh:82
G4double GetDPhi() const
G4double GetYHalfLength() const
G4double GetStartPhiAngle() const
void AddPosition(const G4String &name, const G4ThreeVector &pos)
void GenericPolyconeWrite(xercesc::DOMElement *, const G4GenericPolycone *const)
char boolean
Definition: csz_inflate.cc:208
G4double GetYHalfLength2() const
G4double GetOuterRadius() const
G4double GetStartPhiAngle() const
double phi() const
G4double GetStartPhi() const
G4String GenerateName(const G4String &, const void *const)
Definition: G4GDMLWrite.cc:123
G4double GetInnerRadiusPlusZ() const
void RotationWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &rot)
G4double GetDPhi() const
void CutTubeWrite(xercesc::DOMElement *, const G4CutTubs *const)
G4double GetInnerRadius() const
G4PolyconeHistorical * GetOriginalParameters() const
double xy() const
Definition: Transform3D.h:255
G4OpticalSurfaceFinish GetFinish() const
G4double GetDx() const
G4int GetNofZSections() const
Definition: G4Orb.hh:61
G4double GetZHalfLength() const
G4double GetXHalfLength() const
G4double GetInnerRadius() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void ZplaneWrite(xercesc::DOMElement *, const G4double &, const G4double &, const G4double &)
G4double GetSemiAxisY() const
void ScaleWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &scl)
G4double GetX4HalfLength() const
void G4MultiUnion
Definition: G4MultiUnion.hh:53
G4double GetYHalfLength() const
Definition: G4TwistedBox.hh:74
void HypeWrite(xercesc::DOMElement *, const G4Hype *const)
G4int GetNumberOfFacets() const
double yz() const
Definition: Transform3D.h:267
G4double GetOuterRadius() const
G4double GetRadiusPlusZ() const
G4double GetZHalfLength() const
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
Definition: G4GDMLWrite.cc:136
static const G4double kLinearPrecision
G4double GetTanAlpha() const
G4bool IsGeneric() const
void EltubeWrite(xercesc::DOMElement *, const G4EllipticalTube *const)
double getZ() const
void ParaWrite(xercesc::DOMElement *, const G4Para *const)
G4ThreeVector GetHighNorm() const
void EllipsoidWrite(xercesc::DOMElement *, const G4Ellipsoid *const)
G4ThreeVector GetAngles(const G4RotationMatrix &)
double y() const
ZSection GetZSection(G4int index) const
virtual void SolidsWrite(xercesc::DOMElement *)
void TetWrite(xercesc::DOMElement *, const G4Tet *const)
G4VSolid * GetUnscaledSolid() const
G4PolyhedraHistorical * GetOriginalParameters() const
G4double GetZHalfLength() const
G4double GetZHalfLength() const
void TubeWrite(xercesc::DOMElement *, const G4Tubs *const)
tuple z
Definition: test.py:28
double xx() const
Definition: Transform3D.h:252
G4ThreeVector GetSymAxis() const
G4double GetInnerRadius() const
G4double GetZTopCut() const
void BooleanWrite(xercesc::DOMElement *, const G4BooleanSolid *const)
G4double GetZHalfLength() const
G4double GetAzimuthalAnglePhi() const
G4OpticalSurfaceModel
#define G4endl
Definition: G4ios.hh:61
void TorusWrite(xercesc::DOMElement *, const G4Torus *const)
G4double GetXHalfLength1() const
string fname
Definition: test.py:308
G4double GetOuterRadius() const
G4double GetStartPhiAngle() const
G4PolyhedraSideRZ GetCorner(const G4int index) const
G4double GetYHalfLength1() const
G4double GetDeltaPhiAngle() const
void PositionWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &pos)
void TwistedtrapWrite(xercesc::DOMElement *, const G4TwistedTrap *const)
double G4double
Definition: G4Types.hh:76
G4double GetPhiTwist() const
Definition: G4TwistedBox.hh:76
G4double GetInnerRadiusMinusZ() const
G4double GetSigmaAlpha() const
G4double GetTanAlpha1() const
CLHEP::Hep3Vector getTranslation() const
static const G4double alpha
double zy() const
Definition: Transform3D.h:273
G4int GetNumRZCorner() const
virtual G4ThreeVector GetVertex(G4int i) const =0
G4double GetDeltaThetaAngle() const
G4double GetX1HalfLength() const
void GenTrapWrite(xercesc::DOMElement *, const G4GenericTrap *const)
G4double GetTiltAngleAlpha() const
G4double GetX2HalfLength() const
G4double GetOuterRadiusPlusZ() const
const std::vector< G4TwoVector > & GetVertices() const
G4double GetZHalfLength() const
G4double GetOuterRadius() const
G4double GetXHalfLength() const
Definition: G4TwistedBox.hh:73
xercesc::DOMElement * solidsElement
static const G4double pos
void SphereWrite(xercesc::DOMElement *, const G4Sphere *const)
G4double GetPhiTwist() const
double zx() const
Definition: Transform3D.h:270
G4double GetOuterRadius() const
virtual void AddSolid(const G4VSolid *const)
G4double GetY2HalfLength() const
std::vector< const G4VSolid * > solidList
G4double GetDeltaPhiAngle() const
G4double GetYHalfLength() const