This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / GEANT321 / ggeom / gnbox.F
1 *
2 * $Id$
3 *
4 * $Log$
5 * Revision 1.1.1.1  1995/10/24 10:20:51  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 GNBOX (X, PAR, IACT, SNEXT, SNXT, SAFE)
13 C.
14 C.    ******************************************************************
15 C.    *                                                                *
16 C.    *       COMPUTE DISTANCE UP TO INTERSECTION WITH 'BOX' VOLUME,   *
17 C.    *       FROM INSIDE 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.    *       SAFE  (output) : shortest distance to any boundary       *
28 C.    *                                                                *
29 C.    *    ==>Called by : GNEXT, GTNEXT                                *
30 C.    *         Authors  R.Brun,  P. Weidhaas  *********               *
31 C.    *                                                                *
32 C.    ******************************************************************
33 C.
34 #include "geant321/gconsp.inc"
35       DIMENSION X(6), PAR(6)
36 C.
37 C.    ------------------------------------------------------------------
38 C.
39       SNXT = BIG
40       S1   = BIG
41       S2   = BIG
42       S3   = BIG
43       SAFX1= PAR(1)-X(1)
44       SAFX2= PAR(1)+X(1)
45       SAFY1= PAR(2)-X(2)
46       SAFY2= PAR(2)+X(2)
47       SAFZ1= PAR(3)-X(3)
48       SAFZ2= PAR(3)+X(3)
49  
50       IF (IACT .LT. 3) THEN
51  
52 C       -------------------------------------------------
53 C       |  Compute safety-distance 'SAFE' (P.Weidhaas)  |
54 C       -------------------------------------------------
55  
56         SAFE  = MIN(SAFX1,SAFX2, SAFY1,SAFY2, SAFZ1,SAFZ2)
57  
58         IF (IACT .EQ. 0) GO TO 999
59         IF (IACT .EQ. 1) THEN
60           IF (SNEXT .LT. SAFE) GO TO 999
61         ENDIF
62       ENDIF
63  
64  
65 C     ------------------------------------------------
66 C     |  Compute vector-distance 'SNXT' (McPherson)  |
67 C     ------------------------------------------------
68  
69       IF(X(4).GT.0.) S1 = SAFX1/X(4)
70       IF(X(4).LT.0.) S1 =-SAFX2/X(4)
71       IF(X(5).GT.0.) S2 = SAFY1/X(5)
72       IF(X(5).LT.0.) S2 =-SAFY2/X(5)
73       IF(X(6).GT.0.) S3 = SAFZ1/X(6)
74       IF(X(6).LT.0.) S3 =-SAFZ2/X(6)
75  
76       SNXT  = MIN(S1,S2,S3)
77  
78   999 CONTINUE
79       END