Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / GEANT321 / gdraw / gdnino.F
1 *
2 * $Id$
3 *
4 * $Log$
5 * Revision 1.1.1.1  1995/10/24 10:20:30  cernlib
6 * Geant
7 *
8 *
9 #include "geant321/pilot.h"
10 *CMZ :  3.21/02 28/03/94  01.30.59  by  S.Giani
11 *-- Author :
12       SUBROUTINE GDNINO
13 C.
14 C.    ******************************************************************
15 C.    *                                                                *
16 C.    *       RAY-TRACING                                              *
17 C.    *                                                                *
18 C.    *       Tracking of light rays.                                  *
19 C.    *                                                                *
20 C.    *       Author: S.Giani.                                         *
21 C.    *                                                                *
22 C.    ******************************************************************
23 C.
24 #include "geant321/gcvolu.inc"
25 #include "geant321/gconsp.inc"
26 #include "geant321/gcdraw.inc"
27 #include "geant321/gcflag.inc"
28 #include "geant321/gctmed.inc"
29 #include "geant321/gctrak.inc"
30 #include "geant321/gcbank.inc"
31 #include "geant321/gckine.inc"
32 #if defined(CERNLIB_DEBUG)
33 #include "geant321/gcunit.inc"
34 #endif
35 #if !defined(CERNLIB_SINGLE)
36       PARAMETER (EPSMAC=1.E-6)
37 #endif
38 #if defined(CERNLIB_SINGLE)
39       PARAMETER (EPSMAC=1.E-11)
40 #endif
41 ********************************************************************************
42 #include "geant321/gcfdim.inc"
43 #include "geant321/gcrayt.inc"
44 #include "geant321/gcpixe.inc"
45       DIMENSION CCVV(3),DDVV(2)
46 ********************************************************************************
47 C.
48 C.    ------------------------------------------------------------------
49 C.
50       STEP = BIG
51       IF((BOFLAG.NE.1.).and.(VECT(1).le.XCUT.or.VECT(2).le.YCUT
52      +.or.VECT(3).le.ZCUT))THEN
53        CALL GTNEXT
54       ELSE
55        IGNEXT=1
56        SNEXT=0.0001
57        nlevin=nlevel
58       ENDIF
59       IF (IGNEXT.NE.0) THEN
60          STEP = SNEXT + PREC
61          step=step+.004
62 ***         if(iombra.eq.9)step=step+.001
63          INWVOL= 2
64          LMEC(1)=1
65 *
66 * *** Linear transport
67 *
68          DO 10 I = 1,3
69             VECTMP  = VECT(I) +STEP*VECT(I+3)
70             IF(VECTMP.EQ.VECT(I)) THEN
71 *
72 * *** Correct for machine precision
73 *
74                IF(VECT(I+3).NE.0.) THEN
75                   VECTMP = VECT(I)+ABS(VECT(I))*SIGN(1.,VECT(I+3))*
76      +            EPSMAC
77                ENDIF
78             ENDIF
79 ********************************************************************************
80             IF(BOFLAG.NE.1)THEN
81               VECT(I) = VECTMP
82             ELSE
83               INWVOL=0
84             ENDIF
85    10    CONTINUE
86        NOFLAG=0
87        IF(BOFLAG.NE.1)THEN
88        IF(VECT(1).GT.XCUT.AND.VECT(2).GT.YCUT.AND.
89      +    VECT(3).GT.ZCUT)THEN
90           NOFLAG=1
91           CCXX(1)=1.
92           CCXX(2)=1.
93           CCXX(3)=0.
94           CCXX(4)=0.
95           CCYY(1)=1.
96           CCYY(2)=0.
97           CCYY(3)=1.
98           CCYY(4)=0.
99           CCZZ(1)=1.
100           CCZZ(2)=0.
101           CCZZ(3)=0.
102           CCZZ(4)=1.
103           DO 11 I=1,3
104             CCVV(I)=VECT(I+3)
105  11       CONTINUE
106           STEP1=100000.
107           DDXX=GVSAFE(VECT,-XCUT,CCXX,4)
108           CALL GVLONG(CCVV,CCXX,4,DDVV,NTAU)
109           IF(NTAU.GT.0)THEN
110            IF(DDVV(1).GE.0.)THEN
111              STEP1=DDVV(1)
112            ENDIF
113            APFLAG=(CCXX(2)*XCOSXS)+(CCXX(3)*YCOSYS)+
114      +     (CCXX(4)*ZCOSZS)
115            IXYFLA=1
116           ENDIF
117           DDYY=GVSAFE(VECT,-YCUT,CCYY,4)
118           CALL GVLONG(CCVV,CCYY,4,DDVV,NTAU)
119           IF(NTAU.GT.0)THEN
120            IF(DDVV(1).LT.STEP1.AND.DDVV(1).GE.0.)THEN
121              IXYFLA=2
122              STEP1=DDVV(1)
123              APFLAG=(CCYY(2)*XCOSXS)+(CCYY(3)*YCOSYS)+
124      +       (CCYY(4)*ZCOSZS)
125            ENDIF
126           ENDIF
127           DDZZ=GVSAFE(VECT,-ZCUT,CCZZ,4)
128           CALL GVLONG(CCVV,CCZZ,4,DDVV,NTAU)
129           IF(NTAU.GT.0)THEN
130            IF(DDVV(1).LT.STEP1.AND.DDVV(1).GE.0.)THEN
131              IXYFLA=3
132              STEP1=DDVV(1)
133              APFLAG=(CCZZ(2)*XCOSXS)+(CCZZ(3)*YCOSYS)+
134      +       (CCZZ(4)*ZCOSZS)
135            ENDIF
136           ENDIF
137           STEP1=STEP1+.004
138           DO 12 I=1,3
139             IF(BOFLAG.NE.1)VECT(I)=VECT(I)+STEP1*VECT(I+3)
140  12       CONTINUE
141           IF(IOMBRA.EQ.9)SLENG=SLENG+STEP1
142           IF(IOMBRA.EQ.10)THEN
143             XYZMOD=1./SQRT((XLPOS-VECT(1))**2+(YLPOS-VECT(2))**2+
144      +                     (ZLPOS-VECT(3))**2)
145             XLDIR=(XLPOS-VECT(1))*XYZMOD
146             YLDIR=(YLPOS-VECT(2))*XYZMOD
147             ZLDIR=(ZLPOS-VECT(3))*XYZMOD
148             IF(IXYFLA.EQ.1)THEN
149              APFLAH=(CCXX(2)*XLDIR)+(CCXX(3)*YLDIR)+(CCXX(4)*ZLDIR)
150 *             if(apflah.lt.0.)print *,APFLAH,'=apflah',IXYFLA,'=flag',
151 *     +       CCXX(2),XLDIR,CCXX(3),YLDIR,CCXX(4),ZLDIR
152             ELSEIF(IXYFLA.EQ.2)THEN
153              APFLAH=(CCYY(2)*XLDIR)+(CCYY(3)*YLDIR)+(CCYY(4)*ZLDIR)
154 *             if(apflah.lt.0.)print *,APFLAH,'=apflah',IXYFLA,'=flag',
155 *     +       CCYY(2),XLDIR,CCYY(3),YLDIR,CCYY(4),ZLDIR
156             ELSEIF(IXYFLA.EQ.3)THEN
157              APFLAH=(CCZZ(2)*XLDIR)+(CCZZ(3)*YLDIR)+(CCZZ(4)*ZLDIR)
158             ENDIF
159           ENDIF
160        ENDIF
161        ELSE
162         IF(IOMBRA.EQ.10)THEN
163           IOMBRA=9
164           XYZMOD=1./SQRT((XLPOS-VECT(1))**2+(YLPOS-VECT(2))**2+
165      +                   (ZLPOS-VECT(3))**2)
166           VECT(4)=(XLPOS-VECT(1))*XYZMOD
167           VECT(5)=(YLPOS-VECT(2))*XYZMOD
168           VECT(6)=(ZLPOS-VECT(3))*XYZMOD
169           XLDIR=VECT(4)
170           YLDIR=VECT(5)
171           ZLDIR=VECT(6)
172           SLENG=0.
173         ELSE
174           NSTEP=10000
175           ISTOP=0
176           IF(IOMBRA.EQ.9)IOMBRA=10
177         ENDIF
178        ENDIF
179       ELSE
180           NSTEP=10000
181           ISTOP=0
182           INWVOL= 2
183           LMEC(1)=1
184           STEP=.1
185           IF(IOMBRA.EQ.9)THEN
186              IOMBRA=10
187              PRINT *,'WARNING'
188           ENDIF
189          DO 20 I = 1,3
190            IF(BOFLAG.NE.1)VECT(I)  = VECT(I) +STEP*VECT(I+3)
191 ********************************************************************************
192    20    CONTINUE
193       ENDIF
194       SLENG = SLENG +STEP
195       END