909{
915
916
917
918 G4double Dist, sd=0, xi, yi, zi, rho2, inum, iden, cosPsi, Comp,calf ;
921
922
923 if (fRMin > kRadTolerance)
924 {
925 tolORMin2 = (fRMin - halfRadTolerance)*(fRMin - halfRadTolerance) ;
926 tolIRMin2 = (fRMin + halfRadTolerance)*(fRMin + halfRadTolerance) ;
927 }
928 else
929 {
930 tolORMin2 = 0.0 ;
931 tolIRMin2 = 0.0 ;
932 }
933 tolORMax2 = (fRMax + halfRadTolerance)*(fRMax + halfRadTolerance) ;
934 tolIRMax2 = (fRMax - halfRadTolerance)*(fRMax - halfRadTolerance) ;
935
936
937
938
939
940 distZLow =(p+vZ).dot(fLowNorm);
941
942
943
944 distZHigh = (p-vZ).dot(fHighNorm);
945
946 if ( distZLow >= -halfCarTolerance )
947 {
948 calf = v.
dot(fLowNorm);
949 if (calf<0)
950 {
951 sd = -distZLow/calf;
952 if(sd < 0.0) { sd = 0.0; }
953
954 xi = p.
x() + sd*v.
x() ;
955 yi = p.
y() + sd*v.
y() ;
956 rho2 = xi*xi + yi*yi ;
957
958
959
960 if ((tolIRMin2 <= rho2) && (rho2 <= tolIRMax2))
961 {
962 if (!fPhiFullCutTube && rho2)
963 {
964
965
966 inum = xi*cosCPhi + yi*sinCPhi ;
967 iden = std::sqrt(rho2) ;
968 cosPsi = inum/iden ;
969 if (cosPsi >= cosHDPhiIT) { return sd ; }
970 }
971 else
972 {
973 return sd ;
974 }
975 }
976 }
977 else
978 {
979 if ( sd<halfCarTolerance )
980 {
981 if(calf>=0) { sd=kInfinity; }
982 return sd ;
983 }
984 }
985 }
986
987 if(distZHigh >= -halfCarTolerance )
988 {
989 calf = v.
dot(fHighNorm);
990 if (calf<0)
991 {
992 sd = -distZHigh/calf;
993
994 if(sd < 0.0) { sd = 0.0; }
995
996 xi = p.
x() + sd*v.
x() ;
997 yi = p.
y() + sd*v.
y() ;
998 rho2 = xi*xi + yi*yi ;
999
1000
1001
1002 if ((tolIRMin2 <= rho2) && (rho2 <= tolIRMax2))
1003 {
1004 if (!fPhiFullCutTube && rho2)
1005 {
1006
1007
1008 inum = xi*cosCPhi + yi*sinCPhi ;
1009 iden = std::sqrt(rho2) ;
1010 cosPsi = inum/iden ;
1011 if (cosPsi >= cosHDPhiIT) { return sd ; }
1012 }
1013 else
1014 {
1015 return sd ;
1016 }
1017 }
1018 }
1019 else
1020 {
1021 if ( sd<halfCarTolerance )
1022 {
1023 if(calf>=0) { sd=kInfinity; }
1024 return sd ;
1025 }
1026 }
1027 }
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040 t1 = 1.0 - v.
z()*v.
z() ;
1041 t2 = p.
x()*v.
x() + p.
y()*v.
y() ;
1042 t3 = p.
x()*p.
x() + p.
y()*p.
y() ;
1043 if ( t1 > 0 )
1044 {
1045 b = t2/t1 ;
1046 c = t3 - fRMax*fRMax ;
1047
1048 if ((t3 >= tolORMax2) && (t2<0))
1049 {
1050
1051
1052 c /= t1 ;
1053 d = b*b - c ;
1054
1055 if (d >= 0)
1056 {
1057 sd = c/(-b+std::sqrt(d));
1058 if (sd >= 0)
1059 {
1060 if ( sd>dRmax )
1061 {
1062 G4double fTerm = sd-std::fmod(sd,dRmax);
1064 }
1065
1066
1067 zi = p.
z() + sd*v.
z() ;
1068 xi = p.
x() + sd*v.
x() ;
1069 yi = p.
y() + sd*v.
y() ;
1070 if ((-xi*fLowNorm.
x()-yi*fLowNorm.
y()
1071 -(zi+fDz)*fLowNorm.
z())>-halfCarTolerance)
1072 {
1073 if ((-xi*fHighNorm.
x()-yi*fHighNorm.
y()
1074 +(fDz-zi)*fHighNorm.
z())>-halfCarTolerance)
1075 {
1076
1077
1078 if (fPhiFullCutTube)
1079 {
1080 return sd ;
1081 }
1082 else
1083 {
1084 xi = p.
x() + sd*v.
x() ;
1085 yi = p.
y() + sd*v.
y() ;
1086 cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMax ;
1087 if (cosPsi >= cosHDPhiIT) { return sd ; }
1088 }
1089 }
1090 }
1091 }
1092 }
1093 }
1094 else
1095 {
1096
1097
1098 if ((t3 > tolIRMin2) && (t2 < 0)
1099 && (std::fabs(p.
z()) <= std::fabs(
GetCutZ(p))-halfCarTolerance ))
1100 {
1101
1102
1103 if (!fPhiFullCutTube)
1104 {
1105 inum = p.
x()*cosCPhi + p.
y()*sinCPhi ;
1106 iden = std::sqrt(t3) ;
1107 cosPsi = inum/iden ;
1108 if (cosPsi >= cosHDPhiIT)
1109 {
1110
1111
1112
1113
1114
1115
1116 c = t3-fRMax*fRMax;
1117 if ( c<=0.0 )
1118 {
1119 return 0.0;
1120 }
1121 else
1122 {
1123 c = c/t1 ;
1124 d = b*b-c;
1125 if ( d>=0.0 )
1126 {
1127 snxt = c/(-b+std::sqrt(d));
1128
1129 if ( snxt < halfCarTolerance ) { snxt=0; }
1130 return snxt ;
1131 }
1132 else
1133 {
1134 return kInfinity;
1135 }
1136 }
1137 }
1138 }
1139 else
1140 {
1141
1142
1143
1144
1145
1146
1147 c = t3 - fRMax*fRMax;
1148 if ( c<=0.0 )
1149 {
1150 return 0.0;
1151 }
1152 else
1153 {
1154 c = c/t1 ;
1155 d = b*b-c;
1156 if ( d>=0.0 )
1157 {
1158 snxt= c/(-b+std::sqrt(d));
1159
1160 if ( snxt < halfCarTolerance ) { snxt=0; }
1161 return snxt ;
1162 }
1163 else
1164 {
1165 return kInfinity;
1166 }
1167 }
1168 }
1169 }
1170 }
1171
1172 if ( fRMin )
1173 {
1174 c = (t3 - fRMin*fRMin)/t1 ;
1175 d = b*b - c ;
1176 if ( d >= 0.0 )
1177 {
1178
1179
1180
1181 sd =( b > 0. )? c/(-b - std::sqrt(d)) : (-b + std::sqrt(d));
1182 if (sd >= -10*halfCarTolerance)
1183 {
1184
1185
1186 if (sd < 0.0) { sd = 0.0; }
1187 if (sd>dRmax)
1188 {
1189 G4double fTerm = sd-std::fmod(sd,dRmax);
1191 }
1192 zi = p.
z() + sd*v.
z() ;
1193 xi = p.
x() + sd*v.
x() ;
1194 yi = p.
y() + sd*v.
y() ;
1195 if ((-xi*fLowNorm.
x()-yi*fLowNorm.
y()
1196 -(zi+fDz)*fLowNorm.
z())>-halfCarTolerance)
1197 {
1198 if ((-xi*fHighNorm.
x()-yi*fHighNorm.
y()
1199 +(fDz-zi)*fHighNorm.
z())>-halfCarTolerance)
1200 {
1201
1202
1203 if ( fPhiFullCutTube )
1204 {
1205 return sd ;
1206 }
1207 else
1208 {
1209 cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMin ;
1210 if (cosPsi >= cosHDPhiIT)
1211 {
1212
1213
1214
1215 snxt = sd ;
1216 }
1217 }
1218 }
1219 }
1220 }
1221 }
1222 }
1223 }
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234 if ( !fPhiFullCutTube )
1235 {
1236
1237
1238 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1239
1240 if ( Comp < 0 )
1241 {
1242 Dist = (p.
y()*cosSPhi - p.
x()*sinSPhi) ;
1243
1244 if ( Dist < halfCarTolerance )
1245 {
1246 sd = Dist/Comp ;
1247
1248 if (sd < snxt)
1249 {
1250 if ( sd < 0 ) { sd = 0.0; }
1251 zi = p.
z() + sd*v.
z() ;
1252 xi = p.
x() + sd*v.
x() ;
1253 yi = p.
y() + sd*v.
y() ;
1254 if ((-xi*fLowNorm.
x()-yi*fLowNorm.
y()
1255 -(zi+fDz)*fLowNorm.
z())>-halfCarTolerance)
1256 {
1257 if ((-xi*fHighNorm.
x()-yi*fHighNorm.
y()
1258 +(fDz-zi)*fHighNorm.
z())>-halfCarTolerance)
1259 {
1260 rho2 = xi*xi + yi*yi ;
1261 if ( ( (rho2 >= tolIRMin2) && (rho2 <= tolIRMax2) )
1262 || ( (rho2 > tolORMin2) && (rho2 < tolIRMin2)
1263 && ( v.
y()*cosSPhi - v.
x()*sinSPhi > 0 )
1264 && ( v.
x()*cosSPhi + v.
y()*sinSPhi >= 0 ) )
1265 || ( (rho2 > tolIRMax2) && (rho2 < tolORMax2)
1266 && (v.
y()*cosSPhi - v.
x()*sinSPhi > 0)
1267 && (v.
x()*cosSPhi + v.
y()*sinSPhi < 0) ) )
1268 {
1269
1270
1271
1272 if ((yi*cosCPhi-xi*sinCPhi) <= halfCarTolerance) { snxt = sd; }
1273 }
1274 }
1275 }
1276 }
1277 }
1278 }
1279
1280
1281
1282 Comp = -(v.
x()*sinEPhi - v.
y()*cosEPhi) ;
1283
1284 if (Comp < 0 )
1285 {
1286 Dist = -(p.
y()*cosEPhi - p.
x()*sinEPhi) ;
1287
1288 if ( Dist < halfCarTolerance )
1289 {
1290 sd = Dist/Comp ;
1291
1292 if (sd < snxt)
1293 {
1294 if ( sd < 0 ) { sd = 0; }
1295 zi = p.
z() + sd*v.
z() ;
1296 xi = p.
x() + sd*v.
x() ;
1297 yi = p.
y() + sd*v.
y() ;
1298 if ((-xi*fLowNorm.
x()-yi*fLowNorm.
y()
1299 -(zi+fDz)*fLowNorm.
z())>-halfCarTolerance)
1300 {
1301 if ((-xi*fHighNorm.
x()-yi*fHighNorm.
y()
1302 +(fDz-zi)*fHighNorm.
z())>-halfCarTolerance)
1303 {
1304 xi = p.
x() + sd*v.
x() ;
1305 yi = p.
y() + sd*v.
y() ;
1306 rho2 = xi*xi + yi*yi ;
1307 if ( ( (rho2 >= tolIRMin2) && (rho2 <= tolIRMax2) )
1308 || ( (rho2 > tolORMin2) && (rho2 < tolIRMin2)
1309 && (v.
x()*sinEPhi - v.
y()*cosEPhi > 0)
1310 && (v.
x()*cosEPhi + v.
y()*sinEPhi >= 0) )
1311 || ( (rho2 > tolIRMax2) && (rho2 < tolORMax2)
1312 && (v.
x()*sinEPhi - v.
y()*cosEPhi > 0)
1313 && (v.
x()*cosEPhi + v.
y()*sinEPhi < 0) ) )
1314 {
1315
1316
1317
1318 if ( (yi*cosCPhi-xi*sinCPhi) >= -halfCarTolerance )
1319 {
1320 snxt = sd;
1321 }
1322 }
1323 }
1324 }
1325 }
1326 }
1327 }
1328 }
1329 if ( snxt<halfCarTolerance ) { snxt=0; }
1330
1331 return snxt ;
1332}
double dot(const Hep3Vector &) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const