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