730   G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
 
  731   G4double tolSTheta=0., tolETheta=0. ;
 
  734   const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
 
  735   const G4double halfRminTolerance = fRminTolerance*0.5;
 
  736   const G4double tolORMin2 = (fRmin>halfRminTolerance)
 
  737                ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
 
  739                (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
 
  741                (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
 
  743                (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
 
  747   G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
 
  764   rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
 
  765   rad2 = rho2 + p.
z()*p.
z() ;
 
  766   pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
 
  768   pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
 
  769   pDotV3d = pDotV2d + p.
z()*v.
z() ;
 
  773   if (!fFullThetaSphere)
 
  775     tolSTheta = fSTheta - halfAngTolerance ;
 
  776     tolETheta = eTheta + halfAngTolerance ;
 
  780     if ((rad2!=0.0) || (fRmin!=0.0))
 
  786       G4double vTheta = std::atan2(std::sqrt(v.
x()*v.
x()+v.
y()*v.
y()),v.
z()) ;
 
  787       if ( (vTheta < tolSTheta) || (vTheta > tolETheta) )
 
  809   c = rad2 - fRmax*fRmax ;
 
  811   if (c > fRmaxTolerance*fRmax)
 
  816     d2 = pDotV3d*pDotV3d - 
c ;
 
  820       sd = -pDotV3d - std::sqrt(d2) ;
 
  826           G4double fTerm = sd-std::fmod(sd,dRmax);
 
  829         xi   = p.
x() + sd*v.
x() ;
 
  830         yi   = p.
y() + sd*v.
y() ;
 
  831         rhoi = std::sqrt(xi*xi + yi*yi) ;
 
  833         if (!fFullPhiSphere && rhoi)    
 
  835           cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
 
  837           if (cosPsi >= cosHDPhiOT)
 
  839             if (!fFullThetaSphere)   
 
  841               zi = p.
z() + sd*v.
z() ;
 
  846               iTheta = std::atan2(rhoi,zi) ;
 
  847               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
  860           if (!fFullThetaSphere)    
 
  862             zi = p.
z() + sd*v.
z() ;
 
  867             iTheta = std::atan2(rhoi,zi) ;
 
  868             if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
  890     d2 = pDotV3d*pDotV3d - 
c ;
 
  892     if ( (rad2 > tolIRMax2)
 
  893       && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
 
  900         cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
  902         if (cosPsi>=cosHDPhiIT)
 
  906           if ( !fFullThetaSphere )
 
  908             if ( (pTheta >= tolSTheta + kAngTolerance)
 
  909               && (pTheta <= tolETheta - kAngTolerance) )
 
  922         if ( !fFullThetaSphere )
 
  924           if ( (pTheta >= tolSTheta + kAngTolerance)
 
  925             && (pTheta <= tolETheta - kAngTolerance) )
 
  945     c  = rad2 - fRmin*fRmin ;
 
  946     d2 = pDotV3d*pDotV3d - 
c ;
 
  951     if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
 
  954       if ( !fFullPhiSphere )
 
  959         cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
  960         if (cosPsi >= cosHDPhiIT)
 
  964           if ( !fFullThetaSphere )
 
  966             if ( (pTheta >= tolSTheta + kAngTolerance)
 
  967               && (pTheta <= tolETheta - kAngTolerance) )
 
  980         if ( !fFullThetaSphere )
 
  982           if ( (pTheta >= tolSTheta + kAngTolerance)
 
  983             && (pTheta <= tolETheta - kAngTolerance) )
 
  998         sd = -pDotV3d + std::sqrt(d2) ;
 
  999         if ( sd >= halfRminTolerance )  
 
 1001           xi   = p.
x() + sd*v.
x() ;
 
 1002           yi   = p.
y() + sd*v.
y() ;
 
 1003           rhoi = std::sqrt(xi*xi+yi*yi) ;
 
 1005           if ( !fFullPhiSphere && rhoi )   
 
 1007             cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
 
 1009             if (cosPsi >= cosHDPhiOT)
 
 1011               if ( !fFullThetaSphere )  
 
 1013                 zi = p.
z() + sd*v.
z() ;
 
 1018                 iTheta = std::atan2(rhoi,zi) ;
 
 1019                 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
 
 1032             if ( !fFullThetaSphere )   
 
 1034               zi = p.
z() + sd*v.
z() ;
 
 1039               iTheta = std::atan2(rhoi,zi) ;
 
 1040               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
 1064   if ( !fFullPhiSphere )
 
 1069     Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
 
 1073       Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
 
 1075       if (Dist < halfCarTolerance)
 
 1083             xi    = p.
x() + sd*v.
x() ;
 
 1084             yi    = p.
y() + sd*v.
y() ;
 
 1085             zi    = p.
z() + sd*v.
z() ;
 
 1086             rhoi2 = xi*xi + yi*yi   ;
 
 1087             radi2 = rhoi2 + zi*zi   ;
 
 1098           if ( (radi2 <= tolORMax2)
 
 1099             && (radi2 >= tolORMin2)
 
 1100             && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
 
 1106             if ( !fFullThetaSphere )
 
 1108               iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
 
 1109               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
 1114                 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
 
 1132     Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
 
 1136       Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
 
 1137       if ( Dist < halfCarTolerance )
 
 1145             xi    = p.
x() + sd*v.
x() ;
 
 1146             yi    = p.
y() + sd*v.
y() ;
 
 1147             zi    = p.
z() + sd*v.
z() ;
 
 1148             rhoi2 = xi*xi + yi*yi   ;
 
 1149             radi2 = rhoi2 + zi*zi   ;
 
 1160           if ( (radi2 <= tolORMax2)
 
 1161             && (radi2 >= tolORMin2)
 
 1162             && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
 
 1168             if ( !fFullThetaSphere )
 
 1170               iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
 
 1171               if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
 
 1176                 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
 
 1194   if ( !fFullThetaSphere )
 
 1219       dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
 
 1227       dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
 
 1233     if ( pTheta < tolSTheta )
 
 1238       t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1239       t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1243         c  = dist2STheta/
t1 ;
 
 1250           zi = p.
z() + sd*v.
z();
 
 1252           if ( (sd < 0) || (zi*(fSTheta - 
halfpi) > 0) )
 
 1256           if ((sd >= 0) && (sd < snxt))
 
 1258             xi    = p.
x() + sd*v.
x();
 
 1259             yi    = p.
y() + sd*v.
y();
 
 1260             zi    = p.
z() + sd*v.
z();
 
 1261             rhoi2 = xi*xi + yi*yi;
 
 1262             radi2 = rhoi2 + zi*zi;
 
 1263             if ( (radi2 <= tolORMax2)
 
 1264               && (radi2 >= tolORMin2)
 
 1265               && (zi*(fSTheta - 
halfpi) <= 0) )
 
 1267               if ( !fFullPhiSphere && rhoi2 )  
 
 1269                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1270                 if (cosPsi >= cosHDPhiOT)
 
 1289         t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1290         t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1294           c  = dist2ETheta/
t1 ;
 
 1302             if ( (sd >= 0) && (sd < snxt) )
 
 1304               xi    = p.
x() + sd*v.
x() ;
 
 1305               yi    = p.
y() + sd*v.
y() ;
 
 1306               zi    = p.
z() + sd*v.
z() ;
 
 1307               rhoi2 = xi*xi + yi*yi   ;
 
 1308               radi2 = rhoi2 + zi*zi   ;
 
 1310               if ( (radi2 <= tolORMax2)
 
 1311                 && (radi2 >= tolORMin2)
 
 1312                 && (zi*(eTheta - 
halfpi) <= 0) )
 
 1314                 if (!fFullPhiSphere && rhoi2)   
 
 1316                   cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1317                   if (cosPsi >= cosHDPhiOT)
 
 1332     else if ( pTheta > tolETheta ) 
 
 1338       t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1339       t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1343         c  = dist2ETheta/
t1 ;
 
 1350           zi = p.
z() + sd*v.
z();
 
 1352           if ( (sd < 0) || (zi*(eTheta - 
halfpi) > 0) )
 
 1356           if ( (sd >= 0) && (sd < snxt) )
 
 1358             xi    = p.
x() + sd*v.
x() ;
 
 1359             yi    = p.
y() + sd*v.
y() ;
 
 1360             zi    = p.
z() + sd*v.
z() ;
 
 1361             rhoi2 = xi*xi + yi*yi   ;
 
 1362             radi2 = rhoi2 + zi*zi   ;
 
 1364             if ( (radi2 <= tolORMax2)
 
 1365               && (radi2 >= tolORMin2) 
 
 1366               && (zi*(eTheta - 
halfpi) <= 0) )
 
 1368               if (!fFullPhiSphere && rhoi2)  
 
 1370                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1371                 if (cosPsi >= cosHDPhiOT)
 
 1390         t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1391         t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1395           c  = dist2STheta/
t1 ;
 
 1403             if ( (sd >= 0) && (sd < snxt) )
 
 1405               xi    = p.
x() + sd*v.
x() ;
 
 1406               yi    = p.
y() + sd*v.
y() ;
 
 1407               zi    = p.
z() + sd*v.
z() ;
 
 1408               rhoi2 = xi*xi + yi*yi   ;
 
 1409               radi2 = rhoi2 + zi*zi   ;
 
 1411               if ( (radi2 <= tolORMax2)
 
 1412                 && (radi2 >= tolORMin2)
 
 1413                 && (zi*(fSTheta - 
halfpi) <= 0) )
 
 1415                 if (!fFullPhiSphere && rhoi2)   
 
 1417                   cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1418                   if (cosPsi >= cosHDPhiOT)
 
 1433     else if ( (pTheta < tolSTheta + kAngTolerance)
 
 1434            && (fSTheta > halfAngTolerance) )
 
 1440       t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1441       if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<
halfpi)
 
 1442         || (t2<0  && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>
halfpi)
 
 1443         || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==
halfpi) )
 
 1445         if (!fFullPhiSphere && rho2)  
 
 1447           cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
 1448           if (cosPsi >= cosHDPhiIT)
 
 1461       t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1465         c  = dist2STheta/
t1 ;
 
 1472           if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
 
 1474             xi    = p.
x() + sd*v.
x() ;
 
 1475             yi    = p.
y() + sd*v.
y() ;
 
 1476             zi    = p.
z() + sd*v.
z() ;
 
 1477             rhoi2 = xi*xi + yi*yi   ;
 
 1478             radi2 = rhoi2 + zi*zi   ;
 
 1480             if ( (radi2 <= tolORMax2)
 
 1481               && (radi2 >= tolORMin2)
 
 1482               && (zi*(fSTheta - halfpi) <= 0) )
 
 1484               if ( !fFullPhiSphere && rhoi2 )    
 
 1486                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1487                 if ( cosPsi >= cosHDPhiOT )
 
 1501     else if ((pTheta > tolETheta-kAngTolerance) && (eTheta < 
pi-kAngTolerance))
 
 1508       t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1510       if (   ((t2<0) && (eTheta < halfpi)
 
 1511           && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
 
 1512         ||   ((t2>=0) && (eTheta > halfpi)
 
 1513           && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
 
 1514         ||   ((v.
z()>0) && (eTheta == halfpi)
 
 1515           && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))  )
 
 1517         if (!fFullPhiSphere && rho2)   
 
 1519           cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
 
 1520           if (cosPsi >= cosHDPhiIT)
 
 1533       t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1537         c  = dist2ETheta/
t1 ;
 
 1545           if ( (sd >= halfCarTolerance)
 
 1546             && (sd < snxt) && (eTheta > halfpi) )
 
 1548             xi    = p.
x() + sd*v.
x() ;
 
 1549             yi    = p.
y() + sd*v.
y() ;
 
 1550             zi    = p.
z() + sd*v.
z() ;
 
 1551             rhoi2 = xi*xi + yi*yi   ;
 
 1552             radi2 = rhoi2 + zi*zi   ;
 
 1554             if ( (radi2 <= tolORMax2)
 
 1555               && (radi2 >= tolORMin2)
 
 1556               && (zi*(eTheta - halfpi) <= 0) )
 
 1558               if (!fFullPhiSphere && rhoi2)   
 
 1560                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1561                 if (cosPsi >= cosHDPhiOT)
 
 1580       t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
 
 1581       t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
 
 1585         c  = dist2STheta/
t1 ;
 
 1593           if ((sd >= 0) && (sd < snxt))
 
 1595             xi    = p.
x() + sd*v.
x() ;
 
 1596             yi    = p.
y() + sd*v.
y() ;
 
 1597             zi    = p.
z() + sd*v.
z() ;
 
 1598             rhoi2 = xi*xi + yi*yi   ;
 
 1599             radi2 = rhoi2 + zi*zi   ;
 
 1601             if ( (radi2 <= tolORMax2)
 
 1602               && (radi2 >= tolORMin2)
 
 1603               && (zi*(fSTheta - halfpi) <= 0) )
 
 1605               if (!fFullPhiSphere && rhoi2)   
 
 1607                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1608                 if (cosPsi >= cosHDPhiOT)
 
 1621       t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
 
 1622       t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
 
 1626         c  = dist2ETheta/
t1 ;
 
 1634           if ((sd >= 0) && (sd < snxt))
 
 1636             xi    = p.
x() + sd*v.
x() ;
 
 1637             yi    = p.
y() + sd*v.
y() ;
 
 1638             zi    = p.
z() + sd*v.
z() ;
 
 1639             rhoi2 = xi*xi + yi*yi   ;
 
 1640             radi2 = rhoi2 + zi*zi   ;
 
 1642             if ( (radi2 <= tolORMax2)
 
 1643               && (radi2 >= tolORMin2)
 
 1644               && (zi*(eTheta - halfpi) <= 0) )
 
 1646               if (!fFullPhiSphere && rhoi2)   
 
 1648                 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
 
 1649                 if ( cosPsi >= cosHDPhiOT )
 
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const 
 
static const G4double kInfinity
 
static constexpr double pi
 
static constexpr double halfpi