706{
708 G4double rho2, rad2, pDotV2d, pDotV3d, pTheta ;
709 G4double tolSTheta=0., tolETheta=0. ;
711
712 const G4double halfRmaxTolerance = fRmaxTolerance*0.5;
713 const G4double halfRminTolerance = fRminTolerance*0.5;
714 const G4double tolORMin2 = (fRmin>halfRminTolerance)
715 ? (fRmin-halfRminTolerance)*(fRmin-halfRminTolerance) : 0;
717 (fRmin+halfRminTolerance)*(fRmin+halfRminTolerance);
719 (fRmax+halfRmaxTolerance)*(fRmax+halfRmaxTolerance);
721 (fRmax-halfRmaxTolerance)*(fRmax-halfRmaxTolerance);
722
723
724
725 G4double xi, yi, zi, rhoi, rhoi2, radi2, iTheta ;
726
727
728
730
731
732
734
735
736
738 G4double t1, t2, b, c, d2, d, sd = kInfinity ;
739
740
741
742 rho2 = p.
x()*p.
x() + p.
y()*p.
y() ;
743 rad2 = rho2 + p.
z()*p.
z() ;
744 pTheta = std::atan2(std::sqrt(rho2),p.
z()) ;
745
746 pDotV2d = p.
x()*v.
x() + p.
y()*v.
y() ;
747 pDotV3d = pDotV2d + p.
z()*v.
z() ;
748
749
750
751 if (!fFullThetaSphere)
752 {
753 tolSTheta = fSTheta - halfAngTolerance ;
754 tolETheta = eTheta + halfAngTolerance ;
755
756
757
758 if ((rad2!=0.0) || (fRmin!=0.0))
759 {
760
761 }
762 else
763 {
764 G4double vTheta = std::atan2(std::sqrt(v.
x()*v.
x()+v.
y()*v.
y()),v.
z()) ;
765 if ( (vTheta < tolSTheta) || (vTheta > tolETheta) )
766 {
767 return snxt ;
768 }
769 return snxt = 0.0 ;
770 }
771 }
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787 c = rad2 - fRmax*fRmax ;
788
789 if (c > fRmaxTolerance*fRmax)
790 {
791
792
793
794 d2 = pDotV3d*pDotV3d - c ;
795
796 if ( d2 >= 0 )
797 {
798 sd = -pDotV3d - std::sqrt(d2) ;
799
800 if (sd >= 0 )
801 {
802 if ( sd>dRmax )
803 {
804 G4double fTerm = sd-std::fmod(sd,dRmax);
806 }
807 xi = p.
x() + sd*v.
x() ;
808 yi = p.
y() + sd*v.
y() ;
809 rhoi = std::sqrt(xi*xi + yi*yi) ;
810
811 if (!fFullPhiSphere && rhoi)
812 {
813 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
814
815 if (cosPsi >= cosHDPhiOT)
816 {
817 if (!fFullThetaSphere)
818 {
819 zi = p.
z() + sd*v.
z() ;
820
821
822
823
824 iTheta = std::atan2(rhoi,zi) ;
825 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
826 {
827 return snxt = sd ;
828 }
829 }
830 else
831 {
832 return snxt=sd;
833 }
834 }
835 }
836 else
837 {
838 if (!fFullThetaSphere)
839 {
840 zi = p.
z() + sd*v.
z() ;
841
842
843
844
845 iTheta = std::atan2(rhoi,zi) ;
846 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
847 {
848 return snxt=sd;
849 }
850 }
851 else
852 {
853 return snxt = sd;
854 }
855 }
856 }
857 }
858 else
859 {
860 return snxt=kInfinity;
861 }
862 }
863 else
864 {
865
866
867
868 d2 = pDotV3d*pDotV3d - c ;
869
870 if ( (rad2 > tolIRMax2)
871 && ( (d2 >= fRmaxTolerance*fRmax) && (pDotV3d < 0) ) )
872 {
873 if (!fFullPhiSphere)
874 {
875
876
877
878 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
879
880 if (cosPsi>=cosHDPhiIT)
881 {
882
883
884 if ( !fFullThetaSphere )
885 {
886 if ( (pTheta >= tolSTheta + kAngTolerance)
887 && (pTheta <= tolETheta - kAngTolerance) )
888 {
889 return snxt=0;
890 }
891 }
892 else
893 {
894 return snxt=0;
895 }
896 }
897 }
898 else
899 {
900 if ( !fFullThetaSphere )
901 {
902 if ( (pTheta >= tolSTheta + kAngTolerance)
903 && (pTheta <= tolETheta - kAngTolerance) )
904 {
905 return snxt=0;
906 }
907 }
908 else
909 {
910 return snxt=0;
911 }
912 }
913 }
914 }
915
916
917
918
919
920
921 if (fRmin)
922 {
923 c = rad2 - fRmin*fRmin ;
924 d2 = pDotV3d*pDotV3d - c ;
925
926
927
928
929 if ( (c > -halfRminTolerance) && (rad2 < tolIRMin2)
931 {
932 if ( !fFullPhiSphere )
933 {
934
935
936
937 cosPsi = (p.
x()*cosCPhi+p.
y()*sinCPhi)/std::sqrt(rho2) ;
938 if (cosPsi >= cosHDPhiIT)
939 {
940
941
942 if ( !fFullThetaSphere )
943 {
944 if ( (pTheta >= tolSTheta + kAngTolerance)
945 && (pTheta <= tolETheta - kAngTolerance) )
946 {
947 return snxt=0;
948 }
949 }
950 else
951 {
952 return snxt = 0 ;
953 }
954 }
955 }
956 else
957 {
958 if ( !fFullThetaSphere )
959 {
960 if ( (pTheta >= tolSTheta + kAngTolerance)
961 && (pTheta <= tolETheta - kAngTolerance) )
962 {
963 return snxt = 0 ;
964 }
965 }
966 else
967 {
968 return snxt=0;
969 }
970 }
971 }
972 else
973 {
974 if (d2 >= 0)
975 {
976 sd = -pDotV3d + std::sqrt(d2) ;
977 if ( sd >= halfRminTolerance )
978 {
979 xi = p.
x() + sd*v.
x() ;
980 yi = p.
y() + sd*v.
y() ;
981 rhoi = std::sqrt(xi*xi+yi*yi) ;
982
983 if ( !fFullPhiSphere && rhoi )
984 {
985 cosPsi = (xi*cosCPhi + yi*sinCPhi)/rhoi ;
986
987 if (cosPsi >= cosHDPhiOT)
988 {
989 if ( !fFullThetaSphere )
990 {
991 zi = p.
z() + sd*v.
z() ;
992
993
994
995
996 iTheta = std::atan2(rhoi,zi) ;
997 if ( (iTheta >= tolSTheta) && (iTheta<=tolETheta) )
998 {
999 snxt = sd;
1000 }
1001 }
1002 else
1003 {
1004 snxt=sd;
1005 }
1006 }
1007 }
1008 else
1009 {
1010 if ( !fFullThetaSphere )
1011 {
1012 zi = p.
z() + sd*v.
z() ;
1013
1014
1015
1016
1017 iTheta = std::atan2(rhoi,zi) ;
1018 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1019 {
1020 snxt = sd;
1021 }
1022 }
1023 else
1024 {
1025 snxt = sd;
1026 }
1027 }
1028 }
1029 }
1030 }
1031 }
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042 if ( !fFullPhiSphere )
1043 {
1044
1045
1046
1047 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1048
1049 if ( Comp < 0 )
1050 {
1051 Dist = p.
y()*cosSPhi - p.
x()*sinSPhi ;
1052
1053 if (Dist < halfCarTolerance)
1054 {
1055 sd = Dist/Comp ;
1056
1057 if (sd < snxt)
1058 {
1059 if ( sd > 0 )
1060 {
1061 xi = p.
x() + sd*v.
x() ;
1062 yi = p.
y() + sd*v.
y() ;
1063 zi = p.
z() + sd*v.
z() ;
1064 rhoi2 = xi*xi + yi*yi ;
1065 radi2 = rhoi2 + zi*zi ;
1066 }
1067 else
1068 {
1069 sd = 0 ;
1073 rhoi2 = rho2 ;
1074 radi2 = rad2 ;
1075 }
1076 if ( (radi2 <= tolORMax2)
1077 && (radi2 >= tolORMin2)
1078 && ((yi*cosCPhi-xi*sinCPhi) <= 0) )
1079 {
1080
1081
1082
1083
1084 if ( !fFullThetaSphere )
1085 {
1086 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1087 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1088 {
1089
1090
1091
1092 if ((yi*cosCPhi-xi*sinCPhi) <= 0)
1093 {
1094 snxt = sd;
1095 }
1096 }
1097 }
1098 else
1099 {
1100 snxt = sd;
1101 }
1102 }
1103 }
1104 }
1105 }
1106
1107
1108
1109
1110 Comp = -( v.
x()*sinEPhi-v.
y()*cosEPhi ) ;
1111
1112 if (Comp < 0)
1113 {
1114 Dist = -(p.
y()*cosEPhi-p.
x()*sinEPhi) ;
1115 if ( Dist < halfCarTolerance )
1116 {
1117 sd = Dist/Comp ;
1118
1119 if ( sd < snxt )
1120 {
1121 if (sd > 0)
1122 {
1123 xi = p.
x() + sd*v.
x() ;
1124 yi = p.
y() + sd*v.
y() ;
1125 zi = p.
z() + sd*v.
z() ;
1126 rhoi2 = xi*xi + yi*yi ;
1127 radi2 = rhoi2 + zi*zi ;
1128 }
1129 else
1130 {
1131 sd = 0 ;
1135 rhoi2 = rho2 ;
1136 radi2 = rad2 ;
1137 }
1138 if ( (radi2 <= tolORMax2)
1139 && (radi2 >= tolORMin2)
1140 && ((yi*cosCPhi-xi*sinCPhi) >= 0) )
1141 {
1142
1143
1144
1145
1146 if ( !fFullThetaSphere )
1147 {
1148 iTheta = std::atan2(std::sqrt(rhoi2),zi) ;
1149 if ( (iTheta >= tolSTheta) && (iTheta <= tolETheta) )
1150 {
1151
1152
1153
1154 if ((yi*cosCPhi-xi*sinCPhi) >= 0)
1155 {
1156 snxt = sd;
1157 }
1158 }
1159 }
1160 else
1161 {
1162 snxt = sd;
1163 }
1164 }
1165 }
1166 }
1167 }
1168 }
1169
1170
1171
1172 if ( !fFullThetaSphere )
1173 {
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195 if (fSTheta)
1196 {
1197 dist2STheta = rho2 - p.
z()*p.
z()*tanSTheta2 ;
1198 }
1199 else
1200 {
1201 dist2STheta = kInfinity ;
1202 }
1203 if ( eTheta < pi )
1204 {
1205 dist2ETheta=rho2-p.
z()*p.
z()*tanETheta2;
1206 }
1207 else
1208 {
1209 dist2ETheta=kInfinity;
1210 }
1211 if ( pTheta < tolSTheta )
1212 {
1213
1214
1215
1216 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1217 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1218 if (t1)
1219 {
1220 b = t2/t1 ;
1221 c = dist2STheta/t1 ;
1222 d2 = b*b - c ;
1223
1224 if ( d2 >= 0 )
1225 {
1226 d = std::sqrt(d2) ;
1227 sd = -b - d ;
1228 zi = p.
z() + sd*v.
z();
1229
1230 if ( (sd < 0) || (zi*(fSTheta - halfpi) > 0) )
1231 {
1232 sd = -b+d;
1233 }
1234 if ((sd >= 0) && (sd < snxt))
1235 {
1236 xi = p.
x() + sd*v.
x();
1237 yi = p.
y() + sd*v.
y();
1238 zi = p.
z() + sd*v.
z();
1239 rhoi2 = xi*xi + yi*yi;
1240 radi2 = rhoi2 + zi*zi;
1241 if ( (radi2 <= tolORMax2)
1242 && (radi2 >= tolORMin2)
1243 && (zi*(fSTheta - halfpi) <= 0) )
1244 {
1245 if ( !fFullPhiSphere && rhoi2 )
1246 {
1247 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1248 if (cosPsi >= cosHDPhiOT)
1249 {
1250 snxt = sd;
1251 }
1252 }
1253 else
1254 {
1255 snxt = sd;
1256 }
1257 }
1258 }
1259 }
1260 }
1261
1262
1263
1264
1265 if ( eTheta < pi )
1266 {
1267 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1268 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1269 if (t1)
1270 {
1271 b = t2/t1 ;
1272 c = dist2ETheta/t1 ;
1273 d2 = b*b - c ;
1274
1275 if (d2 >= 0)
1276 {
1277 d = std::sqrt(d2) ;
1278 sd = -b + d ;
1279
1280 if ( (sd >= 0) && (sd < snxt) )
1281 {
1282 xi = p.
x() + sd*v.
x() ;
1283 yi = p.
y() + sd*v.
y() ;
1284 zi = p.
z() + sd*v.
z() ;
1285 rhoi2 = xi*xi + yi*yi ;
1286 radi2 = rhoi2 + zi*zi ;
1287
1288 if ( (radi2 <= tolORMax2)
1289 && (radi2 >= tolORMin2)
1290 && (zi*(eTheta - halfpi) <= 0) )
1291 {
1292 if (!fFullPhiSphere && rhoi2)
1293 {
1294 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1295 if (cosPsi >= cosHDPhiOT)
1296 {
1297 snxt = sd;
1298 }
1299 }
1300 else
1301 {
1302 snxt = sd;
1303 }
1304 }
1305 }
1306 }
1307 }
1308 }
1309 }
1310 else if ( pTheta > tolETheta )
1311 {
1312
1313
1314
1315
1316 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1317 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1318 if (t1)
1319 {
1320 b = t2/t1 ;
1321 c = dist2ETheta/t1 ;
1322 d2 = b*b - c ;
1323
1324 if (d2 >= 0)
1325 {
1326 d = std::sqrt(d2) ;
1327 sd = -b - d ;
1328 zi = p.
z() + sd*v.
z();
1329
1330 if ( (sd < 0) || (zi*(eTheta - halfpi) > 0) )
1331 {
1332 sd = -b + d ;
1333 }
1334 if ( (sd >= 0) && (sd < snxt) )
1335 {
1336 xi = p.
x() + sd*v.
x() ;
1337 yi = p.
y() + sd*v.
y() ;
1338 zi = p.
z() + sd*v.
z() ;
1339 rhoi2 = xi*xi + yi*yi ;
1340 radi2 = rhoi2 + zi*zi ;
1341
1342 if ( (radi2 <= tolORMax2)
1343 && (radi2 >= tolORMin2)
1344 && (zi*(eTheta - halfpi) <= 0) )
1345 {
1346 if (!fFullPhiSphere && rhoi2)
1347 {
1348 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1349 if (cosPsi >= cosHDPhiOT)
1350 {
1351 snxt = sd;
1352 }
1353 }
1354 else
1355 {
1356 snxt = sd;
1357 }
1358 }
1359 }
1360 }
1361 }
1362
1363
1364
1365
1366 if ( fSTheta )
1367 {
1368 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1369 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1370 if (t1)
1371 {
1372 b = t2/t1 ;
1373 c = dist2STheta/t1 ;
1374 d2 = b*b - c ;
1375
1376 if (d2 >= 0)
1377 {
1378 d = std::sqrt(d2) ;
1379 sd = -b + d ;
1380
1381 if ( (sd >= 0) && (sd < snxt) )
1382 {
1383 xi = p.
x() + sd*v.
x() ;
1384 yi = p.
y() + sd*v.
y() ;
1385 zi = p.
z() + sd*v.
z() ;
1386 rhoi2 = xi*xi + yi*yi ;
1387 radi2 = rhoi2 + zi*zi ;
1388
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 else if ( (pTheta < tolSTheta + kAngTolerance)
1412 && (fSTheta > halfAngTolerance) )
1413 {
1414
1415
1416
1417
1418 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1419 if ( (t2>=0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta<halfpi)
1420 || (t2<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta>halfpi)
1421 || (v.
z()<0 && tolIRMin2<rad2 && rad2<tolIRMax2 && fSTheta==halfpi) )
1422 {
1423 if (!fFullPhiSphere && rho2)
1424 {
1425 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1426 if (cosPsi >= cosHDPhiIT)
1427 {
1428 return 0 ;
1429 }
1430 }
1431 else
1432 {
1433 return 0 ;
1434 }
1435 }
1436
1437
1438
1439 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1440 if (t1)
1441 {
1442 b = t2/t1 ;
1443 c = dist2STheta/t1 ;
1444 d2 = b*b - c ;
1445
1446 if (d2 >= 0)
1447 {
1448 d = std::sqrt(d2) ;
1449 sd = -b + d ;
1450 if ( (sd >= halfCarTolerance) && (sd < snxt) && (fSTheta < halfpi) )
1451 {
1452 xi = p.
x() + sd*v.
x() ;
1453 yi = p.
y() + sd*v.
y() ;
1454 zi = p.
z() + sd*v.
z() ;
1455 rhoi2 = xi*xi + yi*yi ;
1456 radi2 = rhoi2 + zi*zi ;
1457
1458 if ( (radi2 <= tolORMax2)
1459 && (radi2 >= tolORMin2)
1460 && (zi*(fSTheta - halfpi) <= 0) )
1461 {
1462 if ( !fFullPhiSphere && rhoi2 )
1463 {
1464 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1465 if ( cosPsi >= cosHDPhiOT )
1466 {
1467 snxt = sd;
1468 }
1469 }
1470 else
1471 {
1472 snxt = sd;
1473 }
1474 }
1475 }
1476 }
1477 }
1478 }
1479 else if ((pTheta > tolETheta-kAngTolerance) && (eTheta <
pi-kAngTolerance))
1480 {
1481
1482
1483
1484
1485
1486 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1487
1488 if ( ((t2<0) && (eTheta < halfpi)
1489 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1490 || ((t2>=0) && (eTheta > halfpi)
1491 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2))
1492 || ((v.
z()>0) && (eTheta == halfpi)
1493 && (tolIRMin2 < rad2) && (rad2 < tolIRMax2)) )
1494 {
1495 if (!fFullPhiSphere && rho2)
1496 {
1497 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(rho2) ;
1498 if (cosPsi >= cosHDPhiIT)
1499 {
1500 return 0 ;
1501 }
1502 }
1503 else
1504 {
1505 return 0 ;
1506 }
1507 }
1508
1509
1510
1511 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1512 if (t1)
1513 {
1514 b = t2/t1 ;
1515 c = dist2ETheta/t1 ;
1516 d2 = b*b - c ;
1517
1518 if (d2 >= 0)
1519 {
1520 d = std::sqrt(d2) ;
1521 sd = -b + d ;
1522
1523 if ( (sd >= halfCarTolerance)
1524 && (sd < snxt) && (eTheta > halfpi) )
1525 {
1526 xi = p.
x() + sd*v.
x() ;
1527 yi = p.
y() + sd*v.
y() ;
1528 zi = p.
z() + sd*v.
z() ;
1529 rhoi2 = xi*xi + yi*yi ;
1530 radi2 = rhoi2 + zi*zi ;
1531
1532 if ( (radi2 <= tolORMax2)
1533 && (radi2 >= tolORMin2)
1534 && (zi*(eTheta - halfpi) <= 0) )
1535 {
1536 if (!fFullPhiSphere && rhoi2)
1537 {
1538 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1539 if (cosPsi >= cosHDPhiOT)
1540 {
1541 snxt = sd;
1542 }
1543 }
1544 else
1545 {
1546 snxt = sd;
1547 }
1548 }
1549 }
1550 }
1551 }
1552 }
1553 else
1554 {
1555
1556
1557
1558 t1 = 1 - v.
z()*v.
z()*(1 + tanSTheta2) ;
1559 t2 = pDotV2d - p.
z()*v.
z()*tanSTheta2 ;
1560 if (t1)
1561 {
1562 b = t2/t1;
1563 c = dist2STheta/t1 ;
1564 d2 = b*b - c ;
1565
1566 if (d2 >= 0)
1567 {
1568 d = std::sqrt(d2) ;
1569 sd = -b + d ;
1570
1571 if ((sd >= 0) && (sd < snxt))
1572 {
1573 xi = p.
x() + sd*v.
x() ;
1574 yi = p.
y() + sd*v.
y() ;
1575 zi = p.
z() + sd*v.
z() ;
1576 rhoi2 = xi*xi + yi*yi ;
1577 radi2 = rhoi2 + zi*zi ;
1578
1579 if ( (radi2 <= tolORMax2)
1580 && (radi2 >= tolORMin2)
1581 && (zi*(fSTheta - halfpi) <= 0) )
1582 {
1583 if (!fFullPhiSphere && rhoi2)
1584 {
1585 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1586 if (cosPsi >= cosHDPhiOT)
1587 {
1588 snxt = sd;
1589 }
1590 }
1591 else
1592 {
1593 snxt = sd;
1594 }
1595 }
1596 }
1597 }
1598 }
1599 t1 = 1 - v.
z()*v.
z()*(1 + tanETheta2) ;
1600 t2 = pDotV2d - p.
z()*v.
z()*tanETheta2 ;
1601 if (t1)
1602 {
1603 b = t2/t1 ;
1604 c = dist2ETheta/t1 ;
1605 d2 = b*b - c ;
1606
1607 if (d2 >= 0)
1608 {
1609 d = std::sqrt(d2) ;
1610 sd = -b + d;
1611
1612 if ((sd >= 0) && (sd < snxt))
1613 {
1614 xi = p.
x() + sd*v.
x() ;
1615 yi = p.
y() + sd*v.
y() ;
1616 zi = p.
z() + sd*v.
z() ;
1617 rhoi2 = xi*xi + yi*yi ;
1618 radi2 = rhoi2 + zi*zi ;
1619
1620 if ( (radi2 <= tolORMax2)
1621 && (radi2 >= tolORMin2)
1622 && (zi*(eTheta - halfpi) <= 0) )
1623 {
1624 if (!fFullPhiSphere && rhoi2)
1625 {
1626 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
1627 if ( cosPsi >= cosHDPhiOT )
1628 {
1629 snxt = sd;
1630 }
1631 }
1632 else
1633 {
1634 snxt = sd;
1635 }
1636 }
1637 }
1638 }
1639 }
1640 }
1641 }
1642 return snxt;
1643}
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const