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 |
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 |
|
IF(MOD(INT(TRACKMODE/10),10).EQ.1) STUDENT = .true. |
80 |
|
|
81 |
IF(IPRINT.EQ.1) THEN |
IF(IPRINT.EQ.1) THEN |
82 |
TRKVERBOSE = .TRUE. |
TRKVERBOSE = .TRUE. |
83 |
TRKDEBUG = .FALSE. |
TRKDEBUG = .FALSE. |
140 |
* ----------------------- |
* ----------------------- |
141 |
10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !! |
10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !! |
142 |
|
|
143 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
* ------------------------------- |
144 |
IF(JFAIL.NE.0) THEN |
* **** Chi2+gaussian minimization |
145 |
IFAIL=1 |
* ------------------------------- |
146 |
CHI2=-9999. |
|
147 |
if(TRKVERBOSE) |
IF(.NOT.STUDENT) THEN |
148 |
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
|
149 |
RETURN |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
150 |
ENDIF |
IF(JFAIL.NE.0) THEN |
151 |
|
IFAIL=1 |
152 |
COST=1e-5 |
CHI2=-9999. |
153 |
DO I=1,5 |
if(TRKVERBOSE) |
154 |
DO J=1,5 |
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
155 |
CHI2DD(I,J)=CHI2DD(I,J)*COST |
RETURN |
156 |
|
ENDIF |
157 |
|
|
158 |
|
c COST=1e-5 |
159 |
|
COST=1. |
160 |
|
DO I=1,5 |
161 |
|
IF(CHI2DD(I,I).NE.0.)COST=COST/DABS(CHI2DD(I,I))**0.2 |
162 |
|
ENDDO |
163 |
|
DO I=1,5 |
164 |
|
DO J=1,5 |
165 |
|
CHI2DD(I,J)=CHI2DD(I,J)*COST |
166 |
|
ENDDO |
167 |
|
c$$$ CHI2D(I)=CHI2D(I)*COST |
168 |
ENDDO |
ENDDO |
|
CHI2D(I)=CHI2D(I)*COST |
|
|
ENDDO |
|
169 |
|
|
170 |
IF(PFIXED.EQ.0.) THEN |
IF(PFIXED.EQ.0.) THEN |
171 |
|
|
172 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
173 |
* track fitting with FREE deflection |
* track fitting with FREE deflection |
174 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
175 |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
176 |
IF(IFA.NE.0) THEN !not positive-defined |
IF(IFA.NE.0) THEN !not positive-defined |
177 |
if(TRKVERBOSE)then |
if(TRKVERBOSE)then |
178 |
PRINT *, |
PRINT *, |
179 |
$ '*** ERROR in mini ***'// |
$ '*** ERROR in mini ***'// |
180 |
$ 'on matrix inversion (not pos-def)' |
$ 'on matrix inversion (not pos-def)' |
181 |
$ ,DET |
$ ,DET |
182 |
endif |
endif |
183 |
IF(CHI2.EQ.0) CHI2=-9999. |
IF(CHI2.EQ.0) CHI2=-9999. |
184 |
IF(CHI2.GT.0) CHI2=-CHI2 |
IF(CHI2.GT.0) CHI2=-CHI2 |
185 |
IFAIL=1 |
IFAIL=1 |
186 |
RETURN |
RETURN |
187 |
ENDIF |
ENDIF |
188 |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
189 |
* ******************************************* |
* ******************************************* |
190 |
* find new value of AL-pha |
* find new value of AL-pha |
191 |
* ******************************************* |
* ******************************************* |
192 |
DO I=1,5 |
DO I=1,5 |
193 |
DAL(I)=0. |
DAL(I)=0. |
194 |
DO J=1,5 |
DO J=1,5 |
195 |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) *COST |
196 |
COV(I,J)=2.*COST*CHI2DD(I,J) |
COV(I,J)=2.*COST*CHI2DD(I,J) |
197 |
ENDDO |
ENDDO |
198 |
ENDDO |
ENDDO |
199 |
DO I=1,5 |
DO I=1,5 |
200 |
AL(I)=AL(I)+DAL(I) |
AL(I)=AL(I)+DAL(I) |
201 |
ENDDO |
ENDDO |
202 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
203 |
* track fitting with FIXED deflection |
* track fitting with FIXED deflection |
204 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
205 |
ELSE |
ELSE |
206 |
AL(5)=1./PFIXED |
AL(5)=1./PFIXED |
207 |
DO I=1,4 |
DO I=1,4 |
208 |
CHI2D_R(I)=CHI2D(I) |
CHI2D_R(I)=CHI2D(I) |
209 |
DO J=1,4 |
DO J=1,4 |
210 |
CHI2DD_R(I,J)=CHI2DD(I,J) |
CHI2DD_R(I,J)=CHI2DD(I,J) |
211 |
|
ENDDO |
212 |
ENDDO |
ENDDO |
213 |
ENDDO |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
214 |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
IF(IFA.NE.0) THEN |
215 |
IF(IFA.NE.0) THEN |
if(TRKVERBOSE)then |
216 |
if(TRKVERBOSE)then |
PRINT *, |
217 |
PRINT *, |
$ '*** ERROR in mini ***'// |
218 |
$ '*** ERROR in mini ***'// |
$ 'on matrix inversion (not pos-def)' |
219 |
$ 'on matrix inversion (not pos-def)' |
$ ,DET |
220 |
$ ,DET |
endif |
221 |
endif |
IF(CHI2.EQ.0) CHI2=-9999. |
222 |
IF(CHI2.EQ.0) CHI2=-9999. |
IF(CHI2.GT.0) CHI2=-CHI2 |
223 |
IF(CHI2.GT.0) CHI2=-CHI2 |
IFAIL=1 |
224 |
IFAIL=1 |
RETURN |
225 |
RETURN |
ENDIF |
226 |
ENDIF |
CALL DSFINV(4,CHI2DD_R,4) |
|
CALL DSFINV(4,CHI2DD_R,4) |
|
227 |
* ******************************************* |
* ******************************************* |
228 |
* find new value of AL-pha |
* find new value of AL-pha |
229 |
* ******************************************* |
* ******************************************* |
230 |
DO I=1,4 |
DO I=1,4 |
231 |
DAL(I)=0. |
DAL(I)=0. |
232 |
DO J=1,4 |
DO J=1,4 |
233 |
DAL(I)=DAL(I)-CHI2DD_R(I,J)*CHI2D_R(J) |
DAL(I)=DAL(I)-CHI2DD_R(I,J)*CHI2D_R(J) *COST |
234 |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
235 |
|
ENDDO |
236 |
|
ENDDO |
237 |
|
DAL(5)=0. |
238 |
|
DO I=1,4 |
239 |
|
AL(I)=AL(I)+DAL(I) |
240 |
ENDDO |
ENDDO |
241 |
|
ENDIF |
242 |
|
|
243 |
|
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5) |
244 |
|
|
245 |
|
c$$$ PRINT*,'DAL ',(DAL(K),K=1,5) |
246 |
|
c$$$ PRINT*,'CHI2DOLD ',(CHI2DOLD(K),K=1,5) |
247 |
|
|
248 |
|
|
249 |
|
ENDIF |
250 |
|
|
251 |
|
* ------------------------------- |
252 |
|
* **** Likelihood+Student minimization |
253 |
|
* ------------------------------- |
254 |
|
|
255 |
|
IF(STUDENT) THEN |
256 |
|
CALL CHISQSTT(1,JFAIL) |
257 |
|
DO I=1,5 |
258 |
|
DAL(I)=0. |
259 |
|
DO J=1,5 |
260 |
|
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) |
261 |
|
ENDDO |
262 |
|
ENDDO |
263 |
|
|
264 |
|
DO I=1,5 |
265 |
|
DO j=1,5 |
266 |
|
COV(I,J) = 2.*CHI2DD(I,J) |
267 |
|
ENDDO |
268 |
|
ENDDO |
269 |
|
|
270 |
|
CHI2TOLL = 1.E-3 |
271 |
|
ALPHA = 3.0 |
272 |
|
BETA = -0.4 |
273 |
|
E=1. |
274 |
|
EA=1. |
275 |
|
EB=1. |
276 |
|
EC=1. |
277 |
|
FA=1. |
278 |
|
FB=1. |
279 |
|
FC=1. |
280 |
|
SUCCESS_OLD = .FALSE. |
281 |
|
SUCCESS_NEW = .FALSE. |
282 |
|
|
283 |
|
CALL CHISQSTT(0,JFAIL) |
284 |
|
c$$$ PRINT*,CHI2 |
285 |
|
CHI2_NEW = CHI2 |
286 |
|
FC = CHI2 |
287 |
|
EC = 0. |
288 |
|
|
289 |
|
100 CONTINUE |
290 |
|
DO I=1,5 |
291 |
|
AL0(I)=AL(I) |
292 |
|
ENDDO |
293 |
|
DO I=1,5 |
294 |
|
AL(I)=AL(I)+E*DAL(I) |
295 |
ENDDO |
ENDDO |
296 |
DAL(5)=0. |
CALL CHISQSTT(0,JFAIL) |
297 |
DO I=1,4 |
CHI2_OLD = CHI2_NEW |
298 |
AL(I)=AL(I)+DAL(I) |
CHI2_NEW = CHI2 |
299 |
|
FA = FB |
300 |
|
FB = FC |
301 |
|
FC = CHI2 |
302 |
|
EA = EB |
303 |
|
EB = EC |
304 |
|
EC = E |
305 |
|
|
306 |
|
c$$$ PRINT*,E,CHI2_NEW |
307 |
|
|
308 |
|
IF(CHI2_NEW.LE.CHI2_OLD) THEN ! success |
309 |
|
IF(DABS(CHI2_NEW-CHI2_OLD).LT.CHI2TOLL) GOTO 101 |
310 |
|
SUCCESS_OLD = SUCCESS_NEW |
311 |
|
SUCCESS_NEW = .TRUE. |
312 |
|
E = E*ALPHA |
313 |
|
ELSE ! failure |
314 |
|
SUCCESS_OLD = SUCCESS_NEW |
315 |
|
SUCCESS_NEW = .FALSE. |
316 |
|
CHI2_NEW = CHI2_OLD |
317 |
|
DO I=1,5 |
318 |
|
AL(I)=AL0(I) |
319 |
|
ENDDO |
320 |
|
IF(SUCCESS_OLD) THEN |
321 |
|
DENOM = (EB-EA)*(FB-FC) - (EB-EC)*(FB-FA) |
322 |
|
IF(DENOM.NE.0.) THEN |
323 |
|
E = EB - 0.5*( (EB-EA)**2*(FB-FC) |
324 |
|
$ - (EB-EC)**2*(FB-FA) ) / DENOM |
325 |
|
ELSE |
326 |
|
E = BETA*E |
327 |
|
ENDIF |
328 |
|
ELSE |
329 |
|
E = BETA*E |
330 |
|
ENDIF |
331 |
|
c$$$ E = BETA*E |
332 |
|
ENDIF |
333 |
|
GOTO 100 |
334 |
|
|
335 |
|
101 CONTINUE |
336 |
|
|
337 |
|
DO I=1,5 |
338 |
|
DAL(I)=E*DAL(I) |
339 |
ENDDO |
ENDDO |
340 |
|
|
341 |
|
c$$$ print*,' ' |
342 |
|
c$$$ PRINT*,'DAL ',(DAL(K),K=1,5) |
343 |
|
c$$$ PRINT*,'CHI2DOLD ',(CHI2DOLD(K),K=1,5) |
344 |
|
c$$$ print*,'==== CHI2 ====' |
345 |
|
c$$$ print*,chi2 |
346 |
|
c$$$ print*,'==== CHI2d ====' |
347 |
|
c$$$ print*,(chi2d(i),i=1,5) |
348 |
|
c$$$ print*,'==== CHI2dd ====' |
349 |
|
c$$$ do j=1,5 |
350 |
|
c$$$ print*,(chi2dd(j,i),i=1,5) |
351 |
|
c$$$ enddo |
352 |
|
c$$$ print*,'================' |
353 |
|
c$$$ print*,' ' |
354 |
|
|
355 |
|
*========= FIN QUI ============= |
356 |
|
|
357 |
ENDIF |
ENDIF |
358 |
|
|
359 |
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5) |
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
364 |
* ---------------------------------------------------- * |
* ---------------------------------------------------- * |
416 |
IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step! |
IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step! |
417 |
ENDDO |
ENDDO |
418 |
|
|
419 |
* new estimate of chi^2: |
***************************** |
420 |
JFAIL=0 !error flag |
* final estimate of chi^2 |
421 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
***************************** |
422 |
IF(JFAIL.NE.0) THEN |
|
423 |
IFAIL=1 |
* ------------------------------- |
424 |
if(TRKVERBOSE)THEN |
* **** Chi2+gaussian minimization |
425 |
CHI2=-9999. |
* ------------------------------- |
426 |
if(TRKVERBOSE) |
|
427 |
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
IF(.NOT.STUDENT) THEN |
428 |
ENDIF |
|
429 |
RETURN |
JFAIL=0 !error flag |
430 |
ENDIF |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
431 |
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 |
|
432 |
IFAIL=1 |
IFAIL=1 |
433 |
RETURN |
if(TRKVERBOSE)THEN |
434 |
|
CHI2=-9999. |
435 |
|
if(TRKVERBOSE) |
436 |
|
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
437 |
|
ENDIF |
438 |
|
RETURN |
439 |
ENDIF |
ENDIF |
440 |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
c COST=1e-7 |
441 |
DO I=1,5 |
COST=1. |
442 |
DAL(I)=0. |
DO I=1,5 |
443 |
DO J=1,5 |
IF(CHI2DD(I,I).NE.0.)COST=COST/DABS(CHI2DD(I,I))**0.2 |
444 |
COV(I,J)=2.*COST*CHI2DD(I,J) |
ENDDO |
445 |
ENDDO |
DO I=1,5 |
446 |
ENDDO |
DO J=1,5 |
447 |
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) |
|
448 |
ENDDO |
ENDDO |
449 |
ENDDO |
ENDDO |
450 |
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
IF(PFIXED.EQ.0.) THEN |
451 |
IF(IFA.NE.0) THEN |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
452 |
if(TRKVERBOSE)then |
IF(IFA.NE.0) THEN !not positive-defined |
453 |
PRINT *, |
if(TRKVERBOSE)then |
454 |
$ '*** ERROR in mini ***'// |
PRINT *, |
455 |
$ 'on matrix inversion (not pos-def)' |
$ '*** ERROR in mini ***'// |
456 |
$ ,DET |
$ 'on matrix inversion (not pos-def)' |
457 |
endif |
$ ,DET |
458 |
IF(CHI2.EQ.0) CHI2=-9999. |
endif |
459 |
IF(CHI2.GT.0) CHI2=-CHI2 |
IF(CHI2.EQ.0) CHI2=-9999. |
460 |
IFAIL=1 |
IF(CHI2.GT.0) CHI2=-CHI2 |
461 |
RETURN |
IFAIL=1 |
462 |
|
RETURN |
463 |
|
ENDIF |
464 |
|
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
465 |
|
DO I=1,5 |
466 |
|
c$$$ DAL(I)=0. |
467 |
|
DO J=1,5 |
468 |
|
COV(I,J)=2.*COST*CHI2DD(I,J) |
469 |
|
ENDDO |
470 |
|
ENDDO |
471 |
|
ELSE |
472 |
|
DO I=1,4 |
473 |
|
CHI2D_R(I)=CHI2D(I) |
474 |
|
DO J=1,4 |
475 |
|
CHI2DD_R(I,J)=CHI2DD(I,J) |
476 |
|
ENDDO |
477 |
|
ENDDO |
478 |
|
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
479 |
|
IF(IFA.NE.0) THEN |
480 |
|
if(TRKVERBOSE)then |
481 |
|
PRINT *, |
482 |
|
$ '*** ERROR in mini ***'// |
483 |
|
$ 'on matrix inversion (not pos-def)' |
484 |
|
$ ,DET |
485 |
|
endif |
486 |
|
IF(CHI2.EQ.0) CHI2=-9999. |
487 |
|
IF(CHI2.GT.0) CHI2=-CHI2 |
488 |
|
IFAIL=1 |
489 |
|
RETURN |
490 |
|
ENDIF |
491 |
|
CALL DSFINV(4,CHI2DD_R,4) |
492 |
|
DO I=1,4 |
493 |
|
c$$$ DAL(I)=0. |
494 |
|
DO J=1,4 |
495 |
|
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
496 |
|
ENDDO |
497 |
|
ENDDO |
498 |
ENDIF |
ENDIF |
499 |
CALL DSFINV(4,CHI2DD_R,4) |
|
500 |
DO I=1,4 |
ENDIF |
501 |
DAL(I)=0. |
|
502 |
DO J=1,4 |
* ------------------------------- |
503 |
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
* **** Likelihood+student minimization |
504 |
|
* ------------------------------- |
505 |
|
|
506 |
|
IF(STUDENT) THEN |
507 |
|
CALL CHISQSTT(1,JFAIL) |
508 |
|
DO I=1,5 |
509 |
|
DO j=1,5 |
510 |
|
COV(I,J) = 2.*CHI2DD(I,J) |
511 |
ENDDO |
ENDDO |
512 |
ENDDO |
ENDDO |
513 |
ENDIF |
ENDIF |
514 |
|
|
515 |
***************************** |
***************************** |
516 |
|
|
517 |
* ------------------------------------ |
* ------------------------------------ |
765 |
RETURN |
RETURN |
766 |
END |
END |
767 |
|
|
768 |
|
****************************************************************************** |
769 |
|
* |
770 |
|
* routine to compute Likelihodd+Student and its derivatives |
771 |
|
* |
772 |
|
* (modified in respect to the previous one in order to include |
773 |
|
* single clusters. In this case the residual is evaluated by |
774 |
|
* calculating the distance between the track intersection and the |
775 |
|
* segment AB associated to the single cluster) |
776 |
|
* |
777 |
|
****************************************************************************** |
778 |
|
|
779 |
|
SUBROUTINE CHISQSTT(IFLAG,JFAIL) |
780 |
|
|
781 |
|
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
782 |
|
|
783 |
|
include 'commontracker.f' !tracker general common |
784 |
|
include 'common_mini_2.f' !common for the tracking procedure |
785 |
|
|
786 |
|
LOGICAL TRKDEBUG,TRKVERBOSE |
787 |
|
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
788 |
|
|
789 |
|
DIMENSION AL_P(5) |
790 |
|
DIMENSION VECTEMP(5) |
791 |
|
c$$$ DIMENSION U(5) ! BFGS |
792 |
|
|
793 |
|
DO I=1,5 |
794 |
|
AL_P(I)=AL(I) |
795 |
|
ENDDO |
796 |
|
JFAIL=0 !error flag |
797 |
|
CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes |
798 |
|
IF(JFAIL.NE.0) THEN |
799 |
|
IF(TRKVERBOSE) |
800 |
|
$ PRINT *,'CHISQSTT ==> error from trk routine POSXYZ !!' |
801 |
|
IFAIL=1 |
802 |
|
RETURN |
803 |
|
ENDIF |
804 |
|
|
805 |
|
DO I=1,nplanes |
806 |
|
DXDAL(I,1)=1. |
807 |
|
DYDAL(I,1)=0. |
808 |
|
DXDAL(I,2)=0. |
809 |
|
DYDAL(I,2)=1. |
810 |
|
COSTHE=DSQRT(1.-AL(3)**2) |
811 |
|
IF(COSTHE.EQ.0.) THEN |
812 |
|
IF(TRKVERBOSE)PRINT *,'=== WARNING ===> COSTHE=0' |
813 |
|
IFAIL=1 |
814 |
|
RETURN |
815 |
|
ENDIF |
816 |
|
DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3 |
817 |
|
DYDAL(I,3)=(ZINI-ZM(I))*DSIN(AL(4))/COSTHE**3 |
818 |
|
DXDAL(I,4)=-AL(3)*(ZINI-ZM(I))*DSIN(AL(4))/COSTHE |
819 |
|
DYDAL(I,4)=AL(3)*(ZINI-ZM(I))*DCOS(AL(4))/COSTHE |
820 |
|
IF(AL(5).NE.0.) THEN |
821 |
|
DXDAL(I,5)= |
822 |
|
+ (XV(I)-(AL(1)+AL(3)/COSTHE*(ZINI-ZM(I)) |
823 |
|
+ *DCOS(AL(4))))/AL(5) |
824 |
|
DYDAL(I,5)= |
825 |
|
+ (YV(I)-(AL(2)+AL(3)/COSTHE*(ZINI-ZM(I)) |
826 |
|
+ *DSIN(AL(4))))/AL(5) |
827 |
|
ELSE |
828 |
|
DXDAL(I,5)=100.*( 0.25 *0.3*0.4*(0.01*(ZINI-ZM(I)))**2 ) |
829 |
|
DYDAL(I,5)=0. |
830 |
|
ENDIF |
831 |
|
ENDDO |
832 |
|
|
833 |
|
IF(IFLAG.EQ.0) THEN ! function calulation |
834 |
|
CHI2=0. |
835 |
|
DO I=1,nplanes |
836 |
|
IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl |
837 |
|
BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I)) |
838 |
|
ALFA = XM_A(I) - BETA * YM_A(I) |
839 |
|
YM(I) = ( YV(I) + BETA*XV(I) - BETA*ALFA )/(1+BETA**2) |
840 |
|
if(YM(I).lt.dmin1(YM_A(I),YM_B(I))) |
841 |
|
$ YM(I)=dmin1(YM_A(I),YM_B(I)) |
842 |
|
if(YM(I).gt.dmax1(YM_A(I),YM_B(I))) |
843 |
|
$ YM(I)=dmax1(YM_A(I),YM_B(I)) |
844 |
|
XM(I) = ALFA + BETA * YM(I) !<<<< measured coordinates |
845 |
|
ELSEIF(XGOOD(I).EQ.0.AND.YGOOD(I).EQ.1)THEN !Y-cl |
846 |
|
BETA = (YM_B(I)-YM_A(I))/(XM_B(I)-XM_A(I)) |
847 |
|
ALFA = YM_A(I) - BETA * XM_A(I) |
848 |
|
XM(I) = ( XV(I) + BETA*YV(I) - BETA*ALFA )/(1+BETA**2) |
849 |
|
if(XM(I).lt.dmin1(XM_A(I),XM_B(I))) |
850 |
|
$ XM(I)=dmin1(XM_A(I),XM_B(I)) |
851 |
|
if(XM(I).gt.dmax1(XM_A(I),XM_B(I))) |
852 |
|
$ XM(I)=dmax1(XM_A(I),XM_B(I)) |
853 |
|
YM(I) = ALFA + BETA * XM(I) !<<<< measured coordinates |
854 |
|
ENDIF |
855 |
|
TERMX = DLOG( (TAILX(I)*RESX(I)**2+(XV(I)-XM(I))**2)/ |
856 |
|
$ (TAILX(I)*RESX(I)**2) ) |
857 |
|
TERMY = DLOG( (TAILY(I)*RESY(I)**2+(YV(I)-YM(I))**2)/ |
858 |
|
$ (TAILY(I)*RESY(I)**2) ) |
859 |
|
CHI2=CHI2 |
860 |
|
$ +(TAILX(I)+1.0)*TERMX *( XGOOD(I) ) |
861 |
|
$ +(TAILY(I)+1.0)*TERMY *( YGOOD(I) ) |
862 |
|
ENDDO |
863 |
|
ENDIF |
864 |
|
|
865 |
|
IF(IFLAG.EQ.1) THEN ! derivative calulation |
866 |
|
DO I=1,5 |
867 |
|
CHI2DOLD(I)=CHI2D(I) |
868 |
|
ENDDO |
869 |
|
DO J=1,5 |
870 |
|
CHI2D(J)=0. |
871 |
|
DO I=1,nplanes |
872 |
|
CHI2D(J)=CHI2D(J) |
873 |
|
$ +2.*(TAILX(I)+1.0)*(XV(I)-XM(I))/ |
874 |
|
$ (TAILX(I)*RESX(I)**2+(XV(I)-XM(I))**2)* |
875 |
|
$ DXDAL(I,J) *XGOOD(I) |
876 |
|
$ +2.*(TAILY(I)+1.0)*(YV(I)-YM(I))/ |
877 |
|
$ (TAILY(I)*RESY(I)**2+(YV(I)-YM(I))**2)* |
878 |
|
$ DYDAL(I,J) *YGOOD(I) |
879 |
|
ENDDO |
880 |
|
ENDDO |
881 |
|
DO K=1,5 |
882 |
|
VECTEMP(K)=0. |
883 |
|
DO M=1,5 |
884 |
|
VECTEMP(K) = VECTEMP(K) + |
885 |
|
$ COV(K,M)/2.*(CHI2D(M)-CHI2DOLD(M)) |
886 |
|
ENDDO |
887 |
|
ENDDO |
888 |
|
DOWN1 = 0. |
889 |
|
DO K=1,5 |
890 |
|
DOWN1 = DOWN1 + DAL(K)*(CHI2D(K)-CHI2DOLD(K)) |
891 |
|
ENDDO |
892 |
|
IF(DOWN1.EQ.0.) THEN |
893 |
|
PRINT*,'WARNING IN MATRIX CALULATION (STUDENT), DOWN1 = 0' |
894 |
|
IFAIL=1 |
895 |
|
RETURN |
896 |
|
ENDIF |
897 |
|
DOWN2 = 0. |
898 |
|
DO K=1,5 |
899 |
|
DO M=1,5 |
900 |
|
DOWN2 = DOWN2 + (CHI2D(K)-CHI2DOLD(K))*VECTEMP(K) |
901 |
|
ENDDO |
902 |
|
ENDDO |
903 |
|
IF(DOWN2.EQ.0.) THEN |
904 |
|
PRINT*,'WARNING IN MATRIX CALULATION (STUDENT), DOWN2 = 0' |
905 |
|
IFAIL=1 |
906 |
|
RETURN |
907 |
|
ENDIF |
908 |
|
c$$$ DO K=1,5 ! BFGS |
909 |
|
c$$$ U(K) = DAL(K)/DOWN1 - VECTEMP(K)/DOWN2 |
910 |
|
c$$$ ENDDO |
911 |
|
DO I=1,5 |
912 |
|
DO J=1,5 |
913 |
|
CHI2DD(I,J) = COV(I,J)/2. |
914 |
|
$ +DAL(I)*DAL(J)/DOWN1 |
915 |
|
$ -VECTEMP(I)*VECTEMP(J)/DOWN2 |
916 |
|
c$$$ $ +DOWN2*U(I)*U(J) ! BFGS |
917 |
|
ENDDO |
918 |
|
ENDDO |
919 |
|
ENDIF |
920 |
|
|
921 |
|
RETURN |
922 |
|
END |
923 |
|
|
924 |
***************************************************************** |
***************************************************************** |
925 |
* |
* |
926 |
* Routine to compute the track intersection points |
* Routine to compute the track intersection points |