260 G4double rho,rho2,rad2,tolRMin,tolRMax;
264 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
265 const G4double halfRminTolerance = fRminTolerance*0.5;
266 const G4double Rmax_minus = fRmax - halfRmaxTolerance;
267 const G4double Rmin_plus = (fRmin > 0) ? fRmin+halfRminTolerance : 0;
269 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
270 rad2 = rho2 + p.
z()*p.
z() ;
275 tolRMax = Rmax_minus;
283 if ( (!fFullPhiSphere) || (!fFullThetaSphere) )
293 if ( (rad2 <= Rmax_minus*Rmax_minus) && (rad2 >= Rmin_plus*Rmin_plus) )
299 tolRMax = fRmax + halfRmaxTolerance;
300 tolRMin = std::max(fRmin-halfRminTolerance, 0.);
301 if ( (rad2 <= tolRMax*tolRMax) && (rad2 >= tolRMin*tolRMin) )
313 if ( !fFullPhiSphere && (rho2 != 0.0) )
315 pPhi = std::atan2(p.
y(),p.
x()) ;
317 if ( pPhi < fSPhi - halfAngTolerance ) { pPhi += twopi; }
318 else if ( pPhi > ePhi + halfAngTolerance ) { pPhi -= twopi; }
320 if ( (pPhi < fSPhi - halfAngTolerance)
321 || (pPhi > ePhi + halfAngTolerance) ) {
return in =
kOutside; }
325 if ( (pPhi < fSPhi + halfAngTolerance)
326 || (pPhi > ePhi - halfAngTolerance) ) { in =
kSurface; }
332 if ( ((rho2 != 0.0) || (p.
z() != 0.0)) && (!fFullThetaSphere) )
334 rho = std::sqrt(rho2);
335 pTheta = std::atan2(rho,p.
z());
339 if ( ((fSTheta > 0.0) && (pTheta < fSTheta + halfAngTolerance))
340 || ((eTheta < pi) && (pTheta > eTheta - halfAngTolerance)) )
342 if ( (( (fSTheta>0.0)&&(pTheta>=fSTheta-halfAngTolerance) )
343 || (fSTheta == 0.0) )
344 && ((eTheta==pi)||(pTheta <= eTheta + halfAngTolerance) ) )
356 if ( ((fSTheta > 0.0)&&(pTheta < fSTheta - halfAngTolerance))
357 ||((eTheta < pi )&&(pTheta > eTheta + halfAngTolerance)) )
374 G4int noSurfaces = 0;
375 G4double rho, rho2, radius, pTheta, pPhi=0.;
377 G4double distSPhi = kInfinity, distEPhi = kInfinity;
378 G4double distSTheta = kInfinity, distETheta = kInfinity;
382 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
383 radius = std::sqrt(rho2+p.
z()*p.
z());
384 rho = std::sqrt(rho2);
386 G4double distRMax = std::fabs(radius-fRmax);
387 if (fRmin != 0.0) distRMin = std::fabs(radius-fRmin);
389 if ( (rho != 0.0) && !fFullSphere )
391 pPhi = std::atan2(p.
y(),p.
x());
393 if (pPhi < fSPhi-halfAngTolerance) { pPhi += twopi; }
394 else if (pPhi > ePhi+halfAngTolerance) { pPhi -= twopi; }
396 if ( !fFullPhiSphere )
400 distSPhi = std::fabs( pPhi-fSPhi );
401 distEPhi = std::fabs( pPhi-ePhi );
403 else if( fRmin == 0.0 )
411 if ( !fFullThetaSphere )
415 pTheta = std::atan2(rho,p.
z());
416 distSTheta = std::fabs(pTheta-fSTheta);
417 distETheta = std::fabs(pTheta-eTheta);
420 -cosSTheta*p.
y()/rho,
427 else if( fRmin == 0.0 )
429 if ( fSTheta != 0.0 )
441 if( radius != 0.0 ) { nR =
G4ThreeVector(p.
x()/radius,p.
y()/radius,p.
z()/radius); }
443 if( distRMax <= halfCarTolerance )
448 if( (fRmin != 0.0) && (distRMin <= halfCarTolerance) )
453 if( !fFullPhiSphere )
455 if (distSPhi <= halfAngTolerance)
460 if (distEPhi <= halfAngTolerance)
466 if ( !fFullThetaSphere )
468 if ((distSTheta <= halfAngTolerance) && (fSTheta > 0.))
471 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm += nZ; }
472 else { sumnorm += nTs; }
474 if ((distETheta <= halfAngTolerance) && (eTheta < pi))
477 if ((radius <= halfCarTolerance) && fFullPhiSphere) { sumnorm -= nZ; }
478 else { sumnorm += nTe; }
479 if(sumnorm.
z() == 0.) { sumnorm += nZ; }
482 if ( noSurfaces == 0 )
485 G4Exception(
"G4Sphere::SurfaceNormal(p)",
"GeomSolids1002",
488 norm = ApproxSurfaceNormal(p);
490 else if ( noSurfaces == 1 ) { norm = sumnorm; }
491 else { norm = sumnorm.
unit(); }
678 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
679 G4double tolSTheta=0., tolETheta=0. ;
682 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
683 const G4double halfRminTolerance = fRminTolerance*0.5;
684 const G4double tolORMin2 = (fRmin>halfRminTolerance)
685 ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
687 (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
689 (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
691 (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
695 G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
708 G4double t1, t2, b, c, d2, d, sd = kInfinity ;
712 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
713 rad2 = rho2 + p.
z()*p.
z() ;
714 pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
716 pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
717 pDotV3d = pDotV2d + p.
z()*v.
z() ;
721 if (!fFullThetaSphere)
723 tolSTheta = fSTheta - halfAngTolerance ;
724 tolETheta = eTheta + halfAngTolerance ;
728 if ((rad2!=0.0) || (fRmin!=0.0))
734 G4double vTheta = std::atan2(std::sqrt(v.
x()*v.
x()+v.
y()*v.
y()),v.
z()) ;
735 if ( (vTheta < tolSTheta) || (vTheta > tolETheta) )
757 c = rad2 - fRmax*fRmax ;
759 if (c > fRmaxTolerance*fRmax)
764 d2 = pDotV3d*pDotV3d - c ;
768 sd = -pDotV3d - std::sqrt(d2) ;
774 G4double fTerm = sd-std::fmod(sd,dRmax);
777 xi = p.
x() + sd*v.
x() ;
778 yi = p.
y() + sd*v.
y() ;
779 rhoi = std::sqrt(xi*xi + yi*yi) ;
781 if (!fFullPhiSphere && (rhoi != 0.0))
783 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
785 if (cosPsi >= cosHDPhiOT)
787 if (!fFullThetaSphere)
789 zi = p.
z() + sd*v.
z() ;
794 iTheta = std::atan2(rhoi,zi) ;
795 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
808 if (!fFullThetaSphere)
810 zi = p.
z() + sd*v.
z() ;
815 iTheta = std::atan2(rhoi,zi) ;
816 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
830 return snxt=kInfinity;
838 d2 = pDotV3d*pDotV3d - c ;
840 if ( (rad2 > tolIRMax2)
841 && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
848 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
850 if (cosPsi>=cosHDPhiIT)
854 if ( !fFullThetaSphere )
856 if ( (pTheta >= tolSTheta + kAngTolerance)
857 && (pTheta <= tolETheta - kAngTolerance) )
870 if ( !fFullThetaSphere )
872 if ( (pTheta >= tolSTheta + kAngTolerance)
873 && (pTheta <= tolETheta - kAngTolerance) )
893 c = rad2 - fRmin*fRmin ;
894 d2 = pDotV3d*pDotV3d - c ;
899 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
902 if ( !fFullPhiSphere )
907 cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
908 if (cosPsi >= cosHDPhiIT)
912 if ( !fFullThetaSphere )
914 if ( (pTheta >= tolSTheta + kAngTolerance)
915 && (pTheta <= tolETheta - kAngTolerance) )
928 if ( !fFullThetaSphere )
930 if ( (pTheta >= tolSTheta + kAngTolerance)
931 && (pTheta <= tolETheta - kAngTolerance) )
946 sd = -pDotV3d + std::sqrt(d2) ;
947 if ( sd >= halfRminTolerance )
949 xi = p.
x() + sd*v.
x() ;
950 yi = p.
y() + sd*v.
y() ;
951 rhoi = std::sqrt(xi*xi+yi*yi) ;
953 if ( !fFullPhiSphere && (rhoi != 0.0) )
955 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
957 if (cosPsi >= cosHDPhiOT)
959 if ( !fFullThetaSphere )
961 zi = p.
z() + sd*v.
z() ;
966 iTheta = std::atan2(rhoi,zi) ;
967 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
980 if ( !fFullThetaSphere )
982 zi = p.
z() + sd*v.
z() ;
987 iTheta = std::atan2(rhoi,zi) ;
988 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1012 if ( !fFullPhiSphere )
1017 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1021 Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
1023 if (Dist < halfCarTolerance)
1031 xi = p.
x() + sd*v.
x() ;
1032 yi = p.
y() + sd*v.
y() ;
1033 zi = p.
z() + sd*v.
z() ;
1034 rhoi2 = xi*xi + yi*yi ;
1035 radi2 = rhoi2 + zi*zi ;
1046 if ( (radi2 <= tolORMax2)
1047 && (radi2 >= tolORMin2)
1048 && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
1054 if ( !fFullThetaSphere )
1056 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1057 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1062 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
1080 Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
1084 Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
1085 if ( Dist < halfCarTolerance )
1093 xi = p.
x() + sd*v.
x() ;
1094 yi = p.
y() + sd*v.
y() ;
1095 zi = p.
z() + sd*v.
z() ;
1096 rhoi2 = xi*xi + yi*yi ;
1097 radi2 = rhoi2 + zi*zi ;
1108 if ( (radi2 <= tolORMax2)
1109 && (radi2 >= tolORMin2)
1110 && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
1116 if ( !fFullThetaSphere )
1118 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1119 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1124 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
1142 if ( !fFullThetaSphere )
1167 dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
1171 dist2STheta = kInfinity ;
1175 dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
1179 dist2ETheta=kInfinity;
1181 if ( pTheta < tolSTheta )
1186 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1187 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1191 c = dist2STheta/t1 ;
1198 zi = p.
z() + sd*v.
z();
1200 if ( (sd < 0) || (zi*(fSTheta - halfpi) > 0) )
1204 if ((sd >= 0) && (sd < snxt))
1206 xi = p.
x() + sd*v.
x();
1207 yi = p.
y() + sd*v.
y();
1208 zi = p.
z() + sd*v.
z();
1209 rhoi2 = xi*xi + yi*yi;
1210 radi2 = rhoi2 + zi*zi;
1211 if ( (radi2 <= tolORMax2)
1212 && (radi2 >= tolORMin2)
1213 && (zi*(fSTheta - halfpi) <= 0) )
1215 if ( !fFullPhiSphere && (rhoi2 != 0.0) )
1217 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1218 if (cosPsi >= cosHDPhiOT)
1237 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1238 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1242 c = dist2ETheta/t1 ;
1250 if ( (sd >= 0) && (sd < snxt) )
1252 xi = p.
x() + sd*v.
x() ;
1253 yi = p.
y() + sd*v.
y() ;
1254 zi = p.
z() + sd*v.
z() ;
1255 rhoi2 = xi*xi + yi*yi ;
1256 radi2 = rhoi2 + zi*zi ;
1258 if ( (radi2 <= tolORMax2)
1259 && (radi2 >= tolORMin2)
1260 && (zi*(eTheta - halfpi) <= 0) )
1262 if (!fFullPhiSphere && (rhoi2 != 0.0))
1264 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1265 if (cosPsi >= cosHDPhiOT)
1280 else if ( pTheta > tolETheta )
1286 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1287 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1291 c = dist2ETheta/t1 ;
1298 zi = p.
z() + sd*v.
z();
1300 if ( (sd < 0) || (zi*(eTheta - halfpi) > 0) )
1304 if ( (sd >= 0) && (sd < snxt) )
1306 xi = p.
x() + sd*v.
x() ;
1307 yi = p.
y() + sd*v.
y() ;
1308 zi = p.
z() + sd*v.
z() ;
1309 rhoi2 = xi*xi + yi*yi ;
1310 radi2 = rhoi2 + zi*zi ;
1312 if ( (radi2 <= tolORMax2)
1313 && (radi2 >= tolORMin2)
1314 && (zi*(eTheta - halfpi) <= 0) )
1316 if (!fFullPhiSphere && (rhoi2 != 0.0))
1318 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1319 if (cosPsi >= cosHDPhiOT)
1336 if ( fSTheta != 0.0 )
1338 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1339 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1343 c = dist2STheta/t1 ;
1351 if ( (sd >= 0) && (sd < snxt) )
1353 xi = p.
x() + sd*v.
x() ;
1354 yi = p.
y() + sd*v.
y() ;
1355 zi = p.
z() + sd*v.
z() ;
1356 rhoi2 = xi*xi + yi*yi ;
1357 radi2 = rhoi2 + zi*zi ;
1359 if ( (radi2 <= tolORMax2)
1360 && (radi2 >= tolORMin2)
1361 && (zi*(fSTheta - halfpi) <= 0) )
1363 if (!fFullPhiSphere && (rhoi2 != 0.0))
1365 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1366 if (cosPsi >= cosHDPhiOT)
1381 else if ( (pTheta < tolSTheta + kAngTolerance)
1382 && (fSTheta > halfAngTolerance) )
1388 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1389 if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<halfpi)
1390 || (t2<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>halfpi)
1391 || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==halfpi) )
1393 if (!fFullPhiSphere && (rho2 != 0.0))
1395 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1396 if (cosPsi >= cosHDPhiIT)
1409 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1413 c = dist2STheta/t1 ;
1420 if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
1422 xi = p.
x() + sd*v.
x() ;
1423 yi = p.
y() + sd*v.
y() ;
1424 zi = p.
z() + sd*v.
z() ;
1425 rhoi2 = xi*xi + yi*yi ;
1426 radi2 = rhoi2 + zi*zi ;
1428 if ( (radi2 <= tolORMax2)
1429 && (radi2 >= tolORMin2)
1430 && (zi*(fSTheta - halfpi) <= 0) )
1432 if ( !fFullPhiSphere && (rhoi2 != 0.0) )
1434 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1435 if ( cosPsi >= cosHDPhiOT )
1449 else if ((pTheta > tolETheta-kAngTolerance) && (eTheta < pi-kAngTolerance))
1456 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1458 if ( ((t2<0) && (eTheta < halfpi)
1459 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1460 || ((t2>=0) && (eTheta > halfpi)
1461 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1462 || ((v.
z()>0) && (eTheta == halfpi)
1463 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2)) )
1465 if (!fFullPhiSphere && (rho2 != 0.0))
1467 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1468 if (cosPsi >= cosHDPhiIT)
1481 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1485 c = dist2ETheta/t1 ;
1493 if ( (sd >= halfCarTolerance)
1494 && (sd < snxt) && (eTheta > halfpi) )
1496 xi = p.
x() + sd*v.
x() ;
1497 yi = p.
y() + sd*v.
y() ;
1498 zi = p.
z() + sd*v.
z() ;
1499 rhoi2 = xi*xi + yi*yi ;
1500 radi2 = rhoi2 + zi*zi ;
1502 if ( (radi2 <= tolORMax2)
1503 && (radi2 >= tolORMin2)
1504 && (zi*(eTheta - halfpi) <= 0) )
1506 if (!fFullPhiSphere && (rhoi2 != 0.0))
1508 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1509 if (cosPsi >= cosHDPhiOT)
1528 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1529 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1533 c = dist2STheta/t1 ;
1541 if ((sd >= 0) && (sd < snxt))
1543 xi = p.
x() + sd*v.
x() ;
1544 yi = p.
y() + sd*v.
y() ;
1545 zi = p.
z() + sd*v.
z() ;
1546 rhoi2 = xi*xi + yi*yi ;
1547 radi2 = rhoi2 + zi*zi ;
1549 if ( (radi2 <= tolORMax2)
1550 && (radi2 >= tolORMin2)
1551 && (zi*(fSTheta - halfpi) <= 0) )
1553 if (!fFullPhiSphere && (rhoi2 != 0.0))
1555 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1556 if (cosPsi >= cosHDPhiOT)
1569 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1570 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1574 c = dist2ETheta/t1 ;
1582 if ((sd >= 0) && (sd < snxt))
1584 xi = p.
x() + sd*v.
x() ;
1585 yi = p.
y() + sd*v.
y() ;
1586 zi = p.
z() + sd*v.
z() ;
1587 rhoi2 = xi*xi + yi*yi ;
1588 radi2 = rhoi2 + zi*zi ;
1590 if ( (radi2 <= tolORMax2)
1591 && (radi2 >= tolORMin2)
1592 && (zi*(eTheta - halfpi) <= 0) )
1594 if (!fFullPhiSphere && (rhoi2 != 0.0))
1596 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1597 if ( cosPsi >= cosHDPhiOT )
1726 G4double sphi= kInfinity,stheta= kInfinity;
1727 ESide side=kNull,sidephi=kNull,sidetheta=kNull;
1729 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
1730 const G4double halfRminTolerance = fRminTolerance*0.5;
1731 const G4double Rmax_plus = fRmax + halfRmaxTolerance;
1732 const G4double Rmin_minus = (fRmin) != 0.0 ? fRmin-halfRminTolerance : 0;
1738 G4double pDistS,compS,pDistE,compE,sphi2,vphi;
1740 G4double rho2,rad2,pDotV2d,pDotV3d;
1747 G4double dist2STheta, dist2ETheta, distTheta;
1752 rho2 = p.
x()*p.
x()+p.
y()*p.
y();
1753 rad2 = rho2+p.
z()*p.
z();
1755 pDotV2d = p.
x()*v.
x()+p.
y()*v.
y();
1756 pDotV3d = pDotV2d+p.
z()*v.
z();
1774 if( (rad2 <= Rmax_plus*Rmax_plus) && (rad2 >= Rmin_minus*Rmin_minus) )
1776 c = rad2 - fRmax*fRmax;
1778 if (c < fRmaxTolerance*fRmax)
1789 d2 = pDotV3d*pDotV3d - c;
1791 if( (c >- fRmaxTolerance*fRmax)
1792 && ((pDotV3d >=0) || (d2 < 0)) )
1804 snxt = -pDotV3d+std::sqrt(d2);
1815 c = rad2 - fRmin*fRmin;
1816 d2 = pDotV3d*pDotV3d - c;
1818 if (c >- fRminTolerance*fRmin)
1820 if ( (c < fRminTolerance*fRmin)
1821 && (d2 >= fRminTolerance*fRmin) && (pDotV3d < 0) )
1823 if(calcNorm) { *validNorm =
false; }
1830 sd = -pDotV3d-std::sqrt(d2);
1845 if ( !fFullThetaSphere )
1872 if( std::fabs(tanSTheta) > 5./kAngTolerance )
1876 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
1885 stheta = -p.
z()/v.
z();
1886 sidetheta = kSTheta;
1891 t1 = 1-v.
z()*v.
z()*(1+tanSTheta2);
1892 t2 = pDotV2d-p.
z()*v.
z()*tanSTheta2;
1893 dist2STheta = rho2-p.
z()*p.
z()*tanSTheta2;
1895 distTheta = std::sqrt(rho2)-p.
z()*tanSTheta;
1897 if( std::fabs(t1) < halfAngTolerance )
1901 if(std::fabs(distTheta) < halfRmaxTolerance)
1903 if( (fSTheta < halfpi) && (p.
z() > 0.) )
1905 if( calcNorm ) { *validNorm =
false; }
1908 else if( (fSTheta > halfpi) && (p.
z() <= 0) )
1915 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
1919 std::sin(fSTheta) );
1926 stheta = -0.5*dist2STheta/t2;
1927 sidetheta = kSTheta;
1932 if( std::fabs(distTheta) < halfRmaxTolerance )
1934 if( (fSTheta > halfpi) && (t2 >= 0.) )
1941 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
1945 std::sin(fSTheta) );
1951 else if( (fSTheta < halfpi) && (t2 < 0.) && (p.
z() >=0.) )
1953 if( calcNorm ) { *validNorm =
false; }
1965 if( fSTheta > halfpi )
1969 if ( ((std::fabs(s) < halfRmaxTolerance) && (t2 < 0.))
1970 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() > 0.) ) )
1974 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() <= 0.) )
1977 sidetheta = kSTheta;
1984 if ( ( (std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.) )
1985 || (sd < 0.) || ( (sd > 0.) && (p.
z() + sd*v.
z() < 0.) ) )
1989 if( (sd > halfRmaxTolerance) && (p.
z() + sd*v.
z() >= 0.) )
1992 sidetheta = kSTheta;
2001 if( std::fabs(tanETheta) > 5./kAngTolerance )
2005 if ( std::fabs( p.
z() ) <= halfRmaxTolerance )
2019 sidetheta = kETheta;
2025 t1 = 1-v.
z()*v.
z()*(1+tanETheta2);
2026 t2 = pDotV2d-p.
z()*v.
z()*tanETheta2;
2027 dist2ETheta = rho2-p.
z()*p.
z()*tanETheta2;
2029 distTheta = std::sqrt(rho2)-p.
z()*tanETheta;
2031 if( std::fabs(t1) < halfAngTolerance )
2035 if(std::fabs(distTheta) < halfRmaxTolerance)
2037 if( (eTheta > halfpi) && (p.
z() < 0.) )
2039 if( calcNorm ) { *validNorm =
false; }
2042 else if ( (eTheta < halfpi) && (p.
z() >= 0) )
2049 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2059 sd = -0.5*dist2ETheta/t2;
2064 sidetheta = kETheta;
2070 if ( std::fabs(distTheta) < halfRmaxTolerance )
2072 if( (eTheta < halfpi) && (t2 >= 0.) )
2079 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2088 else if ( (eTheta > halfpi)
2089 && (t2 < 0.) && (p.
z() <=0.) )
2091 if( calcNorm ) { *validNorm =
false; }
2098 if ( (d2 <halfRmaxTolerance) && (d2 > -halfRmaxTolerance) )
2106 if( eTheta < halfpi )
2110 if( ((std::fabs(sd) < halfRmaxTolerance) && (t2 < 0.))
2115 if( sd > halfRmaxTolerance )
2120 sidetheta = kETheta;
2128 if ( ((std::fabs(sd) < halfRmaxTolerance) && (t2 >= 0.))
2130 || ( (sd > 0.) && (p.
z() + sd*v.
z() > halfRmaxTolerance) ) )
2134 if ( ( sd>halfRmaxTolerance )
2135 && ( p.
z()+sd*v.
z() <= halfRmaxTolerance ) )
2140 sidetheta = kETheta;
2153 if ( !fFullPhiSphere )
2155 if ( (p.
x() != 0.0) || (p.
y() != 0.0) )
2159 pDistS=p.
x()*sinSPhi-p.
y()*cosSPhi;
2160 pDistE=-p.
x()*sinEPhi+p.
y()*cosEPhi;
2164 compS = -sinSPhi*v.
x()+cosSPhi*v.
y() ;
2165 compE = sinEPhi*v.
x()-cosEPhi*v.
y() ;
2168 if ( (pDistS <= 0) && (pDistE <= 0) )
2174 sphi = pDistS/compS ;
2175 xi = p.
x()+sphi*v.
x() ;
2176 yi = p.
y()+sphi*v.
y() ;
2182 vphi = std::atan2(v.
y(),v.
x());
2184 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2185 && ( (ePhi+halfAngTolerance) >= vphi) )
2190 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2197 if ( pDistS > -halfCarTolerance) { sphi = 0; }
2200 else { sphi = kInfinity; }
2204 sphi2=pDistE/compE ;
2207 xi = p.
x()+sphi2*v.
x() ;
2208 yi = p.
y()+sphi2*v.
y() ;
2217 vphi = std::atan2(v.
y(),v.
x()) ;
2219 if( (fSPhi-halfAngTolerance > vphi)
2220 ||(fSPhi+fDPhi+halfAngTolerance < vphi) )
2223 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2; }
2224 else { sphi = 0.0; }
2227 else if ((yi*cosCPhi-xi*sinCPhi)>=0)
2230 if ( pDistE <= -halfCarTolerance )
2242 else if ((pDistS >= 0) && (pDistE >= 0))
2244 if ( pDistS <= pDistE )
2254 if ( (compS < 0) && (compE < 0) ) { sphi = 0; }
2255 else { sphi = kInfinity; }
2262 if ( (compS >= 0) && (compE >= 0) ) { sphi = kInfinity; }
2266 else if ( (pDistS > 0) && (pDistE < 0) )
2274 sphi = pDistE/compE ;
2275 xi = p.
x() + sphi*v.
x() ;
2276 yi = p.
y() + sphi*v.
y() ;
2283 vphi = std::atan2(v.
y(),v.
x());
2285 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2286 && ( (ePhi+halfAngTolerance) >= vphi) )
2291 else if ( ( yi*cosCPhi - xi*sinCPhi ) <= 0 )
2298 if ( pDistE > -halfCarTolerance ) { sphi = 0.; }
2312 sphi = pDistE/compE ;
2313 xi = p.
x() + sphi*v.
x() ;
2314 yi = p.
y() + sphi*v.
y() ;
2322 vphi = std::atan2(v.
y(),v.
x());
2324 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2325 && ( (ePhi+halfAngTolerance) >= vphi) )
2330 else if ( ( yi*cosCPhi - xi*sinCPhi) <= 0 )
2339 else sphi=kInfinity;
2358 xi=p.
x()+sphi*v.
x();
2359 yi=p.
y()+sphi*v.
y();
2366 vphi = std::atan2(v.
y(),v.
x()) ;
2368 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2369 && ( (ePhi+halfAngTolerance) >= vphi) )
2374 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2381 if ( pDistS > -halfCarTolerance ) { sphi = 0; }
2395 sphi = pDistS/compS ;
2396 xi = p.
x()+sphi*v.
x() ;
2397 yi = p.
y()+sphi*v.
y() ;
2405 vphi = std::atan2(v.
y(),v.
x()) ;
2407 if ( ( (fSPhi-halfAngTolerance) <= vphi)
2408 && ( (ePhi+halfAngTolerance) >= vphi) )
2413 else if ( ( yi*cosCPhi - xi*sinCPhi ) >= 0 )
2440 if ( (v.
x() != 0.0) || (v.
y() != 0.0) )
2442 vphi = std::atan2(v.
y(),v.
x()) ;
2443 if ((fSPhi-halfAngTolerance < vphi) && (vphi < ePhi+halfAngTolerance))
2475 xi=p.
x()+snxt*v.
x();
2476 yi=p.
y()+snxt*v.
y();
2477 zi=p.
z()+snxt*v.
z();
2492 else { *validNorm=
false; }
2501 else { *validNorm=
false; }
2505 if( fSTheta == halfpi )
2510 else if ( fSTheta > halfpi )
2512 xi = p.
x() + snxt*v.
x();
2513 yi = p.
y() + snxt*v.
y();
2517 rhoSecTheta = std::sqrt(rho2*(1+tanSTheta2));
2519 -tanSTheta/std::sqrt(1+tanSTheta2));
2527 else { *validNorm=
false; }
2531 if( eTheta == halfpi )
2536 else if ( eTheta < halfpi )
2538 xi=p.
x()+snxt*v.
x();
2539 yi=p.
y()+snxt*v.
y();
2543 rhoSecTheta = std::sqrt(rho2*(1+tanETheta2));
2545 -tanETheta/std::sqrt(1+tanETheta2) );
2553 else { *validNorm=
false; }
2559 std::ostringstream message;
2560 G4long oldprc = message.precision(16);
2561 message <<
"Undefined side for valid surface normal to solid."
2564 <<
"p.x() = " << p.
x()/mm <<
" mm" <<
G4endl
2565 <<
"p.y() = " << p.
y()/mm <<
" mm" <<
G4endl
2568 <<
"v.x() = " << v.
x() <<
G4endl
2569 <<
"v.y() = " << v.
y() <<
G4endl
2572 <<
"snxt = " << snxt/mm <<
" mm" <<
G4endl;
2573 message.precision(oldprc);
2579 if (snxt == kInfinity)
2583 std::ostringstream message;
2584 G4long oldprc = message.precision(16);
2585 message <<
"Logic error: snxt = kInfinity ???" <<
G4endl
2587 <<
"p.x() = " << p.
x()/mm <<
" mm" <<
G4endl
2588 <<
"p.y() = " << p.
y()/mm <<
" mm" <<
G4endl
2590 <<
"Rp = "<< std::sqrt( p.
x()*p.
x()+p.
y()*p.
y()+p.
z()*p.
z() )/mm
2593 <<
"v.x() = " << v.
x() <<
G4endl
2594 <<
"v.y() = " << v.
y() <<
G4endl
2597 <<
"snxt = " << snxt/mm <<
" mm" <<
G4endl;
2598 message.precision(oldprc);