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 |
c$$$ 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,STUDENT,FIRSTSTEPS,FIRSTSTUDENT |
71 |
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
72 |
|
73 |
DIMENSION AL0(5) |
74 |
LOGICAL SUCCESS_NEW,SUCCESS_OLD |
75 |
|
76 |
c$$$ PRINT*,'==========' ! TEST |
77 |
c$$$ PRINT*,'START MINI' ! TEST |
78 |
c$$$ PRINT*,'==========' ! TEST |
79 |
|
80 |
* |
81 |
* define kind of minimization (0x=chi2+gaussian or 1x=likelihood+student) |
82 |
* |
83 |
STUDENT = .false. |
84 |
FIRSTSTEPS = .true. |
85 |
FIRSTSTUDENT = .true. |
86 |
IF(MOD(INT(TRACKMODE/10),10).EQ.1) STUDENT = .true. |
87 |
|
88 |
IF(IPRINT.EQ.1) THEN |
89 |
TRKVERBOSE = .TRUE. |
90 |
TRKDEBUG = .FALSE. |
91 |
ELSEIF(IPRINT.EQ.2)THEN |
92 |
TRKVERBOSE = .TRUE. |
93 |
TRKDEBUG = .TRUE. |
94 |
ELSE |
95 |
TRKVERBOSE = .FALSE. |
96 |
TRKDEBUG = .FALSE. |
97 |
ENDIF |
98 |
|
99 |
* ---------------------------------------------------------- |
100 |
* evaluate average spatial resolution |
101 |
* ---------------------------------------------------------- |
102 |
AVRESX = RESXAV |
103 |
AVRESY = RESYAV |
104 |
NX = 0.0 |
105 |
NY = 0.0 |
106 |
DO IP=1,6 |
107 |
IF( XGOOD(IP).EQ.1 )THEN |
108 |
NX=NX+1.0 |
109 |
AVRESX=AVRESX+RESX(IP) |
110 |
ENDIF |
111 |
IF( YGOOD(IP).EQ.1 )THEN |
112 |
NY=NY+1.0 |
113 |
AVRESY=AVRESY+RESY(IP) |
114 |
ENDIF |
115 |
ENDDO |
116 |
IF(NX.NE.0.0)AVRESX=AVRESX/NX |
117 |
IF(NY.NE.0.0)AVRESY=AVRESY/NY |
118 |
|
119 |
* ---------------------------------------------------------- |
120 |
* define ALTOL(5) ---> tolerances on state vector |
121 |
* |
122 |
* ---------------------------------------------------------- |
123 |
* changed in order to evaluate energy-dependent |
124 |
* tolerances on all 5 parameters |
125 |
cPP FACT=1.0e10 !scale factor to define tolerance on alfa |
126 |
c deflection error (see PDG) |
127 |
DELETA1 = 0.01/0.3/0.4/0.4451**2*SQRT(720./(6.+4.)) |
128 |
DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36) |
129 |
c$$$ ALTOL(1) = AVRESX/FACT !al(1) = x |
130 |
c$$$ ALTOL(2) = AVRESY/FACT !al(2) = y |
131 |
c$$$ ALTOL(3) = DSQRT(AVRESX**2 !al(3)=sin(theta) |
132 |
c$$$ $ +AVRESY**2)/44.51/FACT |
133 |
c$$$ ALTOL(4) = ALTOL(3) !al(4)=phi |
134 |
c deflection error (see PDG) |
135 |
c$$$ DELETA1 = 0.01*AVRESX/0.3/0.4/0.4451**2*SQRT(720./(6.+4.)) |
136 |
c$$$ DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36) |
137 |
* ---------------------------------------------------------- |
138 |
* |
139 |
ISTEP=0 !num. steps to minimize chi^2 |
140 |
JFAIL=0 !error flag |
141 |
CHI2=0 |
142 |
|
143 |
if(TRKDEBUG) print*,'guess: ',al |
144 |
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,AL(5) |
145 |
|
146 |
* |
147 |
* ----------------------- |
148 |
* START MINIMIZATION LOOP |
149 |
* ----------------------- |
150 |
10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !! |
151 |
|
152 |
* ------------------------------- |
153 |
* **** Chi2+gaussian minimization |
154 |
* ------------------------------- |
155 |
|
156 |
IF((.NOT.STUDENT).OR.FIRSTSTEPS) THEN |
157 |
|
158 |
IF(ISTEP.GE.3) FIRSTSTEPS = .false. |
159 |
|
160 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
161 |
IF(JFAIL.NE.0) THEN |
162 |
IFAIL=1 |
163 |
CHI2=-9999. |
164 |
if(TRKVERBOSE) |
165 |
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
166 |
RETURN |
167 |
ENDIF |
168 |
|
169 |
c COST=1e-5 |
170 |
COST=1. |
171 |
DO I=1,5 |
172 |
IF(CHI2DD(I,I).NE.0.)COST=COST/DABS(CHI2DD(I,I))**0.2 |
173 |
ENDDO |
174 |
DO I=1,5 |
175 |
DO J=1,5 |
176 |
CHI2DD(I,J)=CHI2DD(I,J)*COST |
177 |
ENDDO |
178 |
c$$$ CHI2D(I)=CHI2D(I)*COST |
179 |
ENDDO |
180 |
|
181 |
IF(PFIXED.EQ.0.) THEN |
182 |
|
183 |
*------------------------------------------------------------* |
184 |
* track fitting with FREE deflection |
185 |
*------------------------------------------------------------* |
186 |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
187 |
IF(IFA.NE.0) THEN !not positive-defined |
188 |
if(TRKVERBOSE)then |
189 |
PRINT *, |
190 |
$ '*** ERROR in mini ***'// |
191 |
$ 'on matrix inversion (not pos-def)' |
192 |
$ ,DET |
193 |
endif |
194 |
IF(CHI2.EQ.0) CHI2=-9999. |
195 |
IF(CHI2.GT.0) CHI2=-CHI2 |
196 |
IFAIL=1 |
197 |
RETURN |
198 |
ENDIF |
199 |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
200 |
* ******************************************* |
201 |
* find new value of AL-pha |
202 |
* ******************************************* |
203 |
DO I=1,5 |
204 |
DAL(I)=0. |
205 |
DO J=1,5 |
206 |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) *COST |
207 |
COV(I,J)=2.*COST*CHI2DD(I,J) |
208 |
ENDDO |
209 |
ENDDO |
210 |
DO I=1,5 |
211 |
AL(I)=AL(I)+DAL(I) |
212 |
ENDDO |
213 |
*------------------------------------------------------------* |
214 |
* track fitting with FIXED deflection |
215 |
*------------------------------------------------------------* |
216 |
ELSE |
217 |
AL(5)=1./PFIXED |
218 |
DO I=1,4 |
219 |
CHI2D_R(I)=CHI2D(I) |
220 |
DO J=1,4 |
221 |
CHI2DD_R(I,J)=CHI2DD(I,J) |
222 |
ENDDO |
223 |
ENDDO |
224 |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
225 |
IF(IFA.NE.0) THEN |
226 |
if(TRKVERBOSE)then |
227 |
PRINT *, |
228 |
$ '*** ERROR in mini ***'// |
229 |
$ 'on matrix inversion (not pos-def)' |
230 |
$ ,DET |
231 |
endif |
232 |
IF(CHI2.EQ.0) CHI2=-9999. |
233 |
IF(CHI2.GT.0) CHI2=-CHI2 |
234 |
IFAIL=1 |
235 |
RETURN |
236 |
ENDIF |
237 |
CALL DSFINV(4,CHI2DD_R,4) |
238 |
* ******************************************* |
239 |
* find new value of AL-pha |
240 |
* ******************************************* |
241 |
DO I=1,4 |
242 |
DAL(I)=0. |
243 |
DO J=1,4 |
244 |
DAL(I)=DAL(I)-CHI2DD_R(I,J)*CHI2D_R(J) *COST |
245 |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
246 |
ENDDO |
247 |
ENDDO |
248 |
DAL(5)=0. |
249 |
DO I=1,4 |
250 |
AL(I)=AL(I)+DAL(I) |
251 |
ENDDO |
252 |
ENDIF |
253 |
|
254 |
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,AL(5) |
255 |
|
256 |
c$$$ PRINT*,'DAL ',(DAL(K),K=1,5) |
257 |
c$$$ PRINT*,'CHI2DOLD ',(CHI2DOLD(K),K=1,5) |
258 |
|
259 |
|
260 |
ENDIF |
261 |
|
262 |
* ------------------------------- |
263 |
* **** Likelihood+Student minimization |
264 |
* ------------------------------- |
265 |
|
266 |
IF(STUDENT.AND.(.NOT.FIRSTSTEPS)) THEN |
267 |
|
268 |
IF(FIRSTSTUDENT) THEN |
269 |
FIRSTSTUDENT = .false. |
270 |
ISTEP = 1 |
271 |
ENDIF |
272 |
|
273 |
CALL CHISQSTT(1,JFAIL) |
274 |
DO I=1,5 |
275 |
DAL(I)=0. |
276 |
DO J=1,5 |
277 |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) |
278 |
ENDDO |
279 |
ENDDO |
280 |
|
281 |
DO I=1,5 |
282 |
DO j=1,5 |
283 |
COV(I,J) = 2.*CHI2DD(I,J) |
284 |
ENDDO |
285 |
ENDDO |
286 |
|
287 |
CHI2TOLL = 1.E-3 |
288 |
ALPHA = 3.0 |
289 |
BETA = -0.4 |
290 |
E=1. |
291 |
EA=1. |
292 |
EB=1. |
293 |
EC=1. |
294 |
FA=1. |
295 |
FB=1. |
296 |
FC=1. |
297 |
SUCCESS_OLD = .FALSE. |
298 |
SUCCESS_NEW = .FALSE. |
299 |
|
300 |
CALL CHISQSTT(0,JFAIL) |
301 |
c$$$ PRINT*,CHI2 |
302 |
CHI2_NEW = CHI2 |
303 |
FC = CHI2 |
304 |
EC = 0. |
305 |
|
306 |
ICOUNT = 0 |
307 |
100 CONTINUE |
308 |
ICOUNT = ICOUNT+1 |
309 |
|
310 |
DO I=1,5 |
311 |
AL0(I)=AL(I) |
312 |
ENDDO |
313 |
DO I=1,5 |
314 |
AL(I)=AL(I)+E*DAL(I) |
315 |
ENDDO |
316 |
CALL CHISQSTT(0,JFAIL) |
317 |
CHI2_OLD = CHI2_NEW |
318 |
CHI2_NEW = CHI2 |
319 |
FA = FB |
320 |
FB = FC |
321 |
FC = CHI2 |
322 |
EA = EB |
323 |
EB = EC |
324 |
EC = E |
325 |
|
326 |
c$$$ PRINT*,E,CHI2_NEW |
327 |
|
328 |
IF(CHI2_NEW.LE.CHI2_OLD) THEN ! success |
329 |
IF(DABS(CHI2_NEW-CHI2_OLD).LT.CHI2TOLL) GOTO 101 |
330 |
SUCCESS_OLD = SUCCESS_NEW |
331 |
SUCCESS_NEW = .TRUE. |
332 |
E = E*ALPHA |
333 |
ELSE ! failure |
334 |
SUCCESS_OLD = SUCCESS_NEW |
335 |
SUCCESS_NEW = .FALSE. |
336 |
CHI2_NEW = CHI2_OLD |
337 |
DO I=1,5 |
338 |
AL(I)=AL0(I) |
339 |
ENDDO |
340 |
IF(SUCCESS_OLD) THEN |
341 |
DENOM = (EB-EA)*(FB-FC) - (EB-EC)*(FB-FA) |
342 |
IF(DENOM.NE.0.) THEN |
343 |
E = EB - 0.5*( (EB-EA)**2*(FB-FC) |
344 |
$ - (EB-EC)**2*(FB-FA) ) / DENOM |
345 |
ELSE |
346 |
E = BETA*E |
347 |
ENDIF |
348 |
ELSE |
349 |
E = BETA*E |
350 |
ENDIF |
351 |
c$$$ E = BETA*E |
352 |
ENDIF |
353 |
IF(ICOUNT.GT.20) GOTO 101 |
354 |
GOTO 100 |
355 |
|
356 |
101 CONTINUE |
357 |
|
358 |
DO I=1,5 |
359 |
DAL(I)=E*DAL(I) |
360 |
ENDDO |
361 |
|
362 |
c$$$ print*,' ' |
363 |
c$$$ PRINT*,'DAL ',(DAL(K),K=1,5) |
364 |
c$$$ PRINT*,'CHI2DOLD ',(CHI2DOLD(K),K=1,5) |
365 |
c$$$ print*,'==== CHI2 ====' |
366 |
c$$$ print*,chi2 |
367 |
c$$$ print*,'==== CHI2d ====' |
368 |
c$$$ print*,(chi2d(i),i=1,5) |
369 |
c$$$ print*,'==== CHI2dd ====' |
370 |
c$$$ do j=1,5 |
371 |
c$$$ print*,(chi2dd(j,i),i=1,5) |
372 |
c$$$ enddo |
373 |
c$$$ print*,'================' |
374 |
c$$$ print*,' ' |
375 |
|
376 |
*========= FIN QUI ============= |
377 |
|
378 |
ENDIF |
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
*------------------------------------------------------------* |
385 |
* ---------------------------------------------------- * |
386 |
*------------------------------------------------------------* |
387 |
* check parameter bounds: |
388 |
*------------------------------------------------------------* |
389 |
DO I=1,5 |
390 |
IF(AL(I).GT.ALMAX(I).OR.AL(I).LT.ALMIN(I))THEN |
391 |
if(TRKVERBOSE)then |
392 |
PRINT*,' *** WARNING in mini *** ' |
393 |
PRINT*,'MINI_2 ==> AL(',I,') out of range' |
394 |
PRINT*,' value: ',AL(I), |
395 |
$ ' limits: ',ALMIN(I),ALMAX(I) |
396 |
print*,'istep ',istep |
397 |
endif |
398 |
IF(CHI2.EQ.0) CHI2=-9999. |
399 |
IF(CHI2.GT.0) CHI2=-CHI2 |
400 |
IFAIL=1 |
401 |
RETURN |
402 |
ENDIF |
403 |
ENDDO |
404 |
*------------------------------------------------------------* |
405 |
* check number of steps: |
406 |
*------------------------------------------------------------* |
407 |
IF(ISTEP.ge.ISTEPMAX) then |
408 |
c$$$ IFAIL=1 |
409 |
c$$$ if(TRKVERBOSE) |
410 |
c$$$ $ PRINT *,'*** WARNING in mini *** ISTEP.GT.ISTEPMAX=', |
411 |
c$$$ $ ISTEPMAX |
412 |
goto 11 |
413 |
endif |
414 |
*------------------------------------------------------------* |
415 |
* --------------------------------------------- |
416 |
* evaluate deflection tolerance on the basis of |
417 |
* estimated deflection |
418 |
* --------------------------------------------- |
419 |
*------------------------------------------------------------* |
420 |
c$$$ ALTOL(5) = DSQRT(DELETA1**2+DELETA2**2*AL(5)**2)/FACT |
421 |
IF(FACT.EQ.0)THEN |
422 |
IFAIL=1 |
423 |
RETURN |
424 |
ENDIF |
425 |
ALTOL(5) = DSQRT((DELETA1*AVRESX)**2+DELETA2**2*AL(5)**2)/FACT |
426 |
ALTOL(1) = ALTOL(5)/DELETA1 |
427 |
ALTOL(2) = ALTOL(1) |
428 |
ALTOL(3) = DSQRT(ALTOL(1)**2+ALTOL(2)**2)/44.51 |
429 |
ALTOL(4) = ALTOL(3) |
430 |
|
431 |
c$$$ print*,' -- ',(DAL(I),ALTOL(I),' - ',i=1,5) !>>>> new step! |
432 |
|
433 |
*---- check tolerances: |
434 |
c$$$ DO I=1,5 |
435 |
c$$$ if(TRKVERBOSE)print*,i,' -- ',DAL(I),ALTOL(I) !>>>> new step! |
436 |
c$$$ ENDDO |
437 |
c$$$ print*,'chi2 -- ',DCHI2 |
438 |
|
439 |
IF(ISTEP.LT.ISTEPMIN) GOTO 10 ! ***PP*** |
440 |
DO I=1,5 |
441 |
IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step! |
442 |
ENDDO |
443 |
|
444 |
***************************** |
445 |
* final estimate of chi^2 |
446 |
***************************** |
447 |
|
448 |
* ------------------------------- |
449 |
* **** Chi2+gaussian minimization |
450 |
* ------------------------------- |
451 |
|
452 |
IF(.NOT.STUDENT) THEN |
453 |
|
454 |
JFAIL=0 !error flag |
455 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
456 |
IF(JFAIL.NE.0) THEN |
457 |
IFAIL=1 |
458 |
if(TRKVERBOSE)THEN |
459 |
CHI2=-9999. |
460 |
if(TRKVERBOSE) |
461 |
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
462 |
ENDIF |
463 |
RETURN |
464 |
ENDIF |
465 |
c COST=1e-7 |
466 |
COST=1. |
467 |
DO I=1,5 |
468 |
IF(CHI2DD(I,I).NE.0.)COST=COST/DABS(CHI2DD(I,I))**0.2 |
469 |
ENDDO |
470 |
DO I=1,5 |
471 |
DO J=1,5 |
472 |
CHI2DD(I,J)=CHI2DD(I,J)*COST |
473 |
ENDDO |
474 |
ENDDO |
475 |
IF(PFIXED.EQ.0.) THEN |
476 |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
477 |
IF(IFA.NE.0) THEN !not positive-defined |
478 |
if(TRKVERBOSE)then |
479 |
PRINT *, |
480 |
$ '*** ERROR in mini ***'// |
481 |
$ 'on matrix inversion (not pos-def)' |
482 |
$ ,DET |
483 |
endif |
484 |
IF(CHI2.EQ.0) CHI2=-9999. |
485 |
IF(CHI2.GT.0) CHI2=-CHI2 |
486 |
IFAIL=1 |
487 |
RETURN |
488 |
ENDIF |
489 |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
490 |
DO I=1,5 |
491 |
c$$$ DAL(I)=0. |
492 |
DO J=1,5 |
493 |
COV(I,J)=2.*COST*CHI2DD(I,J) |
494 |
ENDDO |
495 |
ENDDO |
496 |
ELSE |
497 |
DO I=1,4 |
498 |
CHI2D_R(I)=CHI2D(I) |
499 |
DO J=1,4 |
500 |
CHI2DD_R(I,J)=CHI2DD(I,J) |
501 |
ENDDO |
502 |
ENDDO |
503 |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
504 |
IF(IFA.NE.0) THEN |
505 |
if(TRKVERBOSE)then |
506 |
PRINT *, |
507 |
$ '*** ERROR in mini ***'// |
508 |
$ 'on matrix inversion (not pos-def)' |
509 |
$ ,DET |
510 |
endif |
511 |
IF(CHI2.EQ.0) CHI2=-9999. |
512 |
IF(CHI2.GT.0) CHI2=-CHI2 |
513 |
IFAIL=1 |
514 |
RETURN |
515 |
ENDIF |
516 |
CALL DSFINV(4,CHI2DD_R,4) |
517 |
DO I=1,4 |
518 |
c$$$ DAL(I)=0. |
519 |
DO J=1,4 |
520 |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
521 |
ENDDO |
522 |
ENDDO |
523 |
ENDIF |
524 |
|
525 |
ENDIF |
526 |
|
527 |
* ------------------------------- |
528 |
* **** Likelihood+student minimization |
529 |
* ------------------------------- |
530 |
|
531 |
IF(STUDENT) THEN |
532 |
CALL CHISQSTT(1,JFAIL) |
533 |
DO I=1,5 |
534 |
DO j=1,5 |
535 |
COV(I,J) = 2.*CHI2DD(I,J) |
536 |
ENDDO |
537 |
ENDDO |
538 |
ENDIF |
539 |
|
540 |
***************************** |
541 |
|
542 |
* ------------------------------------ |
543 |
* Number of Degree Of Freedom |
544 |
ndof=0 |
545 |
do ip=1,nplanes |
546 |
ndof=ndof |
547 |
$ +int(xgood(ip)) |
548 |
$ +int(ygood(ip)) |
549 |
enddo |
550 |
if(pfixed.eq.0.) ndof=ndof-5 ! ***PP*** |
551 |
if(pfixed.ne.0.) ndof=ndof-4 ! ***PP*** |
552 |
if(ndof.le.0.) then |
553 |
ndof = 1 |
554 |
if(TRKVERBOSE) |
555 |
$ print*,'*** WARNING *** in mini n.dof = 0 (set to 1)' |
556 |
endif |
557 |
|
558 |
* ------------------------------------ |
559 |
* Reduced chi^2 |
560 |
CHI2 = CHI2/dble(ndof) |
561 |
c print*,'mini2: chi2 ',chi2 |
562 |
|
563 |
11 CONTINUE |
564 |
|
565 |
if(TRKDEBUG) print*,'mini2: -ok- ',istep,chi2,AL(5) |
566 |
|
567 |
NSTEP=ISTEP ! ***PP*** |
568 |
|
569 |
c$$$ print*,'>>>>> NSTEP = ',NSTEP |
570 |
|
571 |
RETURN |
572 |
END |
573 |
|
574 |
****************************************************************************** |
575 |
* |
576 |
* routine to compute chi^2 and its derivatives |
577 |
* |
578 |
* |
579 |
* (modified in respect to the previous one in order to include |
580 |
* single clusters. In this case the residual is evaluated by |
581 |
* calculating the distance between the track intersection and the |
582 |
* segment AB associated to the single cluster) |
583 |
* |
584 |
****************************************************************************** |
585 |
|
586 |
SUBROUTINE CHISQ(IFLAG,IFAIL) |
587 |
|
588 |
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
589 |
|
590 |
include 'commontracker.f' !tracker general common |
591 |
include 'common_mini_2.f' !common for the tracking procedure |
592 |
|
593 |
DIMENSION XV2(nplanes),YV2(nplanes),XV1(nplanes),YV1(nplanes) |
594 |
$ ,XV0(nplanes),YV0(nplanes) |
595 |
DIMENSION AL_P(5) |
596 |
|
597 |
c LOGICAL TRKVERBOSE |
598 |
c COMMON/TRKD/TRKVERBOSE |
599 |
LOGICAL TRKDEBUG,TRKVERBOSE |
600 |
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
601 |
* |
602 |
* chi^2 computation |
603 |
* |
604 |
DO I=1,5 |
605 |
AL_P(I)=AL(I) |
606 |
ENDDO |
607 |
JFAIL=0 !error flag |
608 |
CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes |
609 |
IF(JFAIL.NE.0) THEN |
610 |
IF(TRKVERBOSE) |
611 |
$ PRINT *,'CHISQ ==> error from trk routine POSXYZ !!' |
612 |
IFAIL=1 |
613 |
RETURN |
614 |
ENDIF |
615 |
DO I=1,nplanes |
616 |
XV0(I)=XV(I) |
617 |
YV0(I)=YV(I) |
618 |
ENDDO |
619 |
* ------------------------------------------------ |
620 |
c$$$ CHI2=0. |
621 |
c$$$ DO I=1,nplanes |
622 |
c$$$ CHI2=CHI2 |
623 |
c$$$ + +(XV(I)-XM(I))**2/RESX(i)**2 *XGOOD(I)*YGOOD(I) |
624 |
c$$$ + +(YV(I)-YM(I))**2/RESY(i)**2 *YGOOD(I)*XGOOD(I) |
625 |
c$$$ ENDDO |
626 |
* --------------------------------------------------------- |
627 |
* For planes with only a X or Y-cl included, instead of |
628 |
* a X-Y couple, the residual for chi^2 calculation is |
629 |
* evaluated by finding the point x-y, along the segment AB, |
630 |
* closest to the track. |
631 |
* The X or Y coordinate, respectivelly for X and Y-cl, is |
632 |
* then assigned to XM or YM, which is then considered the |
633 |
* measured position of the cluster. |
634 |
* --------------------------------------------------------- |
635 |
CHI2=0. |
636 |
DO I=1,nplanes |
637 |
IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl |
638 |
BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I)) |
639 |
ALFA = XM_A(I) - BETA * YM_A(I) |
640 |
YM(I) = ( YV(I) + BETA*XV(I) - BETA*ALFA )/(1+BETA**2) |
641 |
if(YM(I).lt.dmin1(YM_A(I),YM_B(I))) |
642 |
$ YM(I)=dmin1(YM_A(I),YM_B(I)) |
643 |
if(YM(I).gt.dmax1(YM_A(I),YM_B(I))) |
644 |
$ YM(I)=dmax1(YM_A(I),YM_B(I)) |
645 |
XM(I) = ALFA + BETA * YM(I) !<<<< measured coordinates |
646 |
ELSEIF(XGOOD(I).EQ.0.AND.YGOOD(I).EQ.1)THEN !Y-cl |
647 |
BETA = (YM_B(I)-YM_A(I))/(XM_B(I)-XM_A(I)) |
648 |
ALFA = YM_A(I) - BETA * XM_A(I) |
649 |
XM(I) = ( XV(I) + BETA*YV(I) - BETA*ALFA )/(1+BETA**2) |
650 |
if(XM(I).lt.dmin1(XM_A(I),XM_B(I))) |
651 |
$ XM(I)=dmin1(XM_A(I),XM_B(I)) |
652 |
if(XM(I).gt.dmax1(XM_A(I),XM_B(I))) |
653 |
$ XM(I)=dmax1(XM_A(I),XM_B(I)) |
654 |
YM(I) = ALFA + BETA * XM(I) !<<<< measured coordinates |
655 |
ENDIF |
656 |
CHI2=CHI2 |
657 |
+ +(XV(I)-XM(I))**2/RESX(i)**2 *( XGOOD(I)*YGOOD(I) ) |
658 |
+ +(YV(I)-YM(I))**2/RESY(i)**2 *( YGOOD(I)*XGOOD(I) ) |
659 |
+ +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESX(i)**2 |
660 |
+ *( XGOOD(I)*(1-YGOOD(I)) ) |
661 |
+ +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2 |
662 |
+ *( (1-XGOOD(I))*YGOOD(I) ) |
663 |
c$$$ print*,(XV(I)-XM(I))**2/RESX(i)**2 *( XGOOD(I)*YGOOD(I) ) |
664 |
c$$$ print*,(YV(I)-YM(I))**2/RESY(i)**2 *( YGOOD(I)*XGOOD(I) ) |
665 |
c$$$ print*,((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESX(i)**2 |
666 |
c$$$ + *( XGOOD(I)*(1-YGOOD(I)) ) |
667 |
c$$$ print*,((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2 |
668 |
c$$$ + *( (1-XGOOD(I))*YGOOD(I) ) |
669 |
c$$$ print*,XV(I),XM(I),XGOOD(I) |
670 |
c$$$ print*,YV(I),YM(I),YGOOD(I) |
671 |
ENDDO |
672 |
c$$$ print*,'CHISQ ',chi2 |
673 |
* ------------------------------------------------ |
674 |
* |
675 |
* calculation of derivatives (dX/dAL_fa and dY/dAL_fa) |
676 |
* |
677 |
* ////////////////////////////////////////////////// |
678 |
* METHOD 1 -- incremental ratios |
679 |
* ////////////////////////////////////////////////// |
680 |
|
681 |
IF(IFLAG.EQ.1) THEN |
682 |
|
683 |
DO J=1,5 |
684 |
DO JJ=1,5 |
685 |
AL_P(JJ)=AL(JJ) |
686 |
ENDDO |
687 |
AL_P(J)=AL_P(J)+STEPAL(J)/2. |
688 |
JFAIL=0 |
689 |
CALL POSXYZ(AL_P,JFAIL) |
690 |
IF(JFAIL.NE.0) THEN |
691 |
IF(TRKVERBOSE) |
692 |
*23456789012345678901234567890123456789012345678901234567890123456789012 |
693 |
$ PRINT *,'CHISQ ==> error from trk routine POSXYZ' |
694 |
IFAIL=1 |
695 |
RETURN |
696 |
ENDIF |
697 |
DO I=1,nplanes |
698 |
XV2(I)=XV(I) |
699 |
YV2(I)=YV(I) |
700 |
ENDDO |
701 |
AL_P(J)=AL_P(J)-STEPAL(J) |
702 |
JFAIL=0 |
703 |
CALL POSXYZ(AL_P,JFAIL) |
704 |
IF(JFAIL.NE.0) THEN |
705 |
IF(TRKVERBOSE) |
706 |
$ PRINT *,'CHISQ ==> error from trk routine POSXYZ' |
707 |
IFAIL=1 |
708 |
RETURN |
709 |
ENDIF |
710 |
DO I=1,nplanes |
711 |
XV1(I)=XV(I) |
712 |
YV1(I)=YV(I) |
713 |
ENDDO |
714 |
DO I=1,nplanes |
715 |
DXDAL(I,J)=(XV2(I)-XV1(I))/STEPAL(J) |
716 |
DYDAL(I,J)=(YV2(I)-YV1(I))/STEPAL(J) |
717 |
ENDDO |
718 |
ENDDO |
719 |
|
720 |
ENDIF |
721 |
|
722 |
* ////////////////////////////////////////////////// |
723 |
* METHOD 2 -- Bob Golden |
724 |
* ////////////////////////////////////////////////// |
725 |
|
726 |
IF(IFLAG.EQ.2) THEN |
727 |
|
728 |
DO I=1,nplanes |
729 |
DXDAL(I,1)=1. |
730 |
DYDAL(I,1)=0. |
731 |
|
732 |
DXDAL(I,2)=0. |
733 |
DYDAL(I,2)=1. |
734 |
|
735 |
COSTHE=DSQRT(1.-AL(3)**2) |
736 |
IF(COSTHE.EQ.0.) THEN |
737 |
IF(TRKVERBOSE)PRINT *,'=== WARNING ===> COSTHE=0' |
738 |
IFAIL=1 |
739 |
RETURN |
740 |
ENDIF |
741 |
|
742 |
DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3 |
743 |
DYDAL(I,3)=(ZINI-ZM(I))*DSIN(AL(4))/COSTHE**3 |
744 |
|
745 |
DXDAL(I,4)=-AL(3)*(ZINI-ZM(I))*DSIN(AL(4))/COSTHE |
746 |
DYDAL(I,4)=AL(3)*(ZINI-ZM(I))*DCOS(AL(4))/COSTHE |
747 |
|
748 |
IF(AL(5).NE.0.) THEN |
749 |
DXDAL(I,5)= |
750 |
+ (XV(I)-(AL(1)+AL(3)/COSTHE*(ZINI-ZM(I)) |
751 |
+ *DCOS(AL(4))))/AL(5) |
752 |
DYDAL(I,5)= |
753 |
+ (YV(I)-(AL(2)+AL(3)/COSTHE*(ZINI-ZM(I)) |
754 |
+ *DSIN(AL(4))))/AL(5) |
755 |
ELSE |
756 |
DXDAL(I,5)=100.*( 0.25 *0.3*0.4*(0.01*(ZINI-ZM(I)))**2 ) |
757 |
DYDAL(I,5)=0. |
758 |
ENDIF |
759 |
|
760 |
ENDDO |
761 |
ENDIF |
762 |
* |
763 |
* 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 |
764 |
* >>> CHI2D evaluation |
765 |
* |
766 |
DO J=1,5 |
767 |
CHI2D(J)=0. |
768 |
DO I=1,nplanes |
769 |
CHI2D(J)=CHI2D(J) |
770 |
+ +2.*(XV0(I)-XM(I))/RESX(i)**2*DXDAL(I,J) *XGOOD(I) |
771 |
+ +2.*(YV0(I)-YM(I))/RESY(i)**2*DYDAL(I,J) *YGOOD(I) |
772 |
ENDDO |
773 |
ENDDO |
774 |
* |
775 |
* >>> CHI2DD evaluation |
776 |
* |
777 |
DO I=1,5 |
778 |
DO J=1,5 |
779 |
CHI2DD(I,J)=0. |
780 |
DO K=1,nplanes |
781 |
CHI2DD(I,J)=CHI2DD(I,J) |
782 |
+ +2.*DXDAL(K,I)*DXDAL(K,J)/RESX(k)**2 *XGOOD(K) |
783 |
+ +2.*DYDAL(K,I)*DYDAL(K,J)/RESY(k)**2 *YGOOD(K) |
784 |
ENDDO |
785 |
ENDDO |
786 |
ENDDO |
787 |
* 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 |
788 |
|
789 |
RETURN |
790 |
END |
791 |
|
792 |
****************************************************************************** |
793 |
* |
794 |
* routine to compute Likelihodd+Student and its derivatives |
795 |
* |
796 |
* (modified in respect to the previous one in order to include |
797 |
* single clusters. In this case the residual is evaluated by |
798 |
* calculating the distance between the track intersection and the |
799 |
* segment AB associated to the single cluster) |
800 |
* |
801 |
****************************************************************************** |
802 |
|
803 |
SUBROUTINE CHISQSTT(IFLAG,JFAIL) |
804 |
|
805 |
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
806 |
|
807 |
include 'commontracker.f' !tracker general common |
808 |
include 'common_mini_2.f' !common for the tracking procedure |
809 |
|
810 |
LOGICAL TRKDEBUG,TRKVERBOSE |
811 |
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
812 |
|
813 |
DIMENSION AL_P(5) |
814 |
DIMENSION VECTEMP(5) |
815 |
c$$$ DIMENSION U(5) ! BFGS |
816 |
|
817 |
DO I=1,5 |
818 |
AL_P(I)=AL(I) |
819 |
ENDDO |
820 |
JFAIL=0 !error flag |
821 |
CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes |
822 |
IF(JFAIL.NE.0) THEN |
823 |
IF(TRKVERBOSE) |
824 |
$ PRINT *,'CHISQSTT ==> error from trk routine POSXYZ !!' |
825 |
IFAIL=1 |
826 |
RETURN |
827 |
ENDIF |
828 |
|
829 |
DO I=1,nplanes |
830 |
DXDAL(I,1)=1. |
831 |
DYDAL(I,1)=0. |
832 |
DXDAL(I,2)=0. |
833 |
DYDAL(I,2)=1. |
834 |
COSTHE=DSQRT(1.-AL(3)**2) |
835 |
IF(COSTHE.EQ.0.) THEN |
836 |
IF(TRKVERBOSE)PRINT *,'=== WARNING ===> COSTHE=0' |
837 |
IFAIL=1 |
838 |
RETURN |
839 |
ENDIF |
840 |
DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3 |
841 |
DYDAL(I,3)=(ZINI-ZM(I))*DSIN(AL(4))/COSTHE**3 |
842 |
DXDAL(I,4)=-AL(3)*(ZINI-ZM(I))*DSIN(AL(4))/COSTHE |
843 |
DYDAL(I,4)=AL(3)*(ZINI-ZM(I))*DCOS(AL(4))/COSTHE |
844 |
IF(AL(5).NE.0.) THEN |
845 |
DXDAL(I,5)= |
846 |
+ (XV(I)-(AL(1)+AL(3)/COSTHE*(ZINI-ZM(I)) |
847 |
+ *DCOS(AL(4))))/AL(5) |
848 |
DYDAL(I,5)= |
849 |
+ (YV(I)-(AL(2)+AL(3)/COSTHE*(ZINI-ZM(I)) |
850 |
+ *DSIN(AL(4))))/AL(5) |
851 |
ELSE |
852 |
DXDAL(I,5)=100.*( 0.25 *0.3*0.4*(0.01*(ZINI-ZM(I)))**2 ) |
853 |
DYDAL(I,5)=0. |
854 |
ENDIF |
855 |
ENDDO |
856 |
|
857 |
IF(IFLAG.EQ.0) THEN ! function calulation |
858 |
CHI2=0. |
859 |
DO I=1,nplanes |
860 |
IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl |
861 |
BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I)) |
862 |
ALFA = XM_A(I) - BETA * YM_A(I) |
863 |
YM(I) = ( YV(I) + BETA*XV(I) - BETA*ALFA )/(1+BETA**2) |
864 |
if(YM(I).lt.dmin1(YM_A(I),YM_B(I))) |
865 |
$ YM(I)=dmin1(YM_A(I),YM_B(I)) |
866 |
if(YM(I).gt.dmax1(YM_A(I),YM_B(I))) |
867 |
$ YM(I)=dmax1(YM_A(I),YM_B(I)) |
868 |
XM(I) = ALFA + BETA * YM(I) !<<<< measured coordinates |
869 |
ELSEIF(XGOOD(I).EQ.0.AND.YGOOD(I).EQ.1)THEN !Y-cl |
870 |
BETA = (YM_B(I)-YM_A(I))/(XM_B(I)-XM_A(I)) |
871 |
ALFA = YM_A(I) - BETA * XM_A(I) |
872 |
XM(I) = ( XV(I) + BETA*YV(I) - BETA*ALFA )/(1+BETA**2) |
873 |
if(XM(I).lt.dmin1(XM_A(I),XM_B(I))) |
874 |
$ XM(I)=dmin1(XM_A(I),XM_B(I)) |
875 |
if(XM(I).gt.dmax1(XM_A(I),XM_B(I))) |
876 |
$ XM(I)=dmax1(XM_A(I),XM_B(I)) |
877 |
YM(I) = ALFA + BETA * XM(I) !<<<< measured coordinates |
878 |
ENDIF |
879 |
TERMX = DLOG( (TAILX(I)*RESX(I)**2+(XV(I)-XM(I))**2)/ |
880 |
$ (TAILX(I)*RESX(I)**2) ) |
881 |
TERMY = DLOG( (TAILY(I)*RESY(I)**2+(YV(I)-YM(I))**2)/ |
882 |
$ (TAILY(I)*RESY(I)**2) ) |
883 |
CHI2=CHI2 |
884 |
$ +(TAILX(I)+1.0)*TERMX *( XGOOD(I) ) |
885 |
$ +(TAILY(I)+1.0)*TERMY *( YGOOD(I) ) |
886 |
ENDDO |
887 |
ENDIF |
888 |
|
889 |
IF(IFLAG.EQ.1) THEN ! derivative calulation |
890 |
DO I=1,5 |
891 |
CHI2DOLD(I)=CHI2D(I) |
892 |
ENDDO |
893 |
DO J=1,5 |
894 |
CHI2D(J)=0. |
895 |
DO I=1,nplanes |
896 |
CHI2D(J)=CHI2D(J) |
897 |
$ +2.*(TAILX(I)+1.0)*(XV(I)-XM(I))/ |
898 |
$ (TAILX(I)*RESX(I)**2+(XV(I)-XM(I))**2)* |
899 |
$ DXDAL(I,J) *XGOOD(I) |
900 |
$ +2.*(TAILY(I)+1.0)*(YV(I)-YM(I))/ |
901 |
$ (TAILY(I)*RESY(I)**2+(YV(I)-YM(I))**2)* |
902 |
$ DYDAL(I,J) *YGOOD(I) |
903 |
ENDDO |
904 |
ENDDO |
905 |
DO K=1,5 |
906 |
VECTEMP(K)=0. |
907 |
DO M=1,5 |
908 |
VECTEMP(K) = VECTEMP(K) + |
909 |
$ COV(K,M)/2.*(CHI2D(M)-CHI2DOLD(M)) |
910 |
ENDDO |
911 |
ENDDO |
912 |
DOWN1 = 0. |
913 |
DO K=1,5 |
914 |
DOWN1 = DOWN1 + DAL(K)*(CHI2D(K)-CHI2DOLD(K)) |
915 |
ENDDO |
916 |
IF(DOWN1.EQ.0.) THEN |
917 |
PRINT*,'WARNING IN MATRIX CALULATION (STUDENT), DOWN1 = 0' |
918 |
IFAIL=1 |
919 |
RETURN |
920 |
ENDIF |
921 |
DOWN2 = 0. |
922 |
DO K=1,5 |
923 |
DO M=1,5 |
924 |
DOWN2 = DOWN2 + (CHI2D(K)-CHI2DOLD(K))*VECTEMP(K) |
925 |
ENDDO |
926 |
ENDDO |
927 |
IF(DOWN2.EQ.0.) THEN |
928 |
PRINT*,'WARNING IN MATRIX CALULATION (STUDENT), DOWN2 = 0' |
929 |
IFAIL=1 |
930 |
RETURN |
931 |
ENDIF |
932 |
c$$$ DO K=1,5 ! BFGS |
933 |
c$$$ U(K) = DAL(K)/DOWN1 - VECTEMP(K)/DOWN2 |
934 |
c$$$ ENDDO |
935 |
DO I=1,5 |
936 |
DO J=1,5 |
937 |
CHI2DD(I,J) = COV(I,J)/2. |
938 |
$ +DAL(I)*DAL(J)/DOWN1 |
939 |
$ -VECTEMP(I)*VECTEMP(J)/DOWN2 |
940 |
c$$$ $ +DOWN2*U(I)*U(J) ! BFGS |
941 |
ENDDO |
942 |
ENDDO |
943 |
ENDIF |
944 |
|
945 |
RETURN |
946 |
END |
947 |
|
948 |
***************************************************************** |
949 |
* |
950 |
* Routine to compute the track intersection points |
951 |
* on the tracking-system planes, given the track parameters |
952 |
* |
953 |
* The routine is based on GRKUTA, which computes the |
954 |
* trajectory of a charged particle in a magnetic field |
955 |
* by solving the equatins of motion with Runge-Kuta method. |
956 |
* |
957 |
* Variables that have to be assigned when the subroutine |
958 |
* is called are: |
959 |
* |
960 |
* ZM(1,NPLANES) ----> z coordinates of the planes |
961 |
* AL_P(1,5) ----> track-parameter vector |
962 |
* |
963 |
* ----------------------------------------------------------- |
964 |
* NB !!! |
965 |
* The routine works properly only if the |
966 |
* planes are numbered in descending order starting from the |
967 |
* reference plane (ZINI) |
968 |
* ----------------------------------------------------------- |
969 |
* |
970 |
***************************************************************** |
971 |
|
972 |
SUBROUTINE POSXYZ(AL_P,IFAIL) |
973 |
|
974 |
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
975 |
|
976 |
include 'commontracker.f' !tracker general common |
977 |
include 'common_mini_2.f' !common for the tracking procedure |
978 |
|
979 |
c LOGICAL TRKVERBOSE |
980 |
c COMMON/TRKD/TRKVERBOSE |
981 |
LOGICAL TRKDEBUG,TRKVERBOSE |
982 |
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
983 |
c |
984 |
DIMENSION AL_P(5) |
985 |
* |
986 |
cpp DO I=1,nplanes |
987 |
cpp ZV(I)=ZM(I) ! |
988 |
cpp ENDDO |
989 |
* |
990 |
* set parameters for GRKUTA |
991 |
* |
992 |
IF(AL_P(5).NE.0) CHARGE=AL_P(5)/DABS(AL_P(5)) |
993 |
IF(AL_P(5).EQ.0) CHARGE=1. |
994 |
VOUT(1)=AL_P(1) |
995 |
VOUT(2)=AL_P(2) |
996 |
VOUT(3)=ZINI ! DBLE(Z0)-DBLE(ZSPEC) |
997 |
VOUT(4)=AL_P(3)*DCOS(AL_P(4)) |
998 |
VOUT(5)=AL_P(3)*DSIN(AL_P(4)) |
999 |
VOUT(6)=-1.*DSQRT(1.-AL_P(3)**2) |
1000 |
IF(AL_P(5).NE.0.) VOUT(7)=DABS(1./AL_P(5)) |
1001 |
IF(AL_P(5).EQ.0.) VOUT(7)=1.E8 |
1002 |
|
1003 |
c$$$ print*,'POSXY (prima) ',vout |
1004 |
|
1005 |
DO I=1,nplanes |
1006 |
c$$$ ipass = 0 ! TEST |
1007 |
c$$$ PRINT *,'TRACKING -> START PLANE: ',I ! TEST |
1008 |
cPPP step=vout(3)-zm(i) |
1009 |
cPP step=(zm(i)-vout(3))/VOUT(6) |
1010 |
10 DO J=1,7 |
1011 |
VECT(J)=VOUT(J) |
1012 |
VECTINI(J)=VOUT(J) |
1013 |
ENDDO |
1014 |
cPPP step=vect(3)-zm(i) |
1015 |
IF(VOUT(6).GE.0.) THEN |
1016 |
IFAIL=1 |
1017 |
if(TRKVERBOSE) |
1018 |
$ PRINT *,'posxy (grkuta): WARNING ===> backward track!!' |
1019 |
RETURN |
1020 |
ENDIF |
1021 |
step=(zm(i)-vect(3))/VOUT(6) |
1022 |
11 continue |
1023 |
CALL GRKUTA(CHARGE,STEP,VECT,VOUT) |
1024 |
c$$$ ipass = ipass + 1 ! TEST |
1025 |
c$$$ PRINT *,'TRACKING -> STEP: ',ipass,' LENGHT: ', STEP ! TEST |
1026 |
IF(VOUT(3).GT.VECT(3)) THEN |
1027 |
IFAIL=1 |
1028 |
if(TRKVERBOSE) |
1029 |
$ PRINT *,'posxy (grkuta): WARNING ===> backward track!!' |
1030 |
c$$$ if(.TRUE.)print*,'charge',charge |
1031 |
c$$$ if(.TRUE.)print*,'vect',vect |
1032 |
c$$$ if(.TRUE.)print*,'vout',vout |
1033 |
c$$$ if(.TRUE.)print*,'step',step |
1034 |
if(TRKVERBOSE)print*,'charge',charge |
1035 |
if(TRKVERBOSE)print*,'vect',vect |
1036 |
if(TRKVERBOSE)print*,'vout',vout |
1037 |
if(TRKVERBOSE)print*,'step',step |
1038 |
RETURN |
1039 |
ENDIF |
1040 |
Z=VOUT(3) |
1041 |
IF(Z.LE.ZM(I)+TOLL.AND.Z.GE.ZM(I)-TOLL) GOTO 100 |
1042 |
IF(Z.GT.ZM(I)+TOLL) GOTO 10 |
1043 |
IF(Z.LE.ZM(I)-TOLL) THEN |
1044 |
STEP=STEP*(ZM(I)-VECT(3))/(Z-VECT(3)) |
1045 |
DO J=1,7 |
1046 |
VECT(J)=VECTINI(J) |
1047 |
ENDDO |
1048 |
GOTO 11 |
1049 |
ENDIF |
1050 |
|
1051 |
|
1052 |
* ----------------------------------------------- |
1053 |
* evaluate track coordinates |
1054 |
100 XV(I)=VOUT(1) |
1055 |
YV(I)=VOUT(2) |
1056 |
ZV(I)=VOUT(3) |
1057 |
AXV(I)=DATAN(VOUT(4)/VOUT(6))*180./ACOS(-1.) |
1058 |
AYV(I)=DATAN(VOUT(5)/VOUT(6))*180./ACOS(-1.) |
1059 |
* ----------------------------------------------- |
1060 |
|
1061 |
IF(TRACKMODE.EQ.1) THEN |
1062 |
* ----------------------------------------------- |
1063 |
* change of energy by bremsstrahlung for electrons |
1064 |
VOUT(7) = VOUT(7) * 0.997 !0.9968 |
1065 |
* ----------------------------------------------- |
1066 |
ENDIF |
1067 |
c$$$ PRINT *,'TRACKING -> END' ! TEST |
1068 |
|
1069 |
ENDDO |
1070 |
|
1071 |
c$$$ print*,'POSXY (dopo) ',vout |
1072 |
|
1073 |
|
1074 |
RETURN |
1075 |
END |
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
* ********************************************************** |
1082 |
* Some initialization routines |
1083 |
* ********************************************************** |
1084 |
|
1085 |
* ---------------------------------------------------------- |
1086 |
* Routine to initialize COMMON/TRACK/ |
1087 |
* |
1088 |
subroutine track_init |
1089 |
|
1090 |
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
1091 |
|
1092 |
include 'commontracker.f' !tracker general common |
1093 |
include 'common_mini_2.f' !common for the tracking procedure |
1094 |
include 'common_mech.f' |
1095 |
|
1096 |
do i=1,5 |
1097 |
AL(i) = 0. |
1098 |
enddo |
1099 |
|
1100 |
do ip=1,NPLANES |
1101 |
ZM(IP) = fitz(nplanes-ip+1) !init to mech. position |
1102 |
XM(IP) = -100. !0. |
1103 |
YM(IP) = -100. !0. |
1104 |
XM_A(IP) = -100. !0. |
1105 |
YM_A(IP) = -100. !0. |
1106 |
ZM_A(IP) = fitz(nplanes-ip+1) !init to mech. position |
1107 |
XM_B(IP) = -100. !0. |
1108 |
YM_B(IP) = -100. !0. |
1109 |
ZM_B(IP) = fitz(nplanes-ip+1) !init to mech. position |
1110 |
RESX(IP) = 1000. !3.d-4 |
1111 |
RESY(IP) = 1000. !12.d-4 |
1112 |
XGOOD(IP) = 0 |
1113 |
YGOOD(IP) = 0 |
1114 |
DEDXTRK_X(IP) = 0 |
1115 |
DEDXTRK_Y(IP) = 0 |
1116 |
AXV(IP) = 0 |
1117 |
AYV(IP) = 0 |
1118 |
XV(IP) = -100 |
1119 |
YV(IP) = -100 |
1120 |
enddo |
1121 |
|
1122 |
return |
1123 |
end |
1124 |
|
1125 |
|
1126 |
*************************************************** |
1127 |
* * |
1128 |
* * |
1129 |
* * |
1130 |
* * |
1131 |
* * |
1132 |
* * |
1133 |
************************************************** |
1134 |
|
1135 |
subroutine guess() |
1136 |
|
1137 |
c IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
1138 |
|
1139 |
include 'commontracker.f' !tracker general common |
1140 |
include 'common_mini_2.f' !common for the tracking procedure |
1141 |
|
1142 |
REAL*4 XP(NPLANES),ZP(NPLANES),AP(NPLANES),RP(NPLANES) |
1143 |
REAL*4 CHI,XC,ZC,RADIUS |
1144 |
* ---------------------------------------- |
1145 |
* Y view |
1146 |
* ---------------------------------------- |
1147 |
* ---------------------------------------- |
1148 |
* initial guess with a straigth line |
1149 |
* ---------------------------------------- |
1150 |
SZZ=0. |
1151 |
SZY=0. |
1152 |
SSY=0. |
1153 |
SZ=0. |
1154 |
S1=0. |
1155 |
DO I=1,nplanes |
1156 |
IF(YGOOD(I).EQ.1)THEN |
1157 |
YY = YM(I) |
1158 |
IF(XGOOD(I).EQ.0)THEN |
1159 |
YY = (YM_A(I) + YM_B(I))/2 |
1160 |
ENDIF |
1161 |
SZZ=SZZ+ZM(I)*ZM(I) |
1162 |
SZY=SZY+ZM(I)*YY |
1163 |
SSY=SSY+YY |
1164 |
SZ=SZ+ZM(I) |
1165 |
S1=S1+1. |
1166 |
ENDIF |
1167 |
ENDDO |
1168 |
DET=SZZ*S1-SZ*SZ |
1169 |
AY=(SZY*S1-SZ*SSY)/DET |
1170 |
BY=(SZZ*SSY-SZY*SZ)/DET |
1171 |
Y0 = AY*ZINI+BY |
1172 |
* ---------------------------------------- |
1173 |
* X view |
1174 |
* ---------------------------------------- |
1175 |
* ---------------------------------------- |
1176 |
* 1) initial guess with a circle |
1177 |
* ---------------------------------------- |
1178 |
NP=0 |
1179 |
DO I=1,nplanes |
1180 |
IF(XGOOD(I).EQ.1)THEN |
1181 |
XX = XM(I) |
1182 |
IF(YGOOD(I).EQ.0)THEN |
1183 |
XX = (XM_A(I) + XM_B(I))/2 |
1184 |
ENDIF |
1185 |
NP=NP+1 |
1186 |
XP(NP)=XX |
1187 |
ZP(NP)=ZM(I) |
1188 |
ENDIF |
1189 |
ENDDO |
1190 |
IFLAG=0 !no debug mode |
1191 |
CALL TRICIRCLE(NP,XP,ZP,AP,RP,CHI,XC,ZC,RADIUS,IFLAG) |
1192 |
|
1193 |
c$$$ print*,' circle: ',XC,ZC,RADIUS,' --- ',CHI,IFLAG |
1194 |
c$$$ print*,' XP ',(xp(i),i=1,np) |
1195 |
c$$$ print*,' ZP ',(zp(i),i=1,np) |
1196 |
c$$$ print*,' AP ',(ap(i),i=1,np) |
1197 |
c$$$ print*,' XP ',(rp(i),i=1,np) |
1198 |
|
1199 |
IF(IFLAG.NE.0)GOTO 10 !straigth fit |
1200 |
c if(CHI.gt.100)GOTO 10 !straigth fit |
1201 |
ARG = RADIUS**2-(ZINI-ZC)**2 |
1202 |
IF(ARG.LT.0)GOTO 10 !straigth fit |
1203 |
DC = SQRT(ARG) |
1204 |
IF(XC.GT.0)DC=-DC |
1205 |
X0=XC+DC |
1206 |
AX = -(ZINI-ZC)/DC |
1207 |
DEF=100./(RADIUS*0.3*0.43) |
1208 |
IF(XC.GT.0)DEF=-DEF |
1209 |
|
1210 |
|
1211 |
|
1212 |
IF(ABS(X0).GT.30)THEN |
1213 |
c$$$ PRINT*,'STRANGE GUESS: XC,ZC,R ',XC,ZC,RADIUS |
1214 |
c$$$ $ ,' - CHI ',CHI,' - X0,AX,DEF ',X0,AX,DEF |
1215 |
GOTO 10 !straigth fit |
1216 |
ENDIF |
1217 |
GOTO 20 !guess is ok |
1218 |
|
1219 |
* ---------------------------------------- |
1220 |
* 2) initial guess with a straigth line |
1221 |
* - if circle does not intersect reference plane |
1222 |
* - if bad chi**2 |
1223 |
* ---------------------------------------- |
1224 |
10 CONTINUE |
1225 |
SZZ=0. |
1226 |
SZX=0. |
1227 |
SSX=0. |
1228 |
SZ=0. |
1229 |
S1=0. |
1230 |
DO I=1,nplanes |
1231 |
IF(XGOOD(I).EQ.1)THEN |
1232 |
XX = XM(I) |
1233 |
IF(YGOOD(I).EQ.0)THEN |
1234 |
XX = (XM_A(I) + XM_B(I))/2 |
1235 |
ENDIF |
1236 |
SZZ=SZZ+ZM(I)*ZM(I) |
1237 |
SZX=SZX+ZM(I)*XX |
1238 |
SSX=SSX+XX |
1239 |
SZ=SZ+ZM(I) |
1240 |
S1=S1+1. |
1241 |
ENDIF |
1242 |
ENDDO |
1243 |
DET=SZZ*S1-SZ*SZ |
1244 |
AX=(SZX*S1-SZ*SSX)/DET |
1245 |
BX=(SZZ*SSX-SZX*SZ)/DET |
1246 |
DEF = 0 |
1247 |
X0 = AX*ZINI+BX |
1248 |
|
1249 |
20 CONTINUE |
1250 |
* ---------------------------------------- |
1251 |
* guess |
1252 |
* ---------------------------------------- |
1253 |
|
1254 |
AL(1) = X0 |
1255 |
AL(2) = Y0 |
1256 |
tath = sqrt(AY**2+AX**2) |
1257 |
AL(3) = tath/sqrt(1+tath**2) |
1258 |
|
1259 |
AL(4)=0. |
1260 |
IF( AX.NE.0.OR.AY.NE.0. ) THEN |
1261 |
AL(4) = ASIN(AY/SQRT(AX**2+AY**2)) |
1262 |
IF(AX.LT.0.AND.AY.GE.0) AL(4) = ACOS(-1.0)-AL(4) |
1263 |
IF(AX.LT.0.AND.AY.LT.0) AL(4) = -ACOS(-1.0)-AL(4) |
1264 |
ENDIF |
1265 |
IF(AY.GT.0.) AL(4) = AL(4)-ACOS(-1.0) |
1266 |
IF(AY.LE.0.) AL(4) = AL(4)+ACOS(-1.0) |
1267 |
|
1268 |
AL(5) = DEF |
1269 |
|
1270 |
c print*,' guess: ',(al(i),i=1,5) |
1271 |
|
1272 |
end |