869{
871 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
872 G4double tolSTheta=0., tolETheta=0. ;
874
876 static const G4double halfAngTolerance = kAngTolerance*0.5;
877 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
878 const G4double halfRminTolerance = fRminTolerance*0.5;
879 const G4double tolORMin2 = (fRmin>halfRminTolerance)
880 ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
882 (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
884 (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
886 (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
887
888
889
890 G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
891
892
893
895
896
897
899
900
901
903 G4double t1, t2, b, c, d2, d, sd = kInfinity ;
904
905
906
907 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
908 rad2 = rho2 + p.
z()*p.
z() ;
909 pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
910
911 pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
912 pDotV3d = pDotV2d + p.
z()*v.
z() ;
913
914
915
916 if (!fFullThetaSphere)
917 {
918 tolSTheta = fSTheta - halfAngTolerance ;
919 tolETheta = eTheta + halfAngTolerance ;
920 }
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936 c = rad2 - fRmax*fRmax ;
937
938 if (c > fRmaxTolerance*fRmax)
939 {
940
941
942
943 d2 = pDotV3d*pDotV3d - c ;
944
945 if ( d2 >= 0 )
946 {
947 sd = -pDotV3d - std::sqrt(d2) ;
948
949 if (sd >= 0 )
950 {
951 if ( sd>dRmax )
952 {
953 G4double fTerm = sd-std::fmod(sd,dRmax);
955 }
956 xi = p.
x() + sd*v.
x() ;
957 yi = p.
y() + sd*v.
y() ;
958 rhoi = std::sqrt(xi*xi + yi*yi) ;
959
960 if (!fFullPhiSphere && rhoi)
961 {
962 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
963
964 if (cosPsi >= cosHDPhiOT)
965 {
966 if (!fFullThetaSphere)
967 {
968 zi = p.
z() + sd*v.
z() ;
969
970
971
972
973 iTheta = std::atan2(rhoi,zi) ;
974 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
975 {
976 return snxt = sd ;
977 }
978 }
979 else
980 {
981 return snxt=sd;
982 }
983 }
984 }
985 else
986 {
987 if (!fFullThetaSphere)
988 {
989 zi = p.
z() + sd*v.
z() ;
990
991
992
993
994 iTheta = std::atan2(rhoi,zi) ;
995 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
996 {
997 return snxt=sd;
998 }
999 }
1000 else
1001 {
1002 return snxt = sd;
1003 }
1004 }
1005 }
1006 }
1007 else
1008 {
1009 return snxt=kInfinity;
1010 }
1011 }
1012 else
1013 {
1014
1015
1016
1017 d2 = pDotV3d*pDotV3d - c ;
1018
1019 if ( (rad2 > tolIRMax2)
1020 && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
1021 {
1022 if (!fFullPhiSphere)
1023 {
1024
1025
1026
1027 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1028
1029 if (cosPsi>=cosHDPhiIT)
1030 {
1031
1032
1033 if ( !fFullThetaSphere )
1034 {
1035 if ( (pTheta >= tolSTheta + kAngTolerance)
1036 && (pTheta <= tolETheta - kAngTolerance) )
1037 {
1038 return snxt=0;
1039 }
1040 }
1041 else
1042 {
1043 return snxt=0;
1044 }
1045 }
1046 }
1047 else
1048 {
1049 if ( !fFullThetaSphere )
1050 {
1051 if ( (pTheta >= tolSTheta + kAngTolerance)
1052 && (pTheta <= tolETheta - kAngTolerance) )
1053 {
1054 return snxt=0;
1055 }
1056 }
1057 else
1058 {
1059 return snxt=0;
1060 }
1061 }
1062 }
1063 }
1064
1065
1066
1067
1068
1069
1070 if (fRmin)
1071 {
1072 c = rad2 - fRmin*fRmin ;
1073 d2 = pDotV3d*pDotV3d - c ;
1074
1075
1076
1077
1078 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
1080 {
1081 if ( !fFullPhiSphere )
1082 {
1083
1084
1085
1086 cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
1087 if (cosPsi >= cosHDPhiIT)
1088 {
1089
1090
1091 if ( !fFullThetaSphere )
1092 {
1093 if ( (pTheta >= tolSTheta + kAngTolerance)
1094 && (pTheta <= tolETheta - kAngTolerance) )
1095 {
1096 return snxt=0;
1097 }
1098 }
1099 else
1100 {
1101 return snxt = 0 ;
1102 }
1103 }
1104 }
1105 else
1106 {
1107 if ( !fFullThetaSphere )
1108 {
1109 if ( (pTheta >= tolSTheta + kAngTolerance)
1110 && (pTheta <= tolETheta - kAngTolerance) )
1111 {
1112 return snxt = 0 ;
1113 }
1114 }
1115 else
1116 {
1117 return snxt=0;
1118 }
1119 }
1120 }
1121 else
1122 {
1123 if (d2 >= 0)
1124 {
1125 sd = -pDotV3d + std::sqrt(d2) ;
1126 if ( sd >= halfRminTolerance )
1127 {
1128 xi = p.
x() + sd*v.
x() ;
1129 yi = p.
y() + sd*v.
y() ;
1130 rhoi = std::sqrt(xi*xi+yi*yi) ;
1131
1132 if ( !fFullPhiSphere && rhoi )
1133 {
1134 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
1135
1136 if (cosPsi >= cosHDPhiOT)
1137 {
1138 if ( !fFullThetaSphere )
1139 {
1140 zi = p.
z() + sd*v.
z() ;
1141
1142
1143
1144
1145 iTheta = std::atan2(rhoi,zi) ;
1146 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
1147 {
1148 snxt = sd;
1149 }
1150 }
1151 else
1152 {
1153 snxt=sd;
1154 }
1155 }
1156 }
1157 else
1158 {
1159 if ( !fFullThetaSphere )
1160 {
1161 zi = p.
z() + sd*v.
z() ;
1162
1163
1164
1165
1166 iTheta = std::atan2(rhoi,zi) ;
1167 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1168 {
1169 snxt = sd;
1170 }
1171 }
1172 else
1173 {
1174 snxt = sd;
1175 }
1176 }
1177 }
1178 }
1179 }
1180 }
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191 if ( !fFullPhiSphere )
1192 {
1193
1194
1195
1196 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1197
1198 if ( Comp < 0 )
1199 {
1200 Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
1201
1202 if (Dist < halfCarTolerance)
1203 {
1204 sd = Dist/Comp ;
1205
1206 if (sd < snxt)
1207 {
1208 if ( sd > 0 )
1209 {
1210 xi = p.
x() + sd*v.
x() ;
1211 yi = p.
y() + sd*v.
y() ;
1212 zi = p.
z() + sd*v.
z() ;
1213 rhoi2 = xi*xi + yi*yi ;
1214 radi2 = rhoi2 + zi*zi ;
1215 }
1216 else
1217 {
1218 sd = 0 ;
1222 rhoi2 = rho2 ;
1223 radi2 = rad2 ;
1224 }
1225 if ( (radi2 <= tolORMax2)
1226 && (radi2 >= tolORMin2)
1227 && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
1228 {
1229
1230
1231
1232
1233 if ( !fFullThetaSphere )
1234 {
1235 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1236 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1237 {
1238
1239
1240
1241 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
1242 {
1243 snxt = sd;
1244 }
1245 }
1246 }
1247 else
1248 {
1249 snxt = sd;
1250 }
1251 }
1252 }
1253 }
1254 }
1255
1256
1257
1258
1259 Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
1260
1261 if (Comp < 0)
1262 {
1263 Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
1264 if ( Dist < halfCarTolerance )
1265 {
1266 sd = Dist/Comp ;
1267
1268 if ( sd < snxt )
1269 {
1270 if (sd > 0)
1271 {
1272 xi = p.
x() + sd*v.
x() ;
1273 yi = p.
y() + sd*v.
y() ;
1274 zi = p.
z() + sd*v.
z() ;
1275 rhoi2 = xi*xi + yi*yi ;
1276 radi2 = rhoi2 + zi*zi ;
1277 }
1278 else
1279 {
1280 sd = 0 ;
1284 rhoi2 = rho2 ;
1285 radi2 = rad2 ;
1286 }
1287 if ( (radi2 <= tolORMax2)
1288 && (radi2 >= tolORMin2)
1289 && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
1290 {
1291
1292
1293
1294
1295 if ( !fFullThetaSphere )
1296 {
1297 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1298 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1299 {
1300
1301
1302
1303 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
1304 {
1305 snxt = sd;
1306 }
1307 }
1308 }
1309 else
1310 {
1311 snxt = sd;
1312 }
1313 }
1314 }
1315 }
1316 }
1317 }
1318
1319
1320
1321 if ( !fFullThetaSphere )
1322 {
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343 if (fSTheta)
1344 {
1345 dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
1346 }
1347 else
1348 {
1349 dist2STheta = kInfinity ;
1350 }
1351 if ( eTheta < pi )
1352 {
1353 dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
1354 }
1355 else
1356 {
1357 dist2ETheta=kInfinity;
1358 }
1359 if ( pTheta < tolSTheta )
1360 {
1361
1362
1363
1364 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1365 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1366 if (t1)
1367 {
1368 b = t2/t1 ;
1369 c = dist2STheta/t1 ;
1370 d2 = b*b - c ;
1371
1372 if ( d2 >= 0 )
1373 {
1374 d = std::sqrt(d2) ;
1375 sd = -b - d ;
1376 zi = p.
z() + sd*v.
z();
1377
1378 if ( (sd < 0) || (zi*(fSTheta - halfpi) > 0) )
1379 {
1380 sd = -b+d;
1381 }
1382 if ((sd >= 0) && (sd < snxt))
1383 {
1384 xi = p.
x() + sd*v.
x();
1385 yi = p.
y() + sd*v.
y();
1386 zi = p.
z() + sd*v.
z();
1387 rhoi2 = xi*xi + yi*yi;
1388 radi2 = rhoi2 + zi*zi;
1389 if ( (radi2 <= tolORMax2)
1390 && (radi2 >= tolORMin2)
1391 && (zi*(fSTheta - halfpi) <= 0) )
1392 {
1393 if ( !fFullPhiSphere && rhoi2 )
1394 {
1395 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1396 if (cosPsi >= cosHDPhiOT)
1397 {
1398 snxt = sd;
1399 }
1400 }
1401 else
1402 {
1403 snxt = sd;
1404 }
1405 }
1406 }
1407 }
1408 }
1409
1410
1411
1412
1413 if ( eTheta < pi )
1414 {
1415 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1416 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1417 if (t1)
1418 {
1419 b = t2/t1 ;
1420 c = dist2ETheta/t1 ;
1421 d2 = b*b - c ;
1422
1423 if (d2 >= 0)
1424 {
1425 d = std::sqrt(d2) ;
1426 sd = -b + d ;
1427
1428 if ( (sd >= 0) && (sd < snxt) )
1429 {
1430 xi = p.
x() + sd*v.
x() ;
1431 yi = p.
y() + sd*v.
y() ;
1432 zi = p.
z() + sd*v.
z() ;
1433 rhoi2 = xi*xi + yi*yi ;
1434 radi2 = rhoi2 + zi*zi ;
1435
1436 if ( (radi2 <= tolORMax2)
1437 && (radi2 >= tolORMin2)
1438 && (zi*(eTheta - halfpi) <= 0) )
1439 {
1440 if (!fFullPhiSphere && rhoi2)
1441 {
1442 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1443 if (cosPsi >= cosHDPhiOT)
1444 {
1445 snxt = sd;
1446 }
1447 }
1448 else
1449 {
1450 snxt = sd;
1451 }
1452 }
1453 }
1454 }
1455 }
1456 }
1457 }
1458 else if ( pTheta > tolETheta )
1459 {
1460
1461
1462
1463
1464 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1465 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1466 if (t1)
1467 {
1468 b = t2/t1 ;
1469 c = dist2ETheta/t1 ;
1470 d2 = b*b - c ;
1471
1472 if (d2 >= 0)
1473 {
1474 d = std::sqrt(d2) ;
1475 sd = -b - d ;
1476 zi = p.
z() + sd*v.
z();
1477
1478 if ( (sd < 0) || (zi*(eTheta - halfpi) > 0) )
1479 {
1480 sd = -b + d ;
1481 }
1482 if ( (sd >= 0) && (sd < snxt) )
1483 {
1484 xi = p.
x() + sd*v.
x() ;
1485 yi = p.
y() + sd*v.
y() ;
1486 zi = p.
z() + sd*v.
z() ;
1487 rhoi2 = xi*xi + yi*yi ;
1488 radi2 = rhoi2 + zi*zi ;
1489
1490 if ( (radi2 <= tolORMax2)
1491 && (radi2 >= tolORMin2)
1492 && (zi*(eTheta - halfpi) <= 0) )
1493 {
1494 if (!fFullPhiSphere && rhoi2)
1495 {
1496 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1497 if (cosPsi >= cosHDPhiOT)
1498 {
1499 snxt = sd;
1500 }
1501 }
1502 else
1503 {
1504 snxt = sd;
1505 }
1506 }
1507 }
1508 }
1509 }
1510
1511
1512
1513
1514 if ( fSTheta )
1515 {
1516 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1517 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1518 if (t1)
1519 {
1520 b = t2/t1 ;
1521 c = dist2STheta/t1 ;
1522 d2 = b*b - c ;
1523
1524 if (d2 >= 0)
1525 {
1526 d = std::sqrt(d2) ;
1527 sd = -b + d ;
1528
1529 if ( (sd >= 0) && (sd < snxt) )
1530 {
1531 xi = p.
x() + sd*v.
x() ;
1532 yi = p.
y() + sd*v.
y() ;
1533 zi = p.
z() + sd*v.
z() ;
1534 rhoi2 = xi*xi + yi*yi ;
1535 radi2 = rhoi2 + zi*zi ;
1536
1537 if ( (radi2 <= tolORMax2)
1538 && (radi2 >= tolORMin2)
1539 && (zi*(fSTheta - halfpi) <= 0) )
1540 {
1541 if (!fFullPhiSphere && rhoi2)
1542 {
1543 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1544 if (cosPsi >= cosHDPhiOT)
1545 {
1546 snxt = sd;
1547 }
1548 }
1549 else
1550 {
1551 snxt = sd;
1552 }
1553 }
1554 }
1555 }
1556 }
1557 }
1558 }
1559 else if ( (pTheta < tolSTheta + kAngTolerance)
1560 && (fSTheta > halfAngTolerance) )
1561 {
1562
1563
1564
1565
1566 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1567 if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<halfpi)
1568 || (t2<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>halfpi)
1569 || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==halfpi) )
1570 {
1571 if (!fFullPhiSphere && rho2)
1572 {
1573 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1574 if (cosPsi >= cosHDPhiIT)
1575 {
1576 return 0 ;
1577 }
1578 }
1579 else
1580 {
1581 return 0 ;
1582 }
1583 }
1584
1585
1586
1587 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1588 if (t1)
1589 {
1590 b = t2/t1 ;
1591 c = dist2STheta/t1 ;
1592 d2 = b*b - c ;
1593
1594 if (d2 >= 0)
1595 {
1596 d = std::sqrt(d2) ;
1597 sd = -b + d ;
1598 if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
1599 {
1600 xi = p.
x() + sd*v.
x() ;
1601 yi = p.
y() + sd*v.
y() ;
1602 zi = p.
z() + sd*v.
z() ;
1603 rhoi2 = xi*xi + yi*yi ;
1604 radi2 = rhoi2 + zi*zi ;
1605
1606 if ( (radi2 <= tolORMax2)
1607 && (radi2 >= tolORMin2)
1608 && (zi*(fSTheta - halfpi) <= 0) )
1609 {
1610 if ( !fFullPhiSphere && rhoi2 )
1611 {
1612 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1613 if ( cosPsi >= cosHDPhiOT )
1614 {
1615 snxt = sd;
1616 }
1617 }
1618 else
1619 {
1620 snxt = sd;
1621 }
1622 }
1623 }
1624 }
1625 }
1626 }
1627 else if ((pTheta > tolETheta-kAngTolerance) && (eTheta <
pi-kAngTolerance))
1628 {
1629
1630
1631
1632
1633
1634 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1635
1636 if ( ((t2<0) && (eTheta < halfpi)
1637 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1638 || ((t2>=0) && (eTheta > halfpi)
1639 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1640 || ((v.
z()>0) && (eTheta == halfpi)
1641 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2)) )
1642 {
1643 if (!fFullPhiSphere && rho2)
1644 {
1645 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1646 if (cosPsi >= cosHDPhiIT)
1647 {
1648 return 0 ;
1649 }
1650 }
1651 else
1652 {
1653 return 0 ;
1654 }
1655 }
1656
1657
1658
1659 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1660 if (t1)
1661 {
1662 b = t2/t1 ;
1663 c = dist2ETheta/t1 ;
1664 d2 = b*b - c ;
1665
1666 if (d2 >= 0)
1667 {
1668 d = std::sqrt(d2) ;
1669 sd = -b + d ;
1670
1671 if ( (sd >= halfCarTolerance)
1672 && (sd < snxt) && (eTheta > halfpi) )
1673 {
1674 xi = p.
x() + sd*v.
x() ;
1675 yi = p.
y() + sd*v.
y() ;
1676 zi = p.
z() + sd*v.
z() ;
1677 rhoi2 = xi*xi + yi*yi ;
1678 radi2 = rhoi2 + zi*zi ;
1679
1680 if ( (radi2 <= tolORMax2)
1681 && (radi2 >= tolORMin2)
1682 && (zi*(eTheta - halfpi) <= 0) )
1683 {
1684 if (!fFullPhiSphere && rhoi2)
1685 {
1686 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1687 if (cosPsi >= cosHDPhiOT)
1688 {
1689 snxt = sd;
1690 }
1691 }
1692 else
1693 {
1694 snxt = sd;
1695 }
1696 }
1697 }
1698 }
1699 }
1700 }
1701 else
1702 {
1703
1704
1705
1706 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1707 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1708 if (t1)
1709 {
1710 b = t2/t1;
1711 c = dist2STheta/t1 ;
1712 d2 = b*b - c ;
1713
1714 if (d2 >= 0)
1715 {
1716 d = std::sqrt(d2) ;
1717 sd = -b + d ;
1718
1719 if ((sd >= 0) && (sd < snxt))
1720 {
1721 xi = p.
x() + sd*v.
x() ;
1722 yi = p.
y() + sd*v.
y() ;
1723 zi = p.
z() + sd*v.
z() ;
1724 rhoi2 = xi*xi + yi*yi ;
1725 radi2 = rhoi2 + zi*zi ;
1726
1727 if ( (radi2 <= tolORMax2)
1728 && (radi2 >= tolORMin2)
1729 && (zi*(fSTheta - halfpi) <= 0) )
1730 {
1731 if (!fFullPhiSphere && rhoi2)
1732 {
1733 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1734 if (cosPsi >= cosHDPhiOT)
1735 {
1736 snxt = sd;
1737 }
1738 }
1739 else
1740 {
1741 snxt = sd;
1742 }
1743 }
1744 }
1745 }
1746 }
1747 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1748 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1749 if (t1)
1750 {
1751 b = t2/t1 ;
1752 c = dist2ETheta/t1 ;
1753 d2 = b*b - c ;
1754
1755 if (d2 >= 0)
1756 {
1757 d = std::sqrt(d2) ;
1758 sd = -b + d;
1759
1760 if ((sd >= 0) && (sd < snxt))
1761 {
1762 xi = p.
x() + sd*v.
x() ;
1763 yi = p.
y() + sd*v.
y() ;
1764 zi = p.
z() + sd*v.
z() ;
1765 rhoi2 = xi*xi + yi*yi ;
1766 radi2 = rhoi2 + zi*zi ;
1767
1768 if ( (radi2 <= tolORMax2)
1769 && (radi2 >= tolORMin2)
1770 && (zi*(eTheta - halfpi) <= 0) )
1771 {
1772 if (!fFullPhiSphere && rhoi2)
1773 {
1774 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1775 if ( cosPsi >= cosHDPhiOT )
1776 {
1777 snxt = sd;
1778 }
1779 }
1780 else
1781 {
1782 snxt = sd;
1783 }
1784 }
1785 }
1786 }
1787 }
1788 }
1789 }
1790 return snxt;
1791}
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const