5 * Revision 1.1.1.1 1995/10/24 10:21:41 cernlib
9 #include "geant321/pilot.h"
10 #if !defined(CERNLIB_OLD)
11 *CMZ : 3.21/02 03/07/94 17.14.15 by S.Giani
13 SUBROUTINE GINVOL (X, ISAME)
15 C. ******************************************************************
17 C. * SUBR. GINVOL (X, ISAME*) *
19 C. * Checks if particle at point X has left current volume/medium *
20 C. * If so, returns ISAME = 0 and prepares information useful to *
21 C. * identify the new volume entered. *
22 C. * Otherwise, returns ISAME = 1 *
24 C. * Note : INGOTO is set by GTNEXT, to transmit the information *
25 C. * on the one volume which has limited the step SNEXT, *
26 C. * >0 : INth content *
27 C. * =0 : current volume *
28 C. * <0 : -NLONLY, with NLONLY defined as the first 'ONLY' *
29 C. * level up in the tree for the 'NOT-ONLY' volume *
30 C. * where the point X is found to be. *
32 C. * Called by : GNEXT, GTELEC, GTHADR, GTMUON, GTNEXT *
33 C. * Authors : S.Banerjee, R.Brun, F.Bruyant *
35 C. ******************************************************************
37 #include "geant321/gcbank.inc"
38 #include "geant321/gcvolu.inc"
39 #include "geant321/gctrak.inc"
40 #if defined(CERNLIB_USRJMP)
41 #include "geant321/gcjump.inc"
43 #include "geant321/gchvir.inc"
49 C. ------------------------------------------------------------------
51 * SECTION I: The /GCVOLU/ table contains the presumed location of X in the
52 * geometry tree, at level NLEVEL. The suggestion is that INGOTO
53 * is the index of a content at NLEVEL which may also contain X.
54 * If this is so, ISAME=0 and return. INGOTO is left unchanged.
55 * If this is not so, have we left the volume at NLEVEL altogether?
56 * If so, ISAME=0 and INGOTO=0, return. Otherwise, this is the
57 * starting position for a search. Reset search record variables
58 * and proceed to section II.
60 * *** Check if point is in current volume
63 C***** Code Expanded From Routine: GTRNSF
65 100 IF (GRMAT(10,NLEVEL) .EQ. 0.) THEN
66 XC(1) = X(1) - GTRAN(1,NLEVEL)
67 XC(2) = X(2) - GTRAN(2,NLEVEL)
68 XC(3) = X(3) - GTRAN(3,NLEVEL)
71 XL1 = X(1) - GTRAN(1,NLEVEL)
72 XL2 = X(2) - GTRAN(2,NLEVEL)
73 XL3 = X(3) - GTRAN(3,NLEVEL)
74 XC(1) = XL1*GRMAT(1,NLEVEL) + XL2*GRMAT(2,NLEVEL) + XL3*
76 XC(2) = XL1*GRMAT(4,NLEVEL) + XL2*GRMAT(5,NLEVEL) + XL3*
78 XC(3) = XL1*GRMAT(7,NLEVEL) + XL2*GRMAT(8,NLEVEL) + XL3*
85 C***** End of Code Expanded From Routine: GTRNSF
87 JVO = LQ(JVOLUM-LVOLUM(NLEVEL))
89 * Note: At entry the variable INGOTO may contain the index of a volume
90 * contained within the current one at NLEVEL. If so, begin by checking
91 * if X lies inside. This improves the search speed over that of GMEDIA.
94 IF ((INGOTO.LE.0).OR.(INGOTO.GT.NIN)) THEN
98 * *** Entrance in content INGOTO predicted by GTNEXT
102 JVOT = LQ(JVOLUM-IVOT)
103 JPAR = LQ(JGPAR-NLEVEL-1)
106 C***** Code Expanded From Routine: GITRAN
108 C. ------------------------------------------------------------------
110 IF (IROTT .EQ. 0) THEN
111 XT(1) = XC(1) - Q(5+JIN)
112 XT(2) = XC(2) - Q(6+JIN)
113 XT(3) = XC(3) - Q(7+JIN)
116 XL1 = XC(1) - Q(5+JIN)
117 XL2 = XC(2) - Q(6+JIN)
118 XL3 = XC(3) - Q(7+JIN)
120 XT(1) = XL1*Q(JR+1) + XL2*Q(JR+2) + XL3*Q(JR+3)
121 XT(2) = XL1*Q(JR+4) + XL2*Q(JR+5) + XL3*Q(JR+6)
122 XT(3) = XL1*Q(JR+7) + XL2*Q(JR+8) + XL3*Q(JR+9)
125 C***** End of Code Expanded From Routine: GITRAN
127 * * Check if point is in content
129 CALL GINME (XT, Q(JVOT+2), Q(JPAR+1), IYES)
132 * If so, prepare information for volume retrieval, and return
135 LVOLUM(NLEVIN) = IVOT
136 NAMES(NLEVIN) = IQ(JVOLUM+IVOT)
137 NUMBER(NLEVIN) = Q(JIN+3)
138 LINDEX(NLEVIN) = INGOTO
139 LINMX(NLEVIN) = Q(JVO+3)
140 GONLY(NLEVIN) = Q(JIN+8)
141 IF (LQ(LQ(JVOLUM-IVOT)).EQ.0) THEN
142 NLDEV(NLEVIN) = NLDEV(NLEVEL)
144 NLDEV(NLEVIN) = NLEVIN
146 CALL GTRMUL (GTRAN(1,NLEVEL), GRMAT(1,NLEVEL), Q(JIN+5),
147 + IROTT, GTRAN(1,NLEVIN), GRMAT(1,NLEVIN))
153 * End of INGOTO processing
155 JPAR = LQ(JGPAR-NLEVEL)
156 CALL GINME (XC, Q(JVO+2), Q(JPAR+1), IYES)
163 * ** Point is in current volume
167 IF ((INFROM.LE.0).OR.(INFROM.GT.NIN)) THEN
172 IF (INGOTO.GT.0) THEN
175 IQ(JIN) = IBSET(IQ(JIN),4)
178 * SECTION II: X is found inside current node at NLEVEL in /GCVOLU/.
179 * Search all contents for any containing X. Take the
180 * first one found, incrementing NLEVEL and extending the
181 * /GCVOLU/ tables. Otherwise if the list of contents is
182 * exhausted without finding X inside, proceed to Section III.
183 * Note: Since Section II is re-entered from Section III, a blocking word
184 * is used to mark those contents already checked. Upon exit from Section
185 * II, these blocking words are cleared at NLEVEL, but may remain set in
186 * levels between NLEVEL-1 and NLMIN, if any. They must be cleared at exit.
188 * ** Check contents, if any
190 200 JVO = LQ(JVOLUM-LVOLUM(NLEVEL))
193 * * Case with no contents
198 * * Case with contents defined by division
200 ELSEIF (NIN.LT.0) THEN
201 CALL GMEDIV (JVO, IN, XC, 1)
203 IF ((GONLY(NLEVEL).EQ.0).AND.
204 + (NLEVEL.LE.NLEVIN)) THEN
213 * * Case with contents positioned
217 clmoth=q(jvirt+4*(LVOLUM(NLEVEL)-1)+3)
218 chmoth=q(jvirt+4*(LVOLUM(NLEVEL)-1)+4)
219 ndivto=q(jvirt+4*(LVOLUM(NLEVEL)-1)+2)
220 iaxis =q(jvirt+4*(LVOLUM(NLEVEL)-1)+1)
222 ivdiv=((xc(iaxis)-clmoth)*ndivto/(chmoth-clmoth))+1
225 elseif(ivdiv.gt.ndivto)then
229 call gfcoor(xc,iaxis,cx)
231 if((cx-clmoth).lt.-1.)then
233 elseif((cx-chmoth).gt.1.)then
238 elseif(cx.lt.clmoth)then
242 ivdiv=((cx-clmoth)*ndivto/(chmoth-clmoth))+1
245 elseif(ivdiv.gt.ndivto)then
249 jvdiv=lq(jvirt-LVOLUM(NLEVEL))
250 iofset=iq(jvdiv+ivdiv)
251 ncont=iq(jvdiv+iofset+1)
253 if(ncont.eq.0)goto 260
255 JCONT = LQ(JVO-NIN-1)+1
259 * For each selected content in turn, check if point is inside
269 * If the value IQ(JCONT+ICONT)=0 then we are back in the mother.
270 * So jump to 260, the search is finished. Clean-up should be done
271 * only up to ICONT-1, so we set:
277 IF (.NOT.BTEST(IQ(JIN),4)) THEN
278 CALL GMEPOS (JVO, IN, XC, 1)
280 IF ((GONLY(NLEVEL).EQ.0).AND.
281 + (NLEVEL.LE.NLEVIN)) THEN
289 IQ(JIN) = IBSET(IQ(JIN),4)
295 260 IF(NCONT.EQ.NIN) THEN
298 IQ(JIN) = IBCLR(IQ(JIN),4)
308 IQ(JIN) = IBCLR(IQ(JIN),4)
312 IQ(JIN) = IBCLR(IQ(JIN),4)
316 IQ(JIN) = IBCLR(IQ(JIN),4)
323 * SECTION III: X is found at current node (NLEVEL in /GCVOLU/) but not in
324 * any of its contents, if any. If this is a MANY volume,
325 * save it as a candidate best-choice, and continue the search
326 * by backing up the tree one node and proceed to Section II.
327 * If this is an ONLY volume, proceed to Section IV.
329 * *** Point is in current volume/medium, and not in any content
331 300 IF (GONLY(NLEVEL).EQ.0.) THEN
333 * ** Lowest level is 'NOT ONLY'
335 IF (NLMANY.EQ.0) THEN
340 * * Go up the tree up to a volume with positioned contents
342 310 INFR = LINDEX(NLEVEL)
344 JVO = LQ(JVOLUM-LVOLUM(NLEVEL))
346 IF (NIN.LT.0) GO TO 310
348 C***** Code Expanded From Routine: GTRNSF
350 IF (GRMAT(10,NLEVEL) .EQ. 0.) THEN
351 XC(1) = X(1) - GTRAN(1,NLEVEL)
352 XC(2) = X(2) - GTRAN(2,NLEVEL)
353 XC(3) = X(3) - GTRAN(3,NLEVEL)
356 XL1 = X(1) - GTRAN(1,NLEVEL)
357 XL2 = X(2) - GTRAN(2,NLEVEL)
358 XL3 = X(3) - GTRAN(3,NLEVEL)
359 XC(1) = XL1*GRMAT(1,NLEVEL) + XL2*GRMAT(2,NLEVEL) +
360 + XL3* GRMAT(3,NLEVEL)
361 XC(2) = XL1*GRMAT(4,NLEVEL) + XL2*GRMAT(5,NLEVEL) +
362 + XL3* GRMAT(6,NLEVEL)
363 XC(3) = XL1*GRMAT(7,NLEVEL) + XL2*GRMAT(8,NLEVEL) +
364 + XL3* GRMAT(9,NLEVEL)
367 C***** End of Code Expanded From Routine: GTRNSF
370 IQ(JIN) = IBSET(IQ(JIN),4)
371 NLMIN = MIN(NLEVEL,NLMIN)
375 * SECTION IV: This is the end of the search.
376 * (1) Entry at 400: ISAME = 1 The current node (NLEVEL
377 * in /GCVOLU/) is an ONLY volume and there were no contents
378 * in the tree below it which could claim X.
379 * (2) Entry at 450: ISAME = 0 Section II has just found
380 * another volume which has more claim to X than the current
381 * one: either another ONLY or a deeper MANY was found.
382 * Note: A valid structure is assumed, in which no ONLY volumes overlap.
383 * If this rule is violated, or if a daughter is not entirely contained
384 * within the mother volume, the results are unpredictable.
391 480 DO 489 NL=NLMIN,NLEVEL-1
392 JVO = LQ(JVOLUM-LVOLUM(NL))
396 IQ(JIN) = IBCLR(IQ(JIN),4)
400 IF (NLMANY.GT.0) THEN
403 ELSEIF (NLEVEL.GT.NLEVIN) THEN
404 INGOTO = LINDEX(NLEVEL)
410 999 IF(JGSTAT.NE.0) CALL GFSTAT(ISAME)