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 GNCTUB (X, PAR, IACT, SNEXT, SNXT, SAFE)
14 C. ******************************************************************
16 C. * COMPUTE DISTANCE UP TO INTERSECTION WITH 'CTUB' *
17 C. * VOLUME FROM INSIDE POINT X(1-3) ALONG DIRECTION X(4-6) *
19 C. * PAR (input) : volume parameters *
20 C. * IACT (input) : action flag *
21 C. * = 0 Compute SAFE only *
22 C. * = 1 Compute SAFE, and SNXT only if SNEXT .GT.new SAFE *
23 C. * = 2 Compute both SAFE and SNXT *
24 C. * = 3 Compute SNXT only *
25 C. * SNEXT (input) : see IACT = 1 *
26 C. * SNXT (output) : distance to volume boundary *
27 C. * SAFE (output) : shortest distance to any boundary *
29 C. * ==>Called by : GNEXT, GNPCON, GTNEXT *
30 C. * Authors A.McPherson ******** *
31 C. * MODIFICATION LOG. *
32 C. * 18-July-89 M.Guckes modifications due to GEANG 3.13 *
34 C. ******************************************************************
36 #include "geant321/gconsp.inc"
39 C-------------------------------------------------------------
42 R2 = X(1)*X(1) + X(2)*X(2)
44 IF(PAR(5).GE.360.) THEN
50 SAFZ1 = (-PAR(3)-X(3) )*PAR(8)-X(1)*PAR(6)-X(2)*PAR(7)
51 SAFZ2 = (PAR(3)-X(3) )*PAR(11)-X(1)*PAR(9)-X(2)*PAR(10)
52 IF (PAR(1).NE.0.) THEN
61 * *** Compute safety-distance 'SAFE' (P.Weidhaas)
64 IF (IFLAG .EQ. 2) THEN
66 * In addition to the radial distances (SAFR1 and SAFR2) and the
67 * axial distances (SAFZ1 and SAFZ2) we compute here the distance
68 * to the PHI-segment boundary that is closest to the point:
70 * For each PHI-boundary we find the distance from the given
71 * point to the outer (at RMAX) point of the segment boundary
72 * (DISTS1 and DISTS2, resp.). If DISTS1 < DISTS2, we define
73 * SAFSEG to be the distance to segment PHI1. Else we set
74 * SAFSEG to be the distance to segment PHI2.
76 PHI1 = PAR(4) * DEGRAD
77 PHI2 = PAR(5) * DEGRAD
84 * *** Get coordinates of outer endpoints (at ROUT) of both segments.
91 * *** Get distances (squared) from the given point to each endpoint.
93 DISTS1 = (X(1) - XS1)**2 + (X(2) - YS1)**2
94 DISTS2 = (X(1) - XS2)**2 + (X(2) - YS2)**2
96 * *** Get distance to that PHI-segment whose endpoint
97 * *** is closest to the given point.
99 IF (DISTS1 .LE. DISTS2) THEN
100 SAFSEG = ABS(X(1) * SINPH1 - X(2) * COSPH1)
102 SAFSEG = ABS(X(1) * SINPH2 - X(2) * COSPH2)
106 SAFE = MIN (SAFZ1, SAFZ2, SAFR1, SAFR2, SAFSEG)
107 IF (IACT .EQ. 0) GO TO 999
108 IF (IACT .EQ. 1 .AND. SNEXT .LT. SAFE) GO TO 999
111 * *** Compute intersection with z-boundaries
113 V1 = X(4)*PAR(6)+X(5)*PAR(7)+X(6)*PAR(8)
115 V2 = X(4)*PAR(9)+X(5)*PAR(10)+X(6)*PAR(11)
117 IF( SZ1 .GT. 0. ) THEN
122 IF( SZ2 .GT. 0.0 .AND. SZ2 .LT. SNXT) SNXT = SZ2
125 IF (ABS(X(6)).LT.1.)THEN
127 * *** Compute z-intercept with inner cylinder.
131 RMIN2 = PAR(1)*PAR(1)
132 ZP2 = 1./(1.-X(6)*X(6))
133 BA = (X(4)*X(1)+X(5)*X(2))*ZP2
138 XSIN = -BA-SQRT(DIS2)
140 IF(XSIN.LT.SNXT)SNXT = XSIN
146 * *** Compute z-intercept with outer cylinder.
148 RMAX2 = PAR(2)*PAR(2)
151 IF (XZ*XZ+YZ*YZ.GT.RMAX2)THEN
153 ZP2 = 1./(1.-X(6)*X(6))
154 BA = (X(4)*X(1)+X(5)*X(2))*ZP2
160 SRMAX = -BA+SQRT(DIS2)
161 IF(SRMAX.LT.SNXT)SNXT=SRMAX
166 10 IF(IFLAG.EQ.2) THEN
168 * =======>PHI segmented tube
169 * We have checked the radius and Z.
172 DPSGN=X(1)*X(5)-X(2)*X(4)
174 * Tells us which way its going.
177 IF(DPSGN.LT.0.0) PHI2=PAR(4)
180 * Have set up the limit.
184 DX45=X(4)*TSGN-X(5)*TCSG
185 IF(DX45.EQ.0.)GO TO 999
186 SN1=(X(2)*TCSG-X(1)*TSGN)/DX45
188 * Distance until tangents are right.
190 IF(SN1.LT.0.0) GO TO 999
191 IF(ABS(TSGN).GT.1.E-6.AND.(X(2)+SN1*X(5))*TSGN .LT.0.)GO TO
193 IF(ABS(TCSG).GT.1.E-6.AND.(X(1)+SN1*X(4))*TCSG .LT.0.)GO TO
196 * Have checked that the distance is +VE and that the
197 * SINE is the right sign.
199 IF(SN1.LT.SNXT) SNXT=SN1