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 // >> 27 // $Id: G4Para.cc 102294 2017-01-20 11:41:52Z gcosmo $ >> 28 // >> 29 // class G4Para >> 30 // 26 // Implementation for G4Para class 31 // Implementation for G4Para class 27 // 32 // 28 // 21.03.95 P.Kent: Modified for `tolerant' ge << 33 // History: >> 34 // >> 35 // 23.10.05 V.Grichine: bug fixed in DistanceToOut(p,v,...) for the v.x()<0 case >> 36 // 28.04.05 V.Grichine: new SurfaceNormal according to J. Apostolakis proposal >> 37 // 30.11.04 V.Grichine: modifications in SurfaceNormal for edges/vertices and >> 38 // in constructor with vertices >> 39 // 14.02.02 V.Grichine: bug fixed in Inside according to proposal of D.Wright >> 40 // 18.11.99 V.Grichine: kUndef was added to ESide 29 // 31.10.96 V.Grichine: Modifications accordin 41 // 31.10.96 V.Grichine: Modifications according G4Box/Tubs before to commit 30 // 28.04.05 V.Grichine: new SurfaceNormal acco << 42 // 21.03.95 P.Kent: Modified for `tolerant' geom 31 // 29.05.17 E.Tcherniaev: complete revision, s << 43 // 32 ////////////////////////////////////////////// 44 //////////////////////////////////////////////////////////////////////////// 33 45 34 #include "G4Para.hh" 46 #include "G4Para.hh" 35 47 36 #if !defined(G4GEOM_USE_UPARA) << 37 << 38 #include "G4VoxelLimits.hh" 48 #include "G4VoxelLimits.hh" 39 #include "G4AffineTransform.hh" 49 #include "G4AffineTransform.hh" 40 #include "G4BoundingEnvelope.hh" << 41 #include "Randomize.hh" 50 #include "Randomize.hh" 42 51 43 #include "G4VPVParameterisation.hh" 52 #include "G4VPVParameterisation.hh" 44 53 45 #include "G4VGraphicsScene.hh" 54 #include "G4VGraphicsScene.hh" 46 55 47 using namespace CLHEP; 56 using namespace CLHEP; 48 57 49 ////////////////////////////////////////////// << 58 // Private enum: Not for external use >> 59 >> 60 enum ESide {kUndef,kPX,kMX,kPY,kMY,kPZ,kMZ}; >> 61 >> 62 // used internally for normal routine >> 63 >> 64 enum ENSide {kNZ,kNX,kNY}; >> 65 >> 66 ///////////////////////////////////////////////////////////////////// >> 67 // >> 68 // Constructor - check and set half-widths >> 69 >> 70 void G4Para::SetAllParameters( G4double pDx, G4double pDy, G4double pDz, >> 71 G4double pAlpha, G4double pTheta, G4double pPhi ) >> 72 { >> 73 if ( pDx > 0 && pDy > 0 && pDz > 0 ) >> 74 { >> 75 fDx = pDx; >> 76 fDy = pDy; >> 77 fDz = pDz; >> 78 fTalpha = std::tan(pAlpha); >> 79 fTthetaCphi = std::tan(pTheta)*std::cos(pPhi); >> 80 fTthetaSphi = std::tan(pTheta)*std::sin(pPhi); >> 81 } >> 82 else >> 83 { >> 84 std::ostringstream message; >> 85 message << "Invalid Length Parameters for Solid: " << GetName() << G4endl >> 86 << " pDx, pDy, pDz = " >> 87 << pDx << ", " << pDy << ", " << pDz; >> 88 G4Exception("G4Para::SetAllParameters()", "GeomSolids0002", >> 89 FatalException, message); >> 90 } >> 91 fCubicVolume = 0.; >> 92 fSurfaceArea = 0.; >> 93 } >> 94 >> 95 /////////////////////////////////////////////////////////////////////////// 50 // 96 // 51 // Constructor - set & check half widths << 52 97 53 G4Para::G4Para(const G4String& pName, 98 G4Para::G4Para(const G4String& pName, 54 G4double pDx, G4double pD 99 G4double pDx, G4double pDy, G4double pDz, 55 G4double pAlpha, G4double 100 G4double pAlpha, G4double pTheta, G4double pPhi) 56 : G4CSGSolid(pName), halfCarTolerance(0.5*kC << 101 : G4CSGSolid(pName) 57 { 102 { 58 SetAllParameters(pDx, pDy, pDz, pAlpha, pThe << 103 if ((pDx<=0) || (pDy<=0) || (pDz<=0)) 59 fRebuildPolyhedron = false; // default valu << 104 { >> 105 std::ostringstream message; >> 106 message << "Invalid Length Parameters for Solid: " << GetName() << G4endl >> 107 << " pDx, pDy, pDz = " >> 108 << pDx << ", " << pDy << ", " << pDz; >> 109 G4Exception("G4Para::G4Para()", "GeomSolids0002", >> 110 FatalException, message); >> 111 } >> 112 SetAllParameters( pDx, pDy, pDz, pAlpha, pTheta, pPhi); 60 } 113 } 61 114 62 ////////////////////////////////////////////// << 115 //////////////////////////////////////////////////////////////////////// 63 // 116 // 64 // Constructor - design of trapezoid based on << 117 // Constructor - Design of trapezoid based on 8 G4ThreeVector parameters, >> 118 // which are its vertices. Checking of planarity with preparation of >> 119 // fPlanes[] and than calculation of other members 65 120 66 G4Para::G4Para( const G4String& pName, 121 G4Para::G4Para( const G4String& pName, 67 const G4ThreeVector pt[8] ) 122 const G4ThreeVector pt[8] ) 68 : G4CSGSolid(pName), halfCarTolerance(0.5*kC << 123 : G4CSGSolid(pName) 69 { 124 { 70 // Find dimensions and trigonometric values << 125 if (!( pt[0].z()<0 && pt[0].z()==pt[1].z() && pt[0].z()==pt[2].z() && 71 // << 126 pt[0].z()==pt[3].z() && pt[4].z()>0 && pt[4].z()==pt[5].z() && 72 fDx = (pt[3].x() - pt[2].x())*0.5; << 127 pt[4].z()==pt[6].z() && pt[4].z()==pt[7].z() && 73 fDy = (pt[2].y() - pt[1].y())*0.5; << 128 (pt[0].z()+pt[4].z())==0 && 74 fDz = pt[7].z(); << 129 pt[0].y()==pt[1].y() && pt[2].y()==pt[3].y() && 75 CheckParameters(); // check dimensions << 130 pt[4].y()==pt[5].y() && pt[6].y()==pt[7].y() && 76 << 131 ( pt[0].y() + pt[2].y() + pt[4].y() + pt[6].y() ) == 0 && 77 fTalpha = (pt[2].x() + pt[3].x() - pt[1].x() << 132 ( pt[0].x() + pt[1].x() + pt[4].x() + pt[5].x() ) == 0) ) 78 fTthetaCphi = (pt[4].x() + fDy*fTalpha + fDx << 133 { 79 fTthetaSphi = (pt[4].y() + fDy)/fDz; << 134 std::ostringstream message; 80 MakePlanes(); << 135 message << "Invalid vertice coordinates for Solid: " << GetName(); 81 << 136 G4Exception("G4Para::G4Para()", "GeomSolids0002", 82 // Recompute vertices << 137 FatalException, message); 83 // << 138 } 84 G4ThreeVector v[8]; << 139 fDx = ((pt[3]).x()-(pt[2]).x())*0.5; 85 G4double DyTalpha = fDy*fTalpha; << 140 fDy = ((pt[2]).y()-(pt[1]).y())*0.5; 86 G4double DzTthetaSphi = fDz*fTthetaSphi; << 141 fDz = (pt[7]).z(); 87 G4double DzTthetaCphi = fDz*fTthetaCphi; << 142 fTalpha = ((pt[2]).x()+(pt[3]).x()-(pt[1]).x()-(pt[0]).x())*0.25/fDy ; 88 v[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTthe << 143 fTthetaCphi = ((pt[4]).x()+fDy*fTalpha+fDx)/fDz ; 89 v[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTthe << 144 fTthetaSphi = ((pt[4]).y()+fDy)/fDz ; 90 v[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTthe << 145 fCubicVolume = 0.; 91 v[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTthe << 146 fSurfaceArea = 0.; 92 v[4].set( DzTthetaCphi-DyTalpha-fDx, DzTthe << 93 v[5].set( DzTthetaCphi-DyTalpha+fDx, DzTthe << 94 v[6].set( DzTthetaCphi+DyTalpha-fDx, DzTthe << 95 v[7].set( DzTthetaCphi+DyTalpha+fDx, DzTthe << 96 << 97 // Compare with original vertices << 98 // << 99 for (G4int i=0; i<8; ++i) << 100 { << 101 G4double delx = std::abs(pt[i].x() - v[i]. << 102 G4double dely = std::abs(pt[i].y() - v[i]. << 103 G4double delz = std::abs(pt[i].z() - v[i]. << 104 G4double discrepancy = std::max(std::max(d << 105 if (discrepancy > 0.1*kCarTolerance) << 106 { << 107 std::ostringstream message; << 108 G4long oldprc = message.precision(16); << 109 message << "Invalid vertice coordinates << 110 << "\nVertix #" << i << ", discr << 111 << "\n original : " << pt[i] << 112 << "\n recomputed : " << v[i]; << 113 G4cout.precision(oldprc); << 114 G4Exception("G4Para::G4Para()", "GeomSol << 115 FatalException, message); << 116 << 117 } << 118 } << 119 } 147 } 120 148 121 ////////////////////////////////////////////// << 149 /////////////////////////////////////////////////////////////////////// 122 // 150 // 123 // Fake default constructor - sets only member 151 // Fake default constructor - sets only member data and allocates memory 124 // for usage restri << 152 // for usage restricted to object persistency. 125 << 153 // 126 G4Para::G4Para( __void__& a ) 154 G4Para::G4Para( __void__& a ) 127 : G4CSGSolid(a), halfCarTolerance(0.5*kCarTo << 155 : G4CSGSolid(a), fDx(0.), fDy(0.), fDz(0.), >> 156 fTalpha(0.), fTthetaCphi(0.), fTthetaSphi(0.) 128 { 157 { 129 SetAllParameters(1., 1., 1., 0., 0., 0.); << 130 fRebuildPolyhedron = false; // default value << 131 } 158 } 132 159 133 ////////////////////////////////////////////// 160 ////////////////////////////////////////////////////////////////////////// 134 // 161 // 135 // Destructor << 136 162 137 G4Para::~G4Para() = default; << 163 G4Para::~G4Para() >> 164 { >> 165 } 138 166 139 ////////////////////////////////////////////// 167 ////////////////////////////////////////////////////////////////////////// 140 // 168 // 141 // Copy constructor 169 // Copy constructor 142 170 143 G4Para::G4Para(const G4Para& rhs) 171 G4Para::G4Para(const G4Para& rhs) 144 : G4CSGSolid(rhs), halfCarTolerance(rhs.half << 172 : G4CSGSolid(rhs), fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), 145 fDx(rhs.fDx), fDy(rhs.fDy), fDz(rhs.fDz), << 173 fTalpha(rhs.fTalpha), fTthetaCphi(rhs.fTthetaCphi), 146 fTthetaCphi(rhs.fTthetaCphi),fTthetaSphi(r << 174 fTthetaSphi(rhs.fTthetaSphi) 147 { 175 { 148 for (G4int i=0; i<4; ++i) { fPlanes[i] = rhs << 149 } 176 } 150 177 151 ////////////////////////////////////////////// 178 ////////////////////////////////////////////////////////////////////////// 152 // 179 // 153 // Assignment operator 180 // Assignment operator 154 181 155 G4Para& G4Para::operator = (const G4Para& rhs) << 182 G4Para& G4Para::operator = (const G4Para& rhs) 156 { 183 { 157 // Check assignment to self 184 // Check assignment to self 158 // 185 // 159 if (this == &rhs) { return *this; } 186 if (this == &rhs) { return *this; } 160 187 161 // Copy base class data 188 // Copy base class data 162 // 189 // 163 G4CSGSolid::operator=(rhs); 190 G4CSGSolid::operator=(rhs); 164 191 165 // Copy data 192 // Copy data 166 // 193 // 167 halfCarTolerance = rhs.halfCarTolerance; << 194 fDx = rhs.fDx; fDy = rhs.fDy; fDz = rhs.fDz; 168 fDx = rhs.fDx; << 195 fTalpha = rhs.fTalpha; fTthetaCphi = rhs.fTthetaCphi; 169 fDy = rhs.fDy; << 170 fDz = rhs.fDz; << 171 fTalpha = rhs.fTalpha; << 172 fTthetaCphi = rhs.fTthetaCphi; << 173 fTthetaSphi = rhs.fTthetaSphi; 196 fTthetaSphi = rhs.fTthetaSphi; 174 for (G4int i=0; i<4; ++i) { fPlanes[i] = rh << 175 197 176 return *this; 198 return *this; 177 } 199 } 178 200 179 ////////////////////////////////////////////// 201 ////////////////////////////////////////////////////////////////////////// 180 // 202 // 181 // Set all parameters, as for constructor - se << 182 << 183 void G4Para::SetAllParameters(G4double pDx, G4 << 184 G4double pAlpha, << 185 { << 186 // Reset data of the base class << 187 fCubicVolume = 0; << 188 fSurfaceArea = 0; << 189 fRebuildPolyhedron = true; << 190 << 191 // Set parameters << 192 fDx = pDx; << 193 fDy = pDy; << 194 fDz = pDz; << 195 fTalpha = std::tan(pAlpha); << 196 fTthetaCphi = std::tan(pTheta)*std::cos(pPhi << 197 fTthetaSphi = std::tan(pTheta)*std::sin(pPhi << 198 << 199 CheckParameters(); << 200 MakePlanes(); << 201 } << 202 << 203 ////////////////////////////////////////////// << 204 // << 205 // Check dimensions << 206 << 207 void G4Para::CheckParameters() << 208 { << 209 if (fDx < 2*kCarTolerance || << 210 fDy < 2*kCarTolerance || << 211 fDz < 2*kCarTolerance) << 212 { << 213 std::ostringstream message; << 214 message << "Invalid (too small or negative << 215 << GetName() << 216 << "\n X - " << fDx << 217 << "\n Y - " << fDy << 218 << "\n Z - " << fDz; << 219 G4Exception("G4Para::CheckParameters()", " << 220 FatalException, message); << 221 } << 222 } << 223 << 224 ////////////////////////////////////////////// << 225 // << 226 // Set side planes << 227 << 228 void G4Para::MakePlanes() << 229 { << 230 G4ThreeVector vx(1, 0, 0); << 231 G4ThreeVector vy(fTalpha, 1, 0); << 232 G4ThreeVector vz(fTthetaCphi, fTthetaSphi, 1 << 233 << 234 // Set -Y & +Y planes << 235 // << 236 G4ThreeVector ynorm = (vx.cross(vz)).unit(); << 237 << 238 fPlanes[0].a = 0.; << 239 fPlanes[0].b = ynorm.y(); << 240 fPlanes[0].c = ynorm.z(); << 241 fPlanes[0].d = fPlanes[0].b*fDy; // point (0 << 242 << 243 fPlanes[1].a = 0.; << 244 fPlanes[1].b = -fPlanes[0].b; << 245 fPlanes[1].c = -fPlanes[0].c; << 246 fPlanes[1].d = fPlanes[0].d; << 247 << 248 // Set -X & +X planes << 249 // << 250 G4ThreeVector xnorm = (vz.cross(vy)).unit(); << 251 << 252 fPlanes[2].a = xnorm.x(); << 253 fPlanes[2].b = xnorm.y(); << 254 fPlanes[2].c = xnorm.z(); << 255 fPlanes[2].d = fPlanes[2].a*fDx; // point (f << 256 << 257 fPlanes[3].a = -fPlanes[2].a; << 258 fPlanes[3].b = -fPlanes[2].b; << 259 fPlanes[3].c = -fPlanes[2].c; << 260 fPlanes[3].d = fPlanes[2].d; << 261 } << 262 << 263 ////////////////////////////////////////////// << 264 // << 265 // Get volume << 266 << 267 G4double G4Para::GetCubicVolume() << 268 { << 269 // It is like G4Box, since para transformati << 270 if (fCubicVolume == 0) << 271 { << 272 fCubicVolume = 8*fDx*fDy*fDz; << 273 } << 274 return fCubicVolume; << 275 } << 276 << 277 ////////////////////////////////////////////// << 278 // << 279 // Get surface area << 280 << 281 G4double G4Para::GetSurfaceArea() << 282 { << 283 if(fSurfaceArea == 0) << 284 { << 285 G4ThreeVector vx(fDx, 0, 0); << 286 G4ThreeVector vy(fDy*fTalpha, fDy, 0); << 287 G4ThreeVector vz(fDz*fTthetaCphi, fDz*fTth << 288 << 289 G4double sxy = fDx*fDy; // (vx.cross(vy)). << 290 G4double sxz = (vx.cross(vz)).mag(); << 291 G4double syz = (vy.cross(vz)).mag(); << 292 << 293 fSurfaceArea = 8*(sxy+sxz+syz); << 294 } << 295 return fSurfaceArea; << 296 } << 297 << 298 ////////////////////////////////////////////// << 299 // << 300 // Dispatch to parameterisation for replicatio 203 // Dispatch to parameterisation for replication mechanism dimension 301 // computation & modification << 204 // computation & modification. 302 205 303 void G4Para::ComputeDimensions( G4VPVPara 206 void G4Para::ComputeDimensions( G4VPVParameterisation* p, 304 const G4int n, 207 const G4int n, 305 const G4VPhysi 208 const G4VPhysicalVolume* pRep ) 306 { 209 { 307 p->ComputeDimensions(*this,n,pRep); 210 p->ComputeDimensions(*this,n,pRep); 308 } 211 } 309 212 310 ////////////////////////////////////////////// << 311 // << 312 // Get bounding box << 313 << 314 void G4Para::BoundingLimits(G4ThreeVector& pMi << 315 { << 316 G4double dz = GetZHalfLength(); << 317 G4double dx = GetXHalfLength(); << 318 G4double dy = GetYHalfLength(); << 319 << 320 G4double x0 = dz*fTthetaCphi; << 321 G4double x1 = dy*GetTanAlpha(); << 322 G4double xmin = << 323 std::min( << 324 std::min( << 325 std::min(-x0-x1-dx,-x0+x1-dx),x0-x1-dx),x0 << 326 G4double xmax = << 327 std::max( << 328 std::max( << 329 std::max(-x0-x1+dx,-x0+x1+dx),x0-x1+dx),x0 << 330 << 331 G4double y0 = dz*fTthetaSphi; << 332 G4double ymin = std::min(-y0-dy,y0-dy); << 333 G4double ymax = std::max(-y0+dy,y0+dy); << 334 << 335 pMin.set(xmin,ymin,-dz); << 336 pMax.set(xmax,ymax, dz); << 337 << 338 // Check correctness of the bounding box << 339 // << 340 if (pMin.x() >= pMax.x() || pMin.y() >= pMax << 341 { << 342 std::ostringstream message; << 343 message << "Bad bounding box (min >= max) << 344 << GetName() << " !" << 345 << "\npMin = " << pMin << 346 << "\npMax = " << pMax; << 347 G4Exception("G4Para::BoundingLimits()", "G << 348 JustWarning, message); << 349 DumpInfo(); << 350 } << 351 } << 352 213 353 ////////////////////////////////////////////// << 214 ////////////////////////////////////////////////////////////// 354 // 215 // 355 // Calculate extent under transform and specif 216 // Calculate extent under transform and specified limit 356 217 357 G4bool G4Para::CalculateExtent( const EAxis pA 218 G4bool G4Para::CalculateExtent( const EAxis pAxis, 358 const G4VoxelL 219 const G4VoxelLimits& pVoxelLimit, 359 const G4Affine 220 const G4AffineTransform& pTransform, 360 G4double& 221 G4double& pMin, G4double& pMax ) const 361 { 222 { 362 G4ThreeVector bmin, bmax; << 223 G4bool flag; 363 G4bool exist; << 364 224 365 // Check bounding box (bbox) << 225 if (!pTransform.IsRotated()) 366 // << 226 { 367 BoundingLimits(bmin,bmax); << 227 // Special case handling for unrotated trapezoids 368 G4BoundingEnvelope bbox(bmin,bmax); << 228 // Compute z/x/y/ mins and maxs respecting limits, with early returns 369 #ifdef G4BBOX_EXTENT << 229 // if outside limits. Then switch() on pAxis 370 return bbox.CalculateExtent(pAxis,pVoxelLimi << 230 371 #endif << 231 G4int i ; 372 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox << 232 G4double xoffset,xMin,xMax; 373 { << 233 G4double yoffset,yMin,yMax; 374 return exist = pMin < pMax; << 234 G4double zoffset,zMin,zMax; 375 } << 235 G4double temp[8] ; // some points for intersection with zMin/zMax >> 236 >> 237 xoffset=pTransform.NetTranslation().x(); >> 238 yoffset=pTransform.NetTranslation().y(); >> 239 zoffset=pTransform.NetTranslation().z(); >> 240 >> 241 G4ThreeVector pt[8]; // vertices after translation >> 242 pt[0]=G4ThreeVector(xoffset-fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 243 yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz); >> 244 pt[1]=G4ThreeVector(xoffset-fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 245 yoffset-fDz*fTthetaSphi-fDy,zoffset-fDz); >> 246 pt[2]=G4ThreeVector(xoffset-fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 247 yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz); >> 248 pt[3]=G4ThreeVector(xoffset-fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 249 yoffset-fDz*fTthetaSphi+fDy,zoffset-fDz); >> 250 pt[4]=G4ThreeVector(xoffset+fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 251 yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz); >> 252 pt[5]=G4ThreeVector(xoffset+fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 253 yoffset+fDz*fTthetaSphi-fDy,zoffset+fDz); >> 254 pt[6]=G4ThreeVector(xoffset+fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 255 yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz); >> 256 pt[7]=G4ThreeVector(xoffset+fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 257 yoffset+fDz*fTthetaSphi+fDy,zoffset+fDz); >> 258 zMin=zoffset-fDz; >> 259 zMax=zoffset+fDz; >> 260 if ( pVoxelLimit.IsZLimited() ) >> 261 { >> 262 if ( (zMin>pVoxelLimit.GetMaxZExtent()+kCarTolerance) >> 263 || (zMax<pVoxelLimit.GetMinZExtent()-kCarTolerance) ) >> 264 { >> 265 return false; >> 266 } >> 267 else >> 268 { >> 269 if (zMin<pVoxelLimit.GetMinZExtent()) >> 270 { >> 271 zMin=pVoxelLimit.GetMinZExtent(); >> 272 } >> 273 if (zMax>pVoxelLimit.GetMaxZExtent()) >> 274 { >> 275 zMax=pVoxelLimit.GetMaxZExtent(); >> 276 } >> 277 } >> 278 } 376 279 377 // Set bounding envelope (benv) and calculat << 280 temp[0] = pt[0].y()+(pt[4].y()-pt[0].y()) 378 // << 281 *(zMin-pt[0].z())/(pt[4].z()-pt[0].z()) ; 379 G4double dz = GetZHalfLength(); << 282 temp[1] = pt[0].y()+(pt[4].y()-pt[0].y()) 380 G4double dx = GetXHalfLength(); << 283 *(zMax-pt[0].z())/(pt[4].z()-pt[0].z()) ; 381 G4double dy = GetYHalfLength(); << 284 temp[2] = pt[2].y()+(pt[6].y()-pt[2].y()) >> 285 *(zMin-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 286 temp[3] = pt[2].y()+(pt[6].y()-pt[2].y()) >> 287 *(zMax-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 288 yMax = yoffset - std::fabs(fDz*fTthetaSphi) - fDy - fDy ; >> 289 yMin = -yMax ; >> 290 for(i=0;i<4;i++) >> 291 { >> 292 if(temp[i] > yMax) yMax = temp[i] ; >> 293 if(temp[i] < yMin) yMin = temp[i] ; >> 294 } >> 295 >> 296 if (pVoxelLimit.IsYLimited()) >> 297 { >> 298 if ( (yMin>pVoxelLimit.GetMaxYExtent()+kCarTolerance) >> 299 || (yMax<pVoxelLimit.GetMinYExtent()-kCarTolerance) ) >> 300 { >> 301 return false; >> 302 } >> 303 else >> 304 { >> 305 if (yMin<pVoxelLimit.GetMinYExtent()) >> 306 { >> 307 yMin=pVoxelLimit.GetMinYExtent(); >> 308 } >> 309 if (yMax>pVoxelLimit.GetMaxYExtent()) >> 310 { >> 311 yMax=pVoxelLimit.GetMaxYExtent(); >> 312 } >> 313 } >> 314 } 382 315 383 G4double x0 = dz*fTthetaCphi; << 316 temp[0] = pt[0].x()+(pt[4].x()-pt[0].x()) 384 G4double x1 = dy*GetTanAlpha(); << 317 *(zMin-pt[0].z())/(pt[4].z()-pt[0].z()) ; 385 G4double y0 = dz*fTthetaSphi; << 318 temp[1] = pt[0].x()+(pt[4].x()-pt[0].x()) >> 319 *(zMax-pt[0].z())/(pt[4].z()-pt[0].z()) ; >> 320 temp[2] = pt[2].x()+(pt[6].x()-pt[2].x()) >> 321 *(zMin-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 322 temp[3] = pt[2].x()+(pt[6].x()-pt[2].x()) >> 323 *(zMax-pt[2].z())/(pt[6].z()-pt[2].z()) ; >> 324 temp[4] = pt[3].x()+(pt[7].x()-pt[3].x()) >> 325 *(zMin-pt[3].z())/(pt[7].z()-pt[3].z()) ; >> 326 temp[5] = pt[3].x()+(pt[7].x()-pt[3].x()) >> 327 *(zMax-pt[3].z())/(pt[7].z()-pt[3].z()) ; >> 328 temp[6] = pt[1].x()+(pt[5].x()-pt[1].x()) >> 329 *(zMin-pt[1].z())/(pt[5].z()-pt[1].z()) ; >> 330 temp[7] = pt[1].x()+(pt[5].x()-pt[1].x()) >> 331 *(zMax-pt[1].z())/(pt[5].z()-pt[1].z()) ; >> 332 >> 333 xMax = xoffset - std::fabs(fDz*fTthetaCphi) - fDx - fDx -fDx - fDx; >> 334 xMin = -xMax ; >> 335 for(i=0;i<8;i++) >> 336 { >> 337 if(temp[i] > xMax) xMax = temp[i] ; >> 338 if(temp[i] < xMin) xMin = temp[i] ; >> 339 } >> 340 // xMax/Min = f(yMax/Min) ? >> 341 if (pVoxelLimit.IsXLimited()) >> 342 { >> 343 if ( (xMin>pVoxelLimit.GetMaxXExtent()+kCarTolerance) >> 344 || (xMax<pVoxelLimit.GetMinXExtent()-kCarTolerance) ) >> 345 { >> 346 return false; >> 347 } >> 348 else >> 349 { >> 350 if (xMin<pVoxelLimit.GetMinXExtent()) >> 351 { >> 352 xMin=pVoxelLimit.GetMinXExtent(); >> 353 } >> 354 if (xMax>pVoxelLimit.GetMaxXExtent()) >> 355 { >> 356 xMax=pVoxelLimit.GetMaxXExtent(); >> 357 } >> 358 } >> 359 } 386 360 387 G4ThreeVectorList baseA(4), baseB(4); << 361 switch (pAxis) 388 baseA[0].set(-x0-x1-dx,-y0-dy,-dz); << 362 { 389 baseA[1].set(-x0-x1+dx,-y0-dy,-dz); << 363 case kXAxis: 390 baseA[2].set(-x0+x1+dx,-y0+dy,-dz); << 364 pMin=xMin; 391 baseA[3].set(-x0+x1-dx,-y0+dy,-dz); << 365 pMax=xMax; >> 366 break; >> 367 case kYAxis: >> 368 pMin=yMin; >> 369 pMax=yMax; >> 370 break; >> 371 case kZAxis: >> 372 pMin=zMin; >> 373 pMax=zMax; >> 374 break; >> 375 default: >> 376 break; >> 377 } 392 378 393 baseB[0].set(+x0-x1-dx, y0-dy, dz); << 379 pMin-=kCarTolerance; 394 baseB[1].set(+x0-x1+dx, y0-dy, dz); << 380 pMax+=kCarTolerance; 395 baseB[2].set(+x0+x1+dx, y0+dy, dz); << 381 flag = true; 396 baseB[3].set(+x0+x1-dx, y0+dy, dz); << 382 } >> 383 else >> 384 { >> 385 // General rotated case - create and clip mesh to boundaries >> 386 >> 387 G4bool existsAfterClip=false; >> 388 G4ThreeVectorList *vertices; 397 389 398 std::vector<const G4ThreeVectorList *> polyg << 390 pMin=+kInfinity; 399 polygons[0] = &baseA; << 391 pMax=-kInfinity; 400 polygons[1] = &baseB; << 401 392 402 G4BoundingEnvelope benv(bmin,bmax,polygons); << 393 // Calculate rotated vertex coordinates 403 exist = benv.CalculateExtent(pAxis,pVoxelLim << 394 404 return exist; << 395 vertices=CreateRotatedVertices(pTransform); >> 396 ClipCrossSection(vertices,0,pVoxelLimit,pAxis,pMin,pMax); >> 397 ClipCrossSection(vertices,4,pVoxelLimit,pAxis,pMin,pMax); >> 398 ClipBetweenSections(vertices,0,pVoxelLimit,pAxis,pMin,pMax); >> 399 >> 400 if (pMin!=kInfinity||pMax!=-kInfinity) >> 401 { >> 402 existsAfterClip=true; >> 403 >> 404 // Add 2*tolerance to avoid precision troubles >> 405 // >> 406 pMin-=kCarTolerance; >> 407 pMax+=kCarTolerance; >> 408 } >> 409 else >> 410 { >> 411 // Check for case where completely enveloping clipping volume >> 412 // If point inside then we are confident that the solid completely >> 413 // envelopes the clipping volume. Hence set min/max extents according >> 414 // to clipping volume extents along the specified axis. >> 415 >> 416 G4ThreeVector clipCentre( >> 417 (pVoxelLimit.GetMinXExtent()+pVoxelLimit.GetMaxXExtent())*0.5, >> 418 (pVoxelLimit.GetMinYExtent()+pVoxelLimit.GetMaxYExtent())*0.5, >> 419 (pVoxelLimit.GetMinZExtent()+pVoxelLimit.GetMaxZExtent())*0.5); >> 420 >> 421 if (Inside(pTransform.Inverse().TransformPoint(clipCentre))!=kOutside) >> 422 { >> 423 existsAfterClip=true; >> 424 pMin=pVoxelLimit.GetMinExtent(pAxis); >> 425 pMax=pVoxelLimit.GetMaxExtent(pAxis); >> 426 } >> 427 } >> 428 delete vertices ; // 'new' in the function called >> 429 flag = existsAfterClip ; >> 430 } >> 431 return flag; 405 } 432 } 406 433 407 ////////////////////////////////////////////// << 434 ///////////////////////////////////////////////////////////////////////////// 408 // << 409 // Determine where is point p, inside/on_surfa << 410 // 435 // >> 436 // Check in p is inside/on surface/outside solid 411 437 412 EInside G4Para::Inside( const G4ThreeVector& p 438 EInside G4Para::Inside( const G4ThreeVector& p ) const 413 { 439 { 414 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 440 G4double xt, yt, yt1; 415 G4double dx = std::abs(xx) + fPlanes[2].d; << 441 EInside in = kOutside; >> 442 >> 443 yt1 = p.y() - fTthetaSphi*p.z(); >> 444 yt = std::fabs(yt1) ; 416 445 417 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 446 // xt = std::fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt ); 418 G4double dy = std::abs(yy) + fPlanes[0].d; << 419 G4double dxy = std::max(dx,dy); << 420 447 421 G4double dz = std::abs(p.z())-fDz; << 448 xt = std::fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt1 ); 422 G4double dist = std::max(dxy,dz); << 423 449 424 if (dist > halfCarTolerance) return kOutside << 450 if ( std::fabs( p.z() ) <= fDz - kCarTolerance*0.5) 425 return (dist > -halfCarTolerance) ? kSurface << 451 { >> 452 if (yt <= fDy - kCarTolerance*0.5) >> 453 { >> 454 if ( xt <= fDx - kCarTolerance*0.5 ) in = kInside; >> 455 else if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface; >> 456 } >> 457 else if ( yt <= fDy + kCarTolerance*0.5) >> 458 { >> 459 if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface; >> 460 } >> 461 } >> 462 else if ( std::fabs(p.z()) <= fDz + kCarTolerance*0.5 ) >> 463 { >> 464 if ( yt <= fDy + kCarTolerance*0.5) >> 465 { >> 466 if ( xt <= fDx + kCarTolerance*0.5 ) in = kSurface; >> 467 } >> 468 } >> 469 return in; 426 } 470 } 427 471 428 ////////////////////////////////////////////// << 472 /////////////////////////////////////////////////////////////////////////// 429 // 473 // 430 // Determine side where point is, and return c << 474 // Calculate side nearest to p, and return normal >> 475 // If 2+ sides equidistant, first side's normal returned (arbitrarily) 431 476 432 G4ThreeVector G4Para::SurfaceNormal( const G4T 477 G4ThreeVector G4Para::SurfaceNormal( const G4ThreeVector& p ) const 433 { 478 { 434 G4int nsurf = 0; // number of surfaces where << 479 G4ThreeVector norm, sumnorm(0.,0.,0.); >> 480 G4int noSurfaces = 0; >> 481 G4double distx,disty,distz; >> 482 G4double newpx,newpy,xshift; >> 483 G4double calpha,salpha; // Sin/Cos(alpha) - needed to recalc G4Parameter >> 484 G4double tntheta,cosntheta; // tan and cos of normal's theta component >> 485 G4double ycomp; >> 486 G4double delta = 0.5*kCarTolerance; 435 487 436 // Check Z faces << 488 newpx = p.x()-fTthetaCphi*p.z(); 437 // << 489 newpy = p.y()-fTthetaSphi*p.z(); 438 G4double nz = 0; << 439 G4double dz = std::abs(p.z()) - fDz; << 440 if (std::abs(dz) <= halfCarTolerance) << 441 { << 442 nz = (p.z() < 0) ? -1 : 1; << 443 ++nsurf; << 444 } << 445 490 446 // Check Y faces << 491 calpha = 1/std::sqrt(1+fTalpha*fTalpha); 447 // << 492 salpha = -calpha*fTalpha; // NOTE: using MINUS std::sin(alpha) 448 G4double ny = 0; << 493 449 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 494 // xshift = newpx*calpha+newpy*salpha; 450 if (std::abs(fPlanes[0].d + yy) <= halfCarTo << 495 xshift = newpx - newpy*fTalpha; 451 { << 496 452 ny = fPlanes[0].b; << 497 // distx = std::fabs(std::fabs(xshift)-fDx*calpha); 453 nz += fPlanes[0].c; << 498 distx = std::fabs(std::fabs(xshift)-fDx); 454 ++nsurf; << 499 disty = std::fabs(std::fabs(newpy)-fDy); 455 } << 500 distz = std::fabs(std::fabs(p.z())-fDz); 456 else if (std::abs(fPlanes[1].d - yy) <= half << 501 >> 502 tntheta = fTthetaCphi*calpha + fTthetaSphi*salpha; >> 503 cosntheta = 1/std::sqrt(1+tntheta*tntheta); >> 504 ycomp = 1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 505 >> 506 G4ThreeVector nX = G4ThreeVector( calpha*cosntheta, >> 507 salpha*cosntheta, >> 508 -tntheta*cosntheta); >> 509 G4ThreeVector nY = G4ThreeVector( 0, ycomp,-fTthetaSphi*ycomp); >> 510 G4ThreeVector nZ = G4ThreeVector( 0, 0, 1.0); >> 511 >> 512 if (distx <= delta) 457 { 513 { 458 ny = fPlanes[1].b; << 514 noSurfaces ++; 459 nz += fPlanes[1].c; << 515 if ( xshift >= 0.) {sumnorm += nX;} 460 ++nsurf; << 516 else {sumnorm -= nX;} 461 } 517 } 462 << 518 if (disty <= delta) 463 // Check X faces << 464 // << 465 G4double nx = 0; << 466 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 467 if (std::abs(fPlanes[2].d + xx) <= halfCarTo << 468 { 519 { 469 nx = fPlanes[2].a; << 520 noSurfaces ++; 470 ny += fPlanes[2].b; << 521 if ( newpy >= 0.) {sumnorm += nY;} 471 nz += fPlanes[2].c; << 522 else {sumnorm -= nY;} 472 ++nsurf; << 473 } 523 } 474 else if (std::abs(fPlanes[3].d - xx) <= half << 524 if (distz <= delta) 475 { 525 { 476 nx = fPlanes[3].a; << 526 noSurfaces ++; 477 ny += fPlanes[3].b; << 527 if ( p.z() >= 0.) {sumnorm += nZ;} 478 nz += fPlanes[3].c; << 528 else {sumnorm -= nZ;} 479 ++nsurf; << 480 } 529 } 481 << 530 if ( noSurfaces == 0 ) 482 // Return normal << 483 // << 484 if (nsurf == 1) return {nx,ny,nz}; << 485 else if (nsurf != 0) return G4ThreeVector(nx << 486 else << 487 { 531 { 488 // Point is not on the surface << 489 // << 490 #ifdef G4CSGDEBUG 532 #ifdef G4CSGDEBUG 491 std::ostringstream message; << 492 G4int oldprc = message.precision(16); << 493 message << "Point p is not on surface (!?) << 494 << GetName() << G4endl; << 495 message << "Position:\n"; << 496 message << " p.x() = " << p.x()/mm << " << 497 message << " p.y() = " << p.y()/mm << " << 498 message << " p.z() = " << p.z()/mm << " << 499 G4cout.precision(oldprc) ; << 500 G4Exception("G4Para::SurfaceNormal(p)", "G 533 G4Exception("G4Para::SurfaceNormal(p)", "GeomSolids1002", 501 JustWarning, message ); << 534 JustWarning, "Point p is not on surface !?" ); 502 DumpInfo(); << 535 #endif 503 #endif << 536 norm = ApproxSurfaceNormal(p); 504 return ApproxSurfaceNormal(p); << 505 } 537 } >> 538 else if ( noSurfaces == 1 ) {norm = sumnorm;} >> 539 else {norm = sumnorm.unit();} >> 540 >> 541 return norm; 506 } 542 } 507 543 508 ////////////////////////////////////////////// << 544 >> 545 //////////////////////////////////////////////////////////////////////// 509 // 546 // 510 // Algorithm for SurfaceNormal() following the 547 // Algorithm for SurfaceNormal() following the original specification 511 // for points not on the surface 548 // for points not on the surface 512 549 513 G4ThreeVector G4Para::ApproxSurfaceNormal( con 550 G4ThreeVector G4Para::ApproxSurfaceNormal( const G4ThreeVector& p ) const 514 { 551 { 515 G4double dist = -DBL_MAX; << 552 ENSide side; 516 G4int iside = 0; << 553 G4ThreeVector norm; 517 for (G4int i=0; i<4; ++i) << 554 G4double distx,disty,distz; >> 555 G4double newpx,newpy,xshift; >> 556 G4double calpha,salpha; // Sin/Cos(alpha) - needed to recalc G4Parameter >> 557 G4double tntheta,cosntheta; // tan and cos of normal's theta component >> 558 G4double ycomp; >> 559 >> 560 newpx=p.x()-fTthetaCphi*p.z(); >> 561 newpy=p.y()-fTthetaSphi*p.z(); >> 562 >> 563 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 564 salpha=-calpha*fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 565 >> 566 xshift=newpx*calpha+newpy*salpha; >> 567 >> 568 distx=std::fabs(std::fabs(xshift)-fDx*calpha); >> 569 disty=std::fabs(std::fabs(newpy)-fDy); >> 570 distz=std::fabs(std::fabs(p.z())-fDz); >> 571 >> 572 if (distx<disty) 518 { 573 { 519 G4double d = fPlanes[i].a*p.x() + << 574 if (distx<distz) {side=kNX;} 520 fPlanes[i].b*p.y() + << 575 else {side=kNZ;} 521 fPlanes[i].c*p.z() + fPlanes[ << 522 if (d > dist) { dist = d; iside = i; } << 523 } 576 } 524 << 525 G4double distz = std::abs(p.z()) - fDz; << 526 if (dist > distz) << 527 return { fPlanes[iside].a, fPlanes[iside]. << 528 else 577 else 529 return { 0, 0, (G4double)((p.z() < 0) ? -1 << 578 { >> 579 if (disty<distz) {side=kNY;} >> 580 else {side=kNZ;} >> 581 } >> 582 >> 583 switch (side) >> 584 { >> 585 case kNX: >> 586 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 587 if (xshift<0) >> 588 { >> 589 cosntheta=-1/std::sqrt(1+tntheta*tntheta); >> 590 } >> 591 else >> 592 { >> 593 cosntheta=1/std::sqrt(1+tntheta*tntheta); >> 594 } >> 595 norm=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 596 break; >> 597 case kNY: >> 598 if (newpy<0) >> 599 { >> 600 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 601 } >> 602 else >> 603 { >> 604 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 605 } >> 606 norm=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 607 break; >> 608 case kNZ: // Closest to Z >> 609 if (p.z()>=0) >> 610 { >> 611 norm=G4ThreeVector(0,0,1); >> 612 } >> 613 else >> 614 { >> 615 norm=G4ThreeVector(0,0,-1); >> 616 } >> 617 break; >> 618 } >> 619 return norm; 530 } 620 } 531 621 532 ////////////////////////////////////////////// << 622 ////////////////////////////////////////////////////////////////////////////// 533 // 623 // 534 // Calculate distance to shape from outside 624 // Calculate distance to shape from outside 535 // - return kInfinity if no intersection << 625 // - return kInfinity if no intersection 536 << 626 // 537 G4double G4Para::DistanceToIn(const G4ThreeVec << 627 // ALGORITHM: 538 const G4ThreeVec << 628 // For each component, calculate pair of minimum and maximum intersection 539 { << 629 // values for which the particle is in the extent of the shape 540 // Z intersections << 630 // - The smallest (MAX minimum) allowed distance of the pairs is intersect >> 631 // - Z plane intersectin uses tolerance >> 632 // - XZ YZ planes use logic & *SLIGHTLY INCORRECT* tolerance >> 633 // (this saves at least 1 sqrt, 1 multiply and 1 divide... in applicable >> 634 // cases) >> 635 // - Note: XZ and YZ planes each divide space into four regions, >> 636 // characterised by ss1 ss2 >> 637 >> 638 G4double G4Para::DistanceToIn( const G4ThreeVector& p, >> 639 const G4ThreeVector& v ) const >> 640 { >> 641 G4double snxt; // snxt = default return value >> 642 G4double smin,smax; >> 643 G4double tmin,tmax; >> 644 G4double yt,vy,xt,vx; >> 645 G4double max; 541 // 646 // 542 if ((std::abs(p.z()) - fDz) >= -halfCarToler << 647 // Z Intersection range 543 return kInfinity; << 544 G4double invz = (-v.z() == 0) ? DBL_MAX : -1 << 545 G4double dz = (invz < 0) ? fDz : -fDz; << 546 G4double tzmin = (p.z() + dz)*invz; << 547 G4double tzmax = (p.z() - dz)*invz; << 548 << 549 // Y intersections << 550 // 648 // 551 G4double tmin0 = tzmin, tmax0 = tzmax; << 649 if (v.z()>0) 552 G4double cos0 = fPlanes[0].b*v.y() + fPlanes << 650 { 553 G4double disy = fPlanes[0].b*p.y() + fPlanes << 651 max=fDz-p.z(); 554 G4double dis0 = fPlanes[0].d + disy; << 652 if (max>kCarTolerance*0.5) 555 if (dis0 >= -halfCarTolerance) << 653 { >> 654 smax=max/v.z(); >> 655 smin=(-fDz-p.z())/v.z(); >> 656 } >> 657 else >> 658 { >> 659 return snxt=kInfinity; >> 660 } >> 661 } >> 662 else if (v.z()<0) 556 { 663 { 557 if (cos0 >= 0) return kInfinity; << 664 max=-fDz-p.z(); 558 G4double tmp = -dis0/cos0; << 665 if (max<-kCarTolerance*0.5) 559 if (tmin0 < tmp) tmin0 = tmp; << 666 { >> 667 smax=max/v.z(); >> 668 smin=(fDz-p.z())/v.z(); >> 669 } >> 670 else >> 671 { >> 672 return snxt=kInfinity; >> 673 } 560 } 674 } 561 else if (cos0 > 0) << 675 else 562 { 676 { 563 G4double tmp = -dis0/cos0; << 677 if (std::fabs(p.z())<=fDz) // Inside 564 if (tmax0 > tmp) tmax0 = tmp; << 678 { >> 679 smin=0; >> 680 smax=kInfinity; >> 681 } >> 682 else >> 683 { >> 684 return snxt=kInfinity; >> 685 } 565 } 686 } >> 687 >> 688 // >> 689 // Y G4Parallel planes intersection >> 690 // >> 691 >> 692 yt=p.y()-fTthetaSphi*p.z(); >> 693 vy=v.y()-fTthetaSphi*v.z(); 566 694 567 G4double tmin1 = tmin0, tmax1 = tmax0; << 695 if (vy>0) 568 G4double cos1 = -cos0; << 569 G4double dis1 = fPlanes[1].d - disy; << 570 if (dis1 >= -halfCarTolerance) << 571 { 696 { 572 if (cos1 >= 0) return kInfinity; << 697 max=fDy-yt; 573 G4double tmp = -dis1/cos1; << 698 if (max>kCarTolerance*0.5) 574 if (tmin1 < tmp) tmin1 = tmp; << 699 { >> 700 tmax=max/vy; >> 701 tmin=(-fDy-yt)/vy; >> 702 } >> 703 else >> 704 { >> 705 return snxt=kInfinity; >> 706 } 575 } 707 } 576 else if (cos1 > 0) << 708 else if (vy<0) 577 { 709 { 578 G4double tmp = -dis1/cos1; << 710 max=-fDy-yt; 579 if (tmax1 > tmp) tmax1 = tmp; << 711 if (max<-kCarTolerance*0.5) >> 712 { >> 713 tmax=max/vy; >> 714 tmin=(fDy-yt)/vy; >> 715 } >> 716 else >> 717 { >> 718 return snxt=kInfinity; >> 719 } >> 720 } >> 721 else >> 722 { >> 723 if (std::fabs(yt)<=fDy) >> 724 { >> 725 tmin=0; >> 726 tmax=kInfinity; >> 727 } >> 728 else >> 729 { >> 730 return snxt=kInfinity; >> 731 } 580 } 732 } 581 733 582 // X intersections << 734 // Re-Calc valid intersection range 583 // 735 // 584 G4double tmin2 = tmin1, tmax2 = tmax1; << 736 if (tmin>smin) smin=tmin; 585 G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 737 if (tmax<smax) smax=tmax; 586 G4double disx = fPlanes[2].a*p.x() + fPlanes << 738 if (smax<=smin) 587 G4double dis2 = fPlanes[2].d + disx; << 588 if (dis2 >= -halfCarTolerance) << 589 { 739 { 590 if (cos2 >= 0) return kInfinity; << 740 return snxt=kInfinity; 591 G4double tmp = -dis2/cos2; << 592 if (tmin2 < tmp) tmin2 = tmp; << 593 } 741 } 594 else if (cos2 > 0) << 742 else 595 { 743 { 596 G4double tmp = -dis2/cos2; << 744 // 597 if (tmax2 > tmp) tmax2 = tmp; << 745 // X G4Parallel planes intersection >> 746 // >> 747 xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt; >> 748 vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy; >> 749 if (vx>0) >> 750 { >> 751 max=fDx-xt; >> 752 if (max>kCarTolerance*0.5) >> 753 { >> 754 tmax=max/vx; >> 755 tmin=(-fDx-xt)/vx; >> 756 } >> 757 else >> 758 { >> 759 return snxt=kInfinity; >> 760 } >> 761 } >> 762 else if (vx<0) >> 763 { >> 764 max=-fDx-xt; >> 765 if (max<-kCarTolerance*0.5) >> 766 { >> 767 tmax=max/vx; >> 768 tmin=(fDx-xt)/vx; >> 769 } >> 770 else >> 771 { >> 772 return snxt=kInfinity; >> 773 } >> 774 } >> 775 else >> 776 { >> 777 if (std::fabs(xt)<=fDx) >> 778 { >> 779 tmin=0; >> 780 tmax=kInfinity; >> 781 } >> 782 else >> 783 { >> 784 return snxt=kInfinity; >> 785 } >> 786 } >> 787 if (tmin>smin) smin=tmin; >> 788 if (tmax<smax) smax=tmax; 598 } 789 } 599 790 600 G4double tmin3 = tmin2, tmax3 = tmax2; << 791 if (smax>0&&smin<smax) 601 G4double cos3 = -cos2; << 602 G4double dis3 = fPlanes[3].d - disx; << 603 if (dis3 >= -halfCarTolerance) << 604 { 792 { 605 if (cos3 >= 0) return kInfinity; << 793 if (smin>0) 606 G4double tmp = -dis3/cos3; << 794 { 607 if (tmin3 < tmp) tmin3 = tmp; << 795 snxt=smin; >> 796 } >> 797 else >> 798 { >> 799 snxt=0; >> 800 } 608 } 801 } 609 else if (cos3 > 0) << 802 else 610 { 803 { 611 G4double tmp = -dis3/cos3; << 804 snxt=kInfinity; 612 if (tmax3 > tmp) tmax3 = tmp; << 613 } 805 } 614 << 806 return snxt; 615 // Find distance << 616 // << 617 G4double tmin = tmin3, tmax = tmax3; << 618 if (tmax <= tmin + halfCarTolerance) return << 619 return (tmin < halfCarTolerance ) ? 0. : tmi << 620 } 807 } 621 808 622 ////////////////////////////////////////////// << 809 //////////////////////////////////////////////////////////////////////////// 623 // 810 // 624 // Calculate exact shortest distance to any bo 811 // Calculate exact shortest distance to any boundary from outside 625 // - returns 0 is point inside << 812 // - Returns 0 is point inside 626 813 627 G4double G4Para::DistanceToIn( const G4ThreeVe 814 G4double G4Para::DistanceToIn( const G4ThreeVector& p ) const 628 { 815 { 629 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 816 G4double safe=0.0; 630 G4double dx = std::abs(xx) + fPlanes[2].d; << 817 G4double distz1,distz2,disty1,disty2,distx1,distx2; >> 818 G4double trany,cosy,tranx,cosx; 631 819 632 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 820 // Z planes 633 G4double dy = std::abs(yy) + fPlanes[0].d; << 821 // 634 G4double dxy = std::max(dx,dy); << 822 distz1=p.z()-fDz; >> 823 distz2=-fDz-p.z(); >> 824 if (distz1>distz2) >> 825 { >> 826 safe=distz1; >> 827 } >> 828 else >> 829 { >> 830 safe=distz2; >> 831 } 635 832 636 G4double dz = std::abs(p.z())-fDz; << 833 trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system 637 G4double dist = std::max(dxy,dz); << 834 >> 835 // Transformed x into `box' system >> 836 // >> 837 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi); >> 838 disty1=(trany-fDy)*cosy; >> 839 disty2=(-fDy-trany)*cosy; >> 840 >> 841 if (disty1>safe) safe=disty1; >> 842 if (disty2>safe) safe=disty2; 638 843 639 return (dist > 0) ? dist : 0.; << 844 tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany; >> 845 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi); >> 846 distx1=(tranx-fDx)*cosx; >> 847 distx2=(-fDx-tranx)*cosx; >> 848 >> 849 if (distx1>safe) safe=distx1; >> 850 if (distx2>safe) safe=distx2; >> 851 >> 852 if (safe<0) safe=0; >> 853 return safe; 640 } 854 } 641 855 642 ////////////////////////////////////////////// 856 ////////////////////////////////////////////////////////////////////////// 643 // 857 // 644 // Calculate distance to surface of shape from << 858 // Calculate distance to surface of shape from inside 645 // find normal at exit point << 859 // Calculate distance to x/y/z planes - smallest is exiting distance 646 // - when leaving the surface, return 0 << 647 860 648 G4double G4Para::DistanceToOut(const G4ThreeVe 861 G4double G4Para::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v, 649 const G4bool ca 862 const G4bool calcNorm, 650 G4bool* v << 863 G4bool *validNorm, G4ThreeVector *n) const 651 { 864 { 652 // Z intersections << 865 ESide side = kUndef; >> 866 G4double snxt; // snxt = return value >> 867 G4double max,tmax; >> 868 G4double yt,vy,xt,vx; >> 869 >> 870 G4double ycomp,calpha,salpha,tntheta,cosntheta; >> 871 >> 872 // >> 873 // Z Intersections 653 // 874 // 654 if ((std::abs(p.z()) - fDz) >= -halfCarToler << 875 >> 876 if (v.z()>0) 655 { 877 { 656 if (calcNorm) << 878 max=fDz-p.z(); >> 879 if (max>kCarTolerance*0.5) 657 { 880 { 658 *validNorm = true; << 881 snxt=max/v.z(); 659 n->set(0, 0, (p.z() < 0) ? -1 : 1); << 882 side=kPZ; >> 883 } >> 884 else >> 885 { >> 886 if (calcNorm) >> 887 { >> 888 *validNorm=true; >> 889 *n=G4ThreeVector(0,0,1); >> 890 } >> 891 return snxt=0; 660 } 892 } 661 return 0.; << 662 } 893 } 663 G4double vz = v.z(); << 894 else if (v.z()<0) 664 G4double tmax = (vz == 0) ? DBL_MAX : (std:: << 665 G4int iside = (vz < 0) ? -4 : -2; // little << 666 << 667 // Y intersections << 668 // << 669 G4double cos0 = fPlanes[0].b*v.y() + fPlanes << 670 if (cos0 > 0) << 671 { 895 { 672 G4double dis0 = fPlanes[0].b*p.y() + fPlan << 896 max=-fDz-p.z(); 673 if (dis0 >= -halfCarTolerance) << 897 if (max<-kCarTolerance*0.5) >> 898 { >> 899 snxt=max/v.z(); >> 900 side=kMZ; >> 901 } >> 902 else 674 { 903 { 675 if (calcNorm) 904 if (calcNorm) 676 { 905 { 677 *validNorm = true; << 906 *validNorm=true; 678 n->set(0, fPlanes[0].b, fPlanes[0].c); << 907 *n=G4ThreeVector(0,0,-1); 679 } 908 } 680 return 0.; << 909 return snxt=0; 681 } 910 } 682 G4double tmp = -dis0/cos0; << 683 if (tmax > tmp) { tmax = tmp; iside = 0; } << 684 } 911 } >> 912 else >> 913 { >> 914 snxt=kInfinity; >> 915 } >> 916 >> 917 // >> 918 // Y plane intersection >> 919 // >> 920 >> 921 yt=p.y()-fTthetaSphi*p.z(); >> 922 vy=v.y()-fTthetaSphi*v.z(); 685 923 686 G4double cos1 = -cos0; << 924 if (vy>0) 687 if (cos1 > 0) << 688 { 925 { 689 G4double dis1 = fPlanes[1].b*p.y() + fPlan << 926 max=fDy-yt; 690 if (dis1 >= -halfCarTolerance) << 927 if (max>kCarTolerance*0.5) >> 928 { >> 929 tmax=max/vy; >> 930 if (tmax<snxt) >> 931 { >> 932 snxt=tmax; >> 933 side=kPY; >> 934 } >> 935 } >> 936 else 691 { 937 { 692 if (calcNorm) 938 if (calcNorm) >> 939 { >> 940 *validNorm=true; // Leaving via plus Y >> 941 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 942 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 943 } >> 944 return snxt=0; >> 945 } >> 946 } >> 947 else if (vy<0) >> 948 { >> 949 max=-fDy-yt; >> 950 if (max<-kCarTolerance*0.5) >> 951 { >> 952 tmax=max/vy; >> 953 if (tmax<snxt) 693 { 954 { 694 *validNorm = true; << 955 snxt=tmax; 695 n->set(0, fPlanes[1].b, fPlanes[1].c); << 956 side=kMY; 696 } 957 } 697 return 0.; << 698 } 958 } 699 G4double tmp = -dis1/cos1; << 959 else 700 if (tmax > tmp) { tmax = tmp; iside = 1; } << 960 { >> 961 if (calcNorm) >> 962 { >> 963 *validNorm=true; // Leaving via minus Y >> 964 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 965 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 966 } >> 967 return snxt=0; >> 968 } 701 } 969 } 702 970 703 // X intersections << 704 // 971 // 705 G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 972 // X plane intersection 706 if (cos2 > 0) << 973 // >> 974 >> 975 xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt; >> 976 vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy; >> 977 if (vx>0) 707 { 978 { 708 G4double dis2 = fPlanes[2].a*p.x()+fPlanes << 979 max=fDx-xt; 709 if (dis2 >= -halfCarTolerance) << 980 if (max>kCarTolerance*0.5) >> 981 { >> 982 tmax=max/vx; >> 983 if (tmax<snxt) >> 984 { >> 985 snxt=tmax; >> 986 side=kPX; >> 987 } >> 988 } >> 989 else 710 { 990 { 711 if (calcNorm) 991 if (calcNorm) 712 { 992 { 713 *validNorm = true; << 993 *validNorm=true; // Leaving via plus X 714 n->set(fPlanes[2].a, fPlanes[2].b, fP << 994 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 995 salpha=-calpha*fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 996 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 997 cosntheta=1/std::sqrt(1+tntheta*tntheta); >> 998 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); 715 } 999 } 716 return 0.; << 1000 return snxt=0; 717 } 1001 } 718 G4double tmp = -dis2/cos2; << 719 if (tmax > tmp) { tmax = tmp; iside = 2; } << 720 } 1002 } 721 << 1003 else if (vx<0) 722 G4double cos3 = -cos2; << 723 if (cos3 > 0) << 724 { 1004 { 725 G4double dis3 = fPlanes[3].a*p.x()+fPlanes << 1005 max=-fDx-xt; 726 if (dis3 >= -halfCarTolerance) << 1006 if (max<-kCarTolerance*0.5) >> 1007 { >> 1008 tmax=max/vx; >> 1009 if (tmax<snxt) >> 1010 { >> 1011 snxt=tmax; >> 1012 side=kMX; >> 1013 } >> 1014 } >> 1015 else 727 { 1016 { 728 if (calcNorm) 1017 if (calcNorm) 729 { 1018 { 730 *validNorm = true; << 1019 *validNorm=true; // Leaving via minus X 731 n->set(fPlanes[3].a, fPlanes[3].b, fP << 1020 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 1021 salpha=-calpha*fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 1022 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 1023 cosntheta=-1/std::sqrt(1+tntheta*tntheta); >> 1024 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); 732 } 1025 } 733 return 0.; << 1026 return snxt=0; 734 } 1027 } 735 G4double tmp = -dis3/cos3; << 736 if (tmax > tmp) { tmax = tmp; iside = 3; } << 737 } 1028 } 738 1029 739 // Set normal, if required, and return dista << 1030 if (calcNorm) 740 // << 741 if (calcNorm) << 742 { 1031 { 743 *validNorm = true; << 1032 *validNorm=true; 744 if (iside < 0) << 1033 switch (side) 745 n->set(0, 0, iside + 3); // (-4+3)=-1, ( << 1034 { 746 else << 1035 case kMZ: 747 n->set(fPlanes[iside].a, fPlanes[iside]. << 1036 *n=G4ThreeVector(0,0,-1); >> 1037 break; >> 1038 case kPZ: >> 1039 *n=G4ThreeVector(0,0,1); >> 1040 break; >> 1041 case kMY: >> 1042 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 1043 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 1044 break; >> 1045 case kPY: >> 1046 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 1047 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 1048 break; >> 1049 case kMX: >> 1050 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 1051 salpha=-calpha*fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 1052 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 1053 cosntheta=-1/std::sqrt(1+tntheta*tntheta); >> 1054 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 1055 break; >> 1056 case kPX: >> 1057 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 1058 salpha=-calpha*fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 1059 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 1060 cosntheta=1/std::sqrt(1+tntheta*tntheta); >> 1061 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 1062 break; >> 1063 default: >> 1064 DumpInfo(); >> 1065 G4Exception("G4Para::DistanceToOut(p,v,..)", >> 1066 "GeomSolids1002",JustWarning, >> 1067 "Undefined side for valid surface normal to solid."); >> 1068 break; >> 1069 } 748 } 1070 } 749 return tmax; << 1071 return snxt; 750 } 1072 } 751 1073 752 ////////////////////////////////////////////// << 1074 ///////////////////////////////////////////////////////////////////////////// 753 // 1075 // 754 // Calculate exact shortest distance to any bo 1076 // Calculate exact shortest distance to any boundary from inside 755 // - returns 0 is point outside << 1077 // - Returns 0 is point outside 756 1078 757 G4double G4Para::DistanceToOut( const G4ThreeV 1079 G4double G4Para::DistanceToOut( const G4ThreeVector& p ) const 758 { 1080 { >> 1081 G4double safe=0.0; >> 1082 G4double distz1,distz2,disty1,disty2,distx1,distx2; >> 1083 G4double trany,cosy,tranx,cosx; >> 1084 759 #ifdef G4CSGDEBUG 1085 #ifdef G4CSGDEBUG 760 if( Inside(p) == kOutside ) 1086 if( Inside(p) == kOutside ) 761 { 1087 { 762 std::ostringstream message; << 1088 G4int oldprc = G4cout.precision(16) ; 763 G4int oldprc = message.precision(16); << 1089 G4cout << G4endl ; 764 message << "Point p is outside (!?) of sol << 1090 DumpInfo(); 765 message << "Position:\n"; << 1091 G4cout << "Position:" << G4endl << G4endl ; 766 message << " p.x() = " << p.x()/mm << " << 1092 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl ; 767 message << " p.y() = " << p.y()/mm << " << 1093 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl ; 768 message << " p.z() = " << p.z()/mm << " << 1094 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl ; 769 G4cout.precision(oldprc) ; << 1095 G4cout.precision(oldprc) ; 770 G4Exception("G4Para::DistanceToOut(p)", "G << 1096 G4Exception("G4Para::DistanceToOut(p)", "GeomSolids1002", 771 JustWarning, message ); << 1097 JustWarning, "Point p is outside !?" ); 772 DumpInfo(); << 1098 } 773 } << 774 #endif 1099 #endif 775 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 776 G4double dx = std::abs(xx) + fPlanes[2].d; << 777 1100 778 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 1101 // Z planes 779 G4double dy = std::abs(yy) + fPlanes[0].d; << 1102 // 780 G4double dxy = std::max(dx,dy); << 1103 distz1=fDz-p.z(); >> 1104 distz2=fDz+p.z(); >> 1105 if (distz1<distz2) >> 1106 { >> 1107 safe=distz1; >> 1108 } >> 1109 else >> 1110 { >> 1111 safe=distz2; >> 1112 } 781 1113 782 G4double dz = std::abs(p.z())-fDz; << 1114 trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system 783 G4double dist = std::max(dxy,dz); << 784 1115 785 return (dist < 0) ? -dist : 0.; << 1116 // Transformed x into `box' system >> 1117 // >> 1118 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi); >> 1119 disty1=(fDy-trany)*cosy; >> 1120 disty2=(fDy+trany)*cosy; >> 1121 >> 1122 if (disty1<safe) safe=disty1; >> 1123 if (disty2<safe) safe=disty2; >> 1124 >> 1125 tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany; >> 1126 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi); >> 1127 distx1=(fDx-tranx)*cosx; >> 1128 distx2=(fDx+tranx)*cosx; >> 1129 >> 1130 if (distx1<safe) safe=distx1; >> 1131 if (distx2<safe) safe=distx2; >> 1132 >> 1133 if (safe<0) safe=0; >> 1134 return safe; 786 } 1135 } 787 1136 788 ////////////////////////////////////////////// << 1137 //////////////////////////////////////////////////////////////////////////////// 789 // 1138 // 790 // GetEntityType << 1139 // Create a List containing the transformed vertices 791 << 1140 // Ordering [0-3] -fDz cross section 792 G4GeometryType G4Para::GetEntityType() const << 1141 // [4-7] +fDz cross section such that [0] is below [4], 793 { << 1142 // [1] below [5] etc. 794 return {"G4Para"}; << 1143 // Note: >> 1144 // Caller has deletion resposibility >> 1145 >> 1146 G4ThreeVectorList* >> 1147 G4Para::CreateRotatedVertices( const G4AffineTransform& pTransform ) const >> 1148 { >> 1149 G4ThreeVectorList *vertices; >> 1150 vertices=new G4ThreeVectorList(); >> 1151 if (vertices) >> 1152 { >> 1153 vertices->reserve(8); >> 1154 G4ThreeVector vertex0(-fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1155 -fDz*fTthetaSphi-fDy, -fDz); >> 1156 G4ThreeVector vertex1(-fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1157 -fDz*fTthetaSphi-fDy, -fDz); >> 1158 G4ThreeVector vertex2(-fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1159 -fDz*fTthetaSphi+fDy, -fDz); >> 1160 G4ThreeVector vertex3(-fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1161 -fDz*fTthetaSphi+fDy, -fDz); >> 1162 G4ThreeVector vertex4(+fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1163 +fDz*fTthetaSphi-fDy, +fDz); >> 1164 G4ThreeVector vertex5(+fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1165 +fDz*fTthetaSphi-fDy, +fDz); >> 1166 G4ThreeVector vertex6(+fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1167 +fDz*fTthetaSphi+fDy, +fDz); >> 1168 G4ThreeVector vertex7(+fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1169 +fDz*fTthetaSphi+fDy, +fDz); >> 1170 >> 1171 vertices->push_back(pTransform.TransformPoint(vertex0)); >> 1172 vertices->push_back(pTransform.TransformPoint(vertex1)); >> 1173 vertices->push_back(pTransform.TransformPoint(vertex2)); >> 1174 vertices->push_back(pTransform.TransformPoint(vertex3)); >> 1175 vertices->push_back(pTransform.TransformPoint(vertex4)); >> 1176 vertices->push_back(pTransform.TransformPoint(vertex5)); >> 1177 vertices->push_back(pTransform.TransformPoint(vertex6)); >> 1178 vertices->push_back(pTransform.TransformPoint(vertex7)); >> 1179 } >> 1180 else >> 1181 { >> 1182 DumpInfo(); >> 1183 G4Exception("G4Para::CreateRotatedVertices()", >> 1184 "GeomSolids0003", FatalException, >> 1185 "Error in allocation of vertices. Out of memory !"); >> 1186 } >> 1187 return vertices; 795 } 1188 } 796 1189 797 ////////////////////////////////////////////// 1190 ////////////////////////////////////////////////////////////////////////// 798 // 1191 // 799 // IsFaceted << 1192 // GetEntityType 800 1193 801 G4bool G4Para::IsFaceted() const << 1194 G4GeometryType G4Para::GetEntityType() const 802 { 1195 { 803 return true; << 1196 return G4String("G4Para"); 804 } 1197 } 805 1198 806 ////////////////////////////////////////////// 1199 ////////////////////////////////////////////////////////////////////////// 807 // 1200 // 808 // Make a clone of the object 1201 // Make a clone of the object 809 // 1202 // 810 G4VSolid* G4Para::Clone() const 1203 G4VSolid* G4Para::Clone() const 811 { 1204 { 812 return new G4Para(*this); 1205 return new G4Para(*this); 813 } 1206 } 814 1207 815 ////////////////////////////////////////////// 1208 ////////////////////////////////////////////////////////////////////////// 816 // 1209 // 817 // Stream object contents to an output stream 1210 // Stream object contents to an output stream 818 1211 819 std::ostream& G4Para::StreamInfo( std::ostream 1212 std::ostream& G4Para::StreamInfo( std::ostream& os ) const 820 { 1213 { 821 G4double alpha = std::atan(fTalpha); << 1214 G4int oldprc = os.precision(16); 822 G4double theta = std::atan(std::sqrt(fTtheta << 823 fTtheta << 824 G4double phi = std::atan2(fTthetaSphi,fTth << 825 << 826 G4long oldprc = os.precision(16); << 827 os << "------------------------------------- 1215 os << "-----------------------------------------------------------\n" 828 << " *** Dump for solid - " << GetName 1216 << " *** Dump for solid - " << GetName() << " ***\n" 829 << " ================================= 1217 << " ===================================================\n" 830 << " Solid type: G4Para\n" 1218 << " Solid type: G4Para\n" 831 << " Parameters:\n" << 1219 << " Parameters: \n" 832 << " half length X: " << fDx/mm << " m << 1220 << " half length X: " << fDx/mm << " mm \n" 833 << " half length Y: " << fDy/mm << " m << 1221 << " half length Y: " << fDy/mm << " mm \n" 834 << " half length Z: " << fDz/mm << " m << 1222 << " half length Z: " << fDz/mm << " mm \n" 835 << " alpha: " << alpha/degree << "degr << 1223 << " std::tan(alpha) : " << fTalpha/degree << " degrees \n" 836 << " theta: " << theta/degree << "degr << 1224 << " std::tan(theta)*std::cos(phi): " << fTthetaCphi/degree 837 << " phi: " << phi/degree << "degrees\ << 1225 << " degrees \n" >> 1226 << " std::tan(theta)*std::sin(phi): " << fTthetaSphi/degree >> 1227 << " degrees \n" 838 << "------------------------------------- 1228 << "-----------------------------------------------------------\n"; 839 os.precision(oldprc); 1229 os.precision(oldprc); 840 1230 841 return os; 1231 return os; 842 } 1232 } 843 1233 844 ////////////////////////////////////////////// << 1234 ////////////////////////////////////////////////////////////////////////////// >> 1235 // >> 1236 // GetPointOnPlane >> 1237 // Auxiliary method for Get Point on Surface 845 // 1238 // 846 // Return a point randomly and uniformly selec << 847 1239 848 G4ThreeVector G4Para::GetPointOnSurface() cons << 1240 G4ThreeVector G4Para::GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, >> 1241 G4ThreeVector p2, G4ThreeVector p3, >> 1242 G4double& area) const 849 { 1243 { 850 G4double DyTalpha = fDy*fTalpha; << 1244 G4double lambda1, lambda2, chose, aOne, aTwo; 851 G4double DzTthetaSphi = fDz*fTthetaSphi; << 1245 G4ThreeVector t, u, v, w, Area, normal; 852 G4double DzTthetaCphi = fDz*fTthetaCphi; << 1246 853 << 1247 t = p1 - p0; 854 // Set vertices << 1248 u = p2 - p1; 855 // << 1249 v = p3 - p2; 856 G4ThreeVector pt[8]; << 1250 w = p0 - p3; 857 pt[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTth << 1251 858 pt[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTth << 1252 Area = G4ThreeVector(w.y()*v.z() - w.z()*v.y(), 859 pt[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTth << 1253 w.z()*v.x() - w.x()*v.z(), 860 pt[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTth << 1254 w.x()*v.y() - w.y()*v.x()); 861 pt[4].set( DzTthetaCphi-DyTalpha-fDx, DzTth << 1255 862 pt[5].set( DzTthetaCphi-DyTalpha+fDx, DzTth << 1256 aOne = 0.5*Area.mag(); 863 pt[6].set( DzTthetaCphi+DyTalpha-fDx, DzTth << 1257 864 pt[7].set( DzTthetaCphi+DyTalpha+fDx, DzTth << 1258 Area = G4ThreeVector(t.y()*u.z() - t.z()*u.y(), 865 << 1259 t.z()*u.x() - t.x()*u.z(), 866 // Set areas (-Z, -Y, +Y, -X, +X, +Z) << 1260 t.x()*u.y() - t.y()*u.x()); 867 // << 1261 868 G4ThreeVector vx(fDx, 0, 0); << 1262 aTwo = 0.5*Area.mag(); 869 G4ThreeVector vy(DyTalpha, fDy, 0); << 870 G4ThreeVector vz(DzTthetaCphi, DzTthetaSphi, << 871 << 872 G4double sxy = fDx*fDy; // (vx.cross(vy)).ma << 873 G4double sxz = (vx.cross(vz)).mag(); << 874 G4double syz = (vy.cross(vz)).mag(); << 875 1263 876 G4double sface[6] = { sxy, syz, syz, sxz, sx << 1264 area = aOne + aTwo; 877 for (G4int i=1; i<6; ++i) { sface[i] += sfac << 1265 >> 1266 chose = G4RandFlat::shoot(0.,aOne+aTwo); 878 1267 879 // Select face << 1268 if( (chose>=0.) && (chose < aOne) ) 880 // << 1269 { 881 G4double select = sface[5]*G4UniformRand(); << 1270 lambda1 = G4RandFlat::shoot(0.,1.); 882 G4int k = 5; << 1271 lambda2 = G4RandFlat::shoot(0.,lambda1); 883 if (select <= sface[4]) k = 4; << 1272 return (p2+lambda1*v+lambda2*w); 884 if (select <= sface[3]) k = 3; << 1273 } 885 if (select <= sface[2]) k = 2; << 1274 886 if (select <= sface[1]) k = 1; << 1275 // else 887 if (select <= sface[0]) k = 0; << 1276 888 << 1277 lambda1 = G4RandFlat::shoot(0.,1.); 889 // Generate point << 1278 lambda2 = G4RandFlat::shoot(0.,lambda1); 890 // << 1279 return (p0+lambda1*t+lambda2*u); 891 G4int ip[6][3] = {{0,1,2}, {0,4,1}, {2,3,6}, << 892 G4double u = G4UniformRand(); << 893 G4double v = G4UniformRand(); << 894 return (1.-u-v)*pt[ip[k][0]] + u*pt[ip[k][1] << 895 } 1280 } 896 1281 897 ////////////////////////////////////////////// << 1282 ///////////////////////////////////////////////////////////////////////// >> 1283 // >> 1284 // GetPointOnSurface >> 1285 // >> 1286 // Return a point (G4ThreeVector) randomly and uniformly >> 1287 // selected on the solid surface >> 1288 >> 1289 G4ThreeVector G4Para::GetPointOnSurface() const >> 1290 { >> 1291 G4ThreeVector One, Two, Three, Four, Five, Six; >> 1292 G4ThreeVector pt[8] ; >> 1293 G4double chose, aOne, aTwo, aThree, aFour, aFive, aSix; >> 1294 >> 1295 pt[0] = G4ThreeVector(-fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1296 -fDz*fTthetaSphi-fDy, -fDz); >> 1297 pt[1] = G4ThreeVector(-fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1298 -fDz*fTthetaSphi-fDy, -fDz); >> 1299 pt[2] = G4ThreeVector(-fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1300 -fDz*fTthetaSphi+fDy, -fDz); >> 1301 pt[3] = G4ThreeVector(-fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1302 -fDz*fTthetaSphi+fDy, -fDz); >> 1303 pt[4] = G4ThreeVector(+fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1304 +fDz*fTthetaSphi-fDy, +fDz); >> 1305 pt[5] = G4ThreeVector(+fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1306 +fDz*fTthetaSphi-fDy, +fDz); >> 1307 pt[6] = G4ThreeVector(+fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1308 +fDz*fTthetaSphi+fDy, +fDz); >> 1309 pt[7] = G4ThreeVector(+fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1310 +fDz*fTthetaSphi+fDy, +fDz); >> 1311 >> 1312 // make sure we provide the points in a clockwise fashion >> 1313 >> 1314 One = GetPointOnPlane(pt[0],pt[1],pt[3],pt[2], aOne); >> 1315 Two = GetPointOnPlane(pt[4],pt[5],pt[7],pt[6], aTwo); >> 1316 Three = GetPointOnPlane(pt[6],pt[7],pt[3],pt[2], aThree); >> 1317 Four = GetPointOnPlane(pt[4],pt[5],pt[1],pt[0], aFour); >> 1318 Five = GetPointOnPlane(pt[0],pt[2],pt[6],pt[4], aFive); >> 1319 Six = GetPointOnPlane(pt[1],pt[3],pt[7],pt[5], aSix); >> 1320 >> 1321 chose = G4RandFlat::shoot(0.,aOne+aTwo+aThree+aFour+aFive+aSix); >> 1322 >> 1323 if( (chose>=0.) && (chose<aOne) ) >> 1324 { return One; } >> 1325 else if(chose>=aOne && chose<aOne+aTwo) >> 1326 { return Two; } >> 1327 else if(chose>=aOne+aTwo && chose<aOne+aTwo+aThree) >> 1328 { return Three; } >> 1329 else if(chose>=aOne+aTwo+aThree && chose<aOne+aTwo+aThree+aFour) >> 1330 { return Four; } >> 1331 else if(chose>=aOne+aTwo+aThree+aFour && chose<aOne+aTwo+aThree+aFour+aFive) >> 1332 { return Five; } >> 1333 return Six; >> 1334 } >> 1335 >> 1336 //////////////////////////////////////////////////////////////////////////// 898 // 1337 // 899 // Methods for visualisation 1338 // Methods for visualisation 900 1339 901 void G4Para::DescribeYourselfTo ( G4VGraphicsS 1340 void G4Para::DescribeYourselfTo ( G4VGraphicsScene& scene ) const 902 { 1341 { 903 scene.AddSolid (*this); 1342 scene.AddSolid (*this); 904 } 1343 } 905 1344 906 G4Polyhedron* G4Para::CreatePolyhedron () cons 1345 G4Polyhedron* G4Para::CreatePolyhedron () const 907 { 1346 { 908 G4double phi = std::atan2(fTthetaSphi, fTthe 1347 G4double phi = std::atan2(fTthetaSphi, fTthetaCphi); 909 G4double alpha = std::atan(fTalpha); 1348 G4double alpha = std::atan(fTalpha); 910 G4double theta = std::atan(std::sqrt(fTtheta << 1349 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi 911 fTtheta << 1350 +fTthetaSphi*fTthetaSphi)); 912 1351 913 return new G4PolyhedronPara(fDx, fDy, fDz, a 1352 return new G4PolyhedronPara(fDx, fDy, fDz, alpha, theta, phi); 914 } 1353 } 915 #endif << 916 1354