46 |
DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components |
DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components |
47 |
DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !" |
DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !" |
48 |
|
|
49 |
DIMENSION DAL(5) !increment of vector alfa |
c$$$ DIMENSION DAL(5) !increment of vector alfa |
50 |
DIMENSION CHI2DD_R(4,4),CHI2D_R(4) !hessiano e gradiente di chi2 |
DIMENSION CHI2DD_R(4,4),CHI2D_R(4) !hessiano e gradiente di chi2 |
51 |
|
|
52 |
c elena-------- |
c elena-------- |
67 |
|
|
68 |
c LOGICAL TRKDEBUG,TRKVERBOSE |
c LOGICAL TRKDEBUG,TRKVERBOSE |
69 |
c COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
c COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
70 |
LOGICAL TRKDEBUG,TRKVERBOSE |
LOGICAL TRKDEBUG,TRKVERBOSE,STUDENT,FIRSTSTEPS,FIRSTSTUDENT |
71 |
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
72 |
|
|
73 |
|
DIMENSION AL0(5) |
74 |
|
LOGICAL SUCCESS_NEW,SUCCESS_OLD |
75 |
|
* |
76 |
|
* define kind of minimization (0x=chi2+gaussian or 1x=likelihood+student) |
77 |
|
* |
78 |
|
STUDENT = .false. |
79 |
|
FIRSTSTEPS = .true. |
80 |
|
FIRSTSTUDENT = .true. |
81 |
|
IF(MOD(INT(TRACKMODE/10),10).EQ.1) STUDENT = .true. |
82 |
|
|
83 |
IF(IPRINT.EQ.1) THEN |
IF(IPRINT.EQ.1) THEN |
84 |
TRKVERBOSE = .TRUE. |
TRKVERBOSE = .TRUE. |
85 |
TRKDEBUG = .FALSE. |
TRKDEBUG = .FALSE. |
115 |
* ---------------------------------------------------------- |
* ---------------------------------------------------------- |
116 |
* changed in order to evaluate energy-dependent |
* changed in order to evaluate energy-dependent |
117 |
* tolerances on all 5 parameters |
* tolerances on all 5 parameters |
118 |
FACT=100. !scale factor to define tolerance on alfa |
cPP FACT=1.0e10 !scale factor to define tolerance on alfa |
119 |
c deflection error (see PDG) |
c deflection error (see PDG) |
120 |
DELETA1 = 0.01/0.3/0.4/0.4451**2*SQRT(720./(6.+4.)) |
DELETA1 = 0.01/0.3/0.4/0.4451**2*SQRT(720./(6.+4.)) |
121 |
DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36) |
DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36) |
142 |
* ----------------------- |
* ----------------------- |
143 |
10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !! |
10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !! |
144 |
|
|
145 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
* ------------------------------- |
146 |
IF(JFAIL.NE.0) THEN |
* **** Chi2+gaussian minimization |
147 |
IFAIL=1 |
* ------------------------------- |
148 |
CHI2=-9999. |
|
149 |
if(TRKVERBOSE) |
IF((.NOT.STUDENT).OR.FIRSTSTEPS) THEN |
150 |
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
|
151 |
RETURN |
IF(ISTEP.GE.3) FIRSTSTEPS = .false. |
152 |
ENDIF |
|
153 |
|
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
154 |
COST=1e-5 |
IF(JFAIL.NE.0) THEN |
155 |
DO I=1,5 |
IFAIL=1 |
156 |
DO J=1,5 |
CHI2=-9999. |
157 |
CHI2DD(I,J)=CHI2DD(I,J)*COST |
if(TRKVERBOSE) |
158 |
|
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
159 |
|
RETURN |
160 |
|
ENDIF |
161 |
|
|
162 |
|
c COST=1e-5 |
163 |
|
COST=1. |
164 |
|
DO I=1,5 |
165 |
|
IF(CHI2DD(I,I).NE.0.)COST=COST/DABS(CHI2DD(I,I))**0.2 |
166 |
|
ENDDO |
167 |
|
DO I=1,5 |
168 |
|
DO J=1,5 |
169 |
|
CHI2DD(I,J)=CHI2DD(I,J)*COST |
170 |
|
ENDDO |
171 |
|
c$$$ CHI2D(I)=CHI2D(I)*COST |
172 |
ENDDO |
ENDDO |
|
CHI2D(I)=CHI2D(I)*COST |
|
|
ENDDO |
|
173 |
|
|
174 |
IF(PFIXED.EQ.0.) THEN |
IF(PFIXED.EQ.0.) THEN |
175 |
|
|
176 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
177 |
* track fitting with FREE deflection |
* track fitting with FREE deflection |
178 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
179 |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
180 |
IF(IFA.NE.0) THEN !not positive-defined |
IF(IFA.NE.0) THEN !not positive-defined |
181 |
if(TRKVERBOSE)then |
if(TRKVERBOSE)then |
182 |
PRINT *, |
PRINT *, |
183 |
$ '*** ERROR in mini ***'// |
$ '*** ERROR in mini ***'// |
184 |
$ 'on matrix inversion (not pos-def)' |
$ 'on matrix inversion (not pos-def)' |
185 |
$ ,DET |
$ ,DET |
186 |
endif |
endif |
187 |
IF(CHI2.EQ.0) CHI2=-9999. |
IF(CHI2.EQ.0) CHI2=-9999. |
188 |
IF(CHI2.GT.0) CHI2=-CHI2 |
IF(CHI2.GT.0) CHI2=-CHI2 |
189 |
IFAIL=1 |
IFAIL=1 |
190 |
RETURN |
RETURN |
191 |
ENDIF |
ENDIF |
192 |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
193 |
* ******************************************* |
* ******************************************* |
194 |
* find new value of AL-pha |
* find new value of AL-pha |
195 |
* ******************************************* |
* ******************************************* |
196 |
DO I=1,5 |
DO I=1,5 |
197 |
DAL(I)=0. |
DAL(I)=0. |
198 |
DO J=1,5 |
DO J=1,5 |
199 |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) *COST |
200 |
COV(I,J)=2.*COST*CHI2DD(I,J) |
COV(I,J)=2.*COST*CHI2DD(I,J) |
201 |
ENDDO |
ENDDO |
202 |
ENDDO |
ENDDO |
203 |
DO I=1,5 |
DO I=1,5 |
204 |
AL(I)=AL(I)+DAL(I) |
AL(I)=AL(I)+DAL(I) |
205 |
ENDDO |
ENDDO |
206 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
207 |
* track fitting with FIXED deflection |
* track fitting with FIXED deflection |
208 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
209 |
ELSE |
ELSE |
210 |
AL(5)=1./PFIXED |
AL(5)=1./PFIXED |
211 |
DO I=1,4 |
DO I=1,4 |
212 |
CHI2D_R(I)=CHI2D(I) |
CHI2D_R(I)=CHI2D(I) |
213 |
DO J=1,4 |
DO J=1,4 |
214 |
CHI2DD_R(I,J)=CHI2DD(I,J) |
CHI2DD_R(I,J)=CHI2DD(I,J) |
215 |
|
ENDDO |
216 |
ENDDO |
ENDDO |
217 |
ENDDO |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
218 |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
IF(IFA.NE.0) THEN |
219 |
IF(IFA.NE.0) THEN |
if(TRKVERBOSE)then |
220 |
if(TRKVERBOSE)then |
PRINT *, |
221 |
PRINT *, |
$ '*** ERROR in mini ***'// |
222 |
$ '*** ERROR in mini ***'// |
$ 'on matrix inversion (not pos-def)' |
223 |
$ 'on matrix inversion (not pos-def)' |
$ ,DET |
224 |
$ ,DET |
endif |
225 |
endif |
IF(CHI2.EQ.0) CHI2=-9999. |
226 |
IF(CHI2.EQ.0) CHI2=-9999. |
IF(CHI2.GT.0) CHI2=-CHI2 |
227 |
IF(CHI2.GT.0) CHI2=-CHI2 |
IFAIL=1 |
228 |
IFAIL=1 |
RETURN |
229 |
RETURN |
ENDIF |
230 |
ENDIF |
CALL DSFINV(4,CHI2DD_R,4) |
|
CALL DSFINV(4,CHI2DD_R,4) |
|
231 |
* ******************************************* |
* ******************************************* |
232 |
* find new value of AL-pha |
* find new value of AL-pha |
233 |
* ******************************************* |
* ******************************************* |
234 |
DO I=1,4 |
DO I=1,4 |
235 |
DAL(I)=0. |
DAL(I)=0. |
236 |
DO J=1,4 |
DO J=1,4 |
237 |
DAL(I)=DAL(I)-CHI2DD_R(I,J)*CHI2D_R(J) |
DAL(I)=DAL(I)-CHI2DD_R(I,J)*CHI2D_R(J) *COST |
238 |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
239 |
|
ENDDO |
240 |
|
ENDDO |
241 |
|
DAL(5)=0. |
242 |
|
DO I=1,4 |
243 |
|
AL(I)=AL(I)+DAL(I) |
244 |
|
ENDDO |
245 |
|
ENDIF |
246 |
|
|
247 |
|
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5) |
248 |
|
|
249 |
|
c$$$ PRINT*,'DAL ',(DAL(K),K=1,5) |
250 |
|
c$$$ PRINT*,'CHI2DOLD ',(CHI2DOLD(K),K=1,5) |
251 |
|
|
252 |
|
|
253 |
|
ENDIF |
254 |
|
|
255 |
|
* ------------------------------- |
256 |
|
* **** Likelihood+Student minimization |
257 |
|
* ------------------------------- |
258 |
|
|
259 |
|
IF(STUDENT.AND.(.NOT.FIRSTSTEPS)) THEN |
260 |
|
|
261 |
|
IF(FIRSTSTUDENT) THEN |
262 |
|
FIRSTSTUDENT = .false. |
263 |
|
ISTEP = 1 |
264 |
|
ENDIF |
265 |
|
|
266 |
|
CALL CHISQSTT(1,JFAIL) |
267 |
|
DO I=1,5 |
268 |
|
DAL(I)=0. |
269 |
|
DO J=1,5 |
270 |
|
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) |
271 |
|
ENDDO |
272 |
|
ENDDO |
273 |
|
|
274 |
|
DO I=1,5 |
275 |
|
DO j=1,5 |
276 |
|
COV(I,J) = 2.*CHI2DD(I,J) |
277 |
ENDDO |
ENDDO |
278 |
ENDDO |
ENDDO |
279 |
DAL(5)=0. |
|
280 |
DO I=1,4 |
CHI2TOLL = 1.E-3 |
281 |
AL(I)=AL(I)+DAL(I) |
ALPHA = 3.0 |
282 |
|
BETA = -0.4 |
283 |
|
E=1. |
284 |
|
EA=1. |
285 |
|
EB=1. |
286 |
|
EC=1. |
287 |
|
FA=1. |
288 |
|
FB=1. |
289 |
|
FC=1. |
290 |
|
SUCCESS_OLD = .FALSE. |
291 |
|
SUCCESS_NEW = .FALSE. |
292 |
|
|
293 |
|
CALL CHISQSTT(0,JFAIL) |
294 |
|
c$$$ PRINT*,CHI2 |
295 |
|
CHI2_NEW = CHI2 |
296 |
|
FC = CHI2 |
297 |
|
EC = 0. |
298 |
|
|
299 |
|
ICOUNT = 0 |
300 |
|
100 CONTINUE |
301 |
|
ICOUNT = ICOUNT+1 |
302 |
|
|
303 |
|
DO I=1,5 |
304 |
|
AL0(I)=AL(I) |
305 |
|
ENDDO |
306 |
|
DO I=1,5 |
307 |
|
AL(I)=AL(I)+E*DAL(I) |
308 |
ENDDO |
ENDDO |
309 |
|
CALL CHISQSTT(0,JFAIL) |
310 |
|
CHI2_OLD = CHI2_NEW |
311 |
|
CHI2_NEW = CHI2 |
312 |
|
FA = FB |
313 |
|
FB = FC |
314 |
|
FC = CHI2 |
315 |
|
EA = EB |
316 |
|
EB = EC |
317 |
|
EC = E |
318 |
|
|
319 |
|
c$$$ PRINT*,E,CHI2_NEW |
320 |
|
|
321 |
|
IF(CHI2_NEW.LE.CHI2_OLD) THEN ! success |
322 |
|
IF(DABS(CHI2_NEW-CHI2_OLD).LT.CHI2TOLL) GOTO 101 |
323 |
|
SUCCESS_OLD = SUCCESS_NEW |
324 |
|
SUCCESS_NEW = .TRUE. |
325 |
|
E = E*ALPHA |
326 |
|
ELSE ! failure |
327 |
|
SUCCESS_OLD = SUCCESS_NEW |
328 |
|
SUCCESS_NEW = .FALSE. |
329 |
|
CHI2_NEW = CHI2_OLD |
330 |
|
DO I=1,5 |
331 |
|
AL(I)=AL0(I) |
332 |
|
ENDDO |
333 |
|
IF(SUCCESS_OLD) THEN |
334 |
|
DENOM = (EB-EA)*(FB-FC) - (EB-EC)*(FB-FA) |
335 |
|
IF(DENOM.NE.0.) THEN |
336 |
|
E = EB - 0.5*( (EB-EA)**2*(FB-FC) |
337 |
|
$ - (EB-EC)**2*(FB-FA) ) / DENOM |
338 |
|
ELSE |
339 |
|
E = BETA*E |
340 |
|
ENDIF |
341 |
|
ELSE |
342 |
|
E = BETA*E |
343 |
|
ENDIF |
344 |
|
c$$$ E = BETA*E |
345 |
|
ENDIF |
346 |
|
IF(ICOUNT.GT.20) GOTO 101 |
347 |
|
GOTO 100 |
348 |
|
|
349 |
|
101 CONTINUE |
350 |
|
|
351 |
|
DO I=1,5 |
352 |
|
DAL(I)=E*DAL(I) |
353 |
|
ENDDO |
354 |
|
|
355 |
|
c$$$ print*,' ' |
356 |
|
c$$$ PRINT*,'DAL ',(DAL(K),K=1,5) |
357 |
|
c$$$ PRINT*,'CHI2DOLD ',(CHI2DOLD(K),K=1,5) |
358 |
|
c$$$ print*,'==== CHI2 ====' |
359 |
|
c$$$ print*,chi2 |
360 |
|
c$$$ print*,'==== CHI2d ====' |
361 |
|
c$$$ print*,(chi2d(i),i=1,5) |
362 |
|
c$$$ print*,'==== CHI2dd ====' |
363 |
|
c$$$ do j=1,5 |
364 |
|
c$$$ print*,(chi2dd(j,i),i=1,5) |
365 |
|
c$$$ enddo |
366 |
|
c$$$ print*,'================' |
367 |
|
c$$$ print*,' ' |
368 |
|
|
369 |
|
*========= FIN QUI ============= |
370 |
|
|
371 |
ENDIF |
ENDIF |
372 |
|
|
373 |
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5) |
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
378 |
* ---------------------------------------------------- * |
* ---------------------------------------------------- * |
417 |
ALTOL(3) = DSQRT(ALTOL(1)**2+ALTOL(2)**2)/44.51 |
ALTOL(3) = DSQRT(ALTOL(1)**2+ALTOL(2)**2)/44.51 |
418 |
ALTOL(4) = ALTOL(3) |
ALTOL(4) = ALTOL(3) |
419 |
|
|
420 |
|
c$$$ print*,' -- ',(DAL(I),ALTOL(I),' - ',i=1,5) !>>>> new step! |
421 |
|
|
422 |
*---- check tolerances: |
*---- check tolerances: |
423 |
c$$$ DO I=1,5 |
c$$$ DO I=1,5 |
424 |
c$$$ if(TRKVERBOSE)print*,i,' -- ',DAL(I),ALTOL(I) !>>>> new step! |
c$$$ if(TRKVERBOSE)print*,i,' -- ',DAL(I),ALTOL(I) !>>>> new step! |
425 |
c$$$ ENDDO |
c$$$ ENDDO |
426 |
c$$$ print*,'chi2 -- ',DCHI2 |
c$$$ print*,'chi2 -- ',DCHI2 |
427 |
|
|
428 |
IF(ISTEP.LT.3) GOTO 10 ! ***PP*** |
IF(ISTEP.LT.ISTEPMIN) GOTO 10 ! ***PP*** |
429 |
DO I=1,5 |
DO I=1,5 |
430 |
IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step! |
IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step! |
431 |
ENDDO |
ENDDO |
432 |
|
|
433 |
* new estimate of chi^2: |
***************************** |
434 |
JFAIL=0 !error flag |
* final estimate of chi^2 |
435 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
***************************** |
436 |
IF(JFAIL.NE.0) THEN |
|
437 |
IFAIL=1 |
* ------------------------------- |
438 |
if(TRKVERBOSE)THEN |
* **** Chi2+gaussian minimization |
439 |
CHI2=-9999. |
* ------------------------------- |
440 |
if(TRKVERBOSE) |
|
441 |
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
IF(.NOT.STUDENT) THEN |
442 |
ENDIF |
|
443 |
RETURN |
JFAIL=0 !error flag |
444 |
ENDIF |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
445 |
COST=1e-7 |
IF(JFAIL.NE.0) THEN |
|
DO I=1,5 |
|
|
DO J=1,5 |
|
|
CHI2DD(I,J)=CHI2DD(I,J)*COST |
|
|
ENDDO |
|
|
CHI2D(I)=CHI2D(I)*COST |
|
|
ENDDO |
|
|
IF(PFIXED.EQ.0.) THEN |
|
|
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
|
|
IF(IFA.NE.0) THEN !not positive-defined |
|
|
if(TRKVERBOSE)then |
|
|
PRINT *, |
|
|
$ '*** ERROR in mini ***'// |
|
|
$ 'on matrix inversion (not pos-def)' |
|
|
$ ,DET |
|
|
endif |
|
|
IF(CHI2.EQ.0) CHI2=-9999. |
|
|
IF(CHI2.GT.0) CHI2=-CHI2 |
|
446 |
IFAIL=1 |
IFAIL=1 |
447 |
RETURN |
if(TRKVERBOSE)THEN |
448 |
|
CHI2=-9999. |
449 |
|
if(TRKVERBOSE) |
450 |
|
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
451 |
|
ENDIF |
452 |
|
RETURN |
453 |
ENDIF |
ENDIF |
454 |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
c COST=1e-7 |
455 |
DO I=1,5 |
COST=1. |
456 |
DAL(I)=0. |
DO I=1,5 |
457 |
DO J=1,5 |
IF(CHI2DD(I,I).NE.0.)COST=COST/DABS(CHI2DD(I,I))**0.2 |
458 |
COV(I,J)=2.*COST*CHI2DD(I,J) |
ENDDO |
459 |
ENDDO |
DO I=1,5 |
460 |
ENDDO |
DO J=1,5 |
461 |
ELSE |
CHI2DD(I,J)=CHI2DD(I,J)*COST |
|
DO I=1,4 |
|
|
CHI2D_R(I)=CHI2D(I) |
|
|
DO J=1,4 |
|
|
CHI2DD_R(I,J)=CHI2DD(I,J) |
|
462 |
ENDDO |
ENDDO |
463 |
ENDDO |
ENDDO |
464 |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
IF(PFIXED.EQ.0.) THEN |
465 |
IF(IFA.NE.0) THEN |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
466 |
if(TRKVERBOSE)then |
IF(IFA.NE.0) THEN !not positive-defined |
467 |
PRINT *, |
if(TRKVERBOSE)then |
468 |
$ '*** ERROR in mini ***'// |
PRINT *, |
469 |
$ 'on matrix inversion (not pos-def)' |
$ '*** ERROR in mini ***'// |
470 |
$ ,DET |
$ 'on matrix inversion (not pos-def)' |
471 |
endif |
$ ,DET |
472 |
IF(CHI2.EQ.0) CHI2=-9999. |
endif |
473 |
IF(CHI2.GT.0) CHI2=-CHI2 |
IF(CHI2.EQ.0) CHI2=-9999. |
474 |
IFAIL=1 |
IF(CHI2.GT.0) CHI2=-CHI2 |
475 |
RETURN |
IFAIL=1 |
476 |
|
RETURN |
477 |
|
ENDIF |
478 |
|
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
479 |
|
DO I=1,5 |
480 |
|
c$$$ DAL(I)=0. |
481 |
|
DO J=1,5 |
482 |
|
COV(I,J)=2.*COST*CHI2DD(I,J) |
483 |
|
ENDDO |
484 |
|
ENDDO |
485 |
|
ELSE |
486 |
|
DO I=1,4 |
487 |
|
CHI2D_R(I)=CHI2D(I) |
488 |
|
DO J=1,4 |
489 |
|
CHI2DD_R(I,J)=CHI2DD(I,J) |
490 |
|
ENDDO |
491 |
|
ENDDO |
492 |
|
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
493 |
|
IF(IFA.NE.0) THEN |
494 |
|
if(TRKVERBOSE)then |
495 |
|
PRINT *, |
496 |
|
$ '*** ERROR in mini ***'// |
497 |
|
$ 'on matrix inversion (not pos-def)' |
498 |
|
$ ,DET |
499 |
|
endif |
500 |
|
IF(CHI2.EQ.0) CHI2=-9999. |
501 |
|
IF(CHI2.GT.0) CHI2=-CHI2 |
502 |
|
IFAIL=1 |
503 |
|
RETURN |
504 |
|
ENDIF |
505 |
|
CALL DSFINV(4,CHI2DD_R,4) |
506 |
|
DO I=1,4 |
507 |
|
c$$$ DAL(I)=0. |
508 |
|
DO J=1,4 |
509 |
|
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
510 |
|
ENDDO |
511 |
|
ENDDO |
512 |
ENDIF |
ENDIF |
513 |
CALL DSFINV(4,CHI2DD_R,4) |
|
514 |
DO I=1,4 |
ENDIF |
515 |
DAL(I)=0. |
|
516 |
DO J=1,4 |
* ------------------------------- |
517 |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
* **** Likelihood+student minimization |
518 |
|
* ------------------------------- |
519 |
|
|
520 |
|
IF(STUDENT) THEN |
521 |
|
CALL CHISQSTT(1,JFAIL) |
522 |
|
DO I=1,5 |
523 |
|
DO j=1,5 |
524 |
|
COV(I,J) = 2.*CHI2DD(I,J) |
525 |
ENDDO |
ENDDO |
526 |
ENDDO |
ENDDO |
527 |
ENDIF |
ENDIF |
528 |
|
|
529 |
***************************** |
***************************** |
530 |
|
|
531 |
* ------------------------------------ |
* ------------------------------------ |
544 |
$ print*,'*** WARNING *** in mini n.dof = 0 (set to 1)' |
$ print*,'*** WARNING *** in mini n.dof = 0 (set to 1)' |
545 |
endif |
endif |
546 |
|
|
|
if(TRKDEBUG) print*,'mini2: -ok- ',istep,chi2,1./AL(5) |
|
|
|
|
547 |
* ------------------------------------ |
* ------------------------------------ |
548 |
* Reduced chi^2 |
* Reduced chi^2 |
549 |
CHI2 = CHI2/dble(ndof) |
CHI2 = CHI2/dble(ndof) |
552 |
|
|
553 |
11 CONTINUE |
11 CONTINUE |
554 |
|
|
555 |
|
if(TRKDEBUG) print*,'mini2: -ok- ',istep,chi2,1./AL(5) |
556 |
|
|
557 |
NSTEP=ISTEP ! ***PP*** |
NSTEP=ISTEP ! ***PP*** |
558 |
|
|
559 |
|
c$$$ print*,'>>>>> NSTEP = ',NSTEP |
560 |
|
|
561 |
RETURN |
RETURN |
562 |
END |
END |
563 |
|
|
623 |
* measured position of the cluster. |
* measured position of the cluster. |
624 |
* --------------------------------------------------------- |
* --------------------------------------------------------- |
625 |
CHI2=0. |
CHI2=0. |
626 |
DO I=1,nplanes |
DO I=1,nplanes |
627 |
IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl |
IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl |
628 |
BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I)) |
BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I)) |
629 |
ALFA = XM_A(I) - BETA * YM_A(I) |
ALFA = XM_A(I) - BETA * YM_A(I) |
779 |
RETURN |
RETURN |
780 |
END |
END |
781 |
|
|
782 |
|
****************************************************************************** |
783 |
|
* |
784 |
|
* routine to compute Likelihodd+Student and its derivatives |
785 |
|
* |
786 |
|
* (modified in respect to the previous one in order to include |
787 |
|
* single clusters. In this case the residual is evaluated by |
788 |
|
* calculating the distance between the track intersection and the |
789 |
|
* segment AB associated to the single cluster) |
790 |
|
* |
791 |
|
****************************************************************************** |
792 |
|
|
793 |
|
SUBROUTINE CHISQSTT(IFLAG,JFAIL) |
794 |
|
|
795 |
|
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
796 |
|
|
797 |
|
include 'commontracker.f' !tracker general common |
798 |
|
include 'common_mini_2.f' !common for the tracking procedure |
799 |
|
|
800 |
|
LOGICAL TRKDEBUG,TRKVERBOSE |
801 |
|
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
802 |
|
|
803 |
|
DIMENSION AL_P(5) |
804 |
|
DIMENSION VECTEMP(5) |
805 |
|
c$$$ DIMENSION U(5) ! BFGS |
806 |
|
|
807 |
|
DO I=1,5 |
808 |
|
AL_P(I)=AL(I) |
809 |
|
ENDDO |
810 |
|
JFAIL=0 !error flag |
811 |
|
CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes |
812 |
|
IF(JFAIL.NE.0) THEN |
813 |
|
IF(TRKVERBOSE) |
814 |
|
$ PRINT *,'CHISQSTT ==> error from trk routine POSXYZ !!' |
815 |
|
IFAIL=1 |
816 |
|
RETURN |
817 |
|
ENDIF |
818 |
|
|
819 |
|
DO I=1,nplanes |
820 |
|
DXDAL(I,1)=1. |
821 |
|
DYDAL(I,1)=0. |
822 |
|
DXDAL(I,2)=0. |
823 |
|
DYDAL(I,2)=1. |
824 |
|
COSTHE=DSQRT(1.-AL(3)**2) |
825 |
|
IF(COSTHE.EQ.0.) THEN |
826 |
|
IF(TRKVERBOSE)PRINT *,'=== WARNING ===> COSTHE=0' |
827 |
|
IFAIL=1 |
828 |
|
RETURN |
829 |
|
ENDIF |
830 |
|
DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3 |
831 |
|
DYDAL(I,3)=(ZINI-ZM(I))*DSIN(AL(4))/COSTHE**3 |
832 |
|
DXDAL(I,4)=-AL(3)*(ZINI-ZM(I))*DSIN(AL(4))/COSTHE |
833 |
|
DYDAL(I,4)=AL(3)*(ZINI-ZM(I))*DCOS(AL(4))/COSTHE |
834 |
|
IF(AL(5).NE.0.) THEN |
835 |
|
DXDAL(I,5)= |
836 |
|
+ (XV(I)-(AL(1)+AL(3)/COSTHE*(ZINI-ZM(I)) |
837 |
|
+ *DCOS(AL(4))))/AL(5) |
838 |
|
DYDAL(I,5)= |
839 |
|
+ (YV(I)-(AL(2)+AL(3)/COSTHE*(ZINI-ZM(I)) |
840 |
|
+ *DSIN(AL(4))))/AL(5) |
841 |
|
ELSE |
842 |
|
DXDAL(I,5)=100.*( 0.25 *0.3*0.4*(0.01*(ZINI-ZM(I)))**2 ) |
843 |
|
DYDAL(I,5)=0. |
844 |
|
ENDIF |
845 |
|
ENDDO |
846 |
|
|
847 |
|
IF(IFLAG.EQ.0) THEN ! function calulation |
848 |
|
CHI2=0. |
849 |
|
DO I=1,nplanes |
850 |
|
IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl |
851 |
|
BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I)) |
852 |
|
ALFA = XM_A(I) - BETA * YM_A(I) |
853 |
|
YM(I) = ( YV(I) + BETA*XV(I) - BETA*ALFA )/(1+BETA**2) |
854 |
|
if(YM(I).lt.dmin1(YM_A(I),YM_B(I))) |
855 |
|
$ YM(I)=dmin1(YM_A(I),YM_B(I)) |
856 |
|
if(YM(I).gt.dmax1(YM_A(I),YM_B(I))) |
857 |
|
$ YM(I)=dmax1(YM_A(I),YM_B(I)) |
858 |
|
XM(I) = ALFA + BETA * YM(I) !<<<< measured coordinates |
859 |
|
ELSEIF(XGOOD(I).EQ.0.AND.YGOOD(I).EQ.1)THEN !Y-cl |
860 |
|
BETA = (YM_B(I)-YM_A(I))/(XM_B(I)-XM_A(I)) |
861 |
|
ALFA = YM_A(I) - BETA * XM_A(I) |
862 |
|
XM(I) = ( XV(I) + BETA*YV(I) - BETA*ALFA )/(1+BETA**2) |
863 |
|
if(XM(I).lt.dmin1(XM_A(I),XM_B(I))) |
864 |
|
$ XM(I)=dmin1(XM_A(I),XM_B(I)) |
865 |
|
if(XM(I).gt.dmax1(XM_A(I),XM_B(I))) |
866 |
|
$ XM(I)=dmax1(XM_A(I),XM_B(I)) |
867 |
|
YM(I) = ALFA + BETA * XM(I) !<<<< measured coordinates |
868 |
|
ENDIF |
869 |
|
TERMX = DLOG( (TAILX(I)*RESX(I)**2+(XV(I)-XM(I))**2)/ |
870 |
|
$ (TAILX(I)*RESX(I)**2) ) |
871 |
|
TERMY = DLOG( (TAILY(I)*RESY(I)**2+(YV(I)-YM(I))**2)/ |
872 |
|
$ (TAILY(I)*RESY(I)**2) ) |
873 |
|
CHI2=CHI2 |
874 |
|
$ +(TAILX(I)+1.0)*TERMX *( XGOOD(I) ) |
875 |
|
$ +(TAILY(I)+1.0)*TERMY *( YGOOD(I) ) |
876 |
|
ENDDO |
877 |
|
ENDIF |
878 |
|
|
879 |
|
IF(IFLAG.EQ.1) THEN ! derivative calulation |
880 |
|
DO I=1,5 |
881 |
|
CHI2DOLD(I)=CHI2D(I) |
882 |
|
ENDDO |
883 |
|
DO J=1,5 |
884 |
|
CHI2D(J)=0. |
885 |
|
DO I=1,nplanes |
886 |
|
CHI2D(J)=CHI2D(J) |
887 |
|
$ +2.*(TAILX(I)+1.0)*(XV(I)-XM(I))/ |
888 |
|
$ (TAILX(I)*RESX(I)**2+(XV(I)-XM(I))**2)* |
889 |
|
$ DXDAL(I,J) *XGOOD(I) |
890 |
|
$ +2.*(TAILY(I)+1.0)*(YV(I)-YM(I))/ |
891 |
|
$ (TAILY(I)*RESY(I)**2+(YV(I)-YM(I))**2)* |
892 |
|
$ DYDAL(I,J) *YGOOD(I) |
893 |
|
ENDDO |
894 |
|
ENDDO |
895 |
|
DO K=1,5 |
896 |
|
VECTEMP(K)=0. |
897 |
|
DO M=1,5 |
898 |
|
VECTEMP(K) = VECTEMP(K) + |
899 |
|
$ COV(K,M)/2.*(CHI2D(M)-CHI2DOLD(M)) |
900 |
|
ENDDO |
901 |
|
ENDDO |
902 |
|
DOWN1 = 0. |
903 |
|
DO K=1,5 |
904 |
|
DOWN1 = DOWN1 + DAL(K)*(CHI2D(K)-CHI2DOLD(K)) |
905 |
|
ENDDO |
906 |
|
IF(DOWN1.EQ.0.) THEN |
907 |
|
PRINT*,'WARNING IN MATRIX CALULATION (STUDENT), DOWN1 = 0' |
908 |
|
IFAIL=1 |
909 |
|
RETURN |
910 |
|
ENDIF |
911 |
|
DOWN2 = 0. |
912 |
|
DO K=1,5 |
913 |
|
DO M=1,5 |
914 |
|
DOWN2 = DOWN2 + (CHI2D(K)-CHI2DOLD(K))*VECTEMP(K) |
915 |
|
ENDDO |
916 |
|
ENDDO |
917 |
|
IF(DOWN2.EQ.0.) THEN |
918 |
|
PRINT*,'WARNING IN MATRIX CALULATION (STUDENT), DOWN2 = 0' |
919 |
|
IFAIL=1 |
920 |
|
RETURN |
921 |
|
ENDIF |
922 |
|
c$$$ DO K=1,5 ! BFGS |
923 |
|
c$$$ U(K) = DAL(K)/DOWN1 - VECTEMP(K)/DOWN2 |
924 |
|
c$$$ ENDDO |
925 |
|
DO I=1,5 |
926 |
|
DO J=1,5 |
927 |
|
CHI2DD(I,J) = COV(I,J)/2. |
928 |
|
$ +DAL(I)*DAL(J)/DOWN1 |
929 |
|
$ -VECTEMP(I)*VECTEMP(J)/DOWN2 |
930 |
|
c$$$ $ +DOWN2*U(I)*U(J) ! BFGS |
931 |
|
ENDDO |
932 |
|
ENDDO |
933 |
|
ENDIF |
934 |
|
|
935 |
|
RETURN |
936 |
|
END |
937 |
|
|
938 |
***************************************************************** |
***************************************************************** |
939 |
* |
* |
940 |
* Routine to compute the track intersection points |
* Routine to compute the track intersection points |
973 |
c |
c |
974 |
DIMENSION AL_P(5) |
DIMENSION AL_P(5) |
975 |
* |
* |
976 |
DO I=1,nplanes |
cpp DO I=1,nplanes |
977 |
ZV(I)=ZM(I) ! |
cpp ZV(I)=ZM(I) ! |
978 |
ENDDO |
cpp ENDDO |
979 |
* |
* |
980 |
* set parameters for GRKUTA |
* set parameters for GRKUTA |
981 |
* |
* |
993 |
c$$$ print*,'POSXY (prima) ',vout |
c$$$ print*,'POSXY (prima) ',vout |
994 |
|
|
995 |
DO I=1,nplanes |
DO I=1,nplanes |
996 |
step=vout(3)-zv(i) |
cpp step=vout(3)-zv(i) |
997 |
|
step=vout(3)-zm(i) |
998 |
10 DO J=1,7 |
10 DO J=1,7 |
999 |
VECT(J)=VOUT(J) |
VECT(J)=VOUT(J) |
1000 |
VECTINI(J)=VOUT(J) |
VECTINI(J)=VOUT(J) |
1036 |
AYV(I)=DATAN(VOUT(5)/VOUT(6))*180./ACOS(-1.) |
AYV(I)=DATAN(VOUT(5)/VOUT(6))*180./ACOS(-1.) |
1037 |
* ----------------------------------------------- |
* ----------------------------------------------- |
1038 |
|
|
1039 |
|
IF(TRACKMODE.EQ.1) THEN |
1040 |
|
* ----------------------------------------------- |
1041 |
|
* change of energy by bremsstrahlung for electrons |
1042 |
|
VOUT(7) = VOUT(7) * 0.997 !0.9968 |
1043 |
|
* ----------------------------------------------- |
1044 |
|
ENDIF |
1045 |
|
|
1046 |
ENDDO |
ENDDO |
1047 |
|
|
1048 |
c$$$ print*,'POSXY (dopo) ',vout |
c$$$ print*,'POSXY (dopo) ',vout |
1088 |
RESY(IP) = 1000. !12.d-4 |
RESY(IP) = 1000. !12.d-4 |
1089 |
XGOOD(IP) = 0 |
XGOOD(IP) = 0 |
1090 |
YGOOD(IP) = 0 |
YGOOD(IP) = 0 |
1091 |
|
DEDXTRK_X(IP) = 0 |
1092 |
|
DEDXTRK_Y(IP) = 0 |
1093 |
|
AXV(IP) = 0 |
1094 |
|
AYV(IP) = 0 |
1095 |
|
XV(IP) = -100 |
1096 |
|
YV(IP) = -100 |
1097 |
enddo |
enddo |
1098 |
|
|
1099 |
return |
return |
1166 |
ENDDO |
ENDDO |
1167 |
IFLAG=0 !no debug mode |
IFLAG=0 !no debug mode |
1168 |
CALL TRICIRCLE(NP,XP,ZP,AP,RP,CHI,XC,ZC,RADIUS,IFLAG) |
CALL TRICIRCLE(NP,XP,ZP,AP,RP,CHI,XC,ZC,RADIUS,IFLAG) |
1169 |
c print*,' circle: ',XC,ZC,RADIUS,' --- ',CHI,IFLAG |
|
1170 |
|
c$$$ print*,' circle: ',XC,ZC,RADIUS,' --- ',CHI,IFLAG |
1171 |
|
c$$$ print*,' XP ',(xp(i),i=1,np) |
1172 |
|
c$$$ print*,' ZP ',(zp(i),i=1,np) |
1173 |
|
c$$$ print*,' AP ',(ap(i),i=1,np) |
1174 |
|
c$$$ print*,' XP ',(rp(i),i=1,np) |
1175 |
|
|
1176 |
IF(IFLAG.NE.0)GOTO 10 !straigth fit |
IF(IFLAG.NE.0)GOTO 10 !straigth fit |
1177 |
if(CHI.gt.100)GOTO 10 !straigth fit |
c if(CHI.gt.100)GOTO 10 !straigth fit |
1178 |
ARG = RADIUS**2-(ZINI-ZC)**2 |
ARG = RADIUS**2-(ZINI-ZC)**2 |
1179 |
IF(ARG.LT.0)GOTO 10 !straigth fit |
IF(ARG.LT.0)GOTO 10 !straigth fit |
1180 |
DC = SQRT(ARG) |
DC = SQRT(ARG) |
1184 |
DEF=100./(RADIUS*0.3*0.43) |
DEF=100./(RADIUS*0.3*0.43) |
1185 |
IF(XC.GT.0)DEF=-DEF |
IF(XC.GT.0)DEF=-DEF |
1186 |
|
|
1187 |
|
|
1188 |
|
|
1189 |
IF(ABS(X0).GT.30)THEN |
IF(ABS(X0).GT.30)THEN |
1190 |
c$$$ PRINT*,'STRANGE GUESS: XC,ZC,R ',XC,ZC,RADIUS |
c$$$ PRINT*,'STRANGE GUESS: XC,ZC,R ',XC,ZC,RADIUS |
1191 |
c$$$ $ ,' - CHI ',CHI,' - X0,AX,DEF ',X0,AX,DEF |
c$$$ $ ,' - CHI ',CHI,' - X0,AX,DEF ',X0,AX,DEF |