Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / GEANT321 / ggeom / gnoctu.F
CommitLineData
fe4da5cc 1*
2* $Id$
3*
4* $Log$
5* Revision 1.1.1.1 1995/10/24 10:20:52 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 GNOCTU(X, PAR, IACT, SNEXT, SNXT, SAFE)
13C.
14C. ******************************************************************
15C. * *
16C. * COMPUTE DISTANCE UP TO INTERSECTION WITH 'CTUB' *
17C. * VOLUME, FROM OUTSIDE POINT X(1-3) ALONG DIRECTION X(4-6) *
18C. * *
19C. * PAR (input) : volume parameters *
20C. * IACT (input) : action flag *
21C. * = 0 Compute SAFE only *
22C. * = 1 Compute SAFE, and SNXT only if SNEXT .GT.new SAFE *
23C. * = 2 Compute both SAFE and SNXT *
24C. * = 3 Compute SNXT only *
25C. * SNEXT (input) : see IACT = 1 *
26C. * SNXT (output) : distance to volume boundary *
27C. * SAFE (output) : shortest distance to any boundary *
28C. * *
29C. * ==>Called by : GNEXT, GNOPCO, GTNEXT *
30C. * Author A.McPherson ******** *
31C. * MODIFICATION LOG. *
32C. * 18-July-89 M.Guckes modifications due to GEANG 3.13 *
33C. * *
34C. ******************************************************************
35C.
36#include "geant321/gconsp.inc"
37 DIMENSION X(6),PAR(11),SNP(2),CSP(2)
38*
39* ------------------------------------------------------------------
40*
41 SNXT = BIG
42*
43* *** Make sure that (-pi).LT.PHI.GE.(+pi)
44*
45 PH1 = MOD(PAR(4)*DEGRAD,TWOPI)
46 PH2 = MOD(PAR(5)*DEGRAD,TWOPI)
47 DPHI = PH2 - PH1
48 IF(DPHI.LT.TWOPI) THEN
49 DPHI = PH2 - PH1
50 SNP(1) = SIN(PH1)
51 CSP(1) = COS(PH1)
52 SNP(2) = SIN(PH2)
53 CSP(2) = COS(PH2)
54 ELSE
55 PH1 = 0.
56 PH2 = TWOPI
57 DPHI = TWOPI
58 SNP(1) = 0.
59 CSP(1) = 1.
60 SNP(2) = 0.
61 CSP(2) = 1.
62 ENDIF
63C
64*
65* *** Check that current point is outside the CTUB. compute SAFE
66*
67 R02=X(1)*X(1)+X(2)*X(2)
68 R=SQRT(R02)
69 SAF1=PAR(1)-R
70 SAF2=R-PAR(2)
71 SAF3 = ( X(3)+PAR(3) )*PAR(8)+X(1)*PAR(6)+X(2)*PAR(7)
72 SAF4 = ( X(3)-PAR(3) )*PAR(11)+X(1)*PAR(9)+X(2)*PAR(10)
73*
74 IF(IACT.EQ.3) GO TO 20
75*
76* Phi segment (P. Weidhaas)
77* We compute here the distance (SAF5)
78* to the PHI-segment boundary that is closest to the point:
79*
80* SAF5 is only calculated if PHI lies outside the interval
81* [PH1, PH2]. Here PHI is the angle to the given point
82* (thus we only consider SAF5 if the point is outside the
83* PHI-segment : FIOUT > 0.
84* Algorithm to find SAF5 (same as in routine "GNTUBE"):
85* For each PHI-boundary we find the distance from the given
86* point to the outer (at RMAX) point of the segment boundary
87* (DSP1 and DSP2, resp.). If DSP1 < DSP2, we define
88* SAF5 to be the distance to segment PHI1; else we set
89* SAF5 to be the distance to segment PHI2.
90 SAF5=0.
91 IF(R.GT.0.) THEN
92 PHI = ATAN2(X(2),X(1))
93 FIOUT = DPHI*(PHI-PH1)*(PHI-PH2)
94 IF(FIOUT.LE.0.) GO TO 16
95 DSP1 = (X(1)-PAR(2)*CSP(1))**2 + (X(2)-PAR(2)*SNP(1))**2
96 DSP2 = (X(1)-PAR(2)*CSP(2))**2 + (X(2)-PAR(2)*SNP(2))**2
97 IF(DSP1.LE.DSP2) THEN
98 SAF5 = ABS(X(1)*SNP(1) - X(2)*CSP(1))
99 ELSE
100 SAF5 = ABS(X(1)*SNP(2) - X(2)*CSP(2))
101 ENDIF
102 ENDIF
103 16 CONTINUE
104*
105* Compute SAFE
106 SAFE = 0.
107 IF(SAF1.GT.SAFE) SAFE = SAF1
108 IF(SAF2.GT.SAFE) SAFE = SAF2
109 IF(SAF3.GT.SAFE) SAFE = SAF3
110 IF(SAF4.GT.SAFE) SAFE = SAF4
111 IF(SAF5.GT.SAFE) SAFE = SAF5
112*
113* Point inside the volume ?
114 IF(SAFE.EQ.0.) THEN
115 SNXT = -10.
116 GO TO 999
117 ENDIF
118*
119 IF(IACT.EQ.0) GO TO 999
120 IF(IACT.EQ.1.AND.SAFE.GT.SNEXT) GO TO 999
121*
122 20 CONTINUE
123*
124* *** Compute SNXT
125*
126 SMAX=BIG
127 V1 = X(4)*PAR(6)+X(5)*PAR(7)+X(6)*PAR(8)
128 V2 = X(4)*PAR(9)+X(5)*PAR(10)+X(6)*PAR(11)
129 IF( V1 .GE. 0.0 .AND. SAF3 .GE. 0.0 ) GO TO 999
130 IF( V2 .GE. 0.0 .AND. SAF4 .GE. 0.0 ) GO TO 999
131C
132 IF( SAF3 .GT. 0.0 .AND. SAF4 .LE. 0.0 ) THEN
133 SMIN = -SAF3/V1
134 IF( V2 .GT. 0 ) THEN
135 SMAX = -SAF4/V2
136 ELSE
137 SMAX = BIG
138 ENDIF
139 ELSEIF( SAF4 .GT. 0.0 .AND. SAF3 .LE. 0.0 ) THEN
140 SMIN = -SAF4/V2
141 IF( V1 .GT. 0 ) THEN
142 SMAX = -SAF3/V1
143 ELSE
144 SMAX = BIG
145 ENDIF
146 ELSEIF( SAF3 .LE. 0.0 .AND. SAF4 .LE. 0.0 ) THEN
147 SMIN = 0.0
148 SMAX = BIG
149 IF( V1 .GT. 0.0 ) SMAX = -SAF3/V1
150 IF( V2 .GT. 0.0 .AND. SMAX .GT. -SAF4/V2 ) SMAX = -SAF4/V2
151 ENDIF
152*
153 SMIN1=SMIN
154 SMAX1=-1.0
155 SMIN2=SMIN
156 SMAX2=SMAX
157C
158 DXY2=(1+X(6))*(1-X(6))
159 IF(DXY2.LT.1.0E-10.AND.(R.LT.PAR(1)
160 + .OR.R.GT.PAR(2)))GO TO 999
161 IF(DXY2.EQ.0.) GO TO 30
162C
163 BA=(X(1)*X(4)+X(2)*X(5))/DXY2
164 IF(R.GE.PAR(2).AND.BA.GE.0.0) GO TO 999
165C
166 CA=(R02-PAR(2)*PAR(2))/DXY2
167 DISC=BA*BA-CA
168 IF(DISC.LE.0.0) GO TO 999
169C
170 RDISC=SQRT(DISC)
171 SMAR=-BA+RDISC
172 IF(SMAR.LT.SMAX) SMAX=SMAR
173 SMIR=-BA-RDISC
174 IF(SMIR.GT.SMIN) SMIN=SMIR
175 IF(SMAX.LE.SMIN) GO TO 999
176C
177 CA=(R02-PAR(1)*PAR(1))/DXY2
178 DISC=BA*BA-CA
179C
180 SMIN1=SMIN
181 SMAX1=-1.0
182 SMIN2=SMIN
183 SMAX2=SMAX
184C
185 IF(DISC.LE.0.0) GO TO 30
186 RDISC=SQRT(DISC)
187 SMI2=-BA+RDISC
188 IF(SMI2.GT.SMIN2)SMIN2=SMI2
189 SMAX1=-BA-RDISC
190 IF(SMAX.LT.SMAX1) SMAX1=SMAX
191C
192 30 CONTINUE
193C
194 IF( PAR(4) .EQ. 0.0 .AND. PAR(5) .EQ. 360.0 ) GO TO 120
195C
196C Now do the phi stuff.
197C
198 DPSGN=X(1)*X(5)-X(2)*X(4)
199 ISMIN=0
200 ISMAX=0
201C
202 TSGN=SNP(1)
203 TCSG=CSP(1)
204 DEN=X(4)*TSGN-X(5)*TCSG
205 IF(DEN.EQ.0.0) GO TO 40
206 SNL=(X(2)*TCSG-X(1)*TSGN)/DEN
207 IF(ABS(TSGN).GT.1.E-6.AND.(X(2)+SNL*X(5))*TSGN.LT.0.) GO TO 40
208 IF(ABS(TCSG).GT.1.E-6.AND.(X(1)+SNL*X(4))*TCSG.LT.0.) GO TO 40
209C
210 ISMIN=1
211 SMIN=SNL
212 IF(DPSGN.GT.0.0) GO TO 40
213 ISMIN=0
214 ISMAX=1
215 SMAX=SNL
216C
217 40 CONTINUE
218C
219 TSGN=SNP(2)
220 TCSG=CSP(2)
221 DEN=X(4)*TSGN-X(5)*TCSG
222 IF(DEN.EQ.0.0) GO TO 60
223 SNH=(X(2)*TCSG-X(1)*TSGN)/DEN
224 IF(ABS(TSGN).GT.1.E-6.AND.(X(2)+SNH*X(5))*TSGN.LT.0.) GO TO 60
225 IF(ABS(TCSG).GT.1.E-6.AND.(X(1)+SNH*X(4))*TCSG.LT.0.) GO TO 60
226 IF(DPSGN.LT.0.0) GO TO 50
227 ISMAX=1
228 SMAX=SNH
229 GO TO 60
230C
231 50 CONTINUE
232 ISMIN=1
233 SMIN=SNH
234C
235 60 CONTINUE
236C
237 IF(ISMIN.EQ.0.OR.ISMAX.EQ.0) GO TO 90
238 IF(SMAX.LT.0.0.AND.SMAX.GT.SMIN) GO TO 999
239 IF(SMIN.LT.0.0) SMIN=0.0
240 IF(SMAX.LT.0.0) GO TO 110
241 IF(SMAX.GT.SMIN) GO TO 70
242C
243C SMAX +VE and less than SMIN - 2 allowed
244C regions.
245C
246 IF(SMAX.GT.SMIN1.AND.SMAX1.GT.SMIN1) GO TO 130
247 IF(SMIN.GT.SMIN1) SMIN1=SMIN
248 IF(SMAX1.GT.SMIN1) GO TO 130
249 IF(SMAX.GT.SMIN2) GO TO 140
250 IF(SMIN.GT.SMAX2) GO TO 999
251 IF(SMIN.GT.SMIN2) SMIN2=SMIN
252 GO TO 140
253C
254 70 CONTINUE
255 IF(SMIN.GT.SMIN1) SMIN1=SMIN
256 IF(SMAX.LT.SMAX1) SMAX1=SMAX
257 IF(SMAX1.LT.SMIN1) GO TO 80
258 GO TO 130
259C
260 80 CONTINUE
261 IF(SMIN.GT.SMIN2) SMIN2=SMIN
262 IF(SMAX.LT.SMAX2) SMAX2=SMAX
263 IF(SMAX2.LT.SMIN2) GO TO 999
264 GO TO 140
265C
266 90 CONTINUE
267 IF(ISMIN.EQ.1) GO TO 110
268 IF(ISMAX.EQ.0) GO TO 100
269 IF(SMAX.LT.SMAX1) SMAX1=SMAX
270 IF(SMAX.LT.SMAX2) SMAX2=SMAX
271 GO TO 120
272C
273 100 CONTINUE
274 DPH=PAR(5)-PAR(4)
275 IF(DPH.LT.180.0.AND.DPH.GT.0.0) GO TO 999
276 IF(DPH.LT.-180.0) GO TO 999
277 GO TO 120
278C
279 110 CONTINUE
280 IF(SMIN.GT.SMIN1) SMIN1=SMIN
281 IF(SMAX1.GT.SMIN1) GO TO 130
282 IF(SMIN.GT.SMIN2) SMIN2=SMIN
283 IF(SMAX2.LT.SMIN2) GO TO 999
284 GO TO 140
285C
286 120 CONTINUE
287 IF(SMAX1.GT.SMIN1) GO TO 130
288 IF(SMAX2.GT.SMIN2) GO TO 140
289 GO TO 999
290C
291 130 CONTINUE
292 IF(SMIN1.LE.0.)GO TO 999
293 IF(SNXT.GT.SMIN1) SNXT=SMIN1
294 GO TO 999
295C
296 140 CONTINUE
297 IF(SMIN2.LE.0.)GO TO 999
298 IF(SNXT.GT.SMIN2) SNXT=SMIN2
299C
300 999 CONTINUE
301 END