5 * Revision 1.1.1.1 1995/10/24 10:20:51 cernlib
9 #include "geant321/pilot.h"
10 *CMZ : 3.21/02 29/03/94 15.41.29 by S.Giani
12 SUBROUTINE GNCONE(X,P,IACT,IFL,SNEXT,SNXT,SAFE)
13 C. ******************************************************************
15 C. * Compute distance to intersection with boundary surface of *
16 C * volume CONE or CONS, from point X(1),X(2),X(3) inside *
17 C * the volume along track with direction cosines X(4),X(5), *
19 C. * P (input) : volume parameters *
20 C. * IACT (input) : action flag *
21 C. * = 0 Compute SAFE only *
22 C. * = 1 Compute SAFE, compute SNXT only if SAFE.LT.SNEXT *
23 C. * = 2 Compute both SAFE and SNXT *
24 C. * = 3 Compute SNXT only *
25 C. * IFL (input) : 1 for CONE, 2 for PHI segmented CONE *
26 C. * SNEXT (input) : see IACT = 1 *
27 C. * SNXT (output) : distance to volume boundary along track *
28 C. * SAFE (output) : not larger than scalar distance to *
29 C. * volume boundaray *
30 C. * Called by : GNEXT, GNOPCO, GTNEXT *
32 C. * Authors : Michel Maire and Rolf Nierhaus 21-JUN-1990 *
34 C. ******************************************************************
36 C. * 'CONE' is a conical tube. It has 5 parameters : *
37 C. * the half length in z, *
38 C. * the inside and outside radii at the low z limit, *
39 C. * and those at the high z limit. *
40 C. * 'CONS' is a phi segment of a conical tube. It has 7 *
41 C. * parameters, the same 5 as 'CONE' plus the phi limits.*
42 C. * The segment starts at the first limit and includes *
43 C. * increasing phi value up to the second limit or *
44 C. * that plus 360 degrees. *
46 C. ******************************************************************
47 #if !defined(CERNLIB_SINGLE)
48 IMPLICIT DOUBLE PRECISION (A-H,O-Z)
49 REAL SNEXT, SNXT, SAFE
50 PARAMETER (F=0.01745329251994330D0)
52 #if defined(CERNLIB_SINGLE)
53 PARAMETER (F=0.01745329251994330)
57 * this part has to be moved outside the routine
59 TG1=0.5*(P(4)-P(2))/P(1)
60 CR1=1./SQRT(1.+TG1*TG1)
62 TG2=0.5*(P(5)-P(3))/P(1)
63 CR2=1./SQRT(1.+TG2*TG2)
67 IF (P7.LT.P6) P7=P7+F*360.
78 R =SQRT(X(1)**2+X(2)**2)
89 IF ((X(2)*CFIO-X(1)*SFIO).LE.0.) THEN
90 SAF4=ABS(X(1)*S1-X(2)*C1)
92 SAF4=ABS(X(1)*S2-X(2)*C2)
95 SAFE=MIN(SAF1,SAF2,SAF3,SAF4)
96 IF (IACT.EQ.0) GO TO 999
97 IF (IACT.EQ.1.AND.SNEXT.LE.SAFE) GO TO 999
100 * Intersection with z-plane
101 IF (X(6).GT. 1.E-20) THEN
103 ELSEIF (X(6).LT.-1.E-20) THEN
109 * Intersection with cones
110 * Intersection point (x,y,z)
111 * (x,y,z) is on track: x=X(1)+t*X(4)
114 * (x,y,z) is on cone : x**2 + y**2 = (a*z+b)**2
116 * (X(4)**2+X(5)**2-(a*x(6))**2)*t**2
117 * +2.*(X(1)*X(4)+X(2)*X(5)-a*x(6)*(a*x(3)+b))*t
118 * +X(1)**2+X(2)**2-(a*x(3)+b)**2=0
121 T2=X(1)*X(4)+X(2)*X(5)
124 * Intersection with the inner cone
130 * track not parallel to the cone ?
137 IF (DS.GE.ABS(B)) THEN
139 ELSEIF (B.LE.0.) THEN
143 ELSEIF (V.LT.0.) THEN
148 * Intersection with the outer cone
153 * track not parallel to the cone ?
160 IF (DS.GE.ABS(B)) THEN
162 ELSEIF (B.LE.0.) THEN
166 ELSEIF (V.GT.0.) THEN
170 * Intersection with phi-planes
171 * x=r*cos(phi)=X(1)+t*X(4)
172 * y=r*sin(phi)=X(2)+t*X(5)
174 * t=(X(2)*cos(phi)-X(1)*sin(phi))/(X(4)*sin(phi)-X(5)*cos(phi))
179 * track not parallel to the phi1 plane ?
182 S=(X(2)*C1-X(1)*S1)/UN
186 IF ((YI*CFIO-XI*SFIO).LE.0.) SFI1=S
189 * track not parallel to the phi2 plane ?
192 S=(X(2)*C2-X(1)*S2)/UN
196 IF ((YI*CFIO-XI*SFIO).GE.0.) SFI2=S
201 SNXT=MIN(SR1,SR2,SZ,SFI1,SFI2)