257 G4double rho,rho2,rad2,tolRMin,tolRMax;
261 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
262 const G4double halfRminTolerance = fRminTolerance*0.5;
263 const G4double Rmax_minus = fRmax - halfRmaxTolerance;
264 const G4double Rmin_plus = (fRmin > 0) ? fRmin+halfRminTolerance : 0;
266 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
267 rad2 = rho2 + p.
z()*p.
z() ;
272 tolRMax = Rmax_minus;
280 if ( (!fFullPhiSphere) || (!fFullThetaSphere) )
288 if ( (rad2 <= Rmax_minus*Rmax_minus) && (rad2 >= Rmin_plus*Rmin_plus) )
294 tolRMax = fRmax + halfRmaxTolerance;
295 tolRMin = std::max(fRmin-halfRminTolerance, 0.);
296 if ( (rad2 <= tolRMax*tolRMax) && (rad2 >= tolRMin*tolRMin) )
308 if ( !fFullPhiSphere && (rho2 != 0.0) )
310 pPhi = std::atan2(p.
y(),p.
x()) ;
312 if ( pPhi < fSPhi - halfAngTolerance ) { pPhi += twopi; }
313 else if ( pPhi > ePhi + halfAngTolerance ) { pPhi -= twopi; }
315 if ( (pPhi < fSPhi - halfAngTolerance)
316 || (pPhi > ePhi + halfAngTolerance) ) {
return in =
kOutside; }
320 if ( (pPhi < fSPhi + halfAngTolerance)
321 || (pPhi > ePhi - halfAngTolerance) ) { in =
kSurface; }
327 if ( ((rho2 != 0.0) || (p.
z() != 0.0)) && (!fFullThetaSphere) )
329 rho = std::sqrt(rho2);
330 pTheta = std::atan2(rho,p.
z());
334 if ( ((fSTheta > 0.0) && (pTheta < fSTheta + halfAngTolerance))
335 || ((eTheta < pi) && (pTheta > eTheta - halfAngTolerance)) )
337 if ( (( (fSTheta>0.0)&&(pTheta>=fSTheta-halfAngTolerance) )
338 || (fSTheta == 0.0) )
339 && ((eTheta==pi)||(pTheta <= eTheta + halfAngTolerance) ) )
351 if ( ((fSTheta > 0.0)&&(pTheta < fSTheta - halfAngTolerance))
352 ||((eTheta < pi )&&(pTheta > eTheta + halfAngTolerance)) )
369 G4int noSurfaces = 0;
370 G4double rho, rho2, radius, pTheta, pPhi=0.;
372 G4double distSPhi = kInfinity, distEPhi = kInfinity;
373 G4double distSTheta = kInfinity, distETheta = kInfinity;
377 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
378 radius = std::sqrt(rho2+p.
z()*p.
z());
379 rho = std::sqrt(rho2);
381 G4double distRMax = std::fabs(radius-fRmax);
382 if (fRmin != 0.0) { distRMin = std::fabs(radius-fRmin); }
384 if ( (rho != 0.0) && !fFullSphere )
386 pPhi = std::atan2(p.
y(),p.
x());
388 if (pPhi < fSPhi-halfAngTolerance) { pPhi += twopi; }
389 else if (pPhi > ePhi+halfAngTolerance) { pPhi -= twopi; }
391 if ( !fFullPhiSphere )
395 distSPhi = std::fabs( pPhi-fSPhi );
396 distEPhi = std::fabs( pPhi-ePhi );
398 else if( fRmin == 0.0 )
406 if ( !fFullThetaSphere )
410 pTheta = std::atan2(rho,p.
z());
411 distSTheta = std::fabs(pTheta-fSTheta);
412 distETheta = std::fabs(pTheta-eTheta);
415 -cosSTheta*p.
y()/rho,
422 else if( fRmin == 0.0 )
424 if ( fSTheta != 0.0 )
436 if( radius != 0.0 ) { nR =
G4ThreeVector(p.
x()/radius,p.
y()/radius,p.
z()/radius); }
438 if( distRMax <= halfCarTolerance )
443 if( (fRmin != 0.0) && (distRMin <= halfCarTolerance) )
448 if( !fFullPhiSphere )
450 if (distSPhi <= halfAngTolerance)
455 if (distEPhi <= halfAngTolerance)
461 if ( !fFullThetaSphere )
463 if ((distSTheta <= halfAngTolerance) && (fSTheta > 0.))
466 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm += nZ; }
467 else { sumnorm += nTs; }
469 if ((distETheta <= halfAngTolerance) && (eTheta < pi))
472 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm -= nZ; }
473 else { sumnorm += nTe; }
474 if(sumnorm.
z() == 0.) { sumnorm += nZ; }
477 if ( noSurfaces == 0 )
480 G4Exception(
"G4Sphere::SurfaceNormal(p)",
"GeomSolids1002",
483 norm = ApproxSurfaceNormal(p);
485 else if ( noSurfaces == 1 ) { norm = sumnorm; }
486 else { norm = sumnorm.
unit(); }
673 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
674 G4double tolSTheta=0., tolETheta=0. ;
677 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
678 const G4double halfRminTolerance = fRminTolerance*0.5;
679 const G4double tolORMin2 = (fRmin>halfRminTolerance)
680 ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
682 (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
684 (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
686 (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
690 G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
703 G4double t1, t2, b, c, d2, d, sd = kInfinity ;
707 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
708 rad2 = rho2 + p.
z()*p.
z() ;
709 pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
711 pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
712 pDotV3d = pDotV2d + p.
z()*v.
z() ;
716 if (!fFullThetaSphere)
718 tolSTheta = fSTheta - halfAngTolerance ;
719 tolETheta = eTheta + halfAngTolerance ;
723 if ((rad2!=0.0) || (fRmin!=0.0))
729 G4double vTheta = std::atan2(std::sqrt(v.
x()*v.
x()+v.
y()*v.
y()),v.
z()) ;
730 if ( (vTheta < tolSTheta) || (vTheta > tolETheta) )
752 c = rad2 - fRmax*fRmax ;
754 if (c > fRmaxTolerance*fRmax)
759 d2 = pDotV3d*pDotV3d - c ;
763 sd = -pDotV3d - std::sqrt(d2) ;
769 G4double fTerm = sd-std::fmod(sd,dRmax);
772 xi = p.
x() + sd*v.
x() ;
773 yi = p.
y() + sd*v.
y() ;
774 rhoi = std::sqrt(xi*xi + yi*yi) ;
776 if (!fFullPhiSphere && (rhoi != 0.0))
778 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
780 if (cosPsi >= cosHDPhiOT)
782 if (!fFullThetaSphere)
784 zi = p.
z() + sd*v.
z() ;
789 iTheta = std::atan2(rhoi,zi) ;
790 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
803 if (!fFullThetaSphere)
805 zi = p.
z() + sd*v.
z() ;
810 iTheta = std::atan2(rhoi,zi) ;
811 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
825 return snxt=kInfinity;
833 d2 = pDotV3d*pDotV3d - c ;
835 if ( (rad2 > tolIRMax2)
836 && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
843 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
845 if (cosPsi>=cosHDPhiIT)
849 if ( !fFullThetaSphere )
851 if ( (pTheta >= tolSTheta + kAngTolerance)
852 && (pTheta <= tolETheta - kAngTolerance) )
865 if ( !fFullThetaSphere )
867 if ( (pTheta >= tolSTheta + kAngTolerance)
868 && (pTheta <= tolETheta - kAngTolerance) )
888 c = rad2 - fRmin*fRmin ;
889 d2 = pDotV3d*pDotV3d - c ;
894 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
897 if ( !fFullPhiSphere )
902 cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
903 if (cosPsi >= cosHDPhiIT)
907 if ( !fFullThetaSphere )
909 if ( (pTheta >= tolSTheta + kAngTolerance)
910 && (pTheta <= tolETheta - kAngTolerance) )
923 if ( !fFullThetaSphere )
925 if ( (pTheta >= tolSTheta + kAngTolerance)
926 && (pTheta <= tolETheta - kAngTolerance) )
941 sd = -pDotV3d + std::sqrt(d2) ;
942 if ( sd >= halfRminTolerance )
944 xi = p.
x() + sd*v.
x() ;
945 yi = p.
y() + sd*v.
y() ;
946 rhoi = std::sqrt(xi*xi+yi*yi) ;
948 if ( !fFullPhiSphere && (rhoi != 0.0) )
950 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
952 if (cosPsi >= cosHDPhiOT)
954 if ( !fFullThetaSphere )
956 zi = p.
z() + sd*v.
z() ;
961 iTheta = std::atan2(rhoi,zi) ;
962 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
975 if ( !fFullThetaSphere )
977 zi = p.
z() + sd*v.
z() ;
982 iTheta = std::atan2(rhoi,zi) ;
983 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1007 if ( !fFullPhiSphere )
1012 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1016 Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
1018 if (Dist < halfCarTolerance)
1026 xi = p.
x() + sd*v.
x() ;
1027 yi = p.
y() + sd*v.
y() ;
1028 zi = p.
z() + sd*v.
z() ;
1029 rhoi2 = xi*xi + yi*yi ;
1030 radi2 = rhoi2 + zi*zi ;
1041 if ( (radi2 <= tolORMax2)
1042 && (radi2 >= tolORMin2)
1043 && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
1049 if ( !fFullThetaSphere )
1051 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1052 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1057 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
1075 Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
1079 Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
1080 if ( Dist < halfCarTolerance )
1088 xi = p.
x() + sd*v.
x() ;
1089 yi = p.
y() + sd*v.
y() ;
1090 zi = p.
z() + sd*v.
z() ;
1091 rhoi2 = xi*xi + yi*yi ;
1092 radi2 = rhoi2 + zi*zi ;
1103 if ( (radi2 <= tolORMax2)
1104 && (radi2 >= tolORMin2)
1105 && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
1111 if ( !fFullThetaSphere )
1113 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1114 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1119 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
1137 if ( !fFullThetaSphere )
1162 dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
1166 dist2STheta = kInfinity ;
1170 dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
1174 dist2ETheta=kInfinity;
1176 if ( pTheta < tolSTheta )
1181 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1182 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1186 c = dist2STheta/t1 ;
1193 zi = p.
z() + sd*v.
z();
1195 if ( (sd < 0) || (zi*(fSTheta - halfpi) > 0) )
1199 if ((sd >= 0) && (sd < snxt))
1201 xi = p.
x() + sd*v.
x();
1202 yi = p.
y() + sd*v.
y();
1203 zi = p.
z() + sd*v.
z();
1204 rhoi2 = xi*xi + yi*yi;
1205 radi2 = rhoi2 + zi*zi;
1206 if ( (radi2 <= tolORMax2)
1207 && (radi2 >= tolORMin2)
1208 && (zi*(fSTheta - halfpi) <= 0) )
1210 if ( !fFullPhiSphere && (rhoi2 != 0.0) )
1212 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1213 if (cosPsi >= cosHDPhiOT)
1232 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1233 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1237 c = dist2ETheta/t1 ;
1245 if ( (sd >= 0) && (sd < snxt) )
1247 xi = p.
x() + sd*v.
x() ;
1248 yi = p.
y() + sd*v.
y() ;
1249 zi = p.
z() + sd*v.
z() ;
1250 rhoi2 = xi*xi + yi*yi ;
1251 radi2 = rhoi2 + zi*zi ;
1253 if ( (radi2 <= tolORMax2)
1254 && (radi2 >= tolORMin2)
1255 && (zi*(eTheta - halfpi) <= 0) )
1257 if (!fFullPhiSphere && (rhoi2 != 0.0))
1259 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1260 if (cosPsi >= cosHDPhiOT)
1275 else if ( pTheta > tolETheta )
1281 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1282 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1286 c = dist2ETheta/t1 ;
1293 zi = p.
z() + sd*v.
z();
1295 if ( (sd < 0) || (zi*(eTheta - halfpi) > 0) )
1299 if ( (sd >= 0) && (sd < snxt) )
1301 xi = p.
x() + sd*v.
x() ;
1302 yi = p.
y() + sd*v.
y() ;
1303 zi = p.
z() + sd*v.
z() ;
1304 rhoi2 = xi*xi + yi*yi ;
1305 radi2 = rhoi2 + zi*zi ;
1307 if ( (radi2 <= tolORMax2)
1308 && (radi2 >= tolORMin2)
1309 && (zi*(eTheta - halfpi) <= 0) )
1311 if (!fFullPhiSphere && (rhoi2 != 0.0))
1313 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1314 if (cosPsi >= cosHDPhiOT)
1331 if ( fSTheta != 0.0 )
1333 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1334 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1338 c = dist2STheta/t1 ;
1346 if ( (sd >= 0) && (sd < snxt) )
1348 xi = p.
x() + sd*v.
x() ;
1349 yi = p.
y() + sd*v.
y() ;
1350 zi = p.
z() + sd*v.
z() ;
1351 rhoi2 = xi*xi + yi*yi ;
1352 radi2 = rhoi2 + zi*zi ;
1354 if ( (radi2 <= tolORMax2)
1355 && (radi2 >= tolORMin2)
1356 && (zi*(fSTheta - halfpi) <= 0) )
1358 if (!fFullPhiSphere && (rhoi2 != 0.0))
1360 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1361 if (cosPsi >= cosHDPhiOT)
1376 else if ( (pTheta < tolSTheta + kAngTolerance)
1377 && (fSTheta > halfAngTolerance) )
1383 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1384 if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<halfpi)
1385 || (t2<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>halfpi)
1386 || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==halfpi) )
1388 if (!fFullPhiSphere && (rho2 != 0.0))
1390 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1391 if (cosPsi >= cosHDPhiIT)
1404 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1408 c = dist2STheta/t1 ;
1415 if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
1417 xi = p.
x() + sd*v.
x() ;
1418 yi = p.
y() + sd*v.
y() ;
1419 zi = p.
z() + sd*v.
z() ;
1420 rhoi2 = xi*xi + yi*yi ;
1421 radi2 = rhoi2 + zi*zi ;
1423 if ( (radi2 <= tolORMax2)
1424 && (radi2 >= tolORMin2)
1425 && (zi*(fSTheta - halfpi) <= 0) )
1427 if ( !fFullPhiSphere && (rhoi2 != 0.0) )
1429 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1430 if ( cosPsi >= cosHDPhiOT )
1444 else if ((pTheta > tolETheta-kAngTolerance) && (eTheta < pi-kAngTolerance))
1451 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1453 if ( ((t2<0) && (eTheta < halfpi)
1454 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1455 || ((t2>=0) && (eTheta > halfpi)
1456 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1457 || ((v.
z()>0) && (eTheta == halfpi)
1458 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2)) )
1460 if (!fFullPhiSphere && (rho2 != 0.0))
1462 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1463 if (cosPsi >= cosHDPhiIT)
1476 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1480 c = dist2ETheta/t1 ;
1488 if ( (sd >= halfCarTolerance)
1489 && (sd < snxt) && (eTheta > halfpi) )
1491 xi = p.
x() + sd*v.
x() ;
1492 yi = p.
y() + sd*v.
y() ;
1493 zi = p.
z() + sd*v.
z() ;
1494 rhoi2 = xi*xi + yi*yi ;
1495 radi2 = rhoi2 + zi*zi ;
1497 if ( (radi2 <= tolORMax2)
1498 && (radi2 >= tolORMin2)
1499 && (zi*(eTheta - halfpi) <= 0) )
1501 if (!fFullPhiSphere && (rhoi2 != 0.0))
1503 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1504 if (cosPsi >= cosHDPhiOT)
1523 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1524 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1528 c = dist2STheta/t1 ;
1536 if ((sd >= 0) && (sd < snxt))
1538 xi = p.
x() + sd*v.
x() ;
1539 yi = p.
y() + sd*v.
y() ;
1540 zi = p.
z() + sd*v.
z() ;
1541 rhoi2 = xi*xi + yi*yi ;
1542 radi2 = rhoi2 + zi*zi ;
1544 if ( (radi2 <= tolORMax2)
1545 && (radi2 >= tolORMin2)
1546 && (zi*(fSTheta - halfpi) <= 0) )
1548 if (!fFullPhiSphere && (rhoi2 != 0.0))
1550 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1551 if (cosPsi >= cosHDPhiOT)
1564 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1565 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1569 c = dist2ETheta/t1 ;
1577 if ((sd >= 0) && (sd < snxt))
1579 xi = p.
x() + sd*v.
x() ;
1580 yi = p.
y() + sd*v.
y() ;
1581 zi = p.
z() + sd*v.
z() ;
1582 rhoi2 = xi*xi + yi*yi ;
1583 radi2 = rhoi2 + zi*zi ;
1585 if ( (radi2 <= tolORMax2)
1586 && (radi2 >= tolORMin2)
1587 && (zi*(eTheta - halfpi) <= 0) )
1589 if (!fFullPhiSphere && (rhoi2 != 0.0))
1591 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1592 if ( cosPsi >= cosHDPhiOT )
1721 G4double sphi= kInfinity,stheta= kInfinity;
1722 ESide side=kNull,sidephi=kNull,sidetheta=kNull;
1724 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
1725 const G4double halfRminTolerance = fRminTolerance*0.5;
1726 const G4double Rmax_plus = fRmax + halfRmaxTolerance;
1727 const G4double Rmin_minus = (fRmin) != 0.0 ? fRmin-halfRminTolerance : 0;
1733 G4double pDistS,compS,pDistE,compE,sphi2,vphi;
1735 G4double rho2,rad2,pDotV2d,pDotV3d;
1742 G4double dist2STheta, dist2ETheta, distTheta;
1747 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
1748 rad2 = rho2+p.
z()*p.
z();
1750 pDotV2d = p.
x()*v.
x()+p.
y()*v.
y();
1751 pDotV3d = pDotV2d+p.
z()*v.
z();
1769 if( (rad2 <= Rmax_plus*Rmax_plus) && (rad2 >= Rmin_minus*Rmin_minus) )
1771 c = rad2 - fRmax*fRmax;
1773 if (c < fRmaxTolerance*fRmax)
1784 d2 = pDotV3d*pDotV3d - c;
1786 if( (c >- fRmaxTolerance*fRmax)
1787 && ((pDotV3d >=0) || (d2 < 0)) )
1798 snxt = -pDotV3d+std::sqrt(d2);
1808 c = rad2 - fRmin*fRmin;
1809 d2 = pDotV3d*pDotV3d - c;
1811 if (c >- fRminTolerance*fRmin)
1813 if ( (c < fRminTolerance*fRmin)
1814 && (d2 >= fRminTolerance*fRmin) && (pDotV3d < 0) )
1816 if(calcNorm) { *validNorm =
false; }
1822 sd = -pDotV3d-std::sqrt(d2);
1836 if ( !fFullThetaSphere )
1863 if( std::fabs(tanSTheta) > 5./kAngTolerance )
1867 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
1876 stheta = -p.
z()/v.
z();
1877 sidetheta = kSTheta;
1882 t1 = 1-v.
z()*v.
z()*(1+tanSTheta2);
1883 t2 = pDotV2d-p.
z()*v.
z()*tanSTheta2;
1884 dist2STheta = rho2-p.
z()*p.
z()*tanSTheta2;
1886 distTheta = std::sqrt(rho2)-p.
z()*tanSTheta;
1888 if( std::fabs(t1) < halfAngTolerance )
1892 if(std::fabs(distTheta) < halfRmaxTolerance)
1894 if( (fSTheta < halfpi) && (p.
z() > 0.) )
1896 if( calcNorm ) { *validNorm =
false; }
1899 if( (fSTheta > halfpi) && (p.
z() <= 0) )
1906 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
1910 std::sin(fSTheta) );
1920 stheta = -0.5*dist2STheta/t2;
1921 sidetheta = kSTheta;
1926 if( std::fabs(distTheta) < halfRmaxTolerance )
1928 if( (fSTheta > halfpi) && (t2 >= 0.) )
1935 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
1939 std::sin(fSTheta) );
1945 if( (fSTheta < halfpi) && (t2 < 0.) && (p.
z() >=0.) )
1947 if( calcNorm ) { *validNorm =
false; }
1959 if( fSTheta > halfpi )
1963 if ( ((std::fabs(s) < halfRmaxTolerance) && (t2 < 0.))
1964 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() > 0.) ) )
1968 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() <= 0.) )
1971 sidetheta = kSTheta;
1978 if ( ( (std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.) )
1979 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() < 0.) ) )
1983 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() >= 0.) )
1986 sidetheta = kSTheta;
1995 if( std::fabs(tanETheta) > 5./kAngTolerance )
1999 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
2013 sidetheta = kETheta;
2019 t1 = 1-v.
z()*v.
z()*(1+tanETheta2);
2020 t2 = pDotV2d-p.
z()*v.
z()*tanETheta2;
2021 dist2ETheta = rho2-p.
z()*p.
z()*tanETheta2;
2023 distTheta = std::sqrt(rho2)-p.
z()*tanETheta;
2025 if( std::fabs(t1) < halfAngTolerance )
2029 if(std::fabs(distTheta) < halfRmaxTolerance)
2031 if( (eTheta > halfpi) && (p.
z() < 0.) )
2033 if( calcNorm ) { *validNorm =
false; }
2036 if ( (eTheta < halfpi) && (p.
z() >= 0) )
2043 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2053 sd = -0.5*dist2ETheta/t2;
2058 sidetheta = kETheta;
2064 if ( std::fabs(distTheta) < halfRmaxTolerance )
2066 if( (eTheta < halfpi) && (t2 >= 0.) )
2073 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2085 if ( (eTheta > halfpi) && (t2 < 0.) && (p.
z() <=0.) )
2087 if( calcNorm ) { *validNorm =
false; }
2094 if ( (d2 <halfRmaxTolerance) && (d2 > -halfRmaxTolerance) )
2102 if( eTheta < halfpi )
2106 if( ((std::fabs(sd) < halfRmaxTolerance) && (t2 < 0.))
2111 if( sd > halfRmaxTolerance )
2116 sidetheta = kETheta;
2124 if ( ((std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.))
2126 || ( (sd > 0.) && (p.
z() + sd*v.
z() > halfRmaxTolerance) ) )
2130 if ( ( sd>halfRmaxTolerance )
2131 && ( p.
z()+sd*v.
z() <= halfRmaxTolerance ) )
2136 sidetheta = kETheta;
2149 if ( !fFullPhiSphere )
2151 if ( (p.
x() != 0.0) || (p.
y() != 0.0) )
2155 pDistS=p.
x()*sinSPhi-p.
y()*cosSPhi;
2156 pDistE=-p.
x()*sinEPhi+p.
y()*cosEPhi;
2160 compS = -sinSPhi*v.
x()+cosSPhi*v.
y() ;
2161 compE = sinEPhi*v.
x()-cosEPhi*v.
y() ;
2164 if ( (pDistS <= 0) && (pDistE <= 0) )
2170 sphi = pDistS/compS ;
2171 xi = p.
x()+sphi*v.
x() ;
2172 yi = p.
y()+sphi*v.
y() ;
2178 vphi = std::atan2(v.
y(),v.
x());
2180 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2181 && ( (ePhi+halfAngTolerance) >= vphi) )
2186 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2193 if ( pDistS > -halfCarTolerance) { sphi = 0; }
2196 else { sphi = kInfinity; }
2200 sphi2=pDistE/compE ;
2203 xi = p.
x()+sphi2*v.
x() ;
2204 yi = p.
y()+sphi2*v.
y() ;
2213 vphi = std::atan2(v.
y(),v.
x()) ;
2215 if( (fSPhi-halfAngTolerance > vphi)
2216 ||(fSPhi+fDPhi+halfAngTolerance < vphi) )
2219 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2; }
2220 else { sphi = 0.0; }
2223 else if ((yi*cosCPhi-xi*sinCPhi)>=0)
2226 if ( pDistE <= -halfCarTolerance )
2238 else if ((pDistS >= 0) && (pDistE >= 0))
2240 if ( pDistS <= pDistE )
2250 if ( (compS < 0) && (compE < 0) ) { sphi = 0; }
2251 else { sphi = kInfinity; }
2258 if ( (compS >= 0) && (compE >= 0) ) { sphi = kInfinity; }
2262 else if ( (pDistS > 0) && (pDistE < 0) )
2270 sphi = pDistE/compE ;
2271 xi = p.
x() + sphi*v.
x() ;
2272 yi = p.
y() + sphi*v.
y() ;
2279 vphi = std::atan2(v.
y(),v.
x());
2281 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2282 && ( (ePhi+halfAngTolerance) >= vphi) )
2287 else if ( ( yi*cosCPhi - xi*sinCPhi ) <= 0 )
2294 if ( pDistE > -halfCarTolerance ) { sphi = 0.; }
2308 sphi = pDistE/compE ;
2309 xi = p.
x() + sphi*v.
x() ;
2310 yi = p.
y() + sphi*v.
y() ;
2318 vphi = std::atan2(v.
y(),v.
x());
2320 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2321 && ( (ePhi+halfAngTolerance) >= vphi) )
2326 else if ( ( yi*cosCPhi - xi*sinCPhi) <= 0 )
2357 xi=p.
x()+sphi*v.
x();
2358 yi=p.
y()+sphi*v.
y();
2365 vphi = std::atan2(v.
y(),v.
x()) ;
2367 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2368 && ( (ePhi+halfAngTolerance) >= vphi) )
2373 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2380 if ( pDistS > -halfCarTolerance ) { sphi = 0; }
2394 sphi = pDistS/compS ;
2395 xi = p.
x()+sphi*v.
x() ;
2396 yi = p.
y()+sphi*v.
y() ;
2404 vphi = std::atan2(v.
y(),v.
x()) ;
2406 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2407 && ( (ePhi+halfAngTolerance) >= vphi) )
2412 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2439 if ( (v.
x() != 0.0) || (v.
y() != 0.0) )
2441 vphi = std::atan2(v.
y(),v.
x()) ;
2442 if ((fSPhi-halfAngTolerance < vphi) && (vphi < ePhi+halfAngTolerance))
2474 xi=p.
x()+snxt*v.
x();
2475 yi=p.
y()+snxt*v.
y();
2476 zi=p.
z()+snxt*v.
z();
2491 else { *validNorm=
false; }
2500 else { *validNorm=
false; }
2504 if( fSTheta == halfpi )
2509 else if ( fSTheta > halfpi )
2511 xi = p.
x() + snxt*v.
x();
2512 yi = p.
y() + snxt*v.
y();
2516 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2518 -tanSTheta/std::sqrt(1+tanSTheta2));
2526 else { *validNorm=
false; }
2530 if( eTheta == halfpi )
2535 else if ( eTheta < halfpi )
2537 xi=p.
x()+snxt*v.
x();
2538 yi=p.
y()+snxt*v.
y();
2542 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2544 -tanETheta/std::sqrt(1+tanETheta2) );
2552 else { *validNorm=
false; }
2558 std::ostringstream message;
2559 G4long oldprc = message.precision(16);
2560 message <<
"Undefined side for valid surface normal to solid."
2563 <<
"p.x() = " << p.
x()/mm <<
" mm" <<
G4endl
2564 <<
"p.y() = " << p.
y()/mm <<
" mm" <<
G4endl
2567 <<
"v.x() = " << v.
x() <<
G4endl
2568 <<
"v.y() = " << v.
y() <<
G4endl
2571 <<
"snxt = " << snxt/mm <<
" mm" <<
G4endl;
2572 message.precision(oldprc);
2578 if (snxt == kInfinity)
2582 std::ostringstream message;
2583 G4long oldprc = message.precision(16);
2584 message <<
"Logic error: snxt = kInfinity ???" <<
G4endl
2586 <<
"p.x() = " << p.
x()/mm <<
" mm" <<
G4endl
2587 <<
"p.y() = " << p.
y()/mm <<
" mm" <<
G4endl
2589 <<
"Rp = "<< std::sqrt( p.
x()*p.
x()+p.
y()*p.
y()+p.
z()*p.
z() )/mm
2592 <<
"v.x() = " << v.
x() <<
G4endl
2593 <<
"v.y() = " << v.
y() <<
G4endl
2596 <<
"snxt = " << snxt/mm <<
" mm" <<
G4endl;
2597 message.precision(oldprc);