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