/[PAMELA software]/eventviewer/flight/src/grkuta.for
ViewVC logotype

Contents of /eventviewer/flight/src/grkuta.for

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Mon Mar 20 10:36:48 2006 UTC (18 years, 8 months ago) by mocchiut
Branch: FEventViewer
CVS Tags: v1r02, v1r03, v1r00, start
Changes since 1.1: +0 -0 lines
First flight release (limited capabilities)

1 **********************************************************************
2 *
3 *
4 * routine per tracciare la particella di uno STEP
5 *
6 SUBROUTINE GRKUTA (CHARGE,STEP,VECT,VOUT)
7 C.
8 C. ******************************************************************
9 C. * *
10 C. * Runge-Kutta method for tracking a particle through a magnetic *
11 C. * field. Uses Nystroem algorithm (See Handbook Nat. Bur. of *
12 C. * Standards, procedure 25.5.20) *
13 C. * *
14 C. * Input parameters *
15 C. * CHARGE Particle charge *
16 C. * STEP Step size *
17 C. * VECT Initial co-ords,direction cosines,momentum *
18 C. * Output parameters *
19 C. * VOUT Output co-ords,direction cosines,momentum *
20 C. * User routine called *
21 C. * CALL GUFLD(X,F) *
22 C. * *
23 C. * ==>Called by : <USER>, GUSWIM *
24 C. * Authors R.Brun, M.Hansroul ********* *
25 C. * V.Perevoztchikov (CUT STEP implementation) *
26 C. * *
27 C. * *
28 C. ******************************************************************
29 C.
30 IMPLICIT DOUBLE PRECISION(A-H,O-Z)
31 *
32 REAL VVV(3),FFF(3)
33 REAL*8 CHARGE, STEP, VECT(*), VOUT(*), F(4)
34 REAL*8 XYZT(3), XYZ(3), X, Y, Z, XT, YT, ZT
35 DIMENSION SECXS(4),SECYS(4),SECZS(4),HXP(3)
36 EQUIVALENCE (X,XYZ(1)),(Y,XYZ(2)),(Z,XYZ(3)),
37 + (XT,XYZT(1)),(YT,XYZT(2)),(ZT,XYZT(3))
38 *
39 PARAMETER (MAXIT = 1992, MAXCUT = 11)
40 PARAMETER (EC=2.9979251D-4,DLT=1D-4,DLT32=DLT/32)
41 PARAMETER (ZERO=0, ONE=1, TWO=2, THREE=3)
42 PARAMETER (THIRD=ONE/THREE, HALF=ONE/TWO)
43 PARAMETER (PISQUA=.986960440109D+01)
44 PARAMETER (IX=1,IY=2,IZ=3,IPX=4,IPY=5,IPZ=6)
45
46 *.
47 *. ------------------------------------------------------------------
48 *.
49 * This constant is for units CM,GEV/C and KGAUSS
50 *
51 c print *,'GRKUTA+++++ charge ',charge,' step ',step,' vect(3) ',
52 c & vect(3)
53 ITER = 0
54 NCUT = 0
55 DO 10 J=1,7
56 VOUT(J)=VECT(J)
57 c print *,' grkuta j ',j,' vout ',vout(j)
58 c print *,' grkuta j ',j,' vect ',vect(j)
59 10 CONTINUE
60 PINV = EC * CHARGE / VECT(7)
61 TL = 0.
62 H = STEP
63 *
64 *
65 20 REST = STEP-TL
66 IF (DABS(H).GT.DABS(REST)) H = REST
67 DO I=1,3
68 VVV(I)=SNGL(VOUT(I))
69 c print *,'grkuta i ',i,' vvv ',vvv(i)
70 ENDDO
71 c print *,'grkuta pinv ',pinv,' h ',h,' rest ',rest
72
73 CALL GUFLD(VVV,FFF)
74 DO I=1,3
75 F(I)=DBLE(FFF(I))
76 c print *,'grkuta i ',i,' f ',f(i)
77 ENDDO
78 *
79 * Start of integration
80 *
81 X = VOUT(1)
82 Y = VOUT(2)
83 Z = VOUT(3)
84 A = VOUT(4)
85 B = VOUT(5)
86 C = VOUT(6)
87 c print *,' QUI A ',A,' B ',B,' C ',C
88 c print *,' QUI x ',x,' y ',y,' z ',z
89 *
90 H2 = HALF * H
91 H4 = HALF * H2
92 PH = PINV * H
93 PH2 = HALF * PH
94 SECXS(1) = (B * F(3) - C * F(2)) * PH2
95 SECYS(1) = (C * F(1) - A * F(3)) * PH2
96 SECZS(1) = (A * F(2) - B * F(1)) * PH2
97 ANG2 = (SECXS(1)**2 + SECYS(1)**2 + SECZS(1)**2)
98 IF (ANG2.GT.PISQUA) GO TO 40
99 DXT = H2 * A + H4 * SECXS(1)
100 DYT = H2 * B + H4 * SECYS(1)
101 DZT = H2 * C + H4 * SECZS(1)
102 XT = X + DXT
103 YT = Y + DYT
104 ZT = Z + DZT
105 *
106 * Second intermediate point
107 *
108 EST = DABS(DXT)+DABS(DYT)+DABS(DZT)
109 IF (EST.GT.H) GO TO 30
110
111 DO I=1,3
112 VVV(I)=SNGL(XYZT(I))
113 ENDDO
114 CALL GUFLD(VVV,FFF)
115 DO I=1,3
116 F(I)=DBLE(FFF(I))
117 c print *,'2grkuta i ',i,' f ',f(i)
118 ENDDO
119 C CALL GUFLD(XYZT,F)
120 AT = A + SECXS(1)
121 BT = B + SECYS(1)
122 CT = C + SECZS(1)
123 *
124 SECXS(2) = (BT * F(3) - CT * F(2)) * PH2
125 SECYS(2) = (CT * F(1) - AT * F(3)) * PH2
126 SECZS(2) = (AT * F(2) - BT * F(1)) * PH2
127 c print *,'1 at ',xt,' bt ',yt,' ct ',zt
128 AT = A + SECXS(2)
129 BT = B + SECYS(2)
130 CT = C + SECZS(2)
131 c print *,'2 at ',xt,' bt ',yt,' ct ',zt
132 SECXS(3) = (BT * F(3) - CT * F(2)) * PH2
133 SECYS(3) = (CT * F(1) - AT * F(3)) * PH2
134 SECZS(3) = (AT * F(2) - BT * F(1)) * PH2
135 DXT = H * (A + SECXS(3))
136 DYT = H * (B + SECYS(3))
137 DZT = H * (C + SECZS(3))
138 XT = X + DXT
139 YT = Y + DYT
140 ZT = Z + DZT
141 c print *,' xt ',xt,' yt ',yt,' zt ',zt
142 c print *,' dxt ',xt,' dyt ',yt,' dzt ',zt
143 c print *,' at ',xt,' bt ',yt,' ct ',zt
144 AT = A + TWO*SECXS(3)
145 BT = B + TWO*SECYS(3)
146 CT = C + TWO*SECZS(3)
147 *
148 EST = ABS(DXT)+ABS(DYT)+ABS(DZT)
149 IF (EST.GT.2.*ABS(H)) GO TO 30
150
151 DO I=1,3
152 VVV(I)=SNGL(XYZT(I))
153 c print *,'3grkuta i ',i,' vvv ',vvv(i)
154 c print *,'3grkuta i ',i,' xyzt ',xyzt(i)
155 ENDDO
156 CALL GUFLD(VVV,FFF)
157 DO I=1,3
158 F(I)=DBLE(FFF(I))
159 c print *,'3grkuta i ',i,' f ',f(i)
160 c print *,'3grkuta i ',i,' fff ',fff(i)
161 ENDDO
162 C CALL GUFLD(XYZT,F)
163 *
164 Z = Z + (C + (SECZS(1) + SECZS(2) + SECZS(3)) * THIRD) * H
165 Y = Y + (B + (SECYS(1) + SECYS(2) + SECYS(3)) * THIRD) * H
166 X = X + (A + (SECXS(1) + SECXS(2) + SECXS(3)) * THIRD) * H
167 *
168 SECXS(4) = (BT*F(3) - CT*F(2))* PH2
169 c print *,'secxs4 bt ',bt,' ct ',ct,' ph2 ',ph2
170 SECYS(4) = (CT*F(1) - AT*F(3))* PH2
171 SECZS(4) = (AT*F(2) - BT*F(1))* PH2
172 A = A+(SECXS(1)+SECXS(4)+TWO * (SECXS(2)+SECXS(3))) * THIRD
173 c print *,'=> a ',a,' secxs 1 ',SECXS(1),' 4 ',SECXS(4),' 2 ',
174 c & SECXS(2),' 3 ',SECXS(3),' third ',third
175 B = B+(SECYS(1)+SECYS(4)+TWO * (SECYS(2)+SECYS(3))) * THIRD
176 C = C+(SECZS(1)+SECZS(4)+TWO * (SECZS(2)+SECZS(3))) * THIRD
177 *
178 EST = ABS(SECXS(1)+SECXS(4) - (SECXS(2)+SECXS(3)))
179 ++ ABS(SECYS(1)+SECYS(4) - (SECYS(2)+SECYS(3)))
180 ++ ABS(SECZS(1)+SECZS(4) - (SECZS(2)+SECZS(3)))
181 *
182 IF (EST.GT.DLT .AND. ABS(H).GT.1.E-4) GO TO 30
183 ITER = ITER + 1
184 NCUT = 0
185 * If too many iterations, go to HELIX
186 IF (ITER.GT.MAXIT) GO TO 40
187 *
188 TL = TL + H
189 IF (EST.LT.(DLT32)) THEN
190 H = H*TWO
191 ENDIF
192 CBA = ONE/ SQRT(A*A + B*B + C*C)
193 VOUT(1) = X
194 VOUT(2) = Y
195 VOUT(3) = Z
196 VOUT(4) = CBA*A
197 VOUT(5) = CBA*B
198 VOUT(6) = CBA*C
199 REST = STEP - TL
200 IF (STEP.LT.0.) REST = -REST
201 IF (REST .GT. 1.E-5*DABS(STEP)) GO TO 20
202 *
203 c print *,' x ',x,' y ',y,' z ',z,' cba ',cba,
204 c & ' a ',a,' b ',b,' c ',c,' step ',step,
205 c & ' tl ',tl,' rest ',rest,' est ',est,
206 c & ' h ',h,' two ',two,' one ',one
207 GO TO 999
208 *
209 ** CUT STEP
210 30 NCUT = NCUT + 1
211 * If too many cuts , go to HELIX
212 IF (NCUT.GT.MAXCUT) GO TO 40
213 H = H*HALF
214 GO TO 20
215 *
216 ** ANGLE TOO BIG, USE HELIX
217 40 F1 = F(1)
218 F2 = F(2)
219 F3 = F(3)
220 F4 = DSQRT(F1**2+F2**2+F3**2)
221 RHO = -F4*PINV
222 TET = RHO * STEP
223 IF(TET.NE.0.) THEN
224 HNORM = ONE/F4
225 F1 = F1*HNORM
226 F2 = F2*HNORM
227 F3 = F3*HNORM
228 *
229 HXP(1) = F2*VECT(IPZ) - F3*VECT(IPY)
230 HXP(2) = F3*VECT(IPX) - F1*VECT(IPZ)
231 HXP(3) = F1*VECT(IPY) - F2*VECT(IPX)
232
233 HP = F1*VECT(IPX) + F2*VECT(IPY) + F3*VECT(IPZ)
234 *
235 RHO1 = ONE/RHO
236 SINT = DSIN(TET)
237 COST = TWO*DSIN(HALF*TET)**2
238 *
239 G1 = SINT*RHO1
240 G2 = COST*RHO1
241 G3 = (TET-SINT) * HP*RHO1
242 G4 = -COST
243 G5 = SINT
244 G6 = COST * HP
245
246 VOUT(IX) = VECT(IX) + (G1*VECT(IPX) + G2*HXP(1) + G3*F1)
247 VOUT(IY) = VECT(IY) + (G1*VECT(IPY) + G2*HXP(2) + G3*F2)
248 VOUT(IZ) = VECT(IZ) + (G1*VECT(IPZ) + G2*HXP(3) + G3*F3)
249 c print *,' iz ',iz,' vect ',vect(iz),' g1 ',g1,' ipz ',ipz,
250 c & ' vect ',vect(ipz),' g2 ',g2,' hxp ',hxp(3),' g3 ',g3,
251 c & ' f3 ',f3
252
253 VOUT(IPX) = VECT(IPX) + (G4*VECT(IPX) + G5*HXP(1) + G6*F1)
254 VOUT(IPY) = VECT(IPY) + (G4*VECT(IPY) + G5*HXP(2) + G6*F2)
255 VOUT(IPZ) = VECT(IPZ) + (G4*VECT(IPZ) + G5*HXP(3) + G6*F3)
256 *
257 ELSE
258 VOUT(IX) = VECT(IX) + STEP*VECT(IPX)
259 VOUT(IY) = VECT(IY) + STEP*VECT(IPY)
260 VOUT(IZ) = VECT(IZ) + STEP*VECT(IPZ)
261 c print *,' iz ',iz,' vect ',vect(iz),' step ',step,' ipz ',ipz,
262 c & ' vect ',vect(ipz)
263 *
264 ENDIF
265 *
266 999 END
267 *
268 *
269
270
271
272 **********************************************************************
273 *
274 * gives the value of the magnetic field in the tracking point
275 *
276 **********************************************************************
277
278 subroutine gufld(v,f) !coordinates in cm, B field in kGauss
279
280 real v(3),f(3) !coordinates in cm, B field in kGauss, error in kGauss
281
282 real*8 vv(3),ff(3) !inter_B.f works in double precision
283
284
285 do i=1,3
286 vv(i)=v(i)/100. !inter_B.f works in meters
287 c print *,'IN gufld i ',i,' v ',v(i)
288 enddo
289 c inter_B: coordinates in m, B field in Tesla
290 call inter_B(vv(1),vv(2),vv(3),ff)
291 do i=1,3 !change back the field in kGauss
292 f(i)=ff(i)*10.
293 enddo
294 c do i=1,3
295 c print *,'OUT gufld i ',i,' v ',v(i)
296 c enddo
297 return
298 end
299

  ViewVC Help
Powered by ViewVC 1.1.23