667 const G4double dRmax = 50*(fRmax1+fRmax2);
669 G4double tanRMax,secRMax,rMaxAv,rMaxOAv ;
670 G4double tanRMin,secRMin,rMinAv,rMinOAv ;
673 G4double tolORMin,tolORMin2,tolIRMin,tolIRMin2 ;
674 G4double tolORMax2,tolIRMax,tolIRMax2 ;
677 G4double Dist,sd,xi,yi,zi,ri=0.,risec,rhoi2,cosPsi ;
687 tanRMin = (fRmin2 - fRmin1)*0.5/fDz ;
688 secRMin = std::sqrt(1.0 + tanRMin*tanRMin) ;
689 rMinAv = (fRmin1 + fRmin2)*0.5 ;
691 if (rMinAv > halfRadTolerance)
693 rMinOAv = rMinAv - halfRadTolerance ;
699 tanRMax = (fRmax2 - fRmax1)*0.5/fDz ;
700 secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
701 rMaxAv = (fRmax1 + fRmax2)*0.5 ;
702 rMaxOAv = rMaxAv + halfRadTolerance ;
706 tolIDz = fDz - halfCarTolerance ;
707 tolODz = fDz + halfCarTolerance ;
709 if (std::fabs(p.
z()) >= tolIDz)
711 if ( p.
z()*v.
z() < 0 )
713 sd = (std::fabs(p.
z()) - fDz)/std::fabs(v.
z()) ;
715 if( sd < 0.0 ) { sd = 0.0; }
717 xi = p.
x() + sd*v.
x() ;
718 yi = p.
y() + sd*v.
y() ;
719 rhoi2 = xi*xi + yi*yi ;
726 tolORMin = fRmin1 - halfRadTolerance*secRMin ;
727 tolIRMin = fRmin1 + halfRadTolerance*secRMin ;
728 tolIRMax = fRmax1 - halfRadTolerance*secRMin ;
734 tolORMin = fRmin2 - halfRadTolerance*secRMin ;
735 tolIRMin = fRmin2 + halfRadTolerance*secRMin ;
736 tolIRMax = fRmax2 - halfRadTolerance*secRMin ;
743 tolIRMin2 = tolIRMin*tolIRMin ;
750 if ( tolIRMax > 0 ) { tolIRMax2 = tolIRMax*tolIRMax; }
751 else { tolIRMax2 = 0.0; }
753 if ( (tolIRMin2 <= rhoi2) && (rhoi2 <= tolIRMax2) )
755 if ( !fPhiFullCone && rhoi2 )
759 cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
761 if (cosPsi >= cosHDPhiIT) {
return sd; }
794 t1 = 1.0 - v.
z()*v.
z() ;
795 t2 = p.
x()*v.
x() + p.
y()*v.
y() ;
796 t3 = p.
x()*p.
x() + p.
y()*p.
y() ;
797 rin = tanRMin*p.
z() + rMinAv ;
798 rout = tanRMax*p.
z() + rMaxAv ;
803 nt1 = t1 - (tanRMax*v.
z())*(tanRMax*v.
z()) ;
804 nt2 = t2 - tanRMax*v.
z()*rout ;
805 nt3 = t3 - rout*rout ;
807 if (std::fabs(nt1) > kRadTolerance)
812 if ( (nt3 > rout*rout*kRadTolerance*kRadTolerance*secRMax*secRMax)
821 if ((rout < 0) && (nt3 <= 0))
826 if (b>0) { sd = c/(-b-std::sqrt(d)); }
827 else { sd = -b + std::sqrt(d); }
831 if ((b <= 0) && (c >= 0))
833 sd=c/(-b+std::sqrt(d));
839 sd = -b + std::sqrt(d) ;
840 if((sd<0) & (sd>-halfRadTolerance)) sd=0;
852 G4double fTerm = sd-std::fmod(sd,dRmax);
855 zi = p.
z() + sd*v.
z() ;
857 if (std::fabs(zi) <= tolODz)
861 if ( fPhiFullCone ) {
return sd; }
864 xi = p.
x() + sd*v.
x() ;
865 yi = p.
y() + sd*v.
y() ;
866 ri = rMaxAv + zi*tanRMax ;
867 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
869 if ( cosPsi >= cosHDPhiIT ) {
return sd; }
880 if ( ( t3 > (rin + halfRadTolerance*secRMin)*
881 (rin + halfRadTolerance*secRMin) )
882 && (nt2 < 0) && (d >= 0) && (std::fabs(p.
z()) <= tolIDz) )
889 risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
893 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(t3) ;
894 if ( cosPsi >= cosHDPhiIT )
896 if ( Normal.
dot(v) <= 0 ) {
return 0.0; }
901 if ( Normal.
dot(v) <= 0 ) {
return 0.0; }
908 if ( std::fabs(nt2) > kRadTolerance )
915 zi = p.
z() + sd*v.
z() ;
917 if ((std::fabs(zi) <= tolODz) && (nt2 < 0))
921 if ( fPhiFullCone ) {
return sd; }
924 xi = p.
x() + sd*v.
x() ;
925 yi = p.
y() + sd*v.
y() ;
926 ri = rMaxAv + zi*tanRMax ;
927 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
929 if (cosPsi >= cosHDPhiIT) {
return sd; }
951 nt1 = t1 - (tanRMin*v.
z())*(tanRMin*v.
z()) ;
952 nt2 = t2 - tanRMin*v.
z()*rin ;
957 if ( nt3 > rin*kRadTolerance*secRMin )
967 if(b>0){sd = c/( -b-std::sqrt(d));}
968 else {sd = -b + std::sqrt(d) ;}
974 G4double fTerm = sd-std::fmod(sd,dRmax);
977 zi = p.
z() + sd*v.
z() ;
979 if ( std::fabs(zi) <= tolODz )
983 xi = p.
x() + sd*v.
x() ;
984 yi = p.
y() + sd*v.
y() ;
985 ri = rMinAv + zi*tanRMin ;
986 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
988 if (cosPsi >= cosHDPhiIT)
990 if ( sd > halfRadTolerance ) { snxt=sd; }
995 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
997 if ( Normal.
dot(v) <= 0 ) { snxt = sd; }
1003 if ( sd > halfRadTolerance ) {
return sd; }
1008 xi = p.
x() + sd*v.
x() ;
1009 yi = p.
y() + sd*v.
y() ;
1010 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1011 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1012 if ( Normal.
dot(v) <= 0 ) {
return sd; }
1019 else if ( nt3 < -rin*kRadTolerance*secRMin )
1032 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1033 else { sd = -b + std::sqrt(d); }
1034 zi = p.
z() + sd*v.
z() ;
1035 ri = rMinAv + zi*tanRMin ;
1039 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1043 G4double fTerm = sd-std::fmod(sd,dRmax);
1046 if ( !fPhiFullCone )
1048 xi = p.
x() + sd*v.
x() ;
1049 yi = p.
y() + sd*v.
y() ;
1050 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
1052 if (cosPsi >= cosHDPhiOT)
1054 if ( sd > halfRadTolerance ) { snxt=sd; }
1059 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1060 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin);
1061 if ( Normal.
dot(v) <= 0 ) { snxt = sd; }
1067 if( sd > halfRadTolerance ) {
return sd; }
1072 xi = p.
x() + sd*v.
x() ;
1073 yi = p.
y() + sd*v.
y() ;
1074 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1075 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1076 if ( Normal.
dot(v) <= 0 ) {
return sd; }
1083 if (b>0) { sd = -b - std::sqrt(d); }
1084 else { sd = c/(-b+std::sqrt(d)); }
1085 zi = p.
z() + sd*v.
z() ;
1086 ri = rMinAv + zi*tanRMin ;
1088 if ( (sd >= 0) && (ri > 0) && (std::fabs(zi) <= tolODz) )
1092 G4double fTerm = sd-std::fmod(sd,dRmax);
1095 if ( !fPhiFullCone )
1097 xi = p.
x() + sd*v.
x() ;
1098 yi = p.
y() + sd*v.
y() ;
1099 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
1101 if (cosPsi >= cosHDPhiIT)
1103 if ( sd > halfRadTolerance ) { snxt=sd; }
1108 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1109 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin);
1110 if ( Normal.
dot(v) <= 0 ) { snxt = sd; }
1116 if ( sd > halfRadTolerance ) {
return sd; }
1121 xi = p.
x() + sd*v.
x() ;
1122 yi = p.
y() + sd*v.
y() ;
1123 risec = std::sqrt(xi*xi + yi*yi)*secRMin ;
1124 Normal =
G4ThreeVector(-xi/risec,-yi/risec,tanRMin/secRMin) ;
1125 if ( Normal.
dot(v) <= 0 ) {
return sd; }
1139 if ( std::fabs(p.
z()) <= tolODz )
1145 if ( !fPhiFullCone )
1147 cosPsi = (p.
x()*cosCPhi + p.
y()*sinCPhi)/std::sqrt(t3) ;
1149 if (cosPsi >= cosHDPhiIT) {
return 0.0; }
1151 else {
return 0.0; }
1164 if (b>0) { sd = -b - std::sqrt(d); }
1165 else { sd = c/(-b+std::sqrt(d)); }
1166 zi = p.
z() + sd*v.
z() ;
1167 ri = rMinAv + zi*tanRMin ;
1171 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1172 else { sd = -b + std::sqrt(d); }
1174 zi = p.
z() + sd*v.
z() ;
1176 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1180 G4double fTerm = sd-std::fmod(sd,dRmax);
1183 if ( !fPhiFullCone )
1185 xi = p.
x() + sd*v.
x() ;
1186 yi = p.
y() + sd*v.
y() ;
1187 ri = rMinAv + zi*tanRMin ;
1188 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
1190 if ( cosPsi >= cosHDPhiIT ) { snxt = sd; }
1207 if (b>0) { sd = c/(-b-std::sqrt(d)); }
1208 else { sd = -b + std::sqrt(d) ; }
1209 zi = p.
z() + sd*v.
z() ;
1211 if ( (sd >= 0) && (std::fabs(zi) <= tolODz) )
1215 G4double fTerm = sd-std::fmod(sd,dRmax);
1218 if ( !fPhiFullCone )
1220 xi = p.
x() + sd*v.
x();
1221 yi = p.
y() + sd*v.
y();
1222 ri = rMinAv + zi*tanRMin ;
1223 cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri;
1225 if (cosPsi >= cosHDPhiIT) { snxt = sd; }
1244 if ( !fPhiFullCone )
1248 Comp = v.
x()*sinSPhi - v.
y()*cosSPhi ;
1252 Dist = (p.
y()*cosSPhi - p.
x()*sinSPhi) ;
1254 if (Dist < halfCarTolerance)
1260 if ( sd < 0 ) { sd = 0.0; }
1262 zi = p.
z() + sd*v.
z() ;
1264 if ( std::fabs(zi) <= tolODz )
1266 xi = p.
x() + sd*v.
x() ;
1267 yi = p.
y() + sd*v.
y() ;
1268 rhoi2 = xi*xi + yi*yi ;
1269 tolORMin2 = (rMinOAv + zi*tanRMin)*(rMinOAv + zi*tanRMin) ;
1270 tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
1272 if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
1277 if ((yi*cosCPhi - xi*sinCPhi) <= 0 ) { snxt = sd; }
1286 Comp = -(v.
x()*sinEPhi - v.
y()*cosEPhi) ;
1290 Dist = -(p.
y()*cosEPhi - p.
x()*sinEPhi) ;
1291 if (Dist < halfCarTolerance)
1297 if ( sd < 0 ) { sd = 0.0; }
1299 zi = p.
z() + sd*v.
z() ;
1301 if (std::fabs(zi) <= tolODz)
1303 xi = p.
x() + sd*v.
x() ;
1304 yi = p.
y() + sd*v.
y() ;
1305 rhoi2 = xi*xi + yi*yi ;
1306 tolORMin2 = (rMinOAv + zi*tanRMin)*(rMinOAv + zi*tanRMin) ;
1307 tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
1309 if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
1314 if ( (yi*cosCPhi - xi*sinCPhi) >= 0.0 ) { snxt = sd; }
1321 if (snxt < halfCarTolerance) { snxt = 0.; }
static const G4double kInfinity
CLHEP::Hep3Vector G4ThreeVector
double dot(const Hep3Vector &) const
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const