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