5 * Revision 1.1.1.1 1995/10/24 10:20:52 cernlib
9 #include "geant321/pilot.h"
10 *CMZ : 3.21/02 29/03/94 15.41.29 by S.Giani
12 SUBROUTINE GNOCON(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) outside *
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 PARAMETER (F=0.01745329251994330D0)
51 #if defined(CERNLIB_SINGLE)
52 PARAMETER (F=0.01745329251994330)
54 REAL X(6),P(7),SNEXT,SNXT,SAFE
55 PARAMETER (ONE=1,HALF=ONE/2,ZERO=0)
57 * this part has to be moved outside the routine
59 TG1=HALF*(P(4)-P(2))/P(1)
60 CR1=ONE/SQRT(ONE+TG1*TG1)
62 IF (P(2).NE.P(4)) ZV1=-RO1/TG1
64 TG2=HALF*(P(5)-P(3))/P(1)
65 CR2=ONE/SQRT(ONE+TG2*TG2)
67 IF (P(3).NE.P(5)) ZV2=-RO2/TG2
71 IF (P7.LT.P6) P7=P7+F*360
85 R =SQRT(X(1)**2+X(2)**2)
86 RIN =ABS(TG1*X(3)+RO1)
87 ROUT=ABS(TG2*X(3)+RO2)
95 IF (IFL.EQ.2.AND.R.GT.0.) THEN
96 CPSI=(X(1)*CFIO+X(2)*SFIO)/R
97 IF (CPSI.LT.CDFI) THEN
98 IF ((X(2)*CFIO-X(1)*SFIO).LE.0.) THEN
99 SAF4=ABS(X(1)*S1-X(2)*C1)
101 SAF4=ABS(X(1)*S2-X(2)*C2)
105 SAFE=MAX(SAF1,SAF2,SAF3,SAF4)
106 IF (IACT.EQ.0) GO TO 999
107 IF (IACT.EQ.1.AND.SNEXT.LE.SAFE) GO TO 999
110 * Intersection with z-plane
111 * only points outside the z range need to be considered
112 IF (ABS(X(3)).GE.P(1)) THEN
113 IF (X(3)*X(6).LT.0.) THEN
114 S=(ABS(X(3))-P(1))/ABS(X(6))
125 IF (R1Q.LE.RIQ.AND.RIQ.LE.R2Q) THEN
126 IF (IFL.EQ.1.OR.RIQ.LE.0.) GO TO 101
127 CPSI=(XI*CFIO+YI*SFIO)/SQRT(RIQ)
128 IF (CPSI.GE.CDFI) GO TO 101
133 * Intersection with cones
134 * Intersection point (x,y,z)
135 * (x,y,z) is on track: x=X(1)+t*X(4)
138 * (x,y,z) is on cone : x**2 + y**2 = (a*z+b)**2
140 * (X(4)**2+X(5)**2-(a*x(6))**2)*t**2
141 * +2.*(X(1)*X(4)+X(2)*X(5)-a*x(6)*(a*x(3)+b))*t
142 * +X(1)**2+X(2)**2-(a*x(3)+b)**2=0
145 T2=X(1)*X(4)+X(2)*X(5)
148 * Intersection with the outer cone
149 * only points outside the outer cone need to be considered
151 IF ((ZV2*X(3).GT.ZV2*ZV2).OR.(R.GT.ROUT)) THEN
153 V=T2- TG2*X(6)*(TG2*X(3)+RO2)
155 * track not parallel to the cone ?
161 * compute the smallest root first
166 IF (ABS(ZI).LE.P(1)) THEN
167 IF (IFL.EQ.1.OR.ZI.EQ.ZV2) THEN
173 CPSI=(XI*CFIO+YI*SFIO)/RI
174 IF (CPSI.GE.CDFI) SR2=S
179 IF (SR2.EQ.S) GO TO 101
180 * smallest root not ok. Try the biggest one
185 ELSEIF (V.NE.0.) THEN
189 IF (ABS(ZI).LE.P(1)) THEN
190 IF (IFL.EQ.1.OR.ZI.EQ.ZV2) GO TO 101
194 CPSI=(XI*CFIO+YI*SFIO)/RI
195 IF (CPSI.GE.CDFI) GO TO 101
201 * Intersection with the inner cone
205 V=T2- TG1*X(6)*(TG1*X(3)+RO1)
207 * track not parallel to the cone ?
213 * compute the smallest root first
218 IF (ABS(ZI).LE.P(1)) THEN
219 IF (IFL.EQ.1.OR.ZI.EQ.ZV1) THEN
225 CPSI=(XI*CFIO+YI*SFIO)/RI
226 IF (CPSI.GE.CDFI) SR1=S
230 IF (IR.EQ.-1.AND.SR1.GT.9.E9) THEN
231 * smallest root not ok. Try the biggest one
236 ELSEIF (V.NE.0.) THEN
240 IF (ABS(ZI).LE.P(1)) THEN
241 IF (IFL.EQ.1.OR.ZI.EQ.ZV1) THEN
247 CPSI=(XI*CFIO+YI*SFIO)/RI
248 IF (CPSI.GE.CDFI) SR1=S
257 * Intersection with phi-planes
258 * x=r*cos(phi)=X(1)+t*X(4)
259 * y=r*sin(phi)=X(2)+t*X(5)
261 * t=(X(2)*cos(phi)-X(1)*sin(phi))/(X(4)*sin(phi)-X(5)*cos(phi))
264 * track not parallel to the phi1 plane ?
267 S=(X(2)*C1-X(1)*S1)/UN
270 IF (ABS(ZI).LE.P(1)) THEN
276 IF (R1Q.LE.RIQ.AND.RIQ.LE.R2Q) THEN
277 IF ((YI*CFIO-XI*SFIO).LE.0.) THEN
278 IF (S.LT.SNXT) SNXT=S
285 * track not parallel to the phi2 plane ?
288 S=(X(2)*C2-X(1)*S2)/UN
291 IF (ABS(ZI).LE.P(1)) THEN
297 IF (R1Q.LE.RIQ.AND.RIQ.LE.R2Q) THEN
298 IF ((YI*CFIO-XI*SFIO).GE.0.) THEN
299 IF (S.LT.SNXT) SNXT=S