Geant4 Cross Reference |
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 // G4ParameterisationTubs[Rho/Phi/Z] implementation 27 // 28 // 26.05.03 - P.Arce, Initial version 29 // 08.04.04 - I.Hrivnacova, Implemented reflection 30 // 21.04.10 - M.Asai, Added gaps 31 // -------------------------------------------------------------------- 32 33 #include "G4ParameterisationTubs.hh" 34 35 #include <iomanip> 36 #include "G4ThreeVector.hh" 37 #include "G4RotationMatrix.hh" 38 #include "G4VPhysicalVolume.hh" 39 #include "G4LogicalVolume.hh" 40 #include "G4ReflectedSolid.hh" 41 #include "G4Tubs.hh" 42 43 //-------------------------------------------------------------------------- 44 G4VParameterisationTubs:: 45 G4VParameterisationTubs( EAxis axis, G4int nDiv, G4double width, 46 G4double offset, G4VSolid* msolid, 47 DivisionType divType ) 48 : G4VDivisionParameterisation( axis, nDiv, width, offset, divType, msolid ) 49 { 50 auto msol = (G4Tubs*)(msolid); 51 if (msolid->GetEntityType() == "G4ReflectedSolid") 52 { 53 //----- get constituent solid 54 G4VSolid* mConstituentSolid 55 = ((G4ReflectedSolid*)msolid)->GetConstituentMovedSolid(); 56 msol = (G4Tubs*)(mConstituentSolid); 57 fmotherSolid = msol; 58 fReflectedSolid = true; 59 } 60 } 61 62 //------------------------------------------------------------------------ 63 G4VParameterisationTubs::~G4VParameterisationTubs() = default; 64 65 //-------------------------------------------------------------------------- 66 G4ParameterisationTubsRho:: 67 G4ParameterisationTubsRho( EAxis axis, G4int nDiv, 68 G4double width, G4double offset, 69 G4VSolid* msolid, DivisionType divType ) 70 : G4VParameterisationTubs( axis, nDiv, width, offset, msolid, divType ) 71 { 72 CheckParametersValidity(); 73 SetType( "DivisionTubsRho" ); 74 75 auto msol = (G4Tubs*)(fmotherSolid); 76 if( divType == DivWIDTH ) 77 { 78 fnDiv = CalculateNDiv( msol->GetOuterRadius() - msol->GetInnerRadius(), 79 width, offset ); 80 } 81 else if( divType == DivNDIV ) 82 { 83 fwidth = CalculateWidth( msol->GetOuterRadius() - msol->GetInnerRadius(), 84 nDiv, offset ); 85 } 86 87 #ifdef G4DIVDEBUG 88 if( verbose >= 1 ) 89 { 90 G4cout << " G4ParameterisationTubsRho - no divisions " << fnDiv << " = " 91 << nDiv << G4endl 92 << " Offset " << foffset << " = " << offset << G4endl 93 << " Width " << fwidth << " = " << width << G4endl 94 << " DivType " << divType << G4endl; 95 } 96 #endif 97 } 98 99 //-------------------------------------------------------------------------- 100 G4ParameterisationTubsRho::~G4ParameterisationTubsRho() = default; 101 102 //------------------------------------------------------------------------ 103 G4double G4ParameterisationTubsRho::GetMaxParameter() const 104 { 105 auto msol = (G4Tubs*)(fmotherSolid); 106 return msol->GetOuterRadius() - msol->GetInnerRadius(); 107 } 108 109 110 //-------------------------------------------------------------------------- 111 void 112 G4ParameterisationTubsRho:: 113 ComputeTransformation(const G4int, G4VPhysicalVolume* physVol) const 114 { 115 //----- translation 116 G4ThreeVector origin(0.,0.,0.); 117 //----- set translation 118 physVol->SetTranslation( origin ); 119 120 //----- calculate rotation matrix: unit 121 122 #ifdef G4DIVDEBUG 123 if( verbose >= 2 ) 124 { 125 G4cout << " G4ParameterisationTubsRho " << G4endl 126 << " Offset: " << foffset/CLHEP::deg 127 << " - Width: " << fwidth/CLHEP::deg << G4endl; 128 } 129 #endif 130 131 ChangeRotMatrix( physVol ); 132 133 #ifdef G4DIVDEBUG 134 if( verbose >= 2 ) 135 { 136 G4cout << std::setprecision(8) << " G4ParameterisationTubsRho " << G4endl 137 << " Position: " << origin << " - Width: " << fwidth 138 << " - Axis " << faxis << G4endl; 139 } 140 #endif 141 } 142 143 //-------------------------------------------------------------------------- 144 void 145 G4ParameterisationTubsRho:: 146 ComputeDimensions( G4Tubs& tubs, const G4int copyNo, 147 const G4VPhysicalVolume* ) const 148 { 149 auto msol = (G4Tubs*)(fmotherSolid); 150 151 G4double pRMin = msol->GetInnerRadius() + foffset + fwidth*copyNo + fhgap; 152 G4double pRMax = msol->GetInnerRadius() + foffset + fwidth*(copyNo+1) - fhgap; 153 G4double pDz = msol->GetZHalfLength(); 154 //- already rotated G4double pSR = foffset + copyNo*fwidth; 155 G4double pSPhi = msol->GetStartPhiAngle(); 156 G4double pDPhi = msol->GetDeltaPhiAngle();; 157 158 tubs.SetInnerRadius( pRMin ); 159 tubs.SetOuterRadius( pRMax ); 160 tubs.SetZHalfLength( pDz ); 161 tubs.SetStartPhiAngle( pSPhi, false ); 162 tubs.SetDeltaPhiAngle( pDPhi ); 163 164 #ifdef G4DIVDEBUG 165 if( verbose >= 2 ) 166 { 167 G4cout << " G4ParameterisationTubsRho::ComputeDimensions()" << G4endl 168 << " pRMin: " << pRMin << " - pRMax: " << pRMax << G4endl; 169 tubs.DumpInfo(); 170 } 171 #endif 172 } 173 174 //-------------------------------------------------------------------------- 175 G4ParameterisationTubsPhi:: 176 G4ParameterisationTubsPhi( EAxis axis, G4int nDiv, 177 G4double width, G4double offset, 178 G4VSolid* msolid, DivisionType divType ) 179 : G4VParameterisationTubs( axis, nDiv, width, offset, msolid, divType ) 180 { 181 CheckParametersValidity(); 182 SetType( "DivisionTubsPhi" ); 183 184 auto msol = (G4Tubs*)(fmotherSolid); 185 if( divType == DivWIDTH ) 186 { 187 fnDiv = CalculateNDiv( msol->GetDeltaPhiAngle(), width, offset ); 188 } 189 else if( divType == DivNDIV ) 190 { 191 fwidth = CalculateWidth( msol->GetDeltaPhiAngle(), nDiv, offset ); 192 } 193 194 #ifdef G4DIVDEBUG 195 if( verbose >= 1 ) 196 { 197 G4cout << " G4ParameterisationTubsPhi no divisions " << fnDiv << " = " 198 << nDiv << G4endl 199 << " Offset " << foffset << " = " << offset << G4endl 200 << " Width " << fwidth << " = " << width << G4endl; 201 } 202 #endif 203 } 204 205 //-------------------------------------------------------------------------- 206 G4ParameterisationTubsPhi::~G4ParameterisationTubsPhi() = default; 207 208 //------------------------------------------------------------------------ 209 G4double G4ParameterisationTubsPhi::GetMaxParameter() const 210 { 211 auto msol = (G4Tubs*)(fmotherSolid); 212 return msol->GetDeltaPhiAngle(); 213 } 214 215 //-------------------------------------------------------------------------- 216 void 217 G4ParameterisationTubsPhi:: 218 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume *physVol) const 219 { 220 //----- translation 221 G4ThreeVector origin(0.,0.,0.); 222 //----- set translation 223 physVol->SetTranslation( origin ); 224 225 //----- calculate rotation matrix (so that all volumes point to the centre) 226 G4double posi = foffset + copyNo*fwidth; 227 228 #ifdef G4DIVDEBUG 229 if( verbose >= 2 ) 230 { 231 G4cout << " G4ParameterisationTubsPhi - position: " << posi/CLHEP::deg << G4endl 232 << " copyNo: " << copyNo << " - foffset: " << foffset/CLHEP::deg 233 << " - fwidth: " << fwidth/CLHEP::deg << G4endl; 234 } 235 #endif 236 237 ChangeRotMatrix( physVol, -posi ); 238 239 #ifdef G4DIVDEBUG 240 if( verbose >= 2 ) 241 { 242 G4cout << std::setprecision(8) << " G4ParameterisationTubsPhi " << copyNo 243 << G4endl 244 << " Position: " << origin << " - Width: " << fwidth 245 << " - Axis: " << faxis << G4endl; 246 } 247 #endif 248 } 249 250 //-------------------------------------------------------------------------- 251 void 252 G4ParameterisationTubsPhi:: 253 ComputeDimensions( G4Tubs& tubs, const G4int, 254 const G4VPhysicalVolume* ) const 255 { 256 auto msol = (G4Tubs*)(fmotherSolid); 257 258 G4double pRMin = msol->GetInnerRadius(); 259 G4double pRMax = msol->GetOuterRadius(); 260 G4double pDz = msol->GetZHalfLength(); 261 //----- already rotated in 'ComputeTransformation' 262 G4double pSPhi = msol->GetStartPhiAngle() + fhgap; 263 G4double pDPhi = fwidth - 2.*fhgap; 264 265 tubs.SetInnerRadius( pRMin ); 266 tubs.SetOuterRadius( pRMax ); 267 tubs.SetZHalfLength( pDz ); 268 tubs.SetStartPhiAngle( pSPhi, false ); 269 tubs.SetDeltaPhiAngle( pDPhi ); 270 271 #ifdef G4DIVDEBUG 272 if( verbose >= 2 ) 273 { 274 G4cout << " G4ParameterisationTubsPhi::ComputeDimensions" << G4endl 275 << " pSPhi: " << pSPhi << " - pDPhi: " << pDPhi << G4endl; 276 tubs.DumpInfo(); 277 } 278 #endif 279 } 280 281 //-------------------------------------------------------------------------- 282 G4ParameterisationTubsZ:: 283 G4ParameterisationTubsZ( EAxis axis, G4int nDiv, 284 G4double width, G4double offset, 285 G4VSolid* msolid, DivisionType divType ) 286 : G4VParameterisationTubs( axis, nDiv, width, offset, msolid, divType ) 287 { 288 CheckParametersValidity(); 289 SetType( "DivisionTubsZ" ); 290 291 auto msol = (G4Tubs*)(fmotherSolid); 292 if( divType == DivWIDTH ) 293 { 294 fnDiv = CalculateNDiv( 2*msol->GetZHalfLength(), width, offset ); 295 } 296 else if( divType == DivNDIV ) 297 { 298 fwidth = CalculateWidth( 2*msol->GetZHalfLength(), nDiv, offset ); 299 } 300 301 #ifdef G4DIVDEBUG 302 if( verbose >= 1 ) 303 { 304 G4cout << " G4ParameterisationTubsZ: # divisions " << fnDiv << " = " 305 << nDiv << G4endl 306 << " Offset " << foffset << " = " << offset << G4endl 307 << " Width " << fwidth << " = " << width << G4endl; 308 } 309 #endif 310 } 311 312 //-------------------------------------------------------------------------- 313 G4ParameterisationTubsZ::~G4ParameterisationTubsZ() = default; 314 315 //------------------------------------------------------------------------ 316 G4double G4ParameterisationTubsZ::GetMaxParameter() const 317 { 318 auto msol = (G4Tubs*)(fmotherSolid); 319 return 2*msol->GetZHalfLength(); 320 } 321 322 //-------------------------------------------------------------------------- 323 void 324 G4ParameterisationTubsZ:: 325 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume *physVol) const 326 { 327 //----- set translation: along Z axis 328 auto motherTubs = (G4Tubs*)(fmotherSolid); 329 G4double posi = - motherTubs->GetZHalfLength() + OffsetZ() 330 + fwidth/2 + copyNo*fwidth; 331 G4ThreeVector origin(0.,0.,posi); 332 physVol->SetTranslation( origin ); 333 334 //----- calculate rotation matrix: unit 335 336 #ifdef G4DIVDEBUG 337 if( verbose >= 2 ) 338 { 339 G4cout << " G4ParameterisationTubsZ::ComputeTransformation()" << G4endl 340 << " Position: " << posi << " - copyNo: " << copyNo << G4endl 341 << " foffset " << foffset/CLHEP::deg << " - fwidth " << fwidth/CLHEP::deg 342 << G4endl; 343 } 344 #endif 345 346 ChangeRotMatrix( physVol ); 347 348 #ifdef G4DIVDEBUG 349 if( verbose >= 2 ) 350 { 351 G4cout << std::setprecision(8) << " G4ParameterisationTubsZ " << copyNo 352 << G4endl 353 << " Position: " << origin << " - Width: " << fwidth 354 << " - Axis: " << faxis << G4endl; 355 } 356 #endif 357 } 358 359 //-------------------------------------------------------------------------- 360 void 361 G4ParameterisationTubsZ:: 362 ComputeDimensions( G4Tubs& tubs, const G4int, 363 const G4VPhysicalVolume* ) const 364 { 365 auto msol = (G4Tubs*)(fmotherSolid); 366 367 G4double pRMin = msol->GetInnerRadius(); 368 G4double pRMax = msol->GetOuterRadius(); 369 // G4double pDz = msol->GetZHalfLength() / GetNoDiv(); 370 G4double pDz = fwidth/2. - fhgap; 371 G4double pSPhi = msol->GetStartPhiAngle(); 372 G4double pDPhi = msol->GetDeltaPhiAngle(); 373 374 tubs.SetInnerRadius( pRMin ); 375 tubs.SetOuterRadius( pRMax ); 376 tubs.SetZHalfLength( pDz ); 377 tubs.SetStartPhiAngle( pSPhi, false ); 378 tubs.SetDeltaPhiAngle( pDPhi ); 379 380 #ifdef G4DIVDEBUG 381 if( verbose >= 2 ) 382 { 383 G4cout << " G4ParameterisationTubsZ::ComputeDimensions()" << G4endl 384 << " pDz: " << pDz << G4endl; 385 tubs.DumpInfo(); 386 } 387 #endif 388 } 389