This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / GEANT321 / ggeom / gnopgo.F
1 *
2 * $Id$
3 *
4 * $Log$
5 * Revision 1.1.1.1  1995/10/24 10:20:53  cernlib
6 * Geant
7 *
8 *
9 #include "geant321/pilot.h"
10 *CMZ :  3.21/02 29/03/94  15.41.29  by  S.Giani
11 *-- Author :
12       SUBROUTINE GNOPGO (X, PAR, IACT, SNEXT, SNXT, SAFE)
13 C.
14 C.    ******************************************************************
15 C.    *                                                                *
16 C.    *       COMPUTE DISTANCE UP TO INTERSECTION WITH 'PGON' VOLUME,  *
17 C.    *       FROM OUTSIDE POINT X(1-3) ALONG DIRECTION X(4-6)         *
18 C.    *                                                                *
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.    *                       from point X(1-3) along direction X(4-6) *
28 C.    *       SAFE  (output) : shortest distance from point X(1-3) to  *
29 C.    *                       any boundary (possibly overestimated)    *
30 C.    *                                                                *
31 C.    *    ==>Called by : GNEXT, GTNEXT                                *
32 C.    *         Authors   R.Nierhaus, F.Bruyant   *********            *
33 C.    *                                                                *
34 C.    ******************************************************************
35 C.
36 #include "geant321/gconsp.inc"
37       REAL X(*),PAR(*)
38 C
39 C.    ------------------------------------------------------------------
40 *
41       SNXT = BIG
42       IF (IACT.LT.3) THEN
43 *
44 * ***   Compute SAFE
45 *
46          R2 = X(1)**2 +X(2)**2
47          R  = SQRT(R2)
48          DPHI2  = 0.5*PAR(2)*DEGRAD/PAR(3)
49          CDPHI2 = COS(DPHI2)
50          NZ = PAR(4)
51 *
52          IF (X(3).LT.PAR(5)) THEN
53             SAFEZ = PAR(5) -X(3)
54          ELSE IF (X(3).GT.PAR(3*NZ+2)) THEN
55             SAFEZ = X(3) -PAR(3*NZ+2)
56          ELSE
57             SAFEZ = BIG
58          ENDIF
59 *
60          RMIN = BIG
61          RMAX = 0.
62          DO 10 I = 6,3*NZ+3,3
63             IF (PAR(I).LT.RMIN) RMIN = PAR(I)
64             IF (PAR(I+1).GT.RMAX) RMAX = PAR(I+1)
65    10    CONTINUE
66          RMAX = RMAX/CDPHI2
67 *
68 *  **   Treat outside Z-limits first
69 *
70          IF (SAFEZ.LT.0.9*BIG) THEN
71             IF (R.LT.RMIN) THEN
72                SAFE = MAX(SAFEZ,RMIN-R)
73             ELSE IF (R.GT.RMAX) THEN
74                SAFE = MAX(SAFEZ,R-RMAX)
75             ELSE
76                SAFE = SAFEZ
77             ENDIF
78             GO TO 50
79          ELSE
80 *
81 *  **   Now one is inside the Z-limits
82 *
83             DO 20 I = 8,3*NZ+2,3
84               IF (X(3).GT.PAR(I)) GO TO 20
85               IF (PAR(I+1).EQ.PAR(I-2)) THEN
86                  IF (R.LT.PAR(I+1)) THEN
87                     SAFE = PAR(I+1) -R
88                     IF (NZ.EQ.2) GO TO 50
89                     XT3  = X(3) -0.5*(PAR(I)+PAR(I-3))
90                     DZ   = 0.5*(PAR(I)-PAR(I-3))
91                     GO TO 18
92                  ENDIF
93               ELSE IF (PAR(I+2).EQ.PAR(I-1)) THEN
94                  IF (R.GT.PAR(I+2)) THEN
95                     SAFE = R -PAR(I+2)
96                     IF (NZ.EQ.2) GO TO 50
97                     XT3  = X(3) -0.5*(PAR(I)+PAR(I-3))
98                     DZ   = 0.5*(PAR(I)-PAR(I-3))
99                     GO TO 18
100                  ENDIF
101               ENDIF
102 *
103               XT3  = X(3) -0.5*(PAR(I)+PAR(I-3))
104               DZ   = 0.5*(PAR(I)-PAR(I-3))
105               FACT = 0.5*(PAR(I+1)-PAR(I-2))/DZ
106               RAD1 = PAR(I-2) +FACT*(DZ+XT3)
107               IF (R.LT.RAD1) THEN
108                  SAFE = (RAD1-R)/SQRT(1.+FACT**2)
109               ELSE
110                  FACT = 0.5*(PAR(I+2)-PAR(I-1))/DZ
111                  RAD2 = PAR(I-1) +FACT*(DZ+XT3)
112                  RAD2=RAD2/CDPHI2
113                  IF (R.GT.RAD2) THEN
114                     SAFE = (R-RAD2)/SQRT(1.+FACT**2)
115                  ELSE
116                     SAFE = 0.
117                  ENDIF
118               ENDIF
119               IF (NZ.EQ.2) GO TO 19
120 *
121    18         SAFEZ = DZ-ABS(XT3)
122               SAFE  = MIN(SAFEZ,SAFE)
123 *
124    19         IF (R.LT.RMIN) THEN
125                  SAFE = MAX(RMIN-R,SAFE)
126               ELSE IF (R.GT.RMAX) THEN
127                  SAFE = MAX(R-RMAX,SAFE)
128               ENDIF
129               GO TO 50
130    20       CONTINUE
131          ENDIF
132 *
133 *  **   Case of a Phi segmented polygon
134 *               (not coded yet)
135    50    CONTINUE
136 *
137          IF (IACT .EQ. 0) GO TO 999
138          IF (IACT .EQ. 1) THEN
139             IF (SNEXT .LT. SAFE) GO TO 999
140          ENDIF
141       ENDIF
142 *
143       CALL GNOPG1 (X, PAR, SNXT)
144 *
145   999 END