5 * Revision 1.1.1.1 1995/10/24 10:20:54 cernlib
9 #include "geant321/pilot.h"
10 *CMZ : 3.21/02 29/03/94 15.41.30 by S.Giani
12 SUBROUTINE GNTUBE(X,P,IACT,IFL,SNEXT,SNXT,SAFE)
13 C. ******************************************************************
15 C. * Compute distance to intersection with boundary surface of *
16 C * volume TUBE or TUBS, 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 TUBE, 2 for PHI segmented TUBE *
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, GNPCON, GTNEXT *
32 C. * Authors : Michel Maire and Rolf Nierhaus 21-JUN-1990 *
34 C. ******************************************************************
36 C. * 'TUBE' is a tube. It has 3 parameters, the inside radius, *
37 C. * the outside radius and the half length in z. *
38 C. * 'TUBS' is a phi segment of a tube. It has 5 parameters, *
39 C. * the same 3 as 'TUBE' plus the phi limits. The *
40 C. * segment starts at the first limit and includes *
41 C. * increasing phi value up to the second limit or *
42 C. * that plus 360 degrees. *
44 C. ******************************************************************
45 #include "geant321/gconsp.inc"
48 * this part has to be moved outside the routine
52 IF (P5.LT.P4) P5=P5+TWOPI
63 R=SQRT(X(1)**2+X(2)**2)
72 IF ((X(2)*CFIO-X(1)*SFIO).LE.0.) THEN
73 SAF4=ABS(X(1)*S1-X(2)*C1)
75 SAF4=ABS(X(1)*S2-X(2)*C2)
78 SAFE=MIN(SAF1,SAF2,SAF3,SAF4)
79 IF (IACT.EQ.0) GO TO 999
80 IF (IACT.EQ.1.AND.SNEXT.LE.SAFE) GO TO 999
83 * Intersection with z-plane
84 IF (X(6).GT.1.E-20) THEN
86 ELSEIF (X(6).LT.-1.E-20) THEN
92 * Intersection with cylinders
93 * Intersection point (x,y,z)
94 * (x,y,z) is on track : x=X(1)+t*X(4)
97 * (x,y,z) is on cylinder : x**2 + y**2 = R**2
99 * (X(4)**2+X(5)**2)*t**2
100 * +2.*(X(1)*X(4)+X(2)*X(5))*t
101 * +X(1)**2+X(2)**2-R**2=0
104 T2=(X(1)*X(4)+X(2)*X(5))
107 * track parallel to the z-axis
113 * Intersection with inner cylinder
119 IF (SR.GE.0.) GO TO 101
122 * Intersection with outer cylinder
127 * Intersection with phi-planes
128 * x=r*cos(phi)=X(1)+t*X(4)
129 * y=r*sin(phi)=X(2)+t*X(5)
131 * t=(X(2)*cos(phi)-X(1)*sin(phi))/(X(4)*sin(phi)-X(5)*cos(phi))
135 * track not parallel to the phi1 plane ?
138 S=(X(2)*C1-X(1)*S1)/UN
142 IF ((YI*CFIO-XI*SFIO).LE.0.) SFI1=S
145 * track not parallel to the phi2 plane ?
148 S=(X(2)*C2-X(1)*S2)/UN
152 IF ((YI*CFIO-XI*SFIO).GE.0.) SFI2=S
157 SNXT=MIN(SZ,SR,SFI1,SFI2)