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 // class G4ParameterisationPara[X,Y,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 "G4ParameterisationPara.hh" 34 35 #include <iomanip> 36 37 #include "G4PhysicalConstants.hh" 38 #include "G4ThreeVector.hh" 39 #include "G4Transform3D.hh" 40 #include "G4RotationMatrix.hh" 41 #include "G4VPhysicalVolume.hh" 42 #include "G4ReflectedSolid.hh" 43 #include "G4Para.hh" 44 45 //-------------------------------------------------------------------------- 46 G4VParameterisationPara:: 47 G4VParameterisationPara( EAxis axis, G4int nDiv, G4double width, 48 G4double offset, G4VSolid* msolid, 49 DivisionType divType ) 50 : G4VDivisionParameterisation( axis, nDiv, width, offset, divType, msolid ) 51 { 52 auto msol = (G4Para*)(msolid); 53 if (msolid->GetEntityType() == "G4ReflectedSolid") 54 { 55 // Get constituent solid 56 G4VSolid* mConstituentSolid 57 = ((G4ReflectedSolid*)msolid)->GetConstituentMovedSolid(); 58 msol = (G4Para*)(mConstituentSolid); 59 fmotherSolid = msol; 60 61 // Create a new solid with inversed parameters 62 auto newSolid 63 = new G4Para(msol->GetName(), 64 msol->GetXHalfLength(), 65 msol->GetYHalfLength(), 66 msol->GetZHalfLength(), 67 std::atan(msol->GetTanAlpha()), 68 pi - msol->GetSymAxis().theta(), 69 msol->GetSymAxis().phi()); 70 71 msol = newSolid; 72 fmotherSolid = newSolid; 73 fReflectedSolid = true; 74 fDeleteSolid = true; 75 } 76 } 77 78 //------------------------------------------------------------------------ 79 G4VParameterisationPara::~G4VParameterisationPara() = default; 80 81 //------------------------------------------------------------------------ 82 G4ParameterisationParaX:: 83 G4ParameterisationParaX( EAxis axis, G4int nDiv, 84 G4double width, G4double offset, 85 G4VSolid* msolid, DivisionType divType ) 86 : G4VParameterisationPara( axis, nDiv, width, offset, msolid, divType ) 87 { 88 CheckParametersValidity(); 89 SetType( "DivisionParaX" ); 90 91 auto mpara = (G4Para*)(fmotherSolid); 92 if( divType == DivWIDTH ) 93 { 94 fnDiv = CalculateNDiv( 2*mpara->GetXHalfLength(), width, offset ); 95 } 96 else if( divType == DivNDIV ) 97 { 98 fwidth = CalculateWidth( 2*mpara->GetXHalfLength(), nDiv, offset ); 99 } 100 101 #ifdef G4DIVDEBUG 102 if( verbose >= 1 ) 103 { 104 G4cout << " G4ParameterisationParaX - # divisions " << fnDiv 105 << " = " << nDiv << G4endl 106 << " Offset " << foffset << " = " << offset << G4endl 107 << " Width " << fwidth << " = " << width << G4endl; 108 } 109 #endif 110 } 111 112 //------------------------------------------------------------------------ 113 G4double G4ParameterisationParaX::GetMaxParameter() const 114 { 115 auto msol = (G4Para*)(fmotherSolid); 116 return 2*msol->GetXHalfLength(); 117 } 118 119 //------------------------------------------------------------------------ 120 G4ParameterisationParaX::~G4ParameterisationParaX() = default; 121 122 //------------------------------------------------------------------------ 123 void 124 G4ParameterisationParaX:: 125 ComputeTransformation( const G4int copyNo, G4VPhysicalVolume *physVol ) const 126 { 127 auto msol = (G4Para*)(fmotherSolid ); 128 G4double mdx = msol->GetXHalfLength( ); 129 130 //----- translation 131 G4ThreeVector origin(0.,0.,0.); 132 G4double posi = -mdx + foffset+(copyNo+0.5)*fwidth; 133 origin.setX( posi ); 134 135 #ifdef G4DIVDEBUG 136 if( verbose >= 2 ) 137 { 138 G4cout << std::setprecision(8) << " G4ParameterisationParaX " 139 << copyNo << G4endl 140 << " Position: " << origin << " - Axis: " << faxis << G4endl; 141 } 142 #endif 143 144 //----- set translation 145 physVol->SetTranslation( origin ); 146 } 147 148 //-------------------------------------------------------------------------- 149 void 150 G4ParameterisationParaX:: 151 ComputeDimensions(G4Para& para, const G4int, 152 const G4VPhysicalVolume*) const 153 { 154 //---- The division along X of a Para will result a Para 155 auto msol = (G4Para*)(fmotherSolid); 156 157 //---- Get 158 G4double pDx = fwidth/2. - fhgap; 159 G4double pDy = msol->GetYHalfLength(); 160 G4double pDz = msol->GetZHalfLength(); 161 G4double pAlpha = std::atan(msol->GetTanAlpha()); 162 G4double pTheta = msol->GetSymAxis().theta(); 163 G4double pPhi = msol->GetSymAxis().phi(); 164 165 para.SetAllParameters ( pDx, pDy, pDz, pAlpha, pTheta, pPhi ); 166 167 #ifdef G4DIVDEBUG 168 if( verbose >= 1 ) 169 { 170 G4cout << " G4ParameterisationParaX::ComputeDimensions()" 171 << " - Mother PARA " << G4endl; 172 msol->DumpInfo(); 173 G4cout << " - Parameterised PARA: " << G4endl; 174 para.DumpInfo(); 175 } 176 #endif 177 } 178 179 //------------------------------------------------------------------------ 180 G4ParameterisationParaY:: 181 G4ParameterisationParaY( EAxis axis, G4int nDiv, 182 G4double width, G4double offset, 183 G4VSolid* msolid, DivisionType divType ) 184 : G4VParameterisationPara( axis, nDiv, width, offset, msolid, divType ) 185 { 186 CheckParametersValidity(); 187 SetType( "DivisionParaY" ); 188 189 auto mpara = (G4Para*)(fmotherSolid); 190 if( divType == DivWIDTH ) 191 { 192 fnDiv = CalculateNDiv( 2*mpara->GetYHalfLength(), width, offset ); 193 } 194 else if( divType == DivNDIV ) 195 { 196 fwidth = CalculateWidth( 2*mpara->GetYHalfLength(), nDiv, offset ); 197 } 198 199 #ifdef G4DIVDEBUG 200 if( verbose >= 1 ) 201 { 202 G4cout << " G4ParameterisationParaY - # divisions " << fnDiv 203 << " = " << nDiv << G4endl 204 << " Offset " << foffset << " = " << offset << G4endl 205 << " Width " << fwidth << " = " << width << G4endl; 206 } 207 #endif 208 } 209 210 //------------------------------------------------------------------------ 211 G4ParameterisationParaY::~G4ParameterisationParaY() = default; 212 213 //------------------------------------------------------------------------ 214 G4double G4ParameterisationParaY::GetMaxParameter() const 215 { 216 auto msol = (G4Para*)(fmotherSolid); 217 return 2*msol->GetYHalfLength(); 218 } 219 220 //------------------------------------------------------------------------ 221 void 222 G4ParameterisationParaY:: 223 ComputeTransformation( const G4int copyNo, G4VPhysicalVolume *physVol ) const 224 { 225 auto msol = (G4Para*)(fmotherSolid ); 226 G4double mdy = msol->GetYHalfLength( ); 227 228 //----- translation 229 G4ThreeVector origin(0.,0.,0.); 230 G4double posiY = -mdy + foffset+(copyNo+0.5)*fwidth; 231 origin.setY( posiY ); 232 G4double posiX = posiY * msol->GetTanAlpha(); 233 origin.setX( posiX ); 234 235 #ifdef G4DIVDEBUG 236 if( verbose >= 2 ) 237 { 238 G4cout << std::setprecision(8) << " G4ParameterisationParaY " 239 << copyNo << G4endl 240 << " Position: " << origin << " - Axis: " << faxis << G4endl; 241 } 242 #endif 243 244 //----- set translation 245 physVol->SetTranslation( origin ); 246 } 247 248 //-------------------------------------------------------------------------- 249 void 250 G4ParameterisationParaY:: 251 ComputeDimensions(G4Para& para, const G4int, 252 const G4VPhysicalVolume*) const 253 { 254 //---- The division along Y of a Para will result a Para 255 auto msol = (G4Para*)(fmotherSolid); 256 257 //---- Get 258 G4double pDx = msol->GetXHalfLength(); 259 G4double pDy = fwidth/2. - fhgap; 260 G4double pDz = msol->GetZHalfLength(); 261 G4double pAlpha = std::atan(msol->GetTanAlpha()); 262 G4double pTheta = msol->GetSymAxis().theta(); 263 G4double pPhi = msol->GetSymAxis().phi(); 264 265 para.SetAllParameters ( pDx, pDy, pDz, pAlpha, pTheta, pPhi ); 266 267 #ifdef G4DIVDEBUG 268 if( verbose >= -1 ) 269 { 270 G4cout << " G4ParameterisationParaY::ComputeDimensions()" 271 << " - Mother PARA " << G4endl; 272 msol->DumpInfo(); 273 G4cout << " - Parameterised PARA: " << G4endl; 274 para.DumpInfo(); 275 } 276 #endif 277 } 278 279 //------------------------------------------------------------------------ 280 G4ParameterisationParaZ:: 281 G4ParameterisationParaZ( EAxis axis, G4int nDiv, 282 G4double width, G4double offset, 283 G4VSolid* msolid, DivisionType divType ) 284 : G4VParameterisationPara( axis, nDiv, width, offset, msolid, divType ) 285 { 286 CheckParametersValidity(); 287 SetType( "DivisionParaZ" ); 288 289 auto mpara = (G4Para*)(fmotherSolid); 290 if( divType == DivWIDTH ) 291 { 292 fnDiv = CalculateNDiv( 2*mpara->GetZHalfLength(), width, offset ); 293 } 294 else if( divType == DivNDIV ) 295 { 296 fwidth = CalculateWidth( 2*mpara->GetZHalfLength(), nDiv, offset ); 297 } 298 299 #ifdef G4DIVDEBUG 300 if( verbose >= -1 ) 301 { 302 G4cout << " G4ParameterisationParaZ - # divisions " << fnDiv 303 << " = " << nDiv << G4endl 304 << " Offset " << foffset << " = " << offset << G4endl 305 << " Width " << fwidth << " = " << width << G4endl; 306 } 307 #endif 308 } 309 310 //------------------------------------------------------------------------ 311 G4ParameterisationParaZ::~G4ParameterisationParaZ() = default; 312 313 //------------------------------------------------------------------------ 314 G4double G4ParameterisationParaZ::GetMaxParameter() const 315 { 316 auto msol = (G4Para*)(fmotherSolid); 317 return 2*msol->GetZHalfLength(); 318 } 319 320 //------------------------------------------------------------------------ 321 void 322 G4ParameterisationParaZ:: 323 ComputeTransformation( const G4int copyNo, G4VPhysicalVolume *physVol ) const 324 { 325 auto msol = (G4Para*)(fmotherSolid ); 326 G4double mdz = msol->GetZHalfLength( ); 327 328 //----- translation 329 G4double posi = -mdz + OffsetZ() + (copyNo+0.5)*fwidth; 330 G4ThreeVector symAxis = msol->GetSymAxis(); 331 G4ThreeVector origin( symAxis * posi / symAxis.z() ); 332 333 #ifdef G4DIVDEBUG 334 if( verbose >= 2 ) 335 { 336 G4cout << std::setprecision(8) << " G4ParameterisationParaZ " 337 << copyNo << G4endl 338 << " Position: " << origin << " - Axis: " << faxis << G4endl; 339 } 340 #endif 341 342 //----- set translation 343 physVol->SetTranslation( origin ); 344 } 345 346 //-------------------------------------------------------------------------- 347 void 348 G4ParameterisationParaZ:: 349 ComputeDimensions(G4Para& para, const G4int, 350 const G4VPhysicalVolume*) const 351 { 352 //---- The division along Z of a Para will result a Para 353 auto msol = (G4Para*)(fmotherSolid); 354 355 //---- Get 356 G4double pDx = msol->GetXHalfLength(); 357 G4double pDy = msol->GetYHalfLength(); 358 G4double pDz = fwidth/2. - fhgap; 359 G4double pAlpha = std::atan(msol->GetTanAlpha()); 360 G4double pTheta = msol->GetSymAxis().theta(); 361 G4double pPhi = msol->GetSymAxis().phi(); 362 363 para.SetAllParameters ( pDx, pDy, pDz, pAlpha, pTheta, pPhi ); 364 365 #ifdef G4DIVDEBUG 366 if( verbose >= -1 ) 367 { 368 G4cout << " G4ParameterisationParaZ::ComputeDimensions()" 369 << " - Mother PARA " << G4endl; 370 msol->DumpInfo(); 371 G4cout << " - Parameterised PARA: " << G4endl; 372 para.DumpInfo(); 373 } 374 #endif 375 } 376