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