Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4GDMLParamVol implementation << 27 // 26 // 28 // Author: Zoltan Torzsok, November 2007 << 27 // $Id: G4GDMLWriteParamvol.cc,v 1.23.2.1 2009/08/11 08:27:49 gcosmo Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02-patch-02 $ >> 29 // >> 30 // class G4GDMLParamVol Implementation >> 31 // >> 32 // Original author: Zoltan Torzsok, November 2007 >> 33 // 29 // ------------------------------------------- 34 // -------------------------------------------------------------------- 30 35 31 #include "G4GDMLWriteParamvol.hh" 36 #include "G4GDMLWriteParamvol.hh" 32 #include "G4GDMLWriteSolids.hh" << 37 #include <sstream> 33 << 34 #include "G4SystemOfUnits.hh" << 35 #include "G4Box.hh" << 36 #include "G4Trd.hh" << 37 #include "G4Trap.hh" << 38 #include "G4Tubs.hh" << 39 #include "G4Cons.hh" << 40 #include "G4Sphere.hh" << 41 #include "G4Orb.hh" << 42 #include "G4Torus.hh" << 43 #include "G4Ellipsoid.hh" << 44 #include "G4Para.hh" << 45 #include "G4Hype.hh" << 46 #include "G4Polycone.hh" << 47 #include "G4Polyhedra.hh" << 48 #include "G4LogicalVolume.hh" << 49 #include "G4VPhysicalVolume.hh" << 50 #include "G4PVParameterised.hh" << 51 #include "G4VPVParameterisation.hh" << 52 << 53 // ------------------------------------------- << 54 G4GDMLWriteParamvol::G4GDMLWriteParamvol() << 55 : G4GDMLWriteSetup() << 56 { << 57 } << 58 << 59 // ------------------------------------------- << 60 G4GDMLWriteParamvol::~G4GDMLWriteParamvol() << 61 { << 62 } << 63 << 64 // ------------------------------------------- << 65 void G4GDMLWriteParamvol::Box_dimensionsWrite( << 66 xercesc::DOMElement* parametersElement, cons << 67 { << 68 xercesc::DOMElement* box_dimensionsElement = << 69 box_dimensionsElement->setAttributeNode( << 70 NewAttribute("x", 2.0 * box->GetXHalfLengt << 71 box_dimensionsElement->setAttributeNode( << 72 NewAttribute("y", 2.0 * box->GetYHalfLengt << 73 box_dimensionsElement->setAttributeNode( << 74 NewAttribute("z", 2.0 * box->GetZHalfLengt << 75 box_dimensionsElement->setAttributeNode(NewA << 76 parametersElement->appendChild(box_dimension << 77 } << 78 << 79 // ------------------------------------------- << 80 void G4GDMLWriteParamvol::Trd_dimensionsWrite( << 81 xercesc::DOMElement* parametersElement, cons << 82 { << 83 xercesc::DOMElement* trd_dimensionsElement = << 84 trd_dimensionsElement->setAttributeNode( << 85 NewAttribute("x1", 2.0 * trd->GetXHalfLeng << 86 trd_dimensionsElement->setAttributeNode( << 87 NewAttribute("x2", 2.0 * trd->GetXHalfLeng << 88 trd_dimensionsElement->setAttributeNode( << 89 NewAttribute("y1", 2.0 * trd->GetYHalfLeng << 90 trd_dimensionsElement->setAttributeNode( << 91 NewAttribute("y2", 2.0 * trd->GetYHalfLeng << 92 trd_dimensionsElement->setAttributeNode( << 93 NewAttribute("z", 2.0 * trd->GetZHalfLengt << 94 trd_dimensionsElement->setAttributeNode(NewA << 95 parametersElement->appendChild(trd_dimension << 96 } << 97 << 98 // ------------------------------------------- << 99 void G4GDMLWriteParamvol::Trap_dimensionsWrite << 100 xercesc::DOMElement* parametersElement, cons << 101 { << 102 const G4ThreeVector simaxis = trap->GetSymAx << 103 const G4double phi = << 104 (simaxis.z() != 1.0) ? (std::atan(simaxis. << 105 const G4double theta = std::acos(simaxis.z( << 106 const G4double alpha1 = std::atan(trap->GetT << 107 const G4double alpha2 = std::atan(trap->GetT << 108 << 109 xercesc::DOMElement* trap_dimensionsElement << 110 trap_dimensionsElement->setAttributeNode( << 111 NewAttribute("z", 2.0 * trap->GetZHalfLeng << 112 trap_dimensionsElement->setAttributeNode( << 113 NewAttribute("theta", theta / degree)); << 114 trap_dimensionsElement->setAttributeNode(New << 115 trap_dimensionsElement->setAttributeNode( << 116 NewAttribute("y1", 2.0 * trap->GetYHalfLen << 117 trap_dimensionsElement->setAttributeNode( << 118 NewAttribute("x1", 2.0 * trap->GetXHalfLen << 119 trap_dimensionsElement->setAttributeNode( << 120 NewAttribute("x2", 2.0 * trap->GetXHalfLen << 121 trap_dimensionsElement->setAttributeNode( << 122 NewAttribute("alpha1", alpha1 / degree)); << 123 trap_dimensionsElement->setAttributeNode( << 124 NewAttribute("y2", 2.0 * trap->GetYHalfLen << 125 trap_dimensionsElement->setAttributeNode( << 126 NewAttribute("x3", 2.0 * trap->GetXHalfLen << 127 trap_dimensionsElement->setAttributeNode( << 128 NewAttribute("x4", 2.0 * trap->GetXHalfLen << 129 trap_dimensionsElement->setAttributeNode( << 130 NewAttribute("alpha2", alpha2 / degree)); << 131 trap_dimensionsElement->setAttributeNode(New << 132 trap_dimensionsElement->setAttributeNode(New << 133 parametersElement->appendChild(trap_dimensio << 134 } << 135 << 136 // ------------------------------------------- << 137 void G4GDMLWriteParamvol::Tube_dimensionsWrite << 138 xercesc::DOMElement* parametersElement, cons << 139 { << 140 xercesc::DOMElement* tube_dimensionsElement << 141 tube_dimensionsElement->setAttributeNode( << 142 NewAttribute("InR", tube->GetInnerRadius() << 143 tube_dimensionsElement->setAttributeNode( << 144 NewAttribute("OutR", tube->GetOuterRadius( << 145 tube_dimensionsElement->setAttributeNode( << 146 NewAttribute("hz", 2.0 * tube->GetZHalfLen << 147 tube_dimensionsElement->setAttributeNode( << 148 NewAttribute("StartPhi", tube->GetStartPhi << 149 tube_dimensionsElement->setAttributeNode( << 150 NewAttribute("DeltaPhi", tube->GetDeltaPhi << 151 tube_dimensionsElement->setAttributeNode(New << 152 tube_dimensionsElement->setAttributeNode(New << 153 parametersElement->appendChild(tube_dimensio << 154 } << 155 << 156 // ------------------------------------------- << 157 void G4GDMLWriteParamvol::Cone_dimensionsWrite << 158 xercesc::DOMElement* parametersElement, cons << 159 { << 160 xercesc::DOMElement* cone_dimensionsElement << 161 cone_dimensionsElement->setAttributeNode( << 162 NewAttribute("rmin1", cone->GetInnerRadius << 163 cone_dimensionsElement->setAttributeNode( << 164 NewAttribute("rmax1", cone->GetOuterRadius << 165 cone_dimensionsElement->setAttributeNode( << 166 NewAttribute("rmin2", cone->GetInnerRadius << 167 cone_dimensionsElement->setAttributeNode( << 168 NewAttribute("rmax2", cone->GetOuterRadius << 169 cone_dimensionsElement->setAttributeNode( << 170 NewAttribute("z", 2.0 * cone->GetZHalfLeng << 171 cone_dimensionsElement->setAttributeNode( << 172 NewAttribute("startphi", cone->GetStartPhi << 173 cone_dimensionsElement->setAttributeNode( << 174 NewAttribute("deltaphi", cone->GetDeltaPhi << 175 cone_dimensionsElement->setAttributeNode(New << 176 cone_dimensionsElement->setAttributeNode(New << 177 parametersElement->appendChild(cone_dimensio << 178 } << 179 << 180 // ------------------------------------------- << 181 void G4GDMLWriteParamvol::Sphere_dimensionsWri << 182 xercesc::DOMElement* parametersElement, cons << 183 { << 184 xercesc::DOMElement* sphere_dimensionsElemen << 185 NewElement("sphere_dimensions"); << 186 sphere_dimensionsElement->setAttributeNode( << 187 NewAttribute("rmin", sphere->GetInnerRadiu << 188 sphere_dimensionsElement->setAttributeNode( << 189 NewAttribute("rmax", sphere->GetOuterRadiu << 190 sphere_dimensionsElement->setAttributeNode( << 191 NewAttribute("startphi", sphere->GetStartP << 192 sphere_dimensionsElement->setAttributeNode( << 193 NewAttribute("deltaphi", sphere->GetDeltaP << 194 sphere_dimensionsElement->setAttributeNode( << 195 NewAttribute("starttheta", sphere->GetStar << 196 sphere_dimensionsElement->setAttributeNode( << 197 NewAttribute("deltatheta", sphere->GetDelt << 198 sphere_dimensionsElement->setAttributeNode(N << 199 sphere_dimensionsElement->setAttributeNode(N << 200 parametersElement->appendChild(sphere_dimens << 201 } << 202 << 203 // ------------------------------------------- << 204 void G4GDMLWriteParamvol::Orb_dimensionsWrite( << 205 xercesc::DOMElement* parametersElement, cons << 206 { << 207 xercesc::DOMElement* orb_dimensionsElement = << 208 orb_dimensionsElement->setAttributeNode( << 209 NewAttribute("r", orb->GetRadius() / mm)); << 210 orb_dimensionsElement->setAttributeNode(NewA << 211 parametersElement->appendChild(orb_dimension << 212 } << 213 << 214 // ------------------------------------------- << 215 void G4GDMLWriteParamvol::Torus_dimensionsWrit << 216 xercesc::DOMElement* parametersElement, cons << 217 { << 218 xercesc::DOMElement* torus_dimensionsElement << 219 torus_dimensionsElement->setAttributeNode( << 220 NewAttribute("rmin", torus->GetRmin() / mm << 221 torus_dimensionsElement->setAttributeNode( << 222 NewAttribute("rmax", torus->GetRmax() / mm << 223 torus_dimensionsElement->setAttributeNode( << 224 NewAttribute("rtor", torus->GetRtor() / mm << 225 torus_dimensionsElement->setAttributeNode( << 226 NewAttribute("startphi", torus->GetSPhi() << 227 torus_dimensionsElement->setAttributeNode( << 228 NewAttribute("deltaphi", torus->GetDPhi() << 229 torus_dimensionsElement->setAttributeNode(Ne << 230 torus_dimensionsElement->setAttributeNode(Ne << 231 parametersElement->appendChild(torus_dimensi << 232 } << 233 << 234 // ------------------------------------------- << 235 void G4GDMLWriteParamvol::Ellipsoid_dimensions << 236 xercesc::DOMElement* parametersElement, cons << 237 { << 238 xercesc::DOMElement* ellipsoid_dimensionsEle << 239 NewElement("ellipsoid_dimensions"); << 240 ellipsoid_dimensionsElement->setAttributeNod << 241 NewAttribute("ax", ellipsoid->GetSemiAxisM << 242 ellipsoid_dimensionsElement->setAttributeNod << 243 NewAttribute("by", ellipsoid->GetSemiAxisM << 244 ellipsoid_dimensionsElement->setAttributeNod << 245 NewAttribute("cz", ellipsoid->GetSemiAxisM << 246 ellipsoid_dimensionsElement->setAttributeNod << 247 NewAttribute("zcut1", ellipsoid->GetZBotto << 248 ellipsoid_dimensionsElement->setAttributeNod << 249 NewAttribute("zcut2", ellipsoid->GetZTopCu << 250 ellipsoid_dimensionsElement->setAttributeNod << 251 parametersElement->appendChild(ellipsoid_dim << 252 } << 253 << 254 // ------------------------------------------- << 255 void G4GDMLWriteParamvol::Para_dimensionsWrite << 256 xercesc::DOMElement* parametersElement, cons << 257 { << 258 const G4ThreeVector simaxis = para->GetSymAx << 259 << 260 const G4double alpha = std::atan(para->GetTa << 261 const G4double theta = std::acos(simaxis.z() << 262 const G4double phi = << 263 (simaxis.z() != 1.0) ? (std::atan(simaxis. << 264 << 265 xercesc::DOMElement* para_dimensionsElement << 266 para_dimensionsElement->setAttributeNode( << 267 NewAttribute("x", 2.0 * para->GetXHalfLeng << 268 para_dimensionsElement->setAttributeNode( << 269 NewAttribute("y", 2.0 * para->GetYHalfLeng << 270 para_dimensionsElement->setAttributeNode( << 271 NewAttribute("z", 2.0 * para->GetZHalfLeng << 272 para_dimensionsElement->setAttributeNode( << 273 NewAttribute("alpha", alpha / degree)); << 274 para_dimensionsElement->setAttributeNode( << 275 NewAttribute("theta", theta / degree)); << 276 para_dimensionsElement->setAttributeNode(New << 277 para_dimensionsElement->setAttributeNode(New << 278 para_dimensionsElement->setAttributeNode(New << 279 parametersElement->appendChild(para_dimensio << 280 } << 281 << 282 // ------------------------------------------- << 283 void G4GDMLWriteParamvol::Hype_dimensionsWrite << 284 xercesc::DOMElement* parametersElement, cons << 285 { << 286 xercesc::DOMElement* hype_dimensionsElement << 287 hype_dimensionsElement->setAttributeNode( << 288 NewAttribute("rmin", hype->GetInnerRadius( << 289 hype_dimensionsElement->setAttributeNode( << 290 NewAttribute("rmax", hype->GetOuterRadius( << 291 hype_dimensionsElement->setAttributeNode( << 292 NewAttribute("inst", hype->GetInnerStereo( << 293 hype_dimensionsElement->setAttributeNode( << 294 NewAttribute("outst", hype->GetOuterStereo << 295 hype_dimensionsElement->setAttributeNode( << 296 NewAttribute("z", 2.0 * hype->GetZHalfLeng << 297 hype_dimensionsElement->setAttributeNode(New << 298 hype_dimensionsElement->setAttributeNode(New << 299 parametersElement->appendChild(hype_dimensio << 300 } << 301 38 302 // ------------------------------------------- << 39 G4GDMLWriteParamvol:: 303 void G4GDMLWriteParamvol::Polycone_dimensionsW << 40 G4GDMLWriteParamvol() : G4GDMLWriteSetup() 304 xercesc::DOMElement* parametersElement, cons << 305 { << 306 xercesc::DOMElement* pcone_dimensionsElement << 307 NewElement("polycone_dimensions"); << 308 << 309 pcone_dimensionsElement->setAttributeNode( << 310 NewAttribute("numRZ", pcone->GetOriginalPa << 311 pcone_dimensionsElement->setAttributeNode(Ne << 312 "startPhi", pcone->GetOriginalParameters() << 313 pcone_dimensionsElement->setAttributeNode(Ne << 314 "openPhi", pcone->GetOriginalParameters()- << 315 pcone_dimensionsElement->setAttributeNode(Ne << 316 pcone_dimensionsElement->setAttributeNode(Ne << 317 << 318 parametersElement->appendChild(pcone_dimensi << 319 const size_t num_zplanes = pcone->GetOrigi << 320 const G4double* z_array = pcone->GetOrigi << 321 const G4double* rmin_array = pcone->GetOrigi << 322 const G4double* rmax_array = pcone->GetOrigi << 323 << 324 for(std::size_t i = 0; i < num_zplanes; ++i) << 325 { << 326 ZplaneWrite(pcone_dimensionsElement, z_arr << 327 rmax_array[i]); << 328 } << 329 } << 330 << 331 // ------------------------------------------- << 332 void G4GDMLWriteParamvol::Polyhedra_dimensions << 333 xercesc::DOMElement* parametersElement, cons << 334 { 41 { 335 xercesc::DOMElement* polyhedra_dimensionsEle << 336 NewElement("polyhedra_dimensions"); << 337 << 338 polyhedra_dimensionsElement->setAttributeNod << 339 NewAttribute("numRZ", polyhedra->GetOrigin << 340 polyhedra_dimensionsElement->setAttributeNod << 341 NewAttribute("numSide", polyhedra->GetOrig << 342 polyhedra_dimensionsElement->setAttributeNod << 343 "startPhi", polyhedra->GetOriginalParamete << 344 polyhedra_dimensionsElement->setAttributeNod << 345 "openPhi", polyhedra->GetOriginalParameter << 346 polyhedra_dimensionsElement->setAttributeNod << 347 polyhedra_dimensionsElement->setAttributeNod << 348 << 349 parametersElement->appendChild(polyhedra_dim << 350 const size_t num_zplanes = polyhedra->GetO << 351 const G4double* z_array = polyhedra->GetO << 352 const G4double* rmin_array = polyhedra->GetO << 353 const G4double* rmax_array = polyhedra->GetO << 354 << 355 for(std::size_t i = 0; i < num_zplanes; ++i) << 356 { << 357 ZplaneWrite(polyhedra_dimensionsElement, z << 358 rmax_array[i]); << 359 } << 360 } 42 } 361 43 362 // ------------------------------------------- << 44 G4GDMLWriteParamvol:: 363 void G4GDMLWriteParamvol::ParametersWrite(xerc << 45 ~G4GDMLWriteParamvol() 364 const G4VPhysicalVolume* co << 46 { 365 { << 47 } 366 paramvol->GetParameterisation()->ComputeTran << 48 367 index, const_cast<G4VPhysicalVolume*>(para << 49 void G4GDMLWriteParamvol:: 368 G4ThreeVector Angles; << 50 Box_dimensionsWrite(xercesc::DOMElement* parametersElement, 369 G4String name = GenerateName(paramvol->GetNa << 51 const G4Box* const box) 370 std::stringstream os; << 52 { 371 os.precision(15); << 53 xercesc::DOMElement* box_dimensionsElement = NewElement("box_dimensions"); 372 os << index; << 54 box_dimensionsElement-> 373 G4String sncopie = os.str(); << 55 setAttributeNode(NewAttribute("x",2.0*box->GetXHalfLength()/mm)); 374 << 56 box_dimensionsElement-> 375 xercesc::DOMElement* parametersElement = New << 57 setAttributeNode(NewAttribute("y",2.0*box->GetYHalfLength()/mm)); 376 parametersElement->setAttributeNode(NewAttri << 58 box_dimensionsElement-> 377 << 59 setAttributeNode(NewAttribute("z",2.0*box->GetZHalfLength()/mm)); 378 PositionWrite(parametersElement, name + snco << 60 box_dimensionsElement-> 379 paramvol->GetObjectTranslation << 61 setAttributeNode(NewAttribute("lunit","mm")); 380 Angles = GetAngles(paramvol->GetObjectRotati << 62 parametersElement->appendChild(box_dimensionsElement); 381 if(Angles.mag2() > DBL_EPSILON) << 63 } 382 { << 64 383 RotationWrite(parametersElement, name + sn << 65 void G4GDMLWriteParamvol:: 384 GetAngles(paramvol->GetObjec << 66 Trd_dimensionsWrite(xercesc::DOMElement* parametersElement, 385 } << 67 const G4Trd* const trd) 386 paramvolElement->appendChild(parametersEleme << 68 { 387 << 69 xercesc::DOMElement* trd_dimensionsElement = NewElement("trd_dimensions"); 388 G4VSolid* solid = paramvol->GetLogicalVolume << 70 trd_dimensionsElement-> 389 << 71 setAttributeNode(NewAttribute("x1",2.0*trd->GetXHalfLength1()/mm)); 390 if(G4Box* box = dynamic_cast<G4Box*>(solid)) << 72 trd_dimensionsElement-> 391 { << 73 setAttributeNode(NewAttribute("x2",2.0*trd->GetXHalfLength2()/mm)); 392 paramvol->GetParameterisation()->ComputeDi << 74 trd_dimensionsElement-> 393 *box, index, const_cast<G4VPhysicalVolum << 75 setAttributeNode(NewAttribute("y1",2.0*trd->GetYHalfLength1()/mm)); 394 Box_dimensionsWrite(parametersElement, box << 76 trd_dimensionsElement-> 395 } << 77 setAttributeNode(NewAttribute("y2",2.0*trd->GetYHalfLength2()/mm)); 396 else if(G4Trd* trd = dynamic_cast<G4Trd*>(so << 78 trd_dimensionsElement-> 397 { << 79 setAttributeNode(NewAttribute("z",2.0*trd->GetZHalfLength()/mm)); 398 paramvol->GetParameterisation()->ComputeDi << 80 trd_dimensionsElement-> 399 *trd, index, const_cast<G4VPhysicalVolum << 81 setAttributeNode(NewAttribute("lunit","mm")); 400 Trd_dimensionsWrite(parametersElement, trd << 82 parametersElement->appendChild(trd_dimensionsElement); 401 } << 83 } 402 else if(G4Trap* trap = dynamic_cast<G4Trap*> << 84 403 { << 85 void G4GDMLWriteParamvol:: 404 paramvol->GetParameterisation()->ComputeDi << 86 Trap_dimensionsWrite(xercesc::DOMElement* parametersElement, 405 *trap, index, const_cast<G4VPhysicalVolu << 87 const G4Trap* const trap) 406 Trap_dimensionsWrite(parametersElement, tr << 88 { 407 } << 89 const G4ThreeVector simaxis = trap->GetSymAxis(); 408 else if(G4Tubs* tube = dynamic_cast<G4Tubs*> << 90 const G4double phi = (simaxis.z() != 1.0) 409 { << 91 ? (std::atan(simaxis.y()/simaxis.x())) : (0.0); 410 paramvol->GetParameterisation()->ComputeDi << 92 const G4double theta = std::acos(simaxis.z()); 411 *tube, index, const_cast<G4VPhysicalVolu << 93 const G4double alpha1 = std::atan(trap->GetTanAlpha1()); 412 Tube_dimensionsWrite(parametersElement, tu << 94 const G4double alpha2 = std::atan(trap->GetTanAlpha2()); 413 } << 95 414 else if(G4Cons* cone = dynamic_cast<G4Cons*> << 96 xercesc::DOMElement* trap_dimensionsElement = NewElement("trap"); 415 { << 97 trap_dimensionsElement-> 416 paramvol->GetParameterisation()->ComputeDi << 98 setAttributeNode(NewAttribute("z",2.0*trap->GetZHalfLength()/mm)); 417 *cone, index, const_cast<G4VPhysicalVolu << 99 trap_dimensionsElement-> 418 Cone_dimensionsWrite(parametersElement, co << 100 setAttributeNode(NewAttribute("theta",theta/degree)); 419 } << 101 trap_dimensionsElement-> 420 else if(G4Sphere* sphere = dynamic_cast<G4Sp << 102 setAttributeNode(NewAttribute("phi",phi/degree)); 421 { << 103 trap_dimensionsElement-> 422 paramvol->GetParameterisation()->ComputeDi << 104 setAttributeNode(NewAttribute("y1",2.0*trap->GetYHalfLength1()/mm)); 423 *sphere, index, const_cast<G4VPhysicalVo << 105 trap_dimensionsElement-> 424 Sphere_dimensionsWrite(parametersElement, << 106 setAttributeNode(NewAttribute("x1",2.0*trap->GetXHalfLength1()/mm)); 425 } << 107 trap_dimensionsElement-> 426 else if(G4Orb* orb = dynamic_cast<G4Orb*>(so << 108 setAttributeNode(NewAttribute("x2",2.0*trap->GetXHalfLength2()/mm)); 427 { << 109 trap_dimensionsElement-> 428 paramvol->GetParameterisation()->ComputeDi << 110 setAttributeNode(NewAttribute("alpha1",alpha1/degree)); 429 *orb, index, const_cast<G4VPhysicalVolum << 111 trap_dimensionsElement-> 430 Orb_dimensionsWrite(parametersElement, orb << 112 setAttributeNode(NewAttribute("y2",2.0*trap->GetYHalfLength2()/mm)); 431 } << 113 trap_dimensionsElement-> 432 else if(G4Torus* torus = dynamic_cast<G4Toru << 114 setAttributeNode(NewAttribute("x3",2.0*trap->GetXHalfLength3()/mm)); 433 { << 115 trap_dimensionsElement-> 434 paramvol->GetParameterisation()->ComputeDi << 116 setAttributeNode(NewAttribute("x4",2.0*trap->GetXHalfLength4()/mm)); 435 *torus, index, const_cast<G4VPhysicalVol << 117 trap_dimensionsElement-> 436 Torus_dimensionsWrite(parametersElement, t << 118 setAttributeNode(NewAttribute("alpha2",alpha2/degree)); 437 } << 119 trap_dimensionsElement-> 438 else if(G4Ellipsoid* ellipsoid = dynamic_cas << 120 setAttributeNode(NewAttribute("aunit","deg")); 439 { << 121 trap_dimensionsElement-> 440 paramvol->GetParameterisation()->ComputeDi << 122 setAttributeNode(NewAttribute("lunit","mm")); 441 *ellipsoid, index, const_cast<G4VPhysica << 123 parametersElement->appendChild(trap_dimensionsElement); 442 Ellipsoid_dimensionsWrite(parametersElemen << 124 } 443 } << 125 444 else if(G4Para* para = dynamic_cast<G4Para*> << 126 void G4GDMLWriteParamvol:: 445 { << 127 Tube_dimensionsWrite(xercesc::DOMElement* parametersElement, 446 paramvol->GetParameterisation()->ComputeDi << 128 const G4Tubs* const tube) 447 *para, index, const_cast<G4VPhysicalVolu << 129 { 448 Para_dimensionsWrite(parametersElement, pa << 130 xercesc::DOMElement* tube_dimensionsElement = NewElement("tube_dimensions"); 449 } << 131 tube_dimensionsElement-> 450 else if(G4Hype* hype = dynamic_cast<G4Hype*> << 132 setAttributeNode(NewAttribute("InR",tube->GetInnerRadius()/mm)); 451 { << 133 tube_dimensionsElement-> 452 paramvol->GetParameterisation()->ComputeDi << 134 setAttributeNode(NewAttribute("OutR",tube->GetOuterRadius()/mm)); 453 *hype, index, const_cast<G4VPhysicalVolu << 135 tube_dimensionsElement-> 454 Hype_dimensionsWrite(parametersElement, hy << 136 setAttributeNode(NewAttribute("hz",2.0*tube->GetZHalfLength()/mm)); 455 } << 137 tube_dimensionsElement-> 456 else if(G4Polycone* pcone = dynamic_cast<G4P << 138 setAttributeNode(NewAttribute("StartPhi",tube->GetStartPhiAngle()/degree)); 457 { << 139 tube_dimensionsElement-> 458 paramvol->GetParameterisation()->ComputeDi << 140 setAttributeNode(NewAttribute("DeltaPhi",tube->GetDeltaPhiAngle()/degree)); 459 *pcone, index, const_cast<G4VPhysicalVol << 141 tube_dimensionsElement-> 460 Polycone_dimensionsWrite(parametersElement << 142 setAttributeNode(NewAttribute("aunit","deg")); 461 } << 143 tube_dimensionsElement-> 462 else if(G4Polyhedra* polyhedra = dynamic_cas << 144 setAttributeNode(NewAttribute("lunit","mm")); 463 { << 145 parametersElement->appendChild(tube_dimensionsElement); 464 paramvol->GetParameterisation()->ComputeDi << 146 } 465 *polyhedra, index, const_cast<G4VPhysica << 147 466 Polyhedra_dimensionsWrite(parametersElemen << 148 467 } << 149 void G4GDMLWriteParamvol:: 468 else << 150 Cone_dimensionsWrite(xercesc::DOMElement* parametersElement, 469 { << 151 const G4Cons* const cone) 470 G4String error_msg = "Solid '" + solid->Ge << 152 { 471 "' cannot be used in << 153 xercesc::DOMElement* cone_dimensionsElement = NewElement("cone_dimensions"); 472 G4Exception("G4GDMLWriteParamvol::Paramete << 154 cone_dimensionsElement-> 473 FatalException, error_msg); << 155 setAttributeNode(NewAttribute("rmin1",cone->GetInnerRadiusMinusZ()/mm)); 474 } << 156 cone_dimensionsElement-> 475 } << 157 setAttributeNode(NewAttribute("rmax1",cone->GetOuterRadiusMinusZ()/mm)); 476 << 158 cone_dimensionsElement-> 477 // ------------------------------------------- << 159 setAttributeNode(NewAttribute("rmin2",cone->GetInnerRadiusPlusZ()/mm)); 478 void G4GDMLWriteParamvol::ParamvolWrite(xerces << 160 cone_dimensionsElement-> 479 const << 161 setAttributeNode(NewAttribute("rmax2",cone->GetOuterRadiusPlusZ()/mm)); 480 { << 162 cone_dimensionsElement-> 481 const G4String volumeref = GenerateName( << 163 setAttributeNode(NewAttribute("z",2.0*cone->GetZHalfLength()/mm)); 482 paramvol->GetLogicalVolume()->GetName(), p << 164 cone_dimensionsElement-> 483 xercesc::DOMElement* paramvolElement = NewEl << 165 setAttributeNode(NewAttribute("startphi",cone->GetStartPhiAngle()/degree)); 484 paramvolElement->setAttributeNode( << 166 cone_dimensionsElement-> 485 NewAttribute("ncopies", paramvol->GetMulti << 167 setAttributeNode(NewAttribute("deltaphi",cone->GetDeltaPhiAngle()/degree)); 486 xercesc::DOMElement* volumerefElement = NewE << 168 cone_dimensionsElement-> 487 volumerefElement->setAttributeNode(NewAttrib << 169 setAttributeNode(NewAttribute("aunit","deg")); 488 << 170 cone_dimensionsElement-> 489 xercesc::DOMElement* algorithmElement = << 171 setAttributeNode(NewAttribute("lunit","mm")); 490 NewElement("parameterised_position_size"); << 172 parametersElement->appendChild(cone_dimensionsElement); 491 paramvolElement->appendChild(volumerefElemen << 173 } 492 paramvolElement->appendChild(algorithmElemen << 174 493 ParamvolAlgorithmWrite(algorithmElement, par << 175 void G4GDMLWriteParamvol:: 494 volumeElement->appendChild(paramvolElement); << 176 Sphere_dimensionsWrite(xercesc::DOMElement* parametersElement, 495 } << 177 const G4Sphere* const sphere) 496 << 178 { 497 // ------------------------------------------- << 179 xercesc::DOMElement* sphere_dimensionsElement = 498 void G4GDMLWriteParamvol::ParamvolAlgorithmWri << 180 NewElement("sphere_dimensions"); 499 xercesc::DOMElement* paramvolElement, const << 181 sphere_dimensionsElement->setAttributeNode(NewAttribute("rmin", 500 { << 182 sphere->GetInsideRadius()/mm)); 501 const G4String volumeref = GenerateName( << 183 sphere_dimensionsElement->setAttributeNode(NewAttribute("rmax", 502 paramvol->GetLogicalVolume()->GetName(), p << 184 sphere->GetOuterRadius()/mm)); 503 << 185 sphere_dimensionsElement->setAttributeNode(NewAttribute("startphi", 504 const G4int parameterCount = paramvol->GetMu << 186 sphere->GetStartPhiAngle()/degree)); 505 << 187 sphere_dimensionsElement->setAttributeNode(NewAttribute("deltaphi", 506 for(G4int i = 0; i < parameterCount; ++i) << 188 sphere->GetDeltaPhiAngle()/degree)); 507 { << 189 sphere_dimensionsElement->setAttributeNode(NewAttribute("starttheta", 508 ParametersWrite(paramvolElement, paramvol, << 190 sphere->GetStartThetaAngle()/degree)); 509 } << 191 sphere_dimensionsElement->setAttributeNode(NewAttribute("deltatheta", >> 192 sphere->GetDeltaThetaAngle()/degree)); >> 193 sphere_dimensionsElement->setAttributeNode(NewAttribute("aunit","deg")); >> 194 sphere_dimensionsElement->setAttributeNode(NewAttribute("lunit","mm")); >> 195 parametersElement->appendChild(sphere_dimensionsElement); >> 196 } >> 197 >> 198 void G4GDMLWriteParamvol:: >> 199 Orb_dimensionsWrite(xercesc::DOMElement* parametersElement, >> 200 const G4Orb* const orb) >> 201 { >> 202 xercesc::DOMElement* orb_dimensionsElement = NewElement("orb_dimensions"); >> 203 orb_dimensionsElement->setAttributeNode(NewAttribute("r", >> 204 orb->GetRadius()/mm)); >> 205 orb_dimensionsElement->setAttributeNode(NewAttribute("lunit","mm")); >> 206 parametersElement->appendChild(orb_dimensionsElement); >> 207 } >> 208 >> 209 void G4GDMLWriteParamvol:: >> 210 Torus_dimensionsWrite(xercesc::DOMElement* parametersElement, >> 211 const G4Torus* const torus) >> 212 { >> 213 xercesc::DOMElement* torus_dimensionsElement = >> 214 NewElement("torus_dimensions"); >> 215 torus_dimensionsElement-> >> 216 setAttributeNode(NewAttribute("rmin",torus->GetRmin()/mm)); >> 217 torus_dimensionsElement-> >> 218 setAttributeNode(NewAttribute("rmax",torus->GetRmax()/mm)); >> 219 torus_dimensionsElement-> >> 220 setAttributeNode(NewAttribute("rtor",torus->GetRtor()/mm)); >> 221 torus_dimensionsElement-> >> 222 setAttributeNode(NewAttribute("startphi",torus->GetSPhi()/degree)); >> 223 torus_dimensionsElement-> >> 224 setAttributeNode(NewAttribute("deltaphi",torus->GetDPhi()/degree)); >> 225 torus_dimensionsElement-> >> 226 setAttributeNode(NewAttribute("aunit","deg")); >> 227 torus_dimensionsElement-> >> 228 setAttributeNode(NewAttribute("lunit","mm")); >> 229 parametersElement->appendChild(torus_dimensionsElement); >> 230 } >> 231 >> 232 void G4GDMLWriteParamvol:: >> 233 Para_dimensionsWrite(xercesc::DOMElement* parametersElement, >> 234 const G4Para* const para) >> 235 { >> 236 const G4ThreeVector simaxis = para->GetSymAxis(); >> 237 const G4double alpha = std::atan(para->GetTanAlpha()); >> 238 const G4double theta = std::acos(simaxis.z()); >> 239 const G4double phi = (simaxis.z() != 1.0) >> 240 ? (std::atan(simaxis.y()/simaxis.x())) : (0.0); >> 241 >> 242 xercesc::DOMElement* para_dimensionsElement = NewElement("para_dimensions"); >> 243 para_dimensionsElement-> >> 244 setAttributeNode(NewAttribute("x",2.0*para->GetXHalfLength()/mm)); >> 245 para_dimensionsElement-> >> 246 setAttributeNode(NewAttribute("y",2.0*para->GetYHalfLength()/mm)); >> 247 para_dimensionsElement-> >> 248 setAttributeNode(NewAttribute("z",2.0*para->GetZHalfLength()/mm)); >> 249 para_dimensionsElement-> >> 250 setAttributeNode(NewAttribute("alpha",alpha/degree)); >> 251 para_dimensionsElement-> >> 252 setAttributeNode(NewAttribute("theta",theta/degree)); >> 253 para_dimensionsElement-> >> 254 setAttributeNode(NewAttribute("phi",phi/degree)); >> 255 para_dimensionsElement-> >> 256 setAttributeNode(NewAttribute("aunit","deg")); >> 257 para_dimensionsElement-> >> 258 setAttributeNode(NewAttribute("lunit","mm")); >> 259 parametersElement->appendChild(para_dimensionsElement); >> 260 } >> 261 >> 262 void G4GDMLWriteParamvol:: >> 263 Hype_dimensionsWrite(xercesc::DOMElement* parametersElement, >> 264 const G4Hype* const hype) >> 265 { >> 266 xercesc::DOMElement* hype_dimensionsElement = NewElement("hype_dimensions"); >> 267 hype_dimensionsElement-> >> 268 setAttributeNode(NewAttribute("rmin",hype->GetInnerRadius()/mm)); >> 269 hype_dimensionsElement-> >> 270 setAttributeNode(NewAttribute("rmax",hype->GetOuterRadius()/mm)); >> 271 hype_dimensionsElement-> >> 272 setAttributeNode(NewAttribute("inst",hype->GetInnerStereo()/degree)); >> 273 hype_dimensionsElement-> >> 274 setAttributeNode(NewAttribute("outst",hype->GetOuterStereo()/degree)); >> 275 hype_dimensionsElement-> >> 276 setAttributeNode(NewAttribute("z",2.0*hype->GetZHalfLength()/mm)); >> 277 hype_dimensionsElement-> >> 278 setAttributeNode(NewAttribute("aunit","deg")); >> 279 hype_dimensionsElement-> >> 280 setAttributeNode(NewAttribute("lunit","mm")); >> 281 parametersElement->appendChild(hype_dimensionsElement); >> 282 } >> 283 >> 284 void G4GDMLWriteParamvol:: >> 285 ParametersWrite(xercesc::DOMElement* paramvolElement, >> 286 const G4VPhysicalVolume* const paramvol,const G4int& index) >> 287 { >> 288 paramvol->GetParameterisation() >> 289 ->ComputeTransformation(index, const_cast<G4VPhysicalVolume*>(paramvol)); >> 290 G4ThreeVector Angles; >> 291 G4String name = GenerateName(paramvol->GetName(),paramvol); >> 292 std::stringstream os; >> 293 os.precision(15); >> 294 os << index; >> 295 G4String sncopie = os.str(); >> 296 >> 297 xercesc::DOMElement* parametersElement = NewElement("parameters"); >> 298 parametersElement->setAttributeNode(NewAttribute("number",index+1)); >> 299 >> 300 PositionWrite(parametersElement, name+sncopie+"_pos", >> 301 paramvol->GetObjectTranslation()); >> 302 Angles=GetAngles(paramvol->GetObjectRotationValue()); >> 303 if (Angles.mag2()>DBL_EPSILON) >> 304 { >> 305 RotationWrite(parametersElement, name+sncopie+"_rot", >> 306 GetAngles(paramvol->GetObjectRotationValue())); >> 307 } >> 308 paramvolElement->appendChild(parametersElement); >> 309 >> 310 G4VSolid* solid = paramvol->GetLogicalVolume()->GetSolid(); >> 311 >> 312 if (G4Box* box = dynamic_cast<G4Box*>(solid)) >> 313 { >> 314 paramvol->GetParameterisation()->ComputeDimensions(*box,index, >> 315 const_cast<G4VPhysicalVolume*>(paramvol)); >> 316 Box_dimensionsWrite(parametersElement,box); >> 317 } else >> 318 if (G4Trd* trd = dynamic_cast<G4Trd*>(solid)) >> 319 { >> 320 paramvol->GetParameterisation()->ComputeDimensions(*trd,index, >> 321 const_cast<G4VPhysicalVolume*>(paramvol)); >> 322 Trd_dimensionsWrite(parametersElement,trd); >> 323 } else >> 324 if (G4Trap* trap = dynamic_cast<G4Trap*>(solid)) >> 325 { >> 326 paramvol->GetParameterisation()->ComputeDimensions(*trap,index, >> 327 const_cast<G4VPhysicalVolume*>(paramvol)); >> 328 Trap_dimensionsWrite(parametersElement,trap); >> 329 } else >> 330 if (G4Tubs* tube = dynamic_cast<G4Tubs*>(solid)) >> 331 { >> 332 paramvol->GetParameterisation()->ComputeDimensions(*tube,index, >> 333 const_cast<G4VPhysicalVolume*>(paramvol)); >> 334 Tube_dimensionsWrite(parametersElement,tube); >> 335 } else >> 336 if (G4Cons* cone = dynamic_cast<G4Cons*>(solid)) >> 337 { >> 338 paramvol->GetParameterisation()->ComputeDimensions(*cone,index, >> 339 const_cast<G4VPhysicalVolume*>(paramvol)); >> 340 Cone_dimensionsWrite(parametersElement,cone); >> 341 } else >> 342 if (G4Sphere* sphere = dynamic_cast<G4Sphere*>(solid)) >> 343 { >> 344 paramvol->GetParameterisation()->ComputeDimensions(*sphere,index, >> 345 const_cast<G4VPhysicalVolume*>(paramvol)); >> 346 Sphere_dimensionsWrite(parametersElement,sphere); >> 347 } else >> 348 if (G4Orb* orb = dynamic_cast<G4Orb*>(solid)) >> 349 { >> 350 paramvol->GetParameterisation()->ComputeDimensions(*orb,index, >> 351 const_cast<G4VPhysicalVolume*>(paramvol)); >> 352 Orb_dimensionsWrite(parametersElement,orb); >> 353 } else >> 354 if (G4Torus* torus = dynamic_cast<G4Torus*>(solid)) >> 355 { >> 356 paramvol->GetParameterisation()->ComputeDimensions(*torus,index, >> 357 const_cast<G4VPhysicalVolume*>(paramvol)); >> 358 Torus_dimensionsWrite(parametersElement,torus); >> 359 } else >> 360 if (G4Para* para = dynamic_cast<G4Para*>(solid)) >> 361 { >> 362 paramvol->GetParameterisation()->ComputeDimensions(*para,index, >> 363 const_cast<G4VPhysicalVolume*>(paramvol)); >> 364 Para_dimensionsWrite(parametersElement,para); >> 365 } else >> 366 if (G4Hype* hype = dynamic_cast<G4Hype*>(solid)) >> 367 { >> 368 paramvol->GetParameterisation()->ComputeDimensions(*hype,index, >> 369 const_cast<G4VPhysicalVolume*>(paramvol)); >> 370 Hype_dimensionsWrite(parametersElement,hype); >> 371 } >> 372 else >> 373 { >> 374 G4String error_msg = "Solid '" + solid->GetName() >> 375 + "' cannot be used in parameterised volume!"; >> 376 G4Exception("G4GDMLWriteParamvol::ParametersWrite()", >> 377 "InvalidSetup", FatalException, error_msg); >> 378 } >> 379 } >> 380 >> 381 void G4GDMLWriteParamvol:: >> 382 ParamvolWrite(xercesc::DOMElement* volumeElement, >> 383 const G4VPhysicalVolume* const paramvol) >> 384 { >> 385 const G4String volumeref = >> 386 GenerateName(paramvol->GetLogicalVolume()->GetName(), >> 387 paramvol->GetLogicalVolume()); >> 388 xercesc::DOMElement* paramvolElement = NewElement("paramvol"); >> 389 paramvolElement->setAttributeNode(NewAttribute("ncopies", >> 390 paramvol->GetMultiplicity())); >> 391 xercesc::DOMElement* volumerefElement = NewElement("volumeref"); >> 392 volumerefElement->setAttributeNode(NewAttribute("ref",volumeref)); >> 393 >> 394 xercesc::DOMElement* algorithmElement = >> 395 NewElement("parameterised_position_size"); >> 396 paramvolElement->appendChild(volumerefElement); >> 397 paramvolElement->appendChild(algorithmElement); >> 398 ParamvolAlgorithmWrite(algorithmElement,paramvol); >> 399 volumeElement->appendChild(paramvolElement); >> 400 } >> 401 >> 402 void G4GDMLWriteParamvol:: >> 403 ParamvolAlgorithmWrite(xercesc::DOMElement* paramvolElement, >> 404 const G4VPhysicalVolume* const paramvol) >> 405 { >> 406 const G4String volumeref = >> 407 GenerateName(paramvol->GetLogicalVolume()->GetName(), >> 408 paramvol->GetLogicalVolume()); >> 409 >> 410 const G4int parameterCount = paramvol->GetMultiplicity(); >> 411 >> 412 for (G4int i=0; i<parameterCount; i++) >> 413 { >> 414 ParametersWrite(paramvolElement,paramvol,i); >> 415 } 510 } 416 } 511 417