5 * Revision 1.2 1997/11/14 17:44:00 mclareni
6 * Make sure the maximum angle is greater than the minimun
8 * Revision 1.1.1.1 1995/10/24 10:20:10 cernlib
12 #include "geant321/pilot.h"
13 #if !defined(CERNLIB_OLD)
14 *CMZ : 3.21/04 13/12/94 15.29.27 by S.Giani
18 C. ******************************************************************
20 C. * Closes off the geometry setting. *
21 C. * Initializes the search list for the contents of each *
22 C. * volume following the order they have been positioned, and *
23 C. * inserting the content '0' when a call to GSNEXT (-1) has *
24 C. * been required by the user. *
25 C. * Performs the development of the JVOLUM structure for all *
26 C. * volumes with variable parameters, by calling GGDVLP. *
27 C. * Interprets the user calls to GSORD, through GGORD. *
28 C. * Computes and stores in a bank (next to JVOLUM mother bank) *
29 C. * the number of levels in the geometrical tree and the *
30 C. * maximum number of contents per level, by calling GGNLEV. *
31 C. * Sets status bit for CONCAVE volumes, through GGCAVE. *
32 C. * Completes the JSET structure with the list of volume names *
33 C. * which identify uniquely a given physical detector, the *
34 C. * list of bit numbers to pack the corresponding volume copy *
35 C. * numbers, and the generic path(s) in the JVOLUM tree, *
36 C. * through the routine GHCLOS. *
38 C. * Called by : <USER> *
39 C. * Authors : R.Brun, F.Bruyant, S.Giani ********* *
41 C. * Modified by S.Giani for automatic initialization of the new *
42 C. * tracking based on virtual divisions (1993). *
44 C. ******************************************************************
46 #include "geant321/gcbank.inc"
47 #include "geant321/gcflag.inc"
48 #include "geant321/gclist.inc"
49 #include "geant321/gcnum.inc"
50 #include "geant321/gcunit.inc"
51 #include "geant321/gcopti.inc"
52 #include "geant321/gchvir.inc"
56 C. ------------------------------------------------------------------
57 dimension dx(3),tmpmax(7),ndivto(7),qualit(7),ivoaxi(7)
60 COMMON /QUEST/ IQUEST(100)
61 COMMON/GCDINA/jphi2,jclow,jchig,jbuff
63 * *** Stop the run in case of serious anomaly during initialization
72 WRITE (CHMAIL, 1002) NVOLUM
77 NPUSH = NVOLUM -IQ(JVOLUM-2)
78 CALL MZPUSH (IXCONS, JVOLUM, NPUSH, NPUSH,'I')
80 * *** Loop over volumes, create default JNear banks as relevant,
81 * and release unused bank space
87 * *** Check if Tracking medium has been defined
90 IF(NMED.LE.0.OR.NMED.GT.IQ(JTMED-2))THEN
91 WRITE(CHMAIL,1003)IQ(JVOLUM+IVO)
94 IF(LQ(JTMED-NMED).EQ.0)THEN
95 WRITE(CHMAIL,1003)IQ(JVOLUM+IVO)
99 IF (BTEST(IQ(JVO),0)) GO TO 80
101 IQ(JVO) = IBSET(IQ(JVO),0)
106 * reserve enough additional space for sorted volumes
107 IF(NIN.LE.1.OR.NIN.GT.500.OR.IOPTIM.LT.0)THEN
115 DO 90 IN=NINL,NUSED+1,-1
118 CALL MZDROP(IXCONS,JIN,'L')
121 CALL MZPUSH (IXCONS, JVO, NPUSH, 0, 'I')
122 IF (NIN.LE.0) GO TO 80
124 IF(BTEST(IQ(JVO),3)) THEN
132 CALL MZBOOK (IXCONS,JN,JVO,-NIN-1,'VONE',0,0,NEL+1,2,0)
140 IF (IZERO.NE.0) IQ(JN+1) = 0
146 * *** Perform development of JVOLUM structure where necessary
150 * *** Fill GSORD ordering banks if required
152 * Modified by S.Egli to allow GGORDQ to find the optimum sorting for
156 WRITE(6,'(A)')' GGCLOS: Start automatic volume ordering:'
162 IF(ISEARC.GT.0) GO TO 91
163 * check if sorting not possible or not wanted
164 IF(NIN.LE.1.OR.NIN.GT.500.OR.IOPTIM.LT.0)THEN
166 IF(NIN.GT.500.AND.IOPTIM.GE.1)THEN
167 CALL UHTOC(IQ(JVOLUM+IVO),4,NAME,4)
168 WRITE (CHMAIL,1004) NAME,NIN
171 ELSEIF(IOPTIM.EQ.0)THEN
172 IF(ISEARC.LT.0)CALL GGORD (IVO)
173 ELSEIF(IOPTIM.EQ.1)THEN
184 * *** Set status bit for concave volumes
188 * *** Compute maximum number of levels and of contents per level
194 ********************************************************************************
198 call mzlink(ixcons,'/GCHVIR/',jvirt,jvdiv,jcont)
199 call mzlink(ixstor,'/GCDINA/',jphi2,jbuff,jphi2)
207 if(jvirt.ne.0)call mzdrop(ixcons,jvirt,' ')
209 call mzneed(ixcons,nwjvir,'G')
210 if(iquest(11).lt.0)then
211 print *,'No space for jvirt bank'
213 call mzbook(ixcons,jvirt,jvirt,1,'VIRT',nvolum,nvolum,
224 call uhtoc(iq(jvolum+ivo),4,NAME,4)
225 * print *,'VOLUME ',NAME
230 * print *,'No daughters.'
231 * elseif(nin.lt.0)then
232 * print *,'Divided volume.'
233 * elseif(nin.le.1)then
234 * print *,'Only 1 daughter.'
239 if(iswit(9).eq.12345)then
240 print *,'VOLUME ',NAME
245 q(jvirt+4*(ivo-1)+1)=itmpq
252 if(nin.gt.ninmax)then
253 if(jphi2.ne.0)call mzdrop(ixstor,jphi2,' ')
254 if(jclow.ne.0)call mzdrop(ixstor,jclow,' ')
255 if(jchig.ne.0)call mzdrop(ixstor,jchig,' ')
256 call mzbook(ixstor,jphi2,jphi2,2,'PHI2',0,0,
258 call mzbook(ixstor,jclow,jclow,2,'CLOW',0,0,
260 call mzbook(ixstor,jchig,jchig,2,'CHIG',0,0,
263 if(jbuff.ne.0)call mzdrop(ixstor,jbuff,' ')
264 call mzbook(ixstor,jbuff,jbuff,2,'BUFF',0,0,
268 do 110 iaxis=iaxlo,iaxhi
270 * print *,'Quality search for axis ',iaxis
273 call gvdcar(iaxis,ish,0,q(jvo+7),clmoth,chmoth,ierr)
274 if(ierr.eq.1.or.(chmoth.le.clmoth))then
275 * print *,'Not convenient: abandoned!',iaxis
280 elseif(iaxis.le.5)then
281 call gvdrad(iaxis,ish,0,dx,q(jvo+7),clmoth,chmoth,ierr)
283 if(ierr.eq.1.or.(chmoth.le.clmoth))then
284 * print *,'Not convenient: abandoned!',iaxis
289 elseif(iaxis.eq.6)then
290 call gvdphi(ish,0,dx,q(jvo+7),clmoth,chmoth,ierr)
291 if(ierr.eq.1.or.(chmoth.le.clmoth))then
292 * print *,'Not convenient: abandoned!',iaxis
296 elseif((chmoth-clmoth).gt.360..or.chmoth.gt.360)then
297 print *,'(chmoth-clmoth).gt.360.or.chmoth.gt.360'
298 elseif((chmoth-clmoth).eq.360.)then
301 elseif(iaxis.eq.7)then
302 call gvdthe(ish,0,dx,q(jvo+7),clmoth,chmoth,ierr)
304 if(ierr.eq.1.or.(chmoth.le.clmoth))then
305 * print *,'Not convenient: abandoned!',iaxis
312 q(jvirt+4*(ivo-1)+3)=clmoth
313 q(jvirt+4*(ivo-1)+4)=chmoth
315 thimot=abs(chmoth-clmoth)
320 call gvdlim(jvo,in,iaxis,clow,chigh,ierr)
321 if(ierr.eq.1.or.(chigh.le.clow))then
322 * if(ierr.eq.0)print *,'Error in gvdlim: corrected',iaxis
325 elseif(myphif.eq.1)then
329 clow=mod(abs(clow),360.0)
330 if(chigh.ne.360.0)then
331 if(sg.le.0.0)clow=360.-clow
333 chigh=mod(abs(chigh),360.0)
334 if(sg.le.0.0)chigh=360.-chigh
336 if(chigh.lt.clow)then
342 elseif(iaxis.eq.6.and.myphif.eq.0)then
343 if((chigh-chmoth).gt..01.or.(clmoth-clow).gt..01)then
344 if(clmoth.lt.0..and.clow.gt.0.)then
347 if((chigh-chmoth).gt..01)then
349 if(chigh.le.clow)clow=clmoth
350 elseif((clmoth-clow).gt..01)then
352 if(clow.ge.chigh)chigh=chmoth
354 elseif(chigh.lt.0..and.chmoth.gt.0.)then
357 if((chigh-chmoth).gt..01)then
359 if(chigh.le.clow)clow=clmoth
360 elseif((clmoth-clow).gt..01)then
362 if(clow.ge.chigh)chigh=chmoth
367 if((chigh-chmoth).gt..01)then
369 * print *,'iaxis =',iaxis,'protuding daughter',in
370 ** print *,'myphif =',myphif,'myphi2 =',iq(jphi2+in)
371 * print *,'Dhigh=',chigh-chmoth
372 * print *,'Dlow=',clmoth-clow
375 if(chigh.le.clow)clow=clmoth
376 elseif((clmoth-clow).gt..01)then
378 * print *,'iaxis =',iaxis,'protuding daughter',in
379 ** print *,'myphif =',myphif,'myphi2 =',iq(jphi2+in)
380 * print *,'Dhigh=',chigh-chmoth
381 * print *,'Dlow=',clmoth-clow
384 if(clow.ge.chigh)chigh=chmoth
388 if(iq(jphi2+in).eq.0)then
389 tmpthi=abs(chigh-clow)
391 tmpthi=abs(chighm-clowm)
393 if(thimin.gt.tmpthi)thimin=tmpthi
395 if((thimin-thimot).gt.1)then
396 * print *,'thimin.gt.thimot',thimin-thimot,'iax=',iaxis
400 if(thimin.lt.0.04)thimin=0.04
401 tmpndi=2.*thimot/thimin
403 ***** print *,nditmp,' divisions asked for ',nin,' daughters.'
404 ***** if(nditmp.lt.nin)then
406 ***** print *,'Number of divisions corrected to be = ',nin
408 ***** if(nditmp.gt.1000.)print *,'1000 divisions are enough.'
409 ndivto(iaxis)=min(nditmp,1000)
411 q(jvirt+4*(ivo-1)+2)=ndivto(iaxis)
413 if(jvdiv.ne.0)call mzdrop(ixcons,jvdiv,' ')
414 nwvili=ndivto(iaxis)+ivoaxi(itmpq)+11
416 call mzneed(ixcons,nwvili,'G')
417 if(iquest(11).lt.0)then
418 print *,'No space for jvdiv bank',ivo
420 call mzbook(ixcons,jvdiv,jvirt,-ivo,'VLIST',0,0,
424 thisli=thimot/ndivto(iaxis)
433 if(jflag.eq.1)ioff=ndivto(iaxis)
434 do 103 i=1,ndivto(iaxis)
437 if(iq(jphi2+in).eq.0)then
438 if(q(jchig+in).ge.clslic.and.
439 + q(jclow+in).le.chslic)then
446 if(q(jchig+in).ge.clslic.or.
447 + q(jclow+in).le.chslic)then
457 if(i.gt.1.and.iq(jbuff+1).eq.(j-1))then
461 if(iq(jbuff+2).eq.iq(jvdiv+ioff-nposti+2))then
468 do 234 ijk=2,nposti-2
469 do 432 kji=2,nposti-2
470 if(iq(jbuff+ijk).eq.iq(jvdiv+ioff-nposti+kji))then
480 iq(jvdiv+ioff-nposti+nposti)=i
481 iq(jvdiv+i)=ioff-nposti
493 iq(jvdiv+ioff+m)=iq(jbuff+m)
501 if(inbuf1.gt.tmpmax(iaxis))then
504 if(inbuf1.ne.0.)ii=ii+1
511 if(iswit(9).eq.12345)then
512 print *,'words booked =',nwvili,'; words used =',ioff
517 ** do 2 mm=1,ndivto(iaxis)
518 ** myoff=iq(jvdiv+mm)
519 ** if(myoff.ne.mymyof)then
520 ** if(iq(jvdiv+myoff+1).eq.0)then
521 ** print *,'Lower div =',iq(jvdiv+myoff+2)
522 ** print *,'Upper div =',iq(jvdiv+myoff+3)
523 ** elseif(iq(jvdiv+myoff+1).eq.1)then
524 ** print *,'Lower div =',iq(jvdiv+myoff+3)
525 ** print *,'Upper div =',iq(jvdiv+myoff+4)
528 ** mymyof=iq(jvdiv+mm)
533 print *,iaxis,'=iax: not filled divisions: error!'
542 aveave=avelis/ndivto(iaxis)
547 ** print *,'Max n. of objects per div = ',tmpmax(iaxis)
548 ** print *,'Aver. n. of obj. per not-empty div = ',avelis
549 ** print *,'Average n. of objects per div = ',aveave
559 if(qualit(iaxis).lt.tmpq)then
563 if(tmpmax(iaxis).lt.tmpm)then
568 if(iswit(9).eq.12345)then
569 print *,'nin=',nin,' iax=',itmpq,' ndiv=',ndivto(itmpq)
570 print *,'Max n. of objects per div = ',tmpmax(itmpq)
571 print *,'Average n. of objects per div = ',tmpq
574 ** if(isearc.lt.0)then
575 ** jsb=lq(lq(jvo-nin-1))
578 ** jsco=lq(jvo-nin-2)
581 ** do 133 idivor=1,ndivor
582 ** if(iq(jsco+idivor).gt.tmpmor)tmpmor=iq(jsco+idivor)
583 ** tmpqor=tmpqor+iq(jsco+idivor)
585 ** tmpqor=tmpqor/ndivor
586 ** print *,'Gsord: iax=',iaxor,' ndiv=',ndivor
587 ** print *,'Gsord: Max n. of obj. per div = ',tmpmor
588 ** print *,'Gsord: Aver. n. of obj. per div = ',tmpqor
591 ndivst=ndivst+(ndivto(itmpq)+ndivto(itmpq)*(3.+tmpq)+10.)
597 ** print *,'nin=',nin,' iax=',q(jvirt+4*(ivo-1)+1),' ndiv=',
598 ** +q(jvirt+4*(ivo-1)+2)
600 ** iind=q(jvirt+4*(ivo-1)+2)
602 ** jvdiv=lq(jvirt-ivo)
603 ** iofset=iq(jvdiv+n)
604 ** nnobj=iq(jvdiv+iofset+1)
605 ** if(nnobj.gt.ittmp)ittmp=nnobj
607 ** print *,'Max n. of objects per div = ',ittmp
613 if(nin.gt.ninmax)ninmax=nin
615 nwtota=ndivst+nvolum*5+10.
616 if(iswit(9).eq.12345)then
617 print *,'Computed number of words foreseen = ',nwtota
620 if(iswit(9).eq.12345)then
621 print *,'Computed number of words booked = ',nwreal
624 if(iswit(9).eq.12345)then
625 print *,'Computed number of words needed = ',nwneed
627 if(jphi2.ne.0)call mzdrop(ixstor,jphi2,' ')
628 if(jclow.ne.0)call mzdrop(ixstor,jclow,' ')
629 if(jchig.ne.0)call mzdrop(ixstor,jchig,' ')
630 if(jbuff.ne.0)call mzdrop(ixstor,jbuff,' ')
632 ********************************************************************************
634 * *** Scan the volume structure to retrieve the path through
635 * the physical tree for all sensitive detectors
639 * *** Books STAT banks if data card STAT is submitted
641 IF (NSTAT.GT.0) CALL GBSTAT
643 CALL MZGARB (IXCONS, 0)
645 1001 FORMAT (' Severe diagnostic in initialization phase. STOP')
646 1002 FORMAT (' GGCLOS : NVOLUM =',I5,' *****')
647 1003 FORMAT (' Illegal tracking medium number in volume : ',A4)
648 1004 FORMAT (' GGORDQ : Volume ',A4,' has more than 500 (',
649 + I3,') daughters ; volume sorting not possible !')