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 83572 2014-09-01 15:23:27Z 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; 416 442 417 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 443 yt1 = p.y() - fTthetaSphi*p.z(); 418 G4double dy = std::abs(yy) + fPlanes[0].d; << 444 yt = std::fabs(yt1) ; 419 G4double dxy = std::max(dx,dy); << 420 445 421 G4double dz = std::abs(p.z())-fDz; << 446 // xt = std::fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt ); 422 G4double dist = std::max(dxy,dz); << 423 447 424 if (dist > halfCarTolerance) return kOutside << 448 xt = std::fabs( p.x() - fTthetaCphi*p.z() - fTalpha*yt1 ); 425 return (dist > -halfCarTolerance) ? kSurface << 449 >> 450 if ( std::fabs( p.z() ) <= fDz - kCarTolerance*0.5) >> 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; >> 487 >> 488 newpx = p.x()-fTthetaCphi*p.z(); >> 489 newpy = p.y()-fTthetaSphi*p.z(); >> 490 >> 491 calpha = 1/std::sqrt(1+fTalpha*fTalpha); >> 492 if (fTalpha) {salpha = -calpha*fTalpha;} // NOTE: using MINUS std::sin(alpha) >> 493 else {salpha = 0.;} >> 494 >> 495 // xshift = newpx*calpha+newpy*salpha; >> 496 xshift = newpx - newpy*fTalpha; 435 497 436 // Check Z faces << 498 // distx = std::fabs(std::fabs(xshift)-fDx*calpha); 437 // << 499 distx = std::fabs(std::fabs(xshift)-fDx); 438 G4double nz = 0; << 500 disty = std::fabs(std::fabs(newpy)-fDy); 439 G4double dz = std::abs(p.z()) - fDz; << 501 distz = std::fabs(std::fabs(p.z())-fDz); 440 if (std::abs(dz) <= halfCarTolerance) << 441 { << 442 nz = (p.z() < 0) ? -1 : 1; << 443 ++nsurf; << 444 } << 445 502 446 // Check Y faces << 503 tntheta = fTthetaCphi*calpha + fTthetaSphi*salpha; 447 // << 504 cosntheta = 1/std::sqrt(1+tntheta*tntheta); 448 G4double ny = 0; << 505 ycomp = 1/std::sqrt(1+fTthetaSphi*fTthetaSphi); 449 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 506 450 if (std::abs(fPlanes[0].d + yy) <= halfCarTo << 507 G4ThreeVector nX = G4ThreeVector( calpha*cosntheta, 451 { << 508 salpha*cosntheta, 452 ny = fPlanes[0].b; << 509 -tntheta*cosntheta); 453 nz += fPlanes[0].c; << 510 G4ThreeVector nY = G4ThreeVector( 0, ycomp,-fTthetaSphi*ycomp); 454 ++nsurf; << 511 G4ThreeVector nZ = G4ThreeVector( 0, 0, 1.0); 455 } << 512 456 else if (std::abs(fPlanes[1].d - yy) <= half << 513 if (distx <= delta) 457 { 514 { 458 ny = fPlanes[1].b; << 515 noSurfaces ++; 459 nz += fPlanes[1].c; << 516 if ( xshift >= 0.) {sumnorm += nX;} 460 ++nsurf; << 517 else {sumnorm -= nX;} 461 } 518 } 462 << 519 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 { 520 { 469 nx = fPlanes[2].a; << 521 noSurfaces ++; 470 ny += fPlanes[2].b; << 522 if ( newpy >= 0.) {sumnorm += nY;} 471 nz += fPlanes[2].c; << 523 else {sumnorm -= nY;} 472 ++nsurf; << 473 } 524 } 474 else if (std::abs(fPlanes[3].d - xx) <= half << 525 if (distz <= delta) 475 { 526 { 476 nx = fPlanes[3].a; << 527 noSurfaces ++; 477 ny += fPlanes[3].b; << 528 if ( p.z() >= 0.) {sumnorm += nZ;} 478 nz += fPlanes[3].c; << 529 else {sumnorm -= nZ;} 479 ++nsurf; << 480 } 530 } 481 << 531 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 { 532 { 488 // Point is not on the surface << 489 // << 490 #ifdef G4CSGDEBUG 533 #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 534 G4Exception("G4Para::SurfaceNormal(p)", "GeomSolids1002", 501 JustWarning, message ); << 535 JustWarning, "Point p is not on surface !?" ); 502 DumpInfo(); << 536 #endif 503 #endif << 537 norm = ApproxSurfaceNormal(p); 504 return ApproxSurfaceNormal(p); << 505 } 538 } >> 539 else if ( noSurfaces == 1 ) {norm = sumnorm;} >> 540 else {norm = sumnorm.unit();} >> 541 >> 542 return norm; 506 } 543 } 507 544 508 ////////////////////////////////////////////// << 545 >> 546 //////////////////////////////////////////////////////////////////////// 509 // 547 // 510 // Algorithm for SurfaceNormal() following the 548 // Algorithm for SurfaceNormal() following the original specification 511 // for points not on the surface 549 // for points not on the surface 512 550 513 G4ThreeVector G4Para::ApproxSurfaceNormal( con 551 G4ThreeVector G4Para::ApproxSurfaceNormal( const G4ThreeVector& p ) const 514 { 552 { 515 G4double dist = -DBL_MAX; << 553 ENSide side; 516 G4int iside = 0; << 554 G4ThreeVector norm; 517 for (G4int i=0; i<4; ++i) << 555 G4double distx,disty,distz; >> 556 G4double newpx,newpy,xshift; >> 557 G4double calpha,salpha; // Sin/Cos(alpha) - needed to recalc G4Parameter >> 558 G4double tntheta,cosntheta; // tan and cos of normal's theta component >> 559 G4double ycomp; >> 560 >> 561 newpx=p.x()-fTthetaCphi*p.z(); >> 562 newpy=p.y()-fTthetaSphi*p.z(); >> 563 >> 564 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 565 if (fTalpha) >> 566 { >> 567 salpha=-calpha/fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 568 } >> 569 else 518 { 570 { 519 G4double d = fPlanes[i].a*p.x() + << 571 salpha=0; 520 fPlanes[i].b*p.y() + << 521 fPlanes[i].c*p.z() + fPlanes[ << 522 if (d > dist) { dist = d; iside = i; } << 523 } 572 } 524 573 525 G4double distz = std::abs(p.z()) - fDz; << 574 xshift=newpx*calpha+newpy*salpha; 526 if (dist > distz) << 575 527 return { fPlanes[iside].a, fPlanes[iside]. << 576 distx=std::fabs(std::fabs(xshift)-fDx*calpha); >> 577 disty=std::fabs(std::fabs(newpy)-fDy); >> 578 distz=std::fabs(std::fabs(p.z())-fDz); >> 579 >> 580 if (distx<disty) >> 581 { >> 582 if (distx<distz) {side=kNX;} >> 583 else {side=kNZ;} >> 584 } 528 else 585 else 529 return { 0, 0, (G4double)((p.z() < 0) ? -1 << 586 { >> 587 if (disty<distz) {side=kNY;} >> 588 else {side=kNZ;} >> 589 } >> 590 >> 591 switch (side) >> 592 { >> 593 case kNX: >> 594 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 595 if (xshift<0) >> 596 { >> 597 cosntheta=-1/std::sqrt(1+tntheta*tntheta); >> 598 } >> 599 else >> 600 { >> 601 cosntheta=1/std::sqrt(1+tntheta*tntheta); >> 602 } >> 603 norm=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 604 break; >> 605 case kNY: >> 606 if (newpy<0) >> 607 { >> 608 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 609 } >> 610 else >> 611 { >> 612 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 613 } >> 614 norm=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 615 break; >> 616 case kNZ: // Closest to Z >> 617 if (p.z()>=0) >> 618 { >> 619 norm=G4ThreeVector(0,0,1); >> 620 } >> 621 else >> 622 { >> 623 norm=G4ThreeVector(0,0,-1); >> 624 } >> 625 break; >> 626 } >> 627 return norm; 530 } 628 } 531 629 532 ////////////////////////////////////////////// << 630 ////////////////////////////////////////////////////////////////////////////// 533 // 631 // 534 // Calculate distance to shape from outside 632 // Calculate distance to shape from outside 535 // - return kInfinity if no intersection << 633 // - return kInfinity if no intersection 536 << 634 // 537 G4double G4Para::DistanceToIn(const G4ThreeVec << 635 // ALGORITHM: 538 const G4ThreeVec << 636 // For each component, calculate pair of minimum and maximum intersection 539 { << 637 // values for which the particle is in the extent of the shape 540 // Z intersections << 638 // - The smallest (MAX minimum) allowed distance of the pairs is intersect >> 639 // - Z plane intersectin uses tolerance >> 640 // - XZ YZ planes use logic & *SLIGHTLY INCORRECT* tolerance >> 641 // (this saves at least 1 sqrt, 1 multiply and 1 divide... in applicable >> 642 // cases) >> 643 // - Note: XZ and YZ planes each divide space into four regions, >> 644 // characterised by ss1 ss2 >> 645 >> 646 G4double G4Para::DistanceToIn( const G4ThreeVector& p, >> 647 const G4ThreeVector& v ) const >> 648 { >> 649 G4double snxt; // snxt = default return value >> 650 G4double smin,smax; >> 651 G4double tmin,tmax; >> 652 G4double yt,vy,xt,vx; >> 653 G4double max; 541 // 654 // 542 if ((std::abs(p.z()) - fDz) >= -halfCarToler << 655 // 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 // 656 // 551 G4double tmin0 = tzmin, tmax0 = tzmax; << 657 if (v.z()>0) 552 G4double cos0 = fPlanes[0].b*v.y() + fPlanes << 658 { 553 G4double disy = fPlanes[0].b*p.y() + fPlanes << 659 max=fDz-p.z(); 554 G4double dis0 = fPlanes[0].d + disy; << 660 if (max>kCarTolerance*0.5) 555 if (dis0 >= -halfCarTolerance) << 661 { >> 662 smax=max/v.z(); >> 663 smin=(-fDz-p.z())/v.z(); >> 664 } >> 665 else >> 666 { >> 667 return snxt=kInfinity; >> 668 } >> 669 } >> 670 else if (v.z()<0) 556 { 671 { 557 if (cos0 >= 0) return kInfinity; << 672 max=-fDz-p.z(); 558 G4double tmp = -dis0/cos0; << 673 if (max<-kCarTolerance*0.5) 559 if (tmin0 < tmp) tmin0 = tmp; << 674 { >> 675 smax=max/v.z(); >> 676 smin=(fDz-p.z())/v.z(); >> 677 } >> 678 else >> 679 { >> 680 return snxt=kInfinity; >> 681 } 560 } 682 } 561 else if (cos0 > 0) << 683 else 562 { 684 { 563 G4double tmp = -dis0/cos0; << 685 if (std::fabs(p.z())<=fDz) // Inside 564 if (tmax0 > tmp) tmax0 = tmp; << 686 { >> 687 smin=0; >> 688 smax=kInfinity; >> 689 } >> 690 else >> 691 { >> 692 return snxt=kInfinity; >> 693 } 565 } 694 } >> 695 >> 696 // >> 697 // Y G4Parallel planes intersection >> 698 // >> 699 >> 700 yt=p.y()-fTthetaSphi*p.z(); >> 701 vy=v.y()-fTthetaSphi*v.z(); 566 702 567 G4double tmin1 = tmin0, tmax1 = tmax0; << 703 if (vy>0) 568 G4double cos1 = -cos0; << 569 G4double dis1 = fPlanes[1].d - disy; << 570 if (dis1 >= -halfCarTolerance) << 571 { 704 { 572 if (cos1 >= 0) return kInfinity; << 705 max=fDy-yt; 573 G4double tmp = -dis1/cos1; << 706 if (max>kCarTolerance*0.5) 574 if (tmin1 < tmp) tmin1 = tmp; << 707 { >> 708 tmax=max/vy; >> 709 tmin=(-fDy-yt)/vy; >> 710 } >> 711 else >> 712 { >> 713 return snxt=kInfinity; >> 714 } 575 } 715 } 576 else if (cos1 > 0) << 716 else if (vy<0) 577 { 717 { 578 G4double tmp = -dis1/cos1; << 718 max=-fDy-yt; 579 if (tmax1 > tmp) tmax1 = tmp; << 719 if (max<-kCarTolerance*0.5) >> 720 { >> 721 tmax=max/vy; >> 722 tmin=(fDy-yt)/vy; >> 723 } >> 724 else >> 725 { >> 726 return snxt=kInfinity; >> 727 } >> 728 } >> 729 else >> 730 { >> 731 if (std::fabs(yt)<=fDy) >> 732 { >> 733 tmin=0; >> 734 tmax=kInfinity; >> 735 } >> 736 else >> 737 { >> 738 return snxt=kInfinity; >> 739 } 580 } 740 } 581 741 582 // X intersections << 742 // Re-Calc valid intersection range 583 // 743 // 584 G4double tmin2 = tmin1, tmax2 = tmax1; << 744 if (tmin>smin) smin=tmin; 585 G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 745 if (tmax<smax) smax=tmax; 586 G4double disx = fPlanes[2].a*p.x() + fPlanes << 746 if (smax<=smin) 587 G4double dis2 = fPlanes[2].d + disx; << 588 if (dis2 >= -halfCarTolerance) << 589 { 747 { 590 if (cos2 >= 0) return kInfinity; << 748 return snxt=kInfinity; 591 G4double tmp = -dis2/cos2; << 592 if (tmin2 < tmp) tmin2 = tmp; << 593 } 749 } 594 else if (cos2 > 0) << 750 else 595 { 751 { 596 G4double tmp = -dis2/cos2; << 752 // 597 if (tmax2 > tmp) tmax2 = tmp; << 753 // X G4Parallel planes intersection >> 754 // >> 755 xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt; >> 756 vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy; >> 757 if (vx>0) >> 758 { >> 759 max=fDx-xt; >> 760 if (max>kCarTolerance*0.5) >> 761 { >> 762 tmax=max/vx; >> 763 tmin=(-fDx-xt)/vx; >> 764 } >> 765 else >> 766 { >> 767 return snxt=kInfinity; >> 768 } >> 769 } >> 770 else if (vx<0) >> 771 { >> 772 max=-fDx-xt; >> 773 if (max<-kCarTolerance*0.5) >> 774 { >> 775 tmax=max/vx; >> 776 tmin=(fDx-xt)/vx; >> 777 } >> 778 else >> 779 { >> 780 return snxt=kInfinity; >> 781 } >> 782 } >> 783 else >> 784 { >> 785 if (std::fabs(xt)<=fDx) >> 786 { >> 787 tmin=0; >> 788 tmax=kInfinity; >> 789 } >> 790 else >> 791 { >> 792 return snxt=kInfinity; >> 793 } >> 794 } >> 795 if (tmin>smin) smin=tmin; >> 796 if (tmax<smax) smax=tmax; 598 } 797 } 599 798 600 G4double tmin3 = tmin2, tmax3 = tmax2; << 799 if (smax>0&&smin<smax) 601 G4double cos3 = -cos2; << 602 G4double dis3 = fPlanes[3].d - disx; << 603 if (dis3 >= -halfCarTolerance) << 604 { 800 { 605 if (cos3 >= 0) return kInfinity; << 801 if (smin>0) 606 G4double tmp = -dis3/cos3; << 802 { 607 if (tmin3 < tmp) tmin3 = tmp; << 803 snxt=smin; >> 804 } >> 805 else >> 806 { >> 807 snxt=0; >> 808 } 608 } 809 } 609 else if (cos3 > 0) << 810 else 610 { 811 { 611 G4double tmp = -dis3/cos3; << 812 snxt=kInfinity; 612 if (tmax3 > tmp) tmax3 = tmp; << 613 } 813 } 614 << 814 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 } 815 } 621 816 622 ////////////////////////////////////////////// << 817 //////////////////////////////////////////////////////////////////////////// 623 // 818 // 624 // Calculate exact shortest distance to any bo 819 // Calculate exact shortest distance to any boundary from outside 625 // - returns 0 is point inside << 820 // - Returns 0 is point inside 626 821 627 G4double G4Para::DistanceToIn( const G4ThreeVe 822 G4double G4Para::DistanceToIn( const G4ThreeVector& p ) const 628 { 823 { 629 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 824 G4double safe=0.0; 630 G4double dx = std::abs(xx) + fPlanes[2].d; << 825 G4double distz1,distz2,disty1,disty2,distx1,distx2; >> 826 G4double trany,cosy,tranx,cosx; 631 827 632 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 828 // Z planes 633 G4double dy = std::abs(yy) + fPlanes[0].d; << 829 // 634 G4double dxy = std::max(dx,dy); << 830 distz1=p.z()-fDz; >> 831 distz2=-fDz-p.z(); >> 832 if (distz1>distz2) >> 833 { >> 834 safe=distz1; >> 835 } >> 836 else >> 837 { >> 838 safe=distz2; >> 839 } 635 840 636 G4double dz = std::abs(p.z())-fDz; << 841 trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system 637 G4double dist = std::max(dxy,dz); << 842 >> 843 // Transformed x into `box' system >> 844 // >> 845 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi); >> 846 disty1=(trany-fDy)*cosy; >> 847 disty2=(-fDy-trany)*cosy; >> 848 >> 849 if (disty1>safe) safe=disty1; >> 850 if (disty2>safe) safe=disty2; 638 851 639 return (dist > 0) ? dist : 0.; << 852 tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany; >> 853 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi); >> 854 distx1=(tranx-fDx)*cosx; >> 855 distx2=(-fDx-tranx)*cosx; >> 856 >> 857 if (distx1>safe) safe=distx1; >> 858 if (distx2>safe) safe=distx2; >> 859 >> 860 if (safe<0) safe=0; >> 861 return safe; 640 } 862 } 641 863 642 ////////////////////////////////////////////// 864 ////////////////////////////////////////////////////////////////////////// 643 // 865 // 644 // Calculate distance to surface of shape from << 866 // Calculate distance to surface of shape from inside 645 // find normal at exit point << 867 // Calculate distance to x/y/z planes - smallest is exiting distance 646 // - when leaving the surface, return 0 << 647 868 648 G4double G4Para::DistanceToOut(const G4ThreeVe 869 G4double G4Para::DistanceToOut(const G4ThreeVector& p, const G4ThreeVector& v, 649 const G4bool ca 870 const G4bool calcNorm, 650 G4bool* v << 871 G4bool *validNorm, G4ThreeVector *n) const 651 { 872 { 652 // Z intersections << 873 ESide side = kUndef; >> 874 G4double snxt; // snxt = return value >> 875 G4double max,tmax; >> 876 G4double yt,vy,xt,vx; >> 877 >> 878 G4double ycomp,calpha,salpha,tntheta,cosntheta; >> 879 >> 880 // >> 881 // Z Intersections 653 // 882 // 654 if ((std::abs(p.z()) - fDz) >= -halfCarToler << 883 >> 884 if (v.z()>0) 655 { 885 { 656 if (calcNorm) << 886 max=fDz-p.z(); >> 887 if (max>kCarTolerance*0.5) 657 { 888 { 658 *validNorm = true; << 889 snxt=max/v.z(); 659 n->set(0, 0, (p.z() < 0) ? -1 : 1); << 890 side=kPZ; >> 891 } >> 892 else >> 893 { >> 894 if (calcNorm) >> 895 { >> 896 *validNorm=true; >> 897 *n=G4ThreeVector(0,0,1); >> 898 } >> 899 return snxt=0; 660 } 900 } 661 return 0.; << 662 } 901 } 663 G4double vz = v.z(); << 902 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 { 903 { 672 G4double dis0 = fPlanes[0].b*p.y() + fPlan << 904 max=-fDz-p.z(); 673 if (dis0 >= -halfCarTolerance) << 905 if (max<-kCarTolerance*0.5) >> 906 { >> 907 snxt=max/v.z(); >> 908 side=kMZ; >> 909 } >> 910 else 674 { 911 { 675 if (calcNorm) 912 if (calcNorm) 676 { 913 { 677 *validNorm = true; << 914 *validNorm=true; 678 n->set(0, fPlanes[0].b, fPlanes[0].c); << 915 *n=G4ThreeVector(0,0,-1); 679 } 916 } 680 return 0.; << 917 return snxt=0; 681 } 918 } 682 G4double tmp = -dis0/cos0; << 683 if (tmax > tmp) { tmax = tmp; iside = 0; } << 684 } 919 } >> 920 else >> 921 { >> 922 snxt=kInfinity; >> 923 } >> 924 >> 925 // >> 926 // Y plane intersection >> 927 // >> 928 >> 929 yt=p.y()-fTthetaSphi*p.z(); >> 930 vy=v.y()-fTthetaSphi*v.z(); 685 931 686 G4double cos1 = -cos0; << 932 if (vy>0) 687 if (cos1 > 0) << 688 { 933 { 689 G4double dis1 = fPlanes[1].b*p.y() + fPlan << 934 max=fDy-yt; 690 if (dis1 >= -halfCarTolerance) << 935 if (max>kCarTolerance*0.5) >> 936 { >> 937 tmax=max/vy; >> 938 if (tmax<snxt) >> 939 { >> 940 snxt=tmax; >> 941 side=kPY; >> 942 } >> 943 } >> 944 else 691 { 945 { 692 if (calcNorm) 946 if (calcNorm) >> 947 { >> 948 *validNorm=true; // Leaving via plus Y >> 949 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 950 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 951 } >> 952 return snxt=0; >> 953 } >> 954 } >> 955 else if (vy<0) >> 956 { >> 957 max=-fDy-yt; >> 958 if (max<-kCarTolerance*0.5) >> 959 { >> 960 tmax=max/vy; >> 961 if (tmax<snxt) 693 { 962 { 694 *validNorm = true; << 963 snxt=tmax; 695 n->set(0, fPlanes[1].b, fPlanes[1].c); << 964 side=kMY; 696 } 965 } 697 return 0.; << 698 } 966 } 699 G4double tmp = -dis1/cos1; << 967 else 700 if (tmax > tmp) { tmax = tmp; iside = 1; } << 968 { >> 969 if (calcNorm) >> 970 { >> 971 *validNorm=true; // Leaving via minus Y >> 972 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 973 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 974 } >> 975 return snxt=0; >> 976 } 701 } 977 } 702 978 703 // X intersections << 704 // 979 // 705 G4double cos2 = fPlanes[2].a*v.x() + fPlanes << 980 // X plane intersection 706 if (cos2 > 0) << 981 // >> 982 >> 983 xt=p.x()-fTthetaCphi*p.z()-fTalpha*yt; >> 984 vx=v.x()-fTthetaCphi*v.z()-fTalpha*vy; >> 985 if (vx>0) 707 { 986 { 708 G4double dis2 = fPlanes[2].a*p.x()+fPlanes << 987 max=fDx-xt; 709 if (dis2 >= -halfCarTolerance) << 988 if (max>kCarTolerance*0.5) >> 989 { >> 990 tmax=max/vx; >> 991 if (tmax<snxt) >> 992 { >> 993 snxt=tmax; >> 994 side=kPX; >> 995 } >> 996 } >> 997 else 710 { 998 { 711 if (calcNorm) 999 if (calcNorm) 712 { 1000 { 713 *validNorm = true; << 1001 *validNorm=true; // Leaving via plus X 714 n->set(fPlanes[2].a, fPlanes[2].b, fP << 1002 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 1003 if (fTalpha) >> 1004 { >> 1005 salpha=-calpha/fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 1006 } >> 1007 else >> 1008 { >> 1009 salpha=0; >> 1010 } >> 1011 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 1012 cosntheta=1/std::sqrt(1+tntheta*tntheta); >> 1013 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); 715 } 1014 } 716 return 0.; << 1015 return snxt=0; 717 } 1016 } 718 G4double tmp = -dis2/cos2; << 719 if (tmax > tmp) { tmax = tmp; iside = 2; } << 720 } 1017 } 721 << 1018 else if (vx<0) 722 G4double cos3 = -cos2; << 723 if (cos3 > 0) << 724 { 1019 { 725 G4double dis3 = fPlanes[3].a*p.x()+fPlanes << 1020 max=-fDx-xt; 726 if (dis3 >= -halfCarTolerance) << 1021 if (max<-kCarTolerance*0.5) >> 1022 { >> 1023 tmax=max/vx; >> 1024 if (tmax<snxt) >> 1025 { >> 1026 snxt=tmax; >> 1027 side=kMX; >> 1028 } >> 1029 } >> 1030 else 727 { 1031 { 728 if (calcNorm) 1032 if (calcNorm) 729 { 1033 { 730 *validNorm = true; << 1034 *validNorm=true; // Leaving via minus X 731 n->set(fPlanes[3].a, fPlanes[3].b, fP << 1035 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 1036 if (fTalpha) >> 1037 { >> 1038 salpha=-calpha/fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 1039 } >> 1040 else >> 1041 { >> 1042 salpha=0; >> 1043 } >> 1044 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 1045 cosntheta=-1/std::sqrt(1+tntheta*tntheta); >> 1046 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); 732 } 1047 } 733 return 0.; << 1048 return snxt=0; 734 } 1049 } 735 G4double tmp = -dis3/cos3; << 736 if (tmax > tmp) { tmax = tmp; iside = 3; } << 737 } 1050 } 738 1051 739 // Set normal, if required, and return dista << 1052 if (calcNorm) 740 // << 741 if (calcNorm) << 742 { 1053 { 743 *validNorm = true; << 1054 *validNorm=true; 744 if (iside < 0) << 1055 switch (side) 745 n->set(0, 0, iside + 3); // (-4+3)=-1, ( << 1056 { 746 else << 1057 case kMZ: 747 n->set(fPlanes[iside].a, fPlanes[iside]. << 1058 *n=G4ThreeVector(0,0,-1); >> 1059 break; >> 1060 case kPZ: >> 1061 *n=G4ThreeVector(0,0,1); >> 1062 break; >> 1063 case kMY: >> 1064 ycomp=-1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 1065 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 1066 break; >> 1067 case kPY: >> 1068 ycomp=1/std::sqrt(1+fTthetaSphi*fTthetaSphi); >> 1069 *n=G4ThreeVector(0,ycomp,-fTthetaSphi*ycomp); >> 1070 break; >> 1071 case kMX: >> 1072 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 1073 if (fTalpha) >> 1074 { >> 1075 salpha=-calpha/fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 1076 } >> 1077 else >> 1078 { >> 1079 salpha=0; >> 1080 } >> 1081 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 1082 cosntheta=-1/std::sqrt(1+tntheta*tntheta); >> 1083 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 1084 break; >> 1085 case kPX: >> 1086 calpha=1/std::sqrt(1+fTalpha*fTalpha); >> 1087 if (fTalpha) >> 1088 { >> 1089 salpha=-calpha/fTalpha; // NOTE: actually use MINUS std::sin(alpha) >> 1090 } >> 1091 else >> 1092 { >> 1093 salpha=0; >> 1094 } >> 1095 tntheta=fTthetaCphi*calpha+fTthetaSphi*salpha; >> 1096 cosntheta=1/std::sqrt(1+tntheta*tntheta); >> 1097 *n=G4ThreeVector(calpha*cosntheta,salpha*cosntheta,-tntheta*cosntheta); >> 1098 break; >> 1099 default: >> 1100 DumpInfo(); >> 1101 G4Exception("G4Para::DistanceToOut(p,v,..)", >> 1102 "GeomSolids1002",JustWarning, >> 1103 "Undefined side for valid surface normal to solid."); >> 1104 break; >> 1105 } 748 } 1106 } 749 return tmax; << 1107 return snxt; 750 } 1108 } 751 1109 752 ////////////////////////////////////////////// << 1110 ///////////////////////////////////////////////////////////////////////////// 753 // 1111 // 754 // Calculate exact shortest distance to any bo 1112 // Calculate exact shortest distance to any boundary from inside 755 // - returns 0 is point outside << 1113 // - Returns 0 is point outside 756 1114 757 G4double G4Para::DistanceToOut( const G4ThreeV 1115 G4double G4Para::DistanceToOut( const G4ThreeVector& p ) const 758 { 1116 { >> 1117 G4double safe=0.0; >> 1118 G4double distz1,distz2,disty1,disty2,distx1,distx2; >> 1119 G4double trany,cosy,tranx,cosx; >> 1120 759 #ifdef G4CSGDEBUG 1121 #ifdef G4CSGDEBUG 760 if( Inside(p) == kOutside ) 1122 if( Inside(p) == kOutside ) 761 { 1123 { 762 std::ostringstream message; << 1124 G4int oldprc = G4cout.precision(16) ; 763 G4int oldprc = message.precision(16); << 1125 G4cout << G4endl ; 764 message << "Point p is outside (!?) of sol << 1126 DumpInfo(); 765 message << "Position:\n"; << 1127 G4cout << "Position:" << G4endl << G4endl ; 766 message << " p.x() = " << p.x()/mm << " << 1128 G4cout << "p.x() = " << p.x()/mm << " mm" << G4endl ; 767 message << " p.y() = " << p.y()/mm << " << 1129 G4cout << "p.y() = " << p.y()/mm << " mm" << G4endl ; 768 message << " p.z() = " << p.z()/mm << " << 1130 G4cout << "p.z() = " << p.z()/mm << " mm" << G4endl << G4endl ; 769 G4cout.precision(oldprc) ; << 1131 G4cout.precision(oldprc) ; 770 G4Exception("G4Para::DistanceToOut(p)", "G << 1132 G4Exception("G4Para::DistanceToOut(p)", "GeomSolids1002", 771 JustWarning, message ); << 1133 JustWarning, "Point p is outside !?" ); 772 DumpInfo(); << 1134 } 773 } << 774 #endif 1135 #endif 775 G4double xx = fPlanes[2].a*p.x()+fPlanes[2]. << 776 G4double dx = std::abs(xx) + fPlanes[2].d; << 777 1136 778 G4double yy = fPlanes[0].b*p.y()+fPlanes[0]. << 1137 // Z planes 779 G4double dy = std::abs(yy) + fPlanes[0].d; << 1138 // 780 G4double dxy = std::max(dx,dy); << 1139 distz1=fDz-p.z(); >> 1140 distz2=fDz+p.z(); >> 1141 if (distz1<distz2) >> 1142 { >> 1143 safe=distz1; >> 1144 } >> 1145 else >> 1146 { >> 1147 safe=distz2; >> 1148 } 781 1149 782 G4double dz = std::abs(p.z())-fDz; << 1150 trany=p.y()-fTthetaSphi*p.z(); // Transformed y into `box' system 783 G4double dist = std::max(dxy,dz); << 784 1151 785 return (dist < 0) ? -dist : 0.; << 1152 // Transformed x into `box' system >> 1153 // >> 1154 cosy=1.0/std::sqrt(1.0+fTthetaSphi*fTthetaSphi); >> 1155 disty1=(fDy-trany)*cosy; >> 1156 disty2=(fDy+trany)*cosy; >> 1157 >> 1158 if (disty1<safe) safe=disty1; >> 1159 if (disty2<safe) safe=disty2; >> 1160 >> 1161 tranx=p.x()-fTthetaCphi*p.z()-fTalpha*trany; >> 1162 cosx=1.0/std::sqrt(1.0+fTalpha*fTalpha+fTthetaCphi*fTthetaCphi); >> 1163 distx1=(fDx-tranx)*cosx; >> 1164 distx2=(fDx+tranx)*cosx; >> 1165 >> 1166 if (distx1<safe) safe=distx1; >> 1167 if (distx2<safe) safe=distx2; >> 1168 >> 1169 if (safe<0) safe=0; >> 1170 return safe; 786 } 1171 } 787 1172 788 ////////////////////////////////////////////// << 1173 //////////////////////////////////////////////////////////////////////////////// 789 // 1174 // 790 // GetEntityType << 1175 // Create a List containing the transformed vertices 791 << 1176 // Ordering [0-3] -fDz cross section 792 G4GeometryType G4Para::GetEntityType() const << 1177 // [4-7] +fDz cross section such that [0] is below [4], 793 { << 1178 // [1] below [5] etc. 794 return {"G4Para"}; << 1179 // Note: >> 1180 // Caller has deletion resposibility >> 1181 >> 1182 G4ThreeVectorList* >> 1183 G4Para::CreateRotatedVertices( const G4AffineTransform& pTransform ) const >> 1184 { >> 1185 G4ThreeVectorList *vertices; >> 1186 vertices=new G4ThreeVectorList(); >> 1187 if (vertices) >> 1188 { >> 1189 vertices->reserve(8); >> 1190 G4ThreeVector vertex0(-fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1191 -fDz*fTthetaSphi-fDy, -fDz); >> 1192 G4ThreeVector vertex1(-fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1193 -fDz*fTthetaSphi-fDy, -fDz); >> 1194 G4ThreeVector vertex2(-fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1195 -fDz*fTthetaSphi+fDy, -fDz); >> 1196 G4ThreeVector vertex3(-fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1197 -fDz*fTthetaSphi+fDy, -fDz); >> 1198 G4ThreeVector vertex4(+fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1199 +fDz*fTthetaSphi-fDy, +fDz); >> 1200 G4ThreeVector vertex5(+fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1201 +fDz*fTthetaSphi-fDy, +fDz); >> 1202 G4ThreeVector vertex6(+fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1203 +fDz*fTthetaSphi+fDy, +fDz); >> 1204 G4ThreeVector vertex7(+fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1205 +fDz*fTthetaSphi+fDy, +fDz); >> 1206 >> 1207 vertices->push_back(pTransform.TransformPoint(vertex0)); >> 1208 vertices->push_back(pTransform.TransformPoint(vertex1)); >> 1209 vertices->push_back(pTransform.TransformPoint(vertex2)); >> 1210 vertices->push_back(pTransform.TransformPoint(vertex3)); >> 1211 vertices->push_back(pTransform.TransformPoint(vertex4)); >> 1212 vertices->push_back(pTransform.TransformPoint(vertex5)); >> 1213 vertices->push_back(pTransform.TransformPoint(vertex6)); >> 1214 vertices->push_back(pTransform.TransformPoint(vertex7)); >> 1215 } >> 1216 else >> 1217 { >> 1218 DumpInfo(); >> 1219 G4Exception("G4Para::CreateRotatedVertices()", >> 1220 "GeomSolids0003", FatalException, >> 1221 "Error in allocation of vertices. Out of memory !"); >> 1222 } >> 1223 return vertices; 795 } 1224 } 796 1225 797 ////////////////////////////////////////////// 1226 ////////////////////////////////////////////////////////////////////////// 798 // 1227 // 799 // IsFaceted << 1228 // GetEntityType 800 1229 801 G4bool G4Para::IsFaceted() const << 1230 G4GeometryType G4Para::GetEntityType() const 802 { 1231 { 803 return true; << 1232 return G4String("G4Para"); 804 } 1233 } 805 1234 806 ////////////////////////////////////////////// 1235 ////////////////////////////////////////////////////////////////////////// 807 // 1236 // 808 // Make a clone of the object 1237 // Make a clone of the object 809 // 1238 // 810 G4VSolid* G4Para::Clone() const 1239 G4VSolid* G4Para::Clone() const 811 { 1240 { 812 return new G4Para(*this); 1241 return new G4Para(*this); 813 } 1242 } 814 1243 815 ////////////////////////////////////////////// 1244 ////////////////////////////////////////////////////////////////////////// 816 // 1245 // 817 // Stream object contents to an output stream 1246 // Stream object contents to an output stream 818 1247 819 std::ostream& G4Para::StreamInfo( std::ostream 1248 std::ostream& G4Para::StreamInfo( std::ostream& os ) const 820 { 1249 { 821 G4double alpha = std::atan(fTalpha); << 1250 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 << "------------------------------------- 1251 os << "-----------------------------------------------------------\n" 828 << " *** Dump for solid - " << GetName 1252 << " *** Dump for solid - " << GetName() << " ***\n" 829 << " ================================= 1253 << " ===================================================\n" 830 << " Solid type: G4Para\n" 1254 << " Solid type: G4Para\n" 831 << " Parameters:\n" << 1255 << " Parameters: \n" 832 << " half length X: " << fDx/mm << " m << 1256 << " half length X: " << fDx/mm << " mm \n" 833 << " half length Y: " << fDy/mm << " m << 1257 << " half length Y: " << fDy/mm << " mm \n" 834 << " half length Z: " << fDz/mm << " m << 1258 << " half length Z: " << fDz/mm << " mm \n" 835 << " alpha: " << alpha/degree << "degr << 1259 << " std::tan(alpha) : " << fTalpha/degree << " degrees \n" 836 << " theta: " << theta/degree << "degr << 1260 << " std::tan(theta)*std::cos(phi): " << fTthetaCphi/degree 837 << " phi: " << phi/degree << "degrees\ << 1261 << " degrees \n" >> 1262 << " std::tan(theta)*std::sin(phi): " << fTthetaSphi/degree >> 1263 << " degrees \n" 838 << "------------------------------------- 1264 << "-----------------------------------------------------------\n"; 839 os.precision(oldprc); 1265 os.precision(oldprc); 840 1266 841 return os; 1267 return os; 842 } 1268 } 843 1269 844 ////////////////////////////////////////////// << 1270 ////////////////////////////////////////////////////////////////////////////// >> 1271 // >> 1272 // GetPointOnPlane >> 1273 // Auxiliary method for Get Point on Surface 845 // 1274 // 846 // Return a point randomly and uniformly selec << 847 1275 848 G4ThreeVector G4Para::GetPointOnSurface() cons << 1276 G4ThreeVector G4Para::GetPointOnPlane(G4ThreeVector p0, G4ThreeVector p1, >> 1277 G4ThreeVector p2, G4ThreeVector p3, >> 1278 G4double& area) const 849 { 1279 { 850 G4double DyTalpha = fDy*fTalpha; << 1280 G4double lambda1, lambda2, chose, aOne, aTwo; 851 G4double DzTthetaSphi = fDz*fTthetaSphi; << 1281 G4ThreeVector t, u, v, w, Area, normal; 852 G4double DzTthetaCphi = fDz*fTthetaCphi; << 1282 853 << 1283 t = p1 - p0; 854 // Set vertices << 1284 u = p2 - p1; 855 // << 1285 v = p3 - p2; 856 G4ThreeVector pt[8]; << 1286 w = p0 - p3; 857 pt[0].set(-DzTthetaCphi-DyTalpha-fDx, -DzTth << 1287 858 pt[1].set(-DzTthetaCphi-DyTalpha+fDx, -DzTth << 1288 Area = G4ThreeVector(w.y()*v.z() - w.z()*v.y(), 859 pt[2].set(-DzTthetaCphi+DyTalpha-fDx, -DzTth << 1289 w.z()*v.x() - w.x()*v.z(), 860 pt[3].set(-DzTthetaCphi+DyTalpha+fDx, -DzTth << 1290 w.x()*v.y() - w.y()*v.x()); 861 pt[4].set( DzTthetaCphi-DyTalpha-fDx, DzTth << 1291 862 pt[5].set( DzTthetaCphi-DyTalpha+fDx, DzTth << 1292 aOne = 0.5*Area.mag(); 863 pt[6].set( DzTthetaCphi+DyTalpha-fDx, DzTth << 1293 864 pt[7].set( DzTthetaCphi+DyTalpha+fDx, DzTth << 1294 Area = G4ThreeVector(t.y()*u.z() - t.z()*u.y(), 865 << 1295 t.z()*u.x() - t.x()*u.z(), 866 // Set areas (-Z, -Y, +Y, -X, +X, +Z) << 1296 t.x()*u.y() - t.y()*u.x()); 867 // << 1297 868 G4ThreeVector vx(fDx, 0, 0); << 1298 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 1299 876 G4double sface[6] = { sxy, syz, syz, sxz, sx << 1300 area = aOne + aTwo; 877 for (G4int i=1; i<6; ++i) { sface[i] += sfac << 1301 >> 1302 chose = RandFlat::shoot(0.,aOne+aTwo); 878 1303 879 // Select face << 1304 if( (chose>=0.) && (chose < aOne) ) 880 // << 1305 { 881 G4double select = sface[5]*G4UniformRand(); << 1306 lambda1 = RandFlat::shoot(0.,1.); 882 G4int k = 5; << 1307 lambda2 = RandFlat::shoot(0.,lambda1); 883 if (select <= sface[4]) k = 4; << 1308 return (p2+lambda1*v+lambda2*w); 884 if (select <= sface[3]) k = 3; << 1309 } 885 if (select <= sface[2]) k = 2; << 1310 886 if (select <= sface[1]) k = 1; << 1311 // else 887 if (select <= sface[0]) k = 0; << 1312 888 << 1313 lambda1 = RandFlat::shoot(0.,1.); 889 // Generate point << 1314 lambda2 = RandFlat::shoot(0.,lambda1); 890 // << 1315 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 } 1316 } 896 1317 897 ////////////////////////////////////////////// << 1318 ///////////////////////////////////////////////////////////////////////// >> 1319 // >> 1320 // GetPointOnSurface >> 1321 // >> 1322 // Return a point (G4ThreeVector) randomly and uniformly >> 1323 // selected on the solid surface >> 1324 >> 1325 G4ThreeVector G4Para::GetPointOnSurface() const >> 1326 { >> 1327 G4ThreeVector One, Two, Three, Four, Five, Six; >> 1328 G4ThreeVector pt[8] ; >> 1329 G4double chose, aOne, aTwo, aThree, aFour, aFive, aSix; >> 1330 >> 1331 pt[0] = G4ThreeVector(-fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1332 -fDz*fTthetaSphi-fDy, -fDz); >> 1333 pt[1] = G4ThreeVector(-fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1334 -fDz*fTthetaSphi-fDy, -fDz); >> 1335 pt[2] = G4ThreeVector(-fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1336 -fDz*fTthetaSphi+fDy, -fDz); >> 1337 pt[3] = G4ThreeVector(-fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1338 -fDz*fTthetaSphi+fDy, -fDz); >> 1339 pt[4] = G4ThreeVector(+fDz*fTthetaCphi-fDy*fTalpha-fDx, >> 1340 +fDz*fTthetaSphi-fDy, +fDz); >> 1341 pt[5] = G4ThreeVector(+fDz*fTthetaCphi-fDy*fTalpha+fDx, >> 1342 +fDz*fTthetaSphi-fDy, +fDz); >> 1343 pt[6] = G4ThreeVector(+fDz*fTthetaCphi+fDy*fTalpha-fDx, >> 1344 +fDz*fTthetaSphi+fDy, +fDz); >> 1345 pt[7] = G4ThreeVector(+fDz*fTthetaCphi+fDy*fTalpha+fDx, >> 1346 +fDz*fTthetaSphi+fDy, +fDz); >> 1347 >> 1348 // make sure we provide the points in a clockwise fashion >> 1349 >> 1350 One = GetPointOnPlane(pt[0],pt[1],pt[3],pt[2], aOne); >> 1351 Two = GetPointOnPlane(pt[4],pt[5],pt[7],pt[6], aTwo); >> 1352 Three = GetPointOnPlane(pt[6],pt[7],pt[3],pt[2], aThree); >> 1353 Four = GetPointOnPlane(pt[4],pt[5],pt[1],pt[0], aFour); >> 1354 Five = GetPointOnPlane(pt[0],pt[2],pt[6],pt[4], aFive); >> 1355 Six = GetPointOnPlane(pt[1],pt[3],pt[7],pt[5], aSix); >> 1356 >> 1357 chose = RandFlat::shoot(0.,aOne+aTwo+aThree+aFour+aFive+aSix); >> 1358 >> 1359 if( (chose>=0.) && (chose<aOne) ) >> 1360 { return One; } >> 1361 else if(chose>=aOne && chose<aOne+aTwo) >> 1362 { return Two; } >> 1363 else if(chose>=aOne+aTwo && chose<aOne+aTwo+aThree) >> 1364 { return Three; } >> 1365 else if(chose>=aOne+aTwo+aThree && chose<aOne+aTwo+aThree+aFour) >> 1366 { return Four; } >> 1367 else if(chose>=aOne+aTwo+aThree+aFour && chose<aOne+aTwo+aThree+aFour+aFive) >> 1368 { return Five; } >> 1369 return Six; >> 1370 } >> 1371 >> 1372 //////////////////////////////////////////////////////////////////////////// 898 // 1373 // 899 // Methods for visualisation 1374 // Methods for visualisation 900 1375 901 void G4Para::DescribeYourselfTo ( G4VGraphicsS 1376 void G4Para::DescribeYourselfTo ( G4VGraphicsScene& scene ) const 902 { 1377 { 903 scene.AddSolid (*this); 1378 scene.AddSolid (*this); 904 } 1379 } 905 1380 906 G4Polyhedron* G4Para::CreatePolyhedron () cons 1381 G4Polyhedron* G4Para::CreatePolyhedron () const 907 { 1382 { 908 G4double phi = std::atan2(fTthetaSphi, fTthe 1383 G4double phi = std::atan2(fTthetaSphi, fTthetaCphi); 909 G4double alpha = std::atan(fTalpha); 1384 G4double alpha = std::atan(fTalpha); 910 G4double theta = std::atan(std::sqrt(fTtheta << 1385 G4double theta = std::atan(std::sqrt(fTthetaCphi*fTthetaCphi 911 fTtheta << 1386 +fTthetaSphi*fTthetaSphi)); 912 1387 913 return new G4PolyhedronPara(fDx, fDy, fDz, a 1388 return new G4PolyhedronPara(fDx, fDy, fDz, alpha, theta, phi); 914 } 1389 } 915 #endif << 916 1390