/[PAMELA software]/DarthVader/TrackerLevel2/src/F77/mini.f
ViewVC logotype

Contents of /DarthVader/TrackerLevel2/src/F77/mini.f

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Fri Feb 16 14:56:02 2007 UTC (17 years, 9 months ago) by pam-fi
Branch: MAIN
Changes since 1.11: +1 -0 lines
Magnetic field, improoved de/dx, reprocessing tools

1 ************************************************************************
2 *
3 * subroutine to evaluate the vector alfa (AL)
4 * which minimizes CHI^2
5 *
6 * - modified from mini.f in order to call differente chi^2 routine.
7 * The new one includes also single clusters: in this case
8 * the residual is defined as the distance between the track and the
9 * segment AB associated to the single cluster.
10 *
11 *
12 ************************************************************************
13
14
15 SUBROUTINE MINI2(ISTEP,IFAIL,IPRINT)
16
17 IMPLICIT DOUBLE PRECISION (A-H,O-Z)
18
19 include 'commontracker.f' !tracker general common
20 include 'common_mini_2.f' !common for the tracking procedure
21
22 c logical DEBUG
23 c common/dbg/DEBUG
24
25 parameter (dinf=1.d15) !just a huge number...
26 c------------------------------------------------------------------------
27 c variables used in the tracking procedure (mini and its subroutines)
28 c
29 c N.B.: in mini & C. (and in the following block of variables too)
30 c the plane ordering is reversed in respect of normal
31 c ordering, but they maintain their Z coordinates. so plane number 1 is
32 c the first one that a particle meets, and its Z coordinate is > 0
33 c------------------------------------------------------------------------
34 DATA ZINI/23.5/ !!! ***PP*** to be changed !z coordinate of the reference plane
35
36 c DATA XGOOD,YGOOD/nplanes*1.,nplanes*1./ !planes to be used in the tracking
37
38 DATA STEPAL/5*1.d-7/ !alpha vector step
39 DATA ISTEPMAX/100/ !maximum number of steps in the chi^2 minimization
40 DATA TOLL/1.d-8/ !tolerance in reaching the next plane during
41 * !the tracking procedure
42 DATA STEPMAX/100./ !maximum number of steps in the trackin gprocess
43
44 c DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components
45 c DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !"
46 DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components
47 DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !"
48
49 DIMENSION DAL(5) !increment of vector alfa
50 DIMENSION CHI2DD_R(4,4),CHI2D_R(4) !hessiano e gradiente di chi2
51
52 c elena--------
53 REAL*8 AVRESX,AVRESY
54 c elena--------
55
56 INTEGER IFLAG
57 c--------------------------------------------------------
58 c IFLAG =1 ---- chi2 derivatives computed by using
59 c incremental ratios and posxyz.f
60 c IFLAG =2 ---- the approximation of Golden is used
61 c (see chisq.f)
62 c
63 c NB: the two metods gives equivalent results BUT
64 c method 2 is faster!!
65 c--------------------------------------------------------
66 DATA IFLAG/2/
67
68 c LOGICAL TRKDEBUG,TRKVERBOSE
69 c COMMON/TRKD/TRKDEBUG,TRKVERBOSE
70 LOGICAL TRKDEBUG,TRKVERBOSE
71 COMMON/TRKD/TRKDEBUG,TRKVERBOSE
72
73 IF(IPRINT.EQ.1) THEN
74 TRKVERBOSE = .TRUE.
75 TRKDEBUG = .FALSE.
76 ELSEIF(IPRINT.EQ.2)THEN
77 TRKVERBOSE = .TRUE.
78 TRKDEBUG = .TRUE.
79 ELSE
80 TRKVERBOSE = .FALSE.
81 TRKDEBUG = .FALSE.
82 ENDIF
83
84 * ----------------------------------------------------------
85 * evaluate average spatial resolution
86 * ----------------------------------------------------------
87 AVRESX = RESXAV
88 AVRESY = RESYAV
89 DO IP=1,6
90 IF( XGOOD(IP).EQ.1 )THEN
91 NX=NX+1
92 AVRESX=AVRESX+RESX(IP)
93 ENDIF
94 IF(NX.NE.0)AVRESX=AVRESX/NX
95 IF( YGOOD(IP).EQ.1 )THEN
96 NY=NY+1
97 AVRESY=AVRESY+RESY(IP)
98 ENDIF
99 IF(NX.NE.0)AVRESY=AVRESY/NY
100 ENDDO
101
102 * ----------------------------------------------------------
103 * define ALTOL(5) ---> tolerances on state vector
104 *
105 * ----------------------------------------------------------
106 * changed in order to evaluate energy-dependent
107 * tolerances on all 5 parameters
108 FACT=100. !scale factor to define tolerance on alfa
109 c deflection error (see PDG)
110 DELETA1 = 0.01/0.3/0.4/0.4451**2*SQRT(720./(6.+4.))
111 DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36)
112 c$$$ ALTOL(1) = AVRESX/FACT !al(1) = x
113 c$$$ ALTOL(2) = AVRESY/FACT !al(2) = y
114 c$$$ ALTOL(3) = DSQRT(AVRESX**2 !al(3)=sin(theta)
115 c$$$ $ +AVRESY**2)/44.51/FACT
116 c$$$ ALTOL(4) = ALTOL(3) !al(4)=phi
117 c deflection error (see PDG)
118 c$$$ DELETA1 = 0.01*AVRESX/0.3/0.4/0.4451**2*SQRT(720./(6.+4.))
119 c$$$ DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36)
120 * ----------------------------------------------------------
121 *
122 ISTEP=0 !num. steps to minimize chi^2
123 JFAIL=0 !error flag
124 CHI2=0
125
126 if(TRKDEBUG) print*,'guess: ',al
127 if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5)
128
129 *
130 * -----------------------
131 * START MINIMIZATION LOOP
132 * -----------------------
133 10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !!
134
135 CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives
136 IF(JFAIL.NE.0) THEN
137 IFAIL=1
138 CHI2=-9999.
139 if(TRKVERBOSE)
140 $ PRINT *,'*** ERROR in mini *** wrong CHISQ'
141 RETURN
142 ENDIF
143
144 COST=1e-5
145 DO I=1,5
146 DO J=1,5
147 CHI2DD(I,J)=CHI2DD(I,J)*COST
148 ENDDO
149 CHI2D(I)=CHI2D(I)*COST
150 ENDDO
151
152 IF(PFIXED.EQ.0.) THEN
153
154 *------------------------------------------------------------*
155 * track fitting with FREE deflection
156 *------------------------------------------------------------*
157 CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant
158 IF(IFA.NE.0) THEN !not positive-defined
159 if(TRKVERBOSE)then
160 PRINT *,
161 $ '*** ERROR in mini ***'//
162 $ 'on matrix inversion (not pos-def)'
163 $ ,DET
164 endif
165 IF(CHI2.EQ.0) CHI2=-9999.
166 IF(CHI2.GT.0) CHI2=-CHI2
167 IFAIL=1
168 RETURN
169 ENDIF
170 CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion
171 * *******************************************
172 * find new value of AL-pha
173 * *******************************************
174 DO I=1,5
175 DAL(I)=0.
176 DO J=1,5
177 DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J)
178 COV(I,J)=2.*COST*CHI2DD(I,J)
179 ENDDO
180 ENDDO
181 DO I=1,5
182 AL(I)=AL(I)+DAL(I)
183 ENDDO
184 *------------------------------------------------------------*
185 * track fitting with FIXED deflection
186 *------------------------------------------------------------*
187 ELSE
188 AL(5)=1./PFIXED
189 DO I=1,4
190 CHI2D_R(I)=CHI2D(I)
191 DO J=1,4
192 CHI2DD_R(I,J)=CHI2DD(I,J)
193 ENDDO
194 ENDDO
195 CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA)
196 IF(IFA.NE.0) THEN
197 if(TRKVERBOSE)then
198 PRINT *,
199 $ '*** ERROR in mini ***'//
200 $ 'on matrix inversion (not pos-def)'
201 $ ,DET
202 endif
203 IF(CHI2.EQ.0) CHI2=-9999.
204 IF(CHI2.GT.0) CHI2=-CHI2
205 IFAIL=1
206 RETURN
207 ENDIF
208 CALL DSFINV(4,CHI2DD_R,4)
209 * *******************************************
210 * find new value of AL-pha
211 * *******************************************
212 DO I=1,4
213 DAL(I)=0.
214 DO J=1,4
215 DAL(I)=DAL(I)-CHI2DD_R(I,J)*CHI2D_R(J)
216 COV(I,J)=2.*COST*CHI2DD_R(I,J)
217 ENDDO
218 ENDDO
219 DAL(5)=0.
220 DO I=1,4
221 AL(I)=AL(I)+DAL(I)
222 ENDDO
223 ENDIF
224
225 if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5)
226
227 *------------------------------------------------------------*
228 * ---------------------------------------------------- *
229 *------------------------------------------------------------*
230 * check parameter bounds:
231 *------------------------------------------------------------*
232 DO I=1,5
233 IF(AL(I).GT.ALMAX(I).OR.AL(I).LT.ALMIN(I))THEN
234 if(TRKVERBOSE)then
235 PRINT*,' *** WARNING in mini *** '
236 PRINT*,'MINI_2 ==> AL(',I,') out of range'
237 PRINT*,' value: ',AL(I),
238 $ ' limits: ',ALMIN(I),ALMAX(I)
239 print*,'istep ',istep
240 endif
241 IF(CHI2.EQ.0) CHI2=-9999.
242 IF(CHI2.GT.0) CHI2=-CHI2
243 IFAIL=1
244 RETURN
245 ENDIF
246 ENDDO
247 *------------------------------------------------------------*
248 * check number of steps:
249 *------------------------------------------------------------*
250 IF(ISTEP.ge.ISTEPMAX) then
251 c$$$ IFAIL=1
252 c$$$ if(TRKVERBOSE)
253 c$$$ $ PRINT *,'*** WARNING in mini *** ISTEP.GT.ISTEPMAX=',
254 c$$$ $ ISTEPMAX
255 goto 11
256 endif
257 *------------------------------------------------------------*
258 * ---------------------------------------------
259 * evaluate deflection tolerance on the basis of
260 * estimated deflection
261 * ---------------------------------------------
262 *------------------------------------------------------------*
263 c$$$ ALTOL(5) = DSQRT(DELETA1**2+DELETA2**2*AL(5)**2)/FACT
264 ALTOL(5) = DSQRT((DELETA1*AVRESX)**2+DELETA2**2*AL(5)**2)/FACT
265 ALTOL(1) = ALTOL(5)/DELETA1
266 ALTOL(2) = ALTOL(1)
267 ALTOL(3) = DSQRT(ALTOL(1)**2+ALTOL(2)**2)/44.51
268 ALTOL(4) = ALTOL(3)
269
270 *---- check tolerances:
271 c$$$ DO I=1,5
272 c$$$ if(TRKVERBOSE)print*,i,' -- ',DAL(I),ALTOL(I) !>>>> new step!
273 c$$$ ENDDO
274 c$$$ print*,'chi2 -- ',DCHI2
275
276 IF(ISTEP.LT.3) GOTO 10 ! ***PP***
277 DO I=1,5
278 IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step!
279 ENDDO
280
281 * new estimate of chi^2:
282 JFAIL=0 !error flag
283 CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives
284 IF(JFAIL.NE.0) THEN
285 IFAIL=1
286 if(TRKVERBOSE)THEN
287 CHI2=-9999.
288 if(TRKVERBOSE)
289 $ PRINT *,'*** ERROR in mini *** wrong CHISQ'
290 ENDIF
291 RETURN
292 ENDIF
293 COST=1e-7
294 DO I=1,5
295 DO J=1,5
296 CHI2DD(I,J)=CHI2DD(I,J)*COST
297 ENDDO
298 CHI2D(I)=CHI2D(I)*COST
299 ENDDO
300 IF(PFIXED.EQ.0.) THEN
301 CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant
302 IF(IFA.NE.0) THEN !not positive-defined
303 if(TRKVERBOSE)then
304 PRINT *,
305 $ '*** ERROR in mini ***'//
306 $ 'on matrix inversion (not pos-def)'
307 $ ,DET
308 endif
309 IF(CHI2.EQ.0) CHI2=-9999.
310 IF(CHI2.GT.0) CHI2=-CHI2
311 IFAIL=1
312 RETURN
313 ENDIF
314 CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion
315 DO I=1,5
316 DAL(I)=0.
317 DO J=1,5
318 COV(I,J)=2.*COST*CHI2DD(I,J)
319 ENDDO
320 ENDDO
321 ELSE
322 DO I=1,4
323 CHI2D_R(I)=CHI2D(I)
324 DO J=1,4
325 CHI2DD_R(I,J)=CHI2DD(I,J)
326 ENDDO
327 ENDDO
328 CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA)
329 IF(IFA.NE.0) THEN
330 if(TRKVERBOSE)then
331 PRINT *,
332 $ '*** ERROR in mini ***'//
333 $ 'on matrix inversion (not pos-def)'
334 $ ,DET
335 endif
336 IF(CHI2.EQ.0) CHI2=-9999.
337 IF(CHI2.GT.0) CHI2=-CHI2
338 IFAIL=1
339 RETURN
340 ENDIF
341 CALL DSFINV(4,CHI2DD_R,4)
342 DO I=1,4
343 DAL(I)=0.
344 DO J=1,4
345 COV(I,J)=2.*COST*CHI2DD_R(I,J)
346 ENDDO
347 ENDDO
348 ENDIF
349 *****************************
350
351 * ------------------------------------
352 * Number of Degree Of Freedom
353 ndof=0
354 do ip=1,nplanes
355 ndof=ndof
356 $ +int(xgood(ip))
357 $ +int(ygood(ip))
358 enddo
359 if(pfixed.eq.0.) ndof=ndof-5 ! ***PP***
360 if(pfixed.ne.0.) ndof=ndof-4 ! ***PP***
361 if(ndof.le.0.) then
362 ndof = 1
363 if(TRKVERBOSE)
364 $ print*,'*** WARNING *** in mini n.dof = 0 (set to 1)'
365 endif
366
367 if(TRKDEBUG) print*,'mini2: -ok- ',istep,chi2,1./AL(5)
368
369 * ------------------------------------
370 * Reduced chi^2
371 CHI2 = CHI2/dble(ndof)
372
373 c print*,'mini2: chi2 ',chi2
374
375 11 CONTINUE
376
377 NSTEP=ISTEP ! ***PP***
378
379 RETURN
380 END
381
382 ******************************************************************************
383 *
384 * routine to compute chi^2 and its derivatives
385 *
386 *
387 * (modified in respect to the previous one in order to include
388 * single clusters. In this case the residual is evaluated by
389 * calculating the distance between the track intersection and the
390 * segment AB associated to the single cluster)
391 *
392 ******************************************************************************
393
394 SUBROUTINE CHISQ(IFLAG,IFAIL)
395
396 IMPLICIT DOUBLE PRECISION (A-H,O-Z)
397
398 include 'commontracker.f' !tracker general common
399 include 'common_mini_2.f' !common for the tracking procedure
400
401 DIMENSION XV2(nplanes),YV2(nplanes),XV1(nplanes),YV1(nplanes)
402 $ ,XV0(nplanes),YV0(nplanes)
403 DIMENSION AL_P(5)
404
405 c LOGICAL TRKVERBOSE
406 c COMMON/TRKD/TRKVERBOSE
407 LOGICAL TRKDEBUG,TRKVERBOSE
408 COMMON/TRKD/TRKDEBUG,TRKVERBOSE
409 *
410 * chi^2 computation
411 *
412 DO I=1,5
413 AL_P(I)=AL(I)
414 ENDDO
415 JFAIL=0 !error flag
416 CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes
417 IF(JFAIL.NE.0) THEN
418 IF(TRKVERBOSE)
419 $ PRINT *,'CHISQ ==> error from trk routine POSXYZ !!'
420 IFAIL=1
421 RETURN
422 ENDIF
423 DO I=1,nplanes
424 XV0(I)=XV(I)
425 YV0(I)=YV(I)
426 ENDDO
427 * ------------------------------------------------
428 c$$$ CHI2=0.
429 c$$$ DO I=1,nplanes
430 c$$$ CHI2=CHI2
431 c$$$ + +(XV(I)-XM(I))**2/RESX(i)**2 *XGOOD(I)*YGOOD(I)
432 c$$$ + +(YV(I)-YM(I))**2/RESY(i)**2 *YGOOD(I)*XGOOD(I)
433 c$$$ ENDDO
434 * ---------------------------------------------------------
435 * For planes with only a X or Y-cl included, instead of
436 * a X-Y couple, the residual for chi^2 calculation is
437 * evaluated by finding the point x-y, along the segment AB,
438 * closest to the track.
439 * The X or Y coordinate, respectivelly for X and Y-cl, is
440 * then assigned to XM or YM, which is then considered the
441 * measured position of the cluster.
442 * ---------------------------------------------------------
443 CHI2=0.
444 DO I=1,nplanes
445 IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl
446 BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I))
447 ALFA = XM_A(I) - BETA * YM_A(I)
448 YM(I) = ( YV(I) + BETA*XV(I) - BETA*ALFA )/(1+BETA**2)
449 if(YM(I).lt.dmin1(YM_A(I),YM_B(I)))
450 $ YM(I)=dmin1(YM_A(I),YM_B(I))
451 if(YM(I).gt.dmax1(YM_A(I),YM_B(I)))
452 $ YM(I)=dmax1(YM_A(I),YM_B(I))
453 XM(I) = ALFA + BETA * YM(I) !<<<< measured coordinates
454 ELSEIF(XGOOD(I).EQ.0.AND.YGOOD(I).EQ.1)THEN !Y-cl
455 BETA = (YM_B(I)-YM_A(I))/(XM_B(I)-XM_A(I))
456 ALFA = YM_A(I) - BETA * XM_A(I)
457 XM(I) = ( XV(I) + BETA*YV(I) - BETA*ALFA )/(1+BETA**2)
458 if(XM(I).lt.dmin1(XM_A(I),XM_B(I)))
459 $ XM(I)=dmin1(XM_A(I),XM_B(I))
460 if(XM(I).gt.dmax1(XM_A(I),XM_B(I)))
461 $ XM(I)=dmax1(XM_A(I),XM_B(I))
462 YM(I) = ALFA + BETA * XM(I) !<<<< measured coordinates
463 ENDIF
464 CHI2=CHI2
465 + +(XV(I)-XM(I))**2/RESX(i)**2 *( XGOOD(I)*YGOOD(I) )
466 + +(YV(I)-YM(I))**2/RESY(i)**2 *( YGOOD(I)*XGOOD(I) )
467 + +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESX(i)**2
468 + *( XGOOD(I)*(1-YGOOD(I)) )
469 + +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2
470 + *( (1-XGOOD(I))*YGOOD(I) )
471 c$$$ print*,(XV(I)-XM(I))**2/RESX(i)**2 *( XGOOD(I)*YGOOD(I) )
472 c$$$ print*,(YV(I)-YM(I))**2/RESY(i)**2 *( YGOOD(I)*XGOOD(I) )
473 c$$$ print*,((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESX(i)**2
474 c$$$ + *( XGOOD(I)*(1-YGOOD(I)) )
475 c$$$ print*,((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2
476 c$$$ + *( (1-XGOOD(I))*YGOOD(I) )
477 c$$$ print*,XV(I),XM(I),XGOOD(I)
478 c$$$ print*,YV(I),YM(I),YGOOD(I)
479 ENDDO
480 c$$$ print*,'CHISQ ',chi2
481 * ------------------------------------------------
482 *
483 * calculation of derivatives (dX/dAL_fa and dY/dAL_fa)
484 *
485 * //////////////////////////////////////////////////
486 * METHOD 1 -- incremental ratios
487 * //////////////////////////////////////////////////
488
489 IF(IFLAG.EQ.1) THEN
490
491 DO J=1,5
492 DO JJ=1,5
493 AL_P(JJ)=AL(JJ)
494 ENDDO
495 AL_P(J)=AL_P(J)+STEPAL(J)/2.
496 JFAIL=0
497 CALL POSXYZ(AL_P,JFAIL)
498 IF(JFAIL.NE.0) THEN
499 IF(TRKVERBOSE)
500 *23456789012345678901234567890123456789012345678901234567890123456789012
501 $ PRINT *,'CHISQ ==> error from trk routine POSXYZ'
502 IFAIL=1
503 RETURN
504 ENDIF
505 DO I=1,nplanes
506 XV2(I)=XV(I)
507 YV2(I)=YV(I)
508 ENDDO
509 AL_P(J)=AL_P(J)-STEPAL(J)
510 JFAIL=0
511 CALL POSXYZ(AL_P,JFAIL)
512 IF(JFAIL.NE.0) THEN
513 IF(TRKVERBOSE)
514 $ PRINT *,'CHISQ ==> error from trk routine POSXYZ'
515 IFAIL=1
516 RETURN
517 ENDIF
518 DO I=1,nplanes
519 XV1(I)=XV(I)
520 YV1(I)=YV(I)
521 ENDDO
522 DO I=1,nplanes
523 DXDAL(I,J)=(XV2(I)-XV1(I))/STEPAL(J)
524 DYDAL(I,J)=(YV2(I)-YV1(I))/STEPAL(J)
525 ENDDO
526 ENDDO
527
528 ENDIF
529
530 * //////////////////////////////////////////////////
531 * METHOD 2 -- Bob Golden
532 * //////////////////////////////////////////////////
533
534 IF(IFLAG.EQ.2) THEN
535
536 DO I=1,nplanes
537 DXDAL(I,1)=1.
538 DYDAL(I,1)=0.
539
540 DXDAL(I,2)=0.
541 DYDAL(I,2)=1.
542
543 COSTHE=DSQRT(1.-AL(3)**2)
544 IF(COSTHE.EQ.0.) THEN
545 IF(TRKVERBOSE)PRINT *,'=== WARNING ===> COSTHE=0'
546 IFAIL=1
547 RETURN
548 ENDIF
549
550 DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3
551 DYDAL(I,3)=(ZINI-ZM(I))*DSIN(AL(4))/COSTHE**3
552
553 DXDAL(I,4)=-AL(3)*(ZINI-ZM(I))*DSIN(AL(4))/COSTHE
554 DYDAL(I,4)=AL(3)*(ZINI-ZM(I))*DCOS(AL(4))/COSTHE
555
556 IF(AL(5).NE.0.) THEN
557 DXDAL(I,5)=
558 + (XV(I)-(AL(1)+AL(3)/COSTHE*(ZINI-ZM(I))
559 + *DCOS(AL(4))))/AL(5)
560 DYDAL(I,5)=
561 + (YV(I)-(AL(2)+AL(3)/COSTHE*(ZINI-ZM(I))
562 + *DSIN(AL(4))))/AL(5)
563 ELSE
564 DXDAL(I,5)=100.*( 0.25 *0.3*0.4*(0.01*(ZINI-ZM(I)))**2 )
565 DYDAL(I,5)=0.
566 ENDIF
567
568 ENDDO
569 ENDIF
570 *
571 * x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x
572 * >>> CHI2D evaluation
573 *
574 DO J=1,5
575 CHI2D(J)=0.
576 DO I=1,nplanes
577 CHI2D(J)=CHI2D(J)
578 + +2.*(XV0(I)-XM(I))/RESX(i)**2*DXDAL(I,J) *XGOOD(I)
579 + +2.*(YV0(I)-YM(I))/RESY(i)**2*DYDAL(I,J) *YGOOD(I)
580 ENDDO
581 ENDDO
582 *
583 * >>> CHI2DD evaluation
584 *
585 DO I=1,5
586 DO J=1,5
587 CHI2DD(I,J)=0.
588 DO K=1,nplanes
589 CHI2DD(I,J)=CHI2DD(I,J)
590 + +2.*DXDAL(K,I)*DXDAL(K,J)/RESX(k)**2 *XGOOD(K)
591 + +2.*DYDAL(K,I)*DYDAL(K,J)/RESY(k)**2 *YGOOD(K)
592 ENDDO
593 ENDDO
594 ENDDO
595 * x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x
596
597 RETURN
598 END
599
600
601 *****************************************************************
602 *
603 * Routine to compute the track intersection points
604 * on the tracking-system planes, given the track parameters
605 *
606 * The routine is based on GRKUTA, which computes the
607 * trajectory of a charged particle in a magnetic field
608 * by solving the equatins of motion with Runge-Kuta method.
609 *
610 * Variables that have to be assigned when the subroutine
611 * is called are:
612 *
613 * ZM(1,NPLANES) ----> z coordinates of the planes
614 * AL_P(1,5) ----> track-parameter vector
615 *
616 * -----------------------------------------------------------
617 * NB !!!
618 * The routine works properly only if the
619 * planes are numbered in descending order starting from the
620 * reference plane (ZINI)
621 * -----------------------------------------------------------
622 *
623 *****************************************************************
624
625 SUBROUTINE POSXYZ(AL_P,IFAIL)
626
627 IMPLICIT DOUBLE PRECISION (A-H,O-Z)
628
629 include 'commontracker.f' !tracker general common
630 include 'common_mini_2.f' !common for the tracking procedure
631
632 c LOGICAL TRKVERBOSE
633 c COMMON/TRKD/TRKVERBOSE
634 LOGICAL TRKDEBUG,TRKVERBOSE
635 COMMON/TRKD/TRKDEBUG,TRKVERBOSE
636 c
637 DIMENSION AL_P(5)
638 *
639 DO I=1,nplanes
640 ZV(I)=ZM(I) !
641 ENDDO
642 *
643 * set parameters for GRKUTA
644 *
645 IF(AL_P(5).NE.0) CHARGE=AL_P(5)/DABS(AL_P(5))
646 IF(AL_P(5).EQ.0) CHARGE=1.
647 VOUT(1)=AL_P(1)
648 VOUT(2)=AL_P(2)
649 VOUT(3)=ZINI ! DBLE(Z0)-DBLE(ZSPEC)
650 VOUT(4)=AL_P(3)*DCOS(AL_P(4))
651 VOUT(5)=AL_P(3)*DSIN(AL_P(4))
652 VOUT(6)=-1.*DSQRT(1.-AL_P(3)**2)
653 IF(AL_P(5).NE.0.) VOUT(7)=DABS(1./AL_P(5))
654 IF(AL_P(5).EQ.0.) VOUT(7)=1.E8
655
656 c$$$ print*,'POSXY (prima) ',vout
657
658 DO I=1,nplanes
659 step=vout(3)-zv(i)
660 10 DO J=1,7
661 VECT(J)=VOUT(J)
662 VECTINI(J)=VOUT(J)
663 ENDDO
664 11 continue
665 CALL GRKUTA(CHARGE,STEP,VECT,VOUT)
666 IF(VOUT(3).GT.VECT(3)) THEN
667 IFAIL=1
668 if(TRKVERBOSE)
669 $ PRINT *,'posxy (grkuta): WARNING ===> backward track!!'
670 c$$$ if(.TRUE.)print*,'charge',charge
671 c$$$ if(.TRUE.)print*,'vect',vect
672 c$$$ if(.TRUE.)print*,'vout',vout
673 c$$$ if(.TRUE.)print*,'step',step
674 if(TRKVERBOSE)print*,'charge',charge
675 if(TRKVERBOSE)print*,'vect',vect
676 if(TRKVERBOSE)print*,'vout',vout
677 if(TRKVERBOSE)print*,'step',step
678 RETURN
679 ENDIF
680 Z=VOUT(3)
681 IF(Z.LE.ZM(I)+TOLL.AND.Z.GE.ZM(I)-TOLL) GOTO 100
682 IF(Z.GT.ZM(I)+TOLL) GOTO 10
683 IF(Z.LE.ZM(I)-TOLL) THEN
684 STEP=STEP*(ZM(I)-VECT(3))/(Z-VECT(3))
685 DO J=1,7
686 VECT(J)=VECTINI(J)
687 ENDDO
688 GOTO 11
689 ENDIF
690
691
692 * -----------------------------------------------
693 * evaluate track coordinates
694 100 XV(I)=VOUT(1)
695 YV(I)=VOUT(2)
696 ZV(I)=VOUT(3)
697 AXV(I)=DATAN(VOUT(4)/VOUT(6))*180./ACOS(-1.)
698 AYV(I)=DATAN(VOUT(5)/VOUT(6))*180./ACOS(-1.)
699 * -----------------------------------------------
700
701 ENDDO
702
703 c$$$ print*,'POSXY (dopo) ',vout
704
705
706 RETURN
707 END
708
709
710
711
712
713 * **********************************************************
714 * Some initialization routines
715 * **********************************************************
716
717 * ----------------------------------------------------------
718 * Routine to initialize COMMON/TRACK/
719 *
720 subroutine track_init
721
722 IMPLICIT DOUBLE PRECISION (A-H,O-Z)
723
724 include 'commontracker.f' !tracker general common
725 include 'common_mini_2.f' !common for the tracking procedure
726 include 'common_mech.f'
727
728 do i=1,5
729 AL(i) = 0.
730 enddo
731
732 do ip=1,NPLANES
733 ZM(IP) = fitz(nplanes-ip+1) !init to mech. position
734 XM(IP) = -100. !0.
735 YM(IP) = -100. !0.
736 XM_A(IP) = -100. !0.
737 YM_A(IP) = -100. !0.
738 c ZM_A(IP) = 0
739 XM_B(IP) = -100. !0.
740 YM_B(IP) = -100. !0.
741 c ZM_B(IP) = 0
742 RESX(IP) = 1000. !3.d-4
743 RESY(IP) = 1000. !12.d-4
744 XGOOD(IP) = 0
745 YGOOD(IP) = 0
746 enddo
747
748 return
749 end
750
751
752 ***************************************************
753 * *
754 * *
755 * *
756 * *
757 * *
758 * *
759 **************************************************
760
761 subroutine guess()
762
763 c IMPLICIT DOUBLE PRECISION (A-H,O-Z)
764
765 include 'commontracker.f' !tracker general common
766 include 'common_mini_2.f' !common for the tracking procedure
767
768 REAL*4 XP(NPLANES),ZP(NPLANES),AP(NPLANES),RP(NPLANES)
769 REAL*4 CHI,XC,ZC,RADIUS
770 * ----------------------------------------
771 * Y view
772 * ----------------------------------------
773 * ----------------------------------------
774 * initial guess with a straigth line
775 * ----------------------------------------
776 SZZ=0.
777 SZY=0.
778 SSY=0.
779 SZ=0.
780 S1=0.
781 DO I=1,nplanes
782 IF(YGOOD(I).EQ.1)THEN
783 YY = YM(I)
784 IF(XGOOD(I).EQ.0)THEN
785 YY = (YM_A(I) + YM_B(I))/2
786 ENDIF
787 SZZ=SZZ+ZM(I)*ZM(I)
788 SZY=SZY+ZM(I)*YY
789 SSY=SSY+YY
790 SZ=SZ+ZM(I)
791 S1=S1+1.
792 ENDIF
793 ENDDO
794 DET=SZZ*S1-SZ*SZ
795 AY=(SZY*S1-SZ*SSY)/DET
796 BY=(SZZ*SSY-SZY*SZ)/DET
797 Y0 = AY*ZINI+BY
798 * ----------------------------------------
799 * X view
800 * ----------------------------------------
801 * ----------------------------------------
802 * 1) initial guess with a circle
803 * ----------------------------------------
804 NP=0
805 DO I=1,nplanes
806 IF(XGOOD(I).EQ.1)THEN
807 XX = XM(I)
808 IF(YGOOD(I).EQ.0)THEN
809 XX = (XM_A(I) + XM_B(I))/2
810 ENDIF
811 NP=NP+1
812 XP(NP)=XX
813 ZP(NP)=ZM(I)
814 ENDIF
815 ENDDO
816 IFLAG=0 !no debug mode
817 CALL TRICIRCLE(NP,XP,ZP,AP,RP,CHI,XC,ZC,RADIUS,IFLAG)
818 c print*,' circle: ',XC,ZC,RADIUS,' --- ',CHI,IFLAG
819 IF(IFLAG.NE.0)GOTO 10 !straigth fit
820 if(CHI.gt.100)GOTO 10 !straigth fit
821 ARG = RADIUS**2-(ZINI-ZC)**2
822 IF(ARG.LT.0)GOTO 10 !straigth fit
823 DC = SQRT(ARG)
824 IF(XC.GT.0)DC=-DC
825 X0=XC+DC
826 AX = -(ZINI-ZC)/DC
827 DEF=100./(RADIUS*0.3*0.43)
828 IF(XC.GT.0)DEF=-DEF
829
830 IF(ABS(X0).GT.30)THEN
831 c$$$ PRINT*,'STRANGE GUESS: XC,ZC,R ',XC,ZC,RADIUS
832 c$$$ $ ,' - CHI ',CHI,' - X0,AX,DEF ',X0,AX,DEF
833 GOTO 10 !straigth fit
834 ENDIF
835 GOTO 20 !guess is ok
836
837 * ----------------------------------------
838 * 2) initial guess with a straigth line
839 * - if circle does not intersect reference plane
840 * - if bad chi**2
841 * ----------------------------------------
842 10 CONTINUE
843 SZZ=0.
844 SZX=0.
845 SSX=0.
846 SZ=0.
847 S1=0.
848 DO I=1,nplanes
849 IF(XGOOD(I).EQ.1)THEN
850 XX = XM(I)
851 IF(YGOOD(I).EQ.0)THEN
852 XX = (XM_A(I) + XM_B(I))/2
853 ENDIF
854 SZZ=SZZ+ZM(I)*ZM(I)
855 SZX=SZX+ZM(I)*XX
856 SSX=SSX+XX
857 SZ=SZ+ZM(I)
858 S1=S1+1.
859 ENDIF
860 ENDDO
861 DET=SZZ*S1-SZ*SZ
862 AX=(SZX*S1-SZ*SSX)/DET
863 BX=(SZZ*SSX-SZX*SZ)/DET
864 DEF = 0
865 X0 = AX*ZINI+BX
866
867 20 CONTINUE
868 * ----------------------------------------
869 * guess
870 * ----------------------------------------
871
872 AL(1) = X0
873 AL(2) = Y0
874 tath = sqrt(AY**2+AX**2)
875 AL(3) = tath/sqrt(1+tath**2)
876 c$$$ IF(AX.NE.0)THEN
877 c$$$ AL(4)= atan(AY/AX)
878 c$$$ ELSE
879 c$$$ AL(4) = acos(-1.)/2
880 c$$$ IF(AY.LT.0)AL(4) = AL(4)+acos(-1.)
881 c$$$ ENDIF
882 c$$$ IF(AX.LT.0)AL(4)= acos(-1.)+ AL(4)
883 c$$$ AL(4) = -acos(-1.) + AL(4) !from incidence direction to tracking ref.sys.
884
885 c$$$ AL(4) = 0.
886 c$$$ IF(AX.NE.0.AND.AY.NE.0)THEN
887 c$$$ AL(4)= atan(AY/AX)
888 c$$$ ELSEIF(AY.EQ.0)THEN
889 c$$$ AL(4) = 0.
890 c$$$ IF(AX.LT.0)AL(4) = AL(4)+acos(-1.)
891 c$$$ ELSEIF(AX.EQ.0)THEN
892 c$$$ AL(4) = acos(-1.)/2
893 c$$$ IF(AY.LT.0)AL(4) = AL(4)+acos(-1.)
894 c$$$ ENDIF
895 c$$$ IF(AX.LT.0)AL(4)= acos(-1.)+ AL(4)
896 c$$$ AL(4) = -acos(-1.) + AL(4) !from incidence direction to tracking ref.sys.
897
898 c$$$ AL(4)=0.
899 c$$$ IF( AX.NE.0.OR.AY.NE.0. ) THEN
900 c$$$ AL(4) = ASIN(AY/SQRT(AX**2+AY**2))
901 c$$$ IF(AX.LT.0.) AL(4) = ACOS(-1.0)-AL(4)
902 c$$$ ENDIF
903
904 AL(4)=0.
905 IF( AX.NE.0.OR.AY.NE.0. ) THEN
906 AL(4) = ASIN(AY/SQRT(AX**2+AY**2))
907 IF(AX.LT.0.AND.AY.GE.0) AL(4) = ACOS(-1.0)-AL(4)
908 IF(AX.LT.0.AND.AY.LT.0) AL(4) = -ACOS(-1.0)-AL(4)
909 ENDIF
910 IF(AY.GT.0.) AL(4) = AL(4)-ACOS(-1.0)
911 IF(AY.LE.0.) AL(4) = AL(4)+ACOS(-1.0)
912
913 AL(5) = DEF
914
915 c print*,' guess: ',(al(i),i=1,5)
916
917 end

  ViewVC Help
Powered by ViewVC 1.1.23