38 #include <Geant4/G4SystemOfUnits.hh>
39 #include <Geant4/G4Box.hh>
40 #include <Geant4/G4Trd.hh>
41 #include <Geant4/G4Trap.hh>
42 #include <Geant4/G4Tubs.hh>
43 #include <Geant4/G4Cons.hh>
44 #include <Geant4/G4Sphere.hh>
45 #include <Geant4/G4Orb.hh>
46 #include <Geant4/G4Torus.hh>
47 #include <Geant4/G4Ellipsoid.hh>
48 #include <Geant4/G4Para.hh>
49 #include <Geant4/G4Hype.hh>
50 #include <Geant4/G4Polycone.hh>
51 #include <Geant4/G4Polyhedra.hh>
52 #include <Geant4/G4LogicalVolume.hh>
53 #include <Geant4/G4VPhysicalVolume.hh>
54 #include <Geant4/G4PVParameterised.hh>
55 #include <Geant4/G4VPVParameterisation.hh>
69 const G4Box*
const box)
71 xercesc::DOMElement* box_dimensionsElement =
NewElement(
"box_dimensions");
72 box_dimensionsElement->
74 box_dimensionsElement->
76 box_dimensionsElement->
78 box_dimensionsElement->
80 parametersElement->appendChild(box_dimensionsElement);
85 const G4Trd*
const trd)
87 xercesc::DOMElement* trd_dimensionsElement =
NewElement(
"trd_dimensions");
88 trd_dimensionsElement->
89 setAttributeNode(
NewAttribute(
"x1",2.0*trd->GetXHalfLength1()/
mm));
90 trd_dimensionsElement->
91 setAttributeNode(
NewAttribute(
"x2",2.0*trd->GetXHalfLength2()/
mm));
92 trd_dimensionsElement->
93 setAttributeNode(
NewAttribute(
"y1",2.0*trd->GetYHalfLength1()/
mm));
94 trd_dimensionsElement->
95 setAttributeNode(
NewAttribute(
"y2",2.0*trd->GetYHalfLength2()/
mm));
96 trd_dimensionsElement->
98 trd_dimensionsElement->
100 parametersElement->appendChild(trd_dimensionsElement);
105 const G4Trap*
const trap)
107 const G4ThreeVector simaxis = trap->GetSymAxis();
108 const G4double
phi = (simaxis.z() != 1.0)
109 ? (std::atan(simaxis.y()/simaxis.x())) : (0.0);
110 const G4double
theta = std::acos(simaxis.z());
111 const G4double alpha1 = std::atan(trap->GetTanAlpha1());
112 const G4double alpha2 = std::atan(trap->GetTanAlpha2());
114 xercesc::DOMElement* trap_dimensionsElement =
NewElement(
"trap");
115 trap_dimensionsElement->
116 setAttributeNode(
NewAttribute(
"z",2.0*trap->GetZHalfLength()/
mm));
117 trap_dimensionsElement->
119 trap_dimensionsElement->
121 trap_dimensionsElement->
122 setAttributeNode(
NewAttribute(
"y1",2.0*trap->GetYHalfLength1()/
mm));
123 trap_dimensionsElement->
124 setAttributeNode(
NewAttribute(
"x1",2.0*trap->GetXHalfLength1()/
mm));
125 trap_dimensionsElement->
126 setAttributeNode(
NewAttribute(
"x2",2.0*trap->GetXHalfLength2()/
mm));
127 trap_dimensionsElement->
129 trap_dimensionsElement->
130 setAttributeNode(
NewAttribute(
"y2",2.0*trap->GetYHalfLength2()/
mm));
131 trap_dimensionsElement->
132 setAttributeNode(
NewAttribute(
"x3",2.0*trap->GetXHalfLength3()/
mm));
133 trap_dimensionsElement->
134 setAttributeNode(
NewAttribute(
"x4",2.0*trap->GetXHalfLength4()/
mm));
135 trap_dimensionsElement->
137 trap_dimensionsElement->
139 trap_dimensionsElement->
141 parametersElement->appendChild(trap_dimensionsElement);
146 const G4Tubs*
const tube)
148 xercesc::DOMElement* tube_dimensionsElement =
NewElement(
"tube_dimensions");
149 tube_dimensionsElement->
151 tube_dimensionsElement->
153 tube_dimensionsElement->
154 setAttributeNode(
NewAttribute(
"hz",2.0*tube->GetZHalfLength()/
mm));
155 tube_dimensionsElement->
157 tube_dimensionsElement->
159 tube_dimensionsElement->
161 tube_dimensionsElement->
163 parametersElement->appendChild(tube_dimensionsElement);
169 const G4Cons*
const cone)
171 xercesc::DOMElement* cone_dimensionsElement =
NewElement(
"cone_dimensions");
172 cone_dimensionsElement->
173 setAttributeNode(
NewAttribute(
"rmin1",cone->GetInnerRadiusMinusZ()/
mm));
174 cone_dimensionsElement->
175 setAttributeNode(
NewAttribute(
"rmax1",cone->GetOuterRadiusMinusZ()/
mm));
176 cone_dimensionsElement->
177 setAttributeNode(
NewAttribute(
"rmin2",cone->GetInnerRadiusPlusZ()/
mm));
178 cone_dimensionsElement->
179 setAttributeNode(
NewAttribute(
"rmax2",cone->GetOuterRadiusPlusZ()/
mm));
180 cone_dimensionsElement->
181 setAttributeNode(
NewAttribute(
"z",2.0*cone->GetZHalfLength()/
mm));
182 cone_dimensionsElement->
184 cone_dimensionsElement->
186 cone_dimensionsElement->
188 cone_dimensionsElement->
190 parametersElement->appendChild(cone_dimensionsElement);
195 const G4Sphere*
const sphere)
197 xercesc::DOMElement* sphere_dimensionsElement =
199 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"rmin",
200 sphere->GetInnerRadius()/
mm));
201 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"rmax",
202 sphere->GetOuterRadius()/
mm));
203 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"startphi",
204 sphere->GetStartPhiAngle()/
degree));
205 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"deltaphi",
206 sphere->GetDeltaPhiAngle()/
degree));
207 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"starttheta",
208 sphere->GetStartThetaAngle()/
degree));
209 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"deltatheta",
210 sphere->GetDeltaThetaAngle()/
degree));
211 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
212 sphere_dimensionsElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
213 parametersElement->appendChild(sphere_dimensionsElement);
218 const G4Orb*
const orb)
220 xercesc::DOMElement* orb_dimensionsElement =
NewElement(
"orb_dimensions");
221 orb_dimensionsElement->setAttributeNode(
NewAttribute(
"r",
222 orb->GetRadius()/
mm));
223 orb_dimensionsElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
224 parametersElement->appendChild(orb_dimensionsElement);
229 const G4Torus*
const torus)
231 xercesc::DOMElement* torus_dimensionsElement =
233 torus_dimensionsElement->
235 torus_dimensionsElement->
237 torus_dimensionsElement->
239 torus_dimensionsElement->
241 torus_dimensionsElement->
243 torus_dimensionsElement->
245 torus_dimensionsElement->
247 parametersElement->appendChild(torus_dimensionsElement);
252 const G4Ellipsoid*
const ellipsoid)
254 xercesc::DOMElement* ellipsoid_dimensionsElement =
256 ellipsoid_dimensionsElement->
257 setAttributeNode(
NewAttribute(
"ax",ellipsoid->GetSemiAxisMax(0)/
mm));
258 ellipsoid_dimensionsElement->
259 setAttributeNode(
NewAttribute(
"by",ellipsoid->GetSemiAxisMax(1)/
mm));
260 ellipsoid_dimensionsElement->
261 setAttributeNode(
NewAttribute(
"cz",ellipsoid->GetSemiAxisMax(2)/
mm));
262 ellipsoid_dimensionsElement->
263 setAttributeNode(
NewAttribute(
"zcut1",ellipsoid->GetZBottomCut()/
mm));
264 ellipsoid_dimensionsElement->
265 setAttributeNode(
NewAttribute(
"zcut2",ellipsoid->GetZTopCut()/
mm));
266 ellipsoid_dimensionsElement->
268 parametersElement->appendChild(ellipsoid_dimensionsElement);
273 const G4Para*
const para)
275 const G4ThreeVector simaxis = para->GetSymAxis();
277 const G4double
alpha = std::atan(para->GetTanAlpha());
278 const G4double
theta = std::acos(simaxis.z());
279 const G4double
phi = (simaxis.z() != 1.0)
280 ? (std::atan(simaxis.y()/simaxis.x())) : (0.0);
282 xercesc::DOMElement* para_dimensionsElement =
NewElement(
"para_dimensions");
283 para_dimensionsElement->
284 setAttributeNode(
NewAttribute(
"x",2.0*para->GetXHalfLength()/
mm));
285 para_dimensionsElement->
286 setAttributeNode(
NewAttribute(
"y",2.0*para->GetYHalfLength()/
mm));
287 para_dimensionsElement->
288 setAttributeNode(
NewAttribute(
"z",2.0*para->GetZHalfLength()/
mm));
289 para_dimensionsElement->
291 para_dimensionsElement->
293 para_dimensionsElement->
295 para_dimensionsElement->
297 para_dimensionsElement->
299 parametersElement->appendChild(para_dimensionsElement);
304 const G4Hype*
const hype)
306 xercesc::DOMElement* hype_dimensionsElement =
NewElement(
"hype_dimensions");
307 hype_dimensionsElement->
309 hype_dimensionsElement->
311 hype_dimensionsElement->
313 hype_dimensionsElement->
315 hype_dimensionsElement->
316 setAttributeNode(
NewAttribute(
"z",2.0*hype->GetZHalfLength()/
mm));
317 hype_dimensionsElement->
319 hype_dimensionsElement->
321 parametersElement->appendChild(hype_dimensionsElement);
326 const G4Polycone*
const pcone)
328 xercesc::DOMElement* pcone_dimensionsElement
331 pcone_dimensionsElement->setAttributeNode(
NewAttribute(
"numRZ",
332 pcone->GetOriginalParameters()->Num_z_planes));
333 pcone_dimensionsElement->setAttributeNode(
NewAttribute(
"startPhi",
334 pcone->GetOriginalParameters()->Start_angle/
degree));
335 pcone_dimensionsElement->setAttributeNode(
NewAttribute(
"openPhi",
336 pcone->GetOriginalParameters()->Opening_angle/
degree));
337 pcone_dimensionsElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
338 pcone_dimensionsElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
340 parametersElement->appendChild(pcone_dimensionsElement);
341 const size_t num_zplanes = pcone->GetOriginalParameters()->Num_z_planes;
342 const G4double* z_array = pcone->GetOriginalParameters()->Z_values;
343 const G4double* rmin_array = pcone->GetOriginalParameters()->Rmin;
344 const G4double* rmax_array = pcone->GetOriginalParameters()->Rmax;
346 for (
size_t i=0; i<num_zplanes; i++)
349 rmin_array[i],rmax_array[i]);
355 const G4Polyhedra*
const polyhedra)
357 xercesc::DOMElement* polyhedra_dimensionsElement
360 polyhedra_dimensionsElement->setAttributeNode(
NewAttribute(
"numRZ",
361 polyhedra->GetOriginalParameters()->Num_z_planes));
362 polyhedra_dimensionsElement->setAttributeNode(
NewAttribute(
"numSide",
363 polyhedra->GetOriginalParameters()->numSide));
364 polyhedra_dimensionsElement->setAttributeNode(
NewAttribute(
"startPhi",
365 polyhedra->GetOriginalParameters()->Start_angle/
degree));
366 polyhedra_dimensionsElement->setAttributeNode(
NewAttribute(
"openPhi",
367 polyhedra->GetOriginalParameters()->Opening_angle/
degree));
368 polyhedra_dimensionsElement->setAttributeNode(
NewAttribute(
"aunit",
"deg"));
369 polyhedra_dimensionsElement->setAttributeNode(
NewAttribute(
"lunit",
"mm"));
371 parametersElement->appendChild(polyhedra_dimensionsElement);
372 const size_t num_zplanes = polyhedra->GetOriginalParameters()->Num_z_planes;
373 const G4double* z_array = polyhedra->GetOriginalParameters()->Z_values;
374 const G4double* rmin_array = polyhedra->GetOriginalParameters()->Rmin;
375 const G4double* rmax_array = polyhedra->GetOriginalParameters()->Rmax;
377 for (
size_t i=0; i<num_zplanes; i++)
379 ZplaneWrite(polyhedra_dimensionsElement,z_array[i],
380 rmin_array[i],rmax_array[i]);
386 const G4VPhysicalVolume*
const paramvol,
const G4int& index)
388 paramvol->GetParameterisation()
389 ->ComputeTransformation(index, const_cast<G4VPhysicalVolume*>(paramvol));
390 G4ThreeVector Angles;
392 std::stringstream os;
395 G4String sncopie = os.str();
397 xercesc::DOMElement* parametersElement =
NewElement(
"parameters");
398 parametersElement->setAttributeNode(
NewAttribute(
"number",index+1));
401 paramvol->GetObjectTranslation());
402 Angles=
GetAngles(paramvol->GetObjectRotationValue());
403 if (Angles.mag2()>DBL_EPSILON)
406 GetAngles(paramvol->GetObjectRotationValue()));
408 paramvolElement->appendChild(parametersElement);
410 G4VSolid*
solid = paramvol->GetLogicalVolume()->GetSolid();
412 if (G4Box*
box = dynamic_cast<G4Box*>(solid))
414 paramvol->GetParameterisation()->ComputeDimensions(*
box,index,
415 const_cast<G4VPhysicalVolume*>(paramvol));
418 if (G4Trd* trd = dynamic_cast<G4Trd*>(solid))
420 paramvol->GetParameterisation()->ComputeDimensions(*trd,index,
421 const_cast<G4VPhysicalVolume*>(paramvol));
424 if (G4Trap* trap = dynamic_cast<G4Trap*>(solid))
426 paramvol->GetParameterisation()->ComputeDimensions(*trap,index,
427 const_cast<G4VPhysicalVolume*>(paramvol));
430 if (G4Tubs* tube = dynamic_cast<G4Tubs*>(solid))
432 paramvol->GetParameterisation()->ComputeDimensions(*tube,index,
433 const_cast<G4VPhysicalVolume*>(paramvol));
436 if (G4Cons* cone = dynamic_cast<G4Cons*>(solid))
438 paramvol->GetParameterisation()->ComputeDimensions(*cone,index,
439 const_cast<G4VPhysicalVolume*>(paramvol));
442 if (G4Sphere* sphere = dynamic_cast<G4Sphere*>(solid))
444 paramvol->GetParameterisation()->ComputeDimensions(*sphere,index,
445 const_cast<G4VPhysicalVolume*>(paramvol));
448 if (G4Orb* orb = dynamic_cast<G4Orb*>(solid))
450 paramvol->GetParameterisation()->ComputeDimensions(*orb,index,
451 const_cast<G4VPhysicalVolume*>(paramvol));
454 if (G4Torus* torus = dynamic_cast<G4Torus*>(solid))
456 paramvol->GetParameterisation()->ComputeDimensions(*torus,index,
457 const_cast<G4VPhysicalVolume*>(paramvol));
460 if (G4Ellipsoid* ellipsoid = dynamic_cast<G4Ellipsoid*>(solid))
462 paramvol->GetParameterisation()->ComputeDimensions(*ellipsoid,index,
463 const_cast<G4VPhysicalVolume*>(paramvol));
466 if (G4Para* para = dynamic_cast<G4Para*>(solid))
468 paramvol->GetParameterisation()->ComputeDimensions(*para,index,
469 const_cast<G4VPhysicalVolume*>(paramvol));
472 if (G4Hype* hype = dynamic_cast<G4Hype*>(solid))
474 paramvol->GetParameterisation()->ComputeDimensions(*hype,index,
475 const_cast<G4VPhysicalVolume*>(paramvol));
478 if (G4Polycone* pcone = dynamic_cast<G4Polycone*>(solid))
480 paramvol->GetParameterisation()->ComputeDimensions(*pcone,index,
481 const_cast<G4VPhysicalVolume*>(paramvol));
484 if (G4Polyhedra* polyhedra = dynamic_cast<G4Polyhedra*>(solid))
486 paramvol->GetParameterisation()->ComputeDimensions(*polyhedra,index,
487 const_cast<G4VPhysicalVolume*>(paramvol));
492 G4String error_msg =
"Solid '" + solid->GetName()
493 +
"' cannot be used in parameterised volume!";
494 G4Exception(
"PHG4GDMLWriteParamvol::ParametersWrite()",
495 "InvalidSetup", FatalException, error_msg);
501 const G4VPhysicalVolume*
const paramvol)
503 const G4String volumeref =
505 paramvol->GetLogicalVolume());
506 xercesc::DOMElement* paramvolElement =
NewElement(
"paramvol");
507 paramvolElement->setAttributeNode(
NewAttribute(
"ncopies",
508 paramvol->GetMultiplicity()));
509 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
510 volumerefElement->setAttributeNode(
NewAttribute(
"ref",volumeref));
512 xercesc::DOMElement* algorithmElement =
514 paramvolElement->appendChild(volumerefElement);
515 paramvolElement->appendChild(algorithmElement);
517 volumeElement->appendChild(paramvolElement);
522 const G4VPhysicalVolume*
const paramvol)
524 const G4String volumeref =
526 paramvol->GetLogicalVolume());
528 const G4int parameterCount = paramvol->GetMultiplicity();
530 for (G4int i=0; i<parameterCount; i++)