5 * Revision 1.1.1.1 1995/10/24 10:20:53 cernlib
9 #include "geant321/pilot.h"
10 *CMZ : 3.21/02 29/03/94 15.41.30 by S.Giani
12 *********************************************************************
13 ***** GNPGO1 ********************************************************
15 * GNPGO1 ... 15-AUG-1991
19 *********************************************************************
21 * Copyright CERN, Geneva 1991 - Copyright and any other
22 * appropriate legal protection of these computer programs and
23 * associated documentation reserved in all countries of the
26 *********************************************************************
28 * Subroutine GNPGO1 is called by GNPGON for the computation
29 * of SNXT, the distance from a point P along a track T to a
30 * boundary surface of a Geant volume V of shape PGON. The point
31 * P is inside the volume V.
33 * V is generally a composite volume consisting of several
34 * sections. The sections have boundary surfaces orthogonal to
35 * the Z-axis. Each section consists generally of several
36 * sectors. Each sector is an "elementary" convex volume. This
37 * package assumes it is either a hexahedron or a pentahedron. If
38 * it is a pentahedron, it has 6 vertices, of which two are on
39 * the Z-axis. All sectors of the same section are congruent.
40 * Each section has the same number of sectors.
42 * We describe each surface by 6 parameters: the first three
43 * are the coordinates of a point on the surface
44 * XS(I),YS(I),ZS(I), the other three are the components of the
45 * normal vector of the surface XN(I),YN(I),ZN(I). I is the index
46 * of the surface. We consider only one sector at a time, and the
47 * number of boundary surfaces is never larger then 6. Each
48 * surface divides the space into two regions: the positive
49 * region and the negative region. We choose the direction of the
50 * normal vectors of the boundary surfaces such that the bounded
51 * volume is within the positive region of each surface, that is,
52 * the normal vector is pointing to the inside of the volume.
54 ***** Subroutine GNPGO1 *************************** 15-AUG-1991 *****
55 SUBROUTINE GNPGO1(X,P,SNXT)
56 #if !defined(CERNLIB_SINGLE)
57 IMPLICIT DOUBLE PRECISION (A-H,O-Z)
60 #if defined(CERNLIB_SINGLE)
61 PARAMETER (F=0.01745329251994330,TPI=6.283185307179586)
63 #if !defined(CERNLIB_SINGLE)
64 PARAMETER (F=0.01745329251994330D0,TPI=6.283185307179586D0)
66 PARAMETER (ONE=1,HALF=ONE/2,ZERO=0.)
67 DIMENSION XS(6), YS(6), ZS(6), XN(6), YN(6), ZN(6)
76 * IMAX -> number of Z-sections
78 * JMAX -> number of Phi-sectors
81 * Find current elementary volume
82 IF (ZP.LE.P(5)) RETURN
83 * Current point (XP,YP,ZP) is below first section.
85 IF (ZP.LT.P(5+3*II)) THEN
91 * Current point (XP,YP,ZP) is above last section.
93 IF (XP.EQ.0..AND.YP.EQ.0.) XP=1.E-20
95 IF (PHI.LT.0.) PHI=PHI+TPI
98 IF (PHI1.LT.0.) PHI1=PHI1+TPI
99 IF (PHI1.GE.TPI) PHI1=PHI1-TPI
101 IF (ABS(PHI1-TPI).LT.1D-7) PHI1=0.
103 J=PHI1*P(3)/(F*P(2))+ONE
104 IF (P(2).EQ.360.) THEN
107 ELSEIF (JMAX.LT.J) THEN
111 IF (JMAX.LT.J.OR.J.LT.1) RETURN
112 * Current point is outside Phi-range.
113 C***** Code Expanded From Routine: GNPGO2
114 * GNPGO2 finds the vector distance to the boundary surface
115 * of the current elementary volume.
116 * I is Z-section, J is Phi-sector.
117 * GNPGO2 calls GNPGO4 five or six times for the storage of
118 * the surface coefficients of its boundary surfaces.
128 P11X = F*(P(1)+(J-1)*P(2)/JMAX)
129 P2 = F*(P(1)+J*P(2)/JMAX)
130 PP = HALF*(P11X + P2)
133 DMX = HALF*(D1X + D2X)
134 DMN = HALF*(D1N + D2N)
135 THX = ATAN((D2X - D1X)/(Z2 - Z1))
140 C***** Code Expanded From Routine: GNPGO4
141 * Store surface coefficients
148 C***** End of Code Expanded From Routine: GNPGO4
149 C***** Code Expanded From Routine: GNPGO9
150 * Logical function GNPGO9 returns TRUE if the point
151 * (XP,YP,ZP) is within the positive region of the surface with
152 * index I. This is the case if the scalar product of
153 * (XP-XS,YP-YS,ZP-ZS) and (XN,YN,ZN) is positive (or zero).
154 RESULT=(XP-XS(5))*XN(5)+(YP-YS(5))*YN(5)+(ZP-ZS(5))*ZN(5)
156 IF (.NOT.FLG) GO TO 50
158 IF (DMN .NE. 0.) THEN
160 THN = ATAN((D2N - D1N)/(Z2 - Z1))
165 C***** Code Expanded From Routine: GNPGO4
172 C***** End of Code Expanded From Routine: GNPGO4
173 C***** Code Expanded From Routine: GNPGO9
174 RESULT=(XP-XS(6))*XN(6)+(YP-YS(6))*YN(6)+(ZP-ZS(6))*ZN(6)
176 IF (.NOT.FLG) GO TO 50
178 C***** Code Expanded From Routine: GNPGO4
185 C***** End of Code Expanded From Routine: GNPGO4
186 C***** Code Expanded From Routine: GNPGO4
193 C***** End of Code Expanded From Routine: GNPGO4
194 C***** Code Expanded From Routine: GNPGO4
201 C***** End of Code Expanded From Routine: GNPGO4
202 C***** Code Expanded From Routine: GNPGO4
209 C***** End of Code Expanded From Routine: GNPGO4
210 C***** Code Expanded From Routine: GNPGO5
211 * Vector distance to volume boundary
214 C***** Code Expanded From Routine: GNPGO7
215 * To find the distance from a point (XP,YP,ZP) along a
216 * track with direction cosines (XD,YD,ZD) to a surface
217 * (XS,YS,ZS)(XN,YN,ZN), we compute first the scalar product of
218 * the vector (XS-XP,YS-YP,ZS-ZP) with the normal vector
219 * (XN,YN,ZN), then the scalar product of the vectors (XD,YD,ZD)
220 * and (XN,YN,ZN). The first scalar product is the shortest
221 * distance from the point to the plane, the second scalar
222 * product is the cosine of the angle between the track and the
223 * plane normal. The quotient is the vector distance. If this
224 * vector distance is positive (or zero) we set the logical
225 * variable FLAG TRUE. GNPGO7 is called with three parameters
226 * I,FLAG and DIST. I is the index of the surface, and DIST is
227 * the vector distance if FLAG is TRUE.
228 SPPMSN = (XP - XS(IS))*XN(IS) + (YP - YS(IS))*YN(IS) + (ZP -
230 SPDN = XD*XN(IS) + YD*YN(IS) + ZD*ZN(IS)
231 IF (SPDN .EQ. 0.) THEN
234 DIST1 = -(SPPMSN + .0001)/SPDN
237 C***** End of Code Expanded From Routine: GNPGO7
238 IF (FLAG) SNXT1 = MIN(DIST1,SNXT1)
241 C***** End of Code Expanded From Routine: GNPGO2
247 * The current point (XP,YP,ZP) is propagated along the track
248 * to the boundary of the current elementary volume.