12 |
************************************************************************ |
************************************************************************ |
13 |
|
|
14 |
|
|
15 |
SUBROUTINE MINI_2(ISTEP,IFAIL) |
SUBROUTINE MINI2(ISTEP,IFAIL,IPRINT) |
16 |
|
|
17 |
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
18 |
|
|
19 |
include 'commontracker.f' !tracker general common |
include 'commontracker.f' !tracker general common |
20 |
include 'common_mini_2.f' !common for the tracking procedure |
include 'common_mini_2.f' !common for the tracking procedure |
21 |
|
|
22 |
logical DEBUG |
c logical DEBUG |
23 |
common/dbg/DEBUG |
c common/dbg/DEBUG |
24 |
|
|
25 |
parameter (inf=1.e8) !just a huge number... |
parameter (dinf=1.d15) !just a huge number... |
26 |
c------------------------------------------------------------------------ |
c------------------------------------------------------------------------ |
27 |
c variables used in the tracking procedure (mini and its subroutines) |
c variables used in the tracking procedure (mini and its subroutines) |
28 |
c |
c |
31 |
c ordering, but they maintain their Z coordinates. so plane number 1 is |
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 |
c the first one that a particle meets, and its Z coordinate is > 0 |
33 |
c------------------------------------------------------------------------ |
c------------------------------------------------------------------------ |
34 |
DATA ZINI/23.5/ !z coordinate of the reference plane |
DATA ZINI/23.5/ !!! ***PP*** to be changed !z coordinate of the reference plane |
35 |
|
|
36 |
DATA XGOOD,YGOOD/nplanes*1.,nplanes*1./ !planes to be used in the tracking |
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 |
DATA STEPAL/5*1.d-7/ !alpha vector step |
39 |
DATA ISTEPMAX/100/ !maximum number of steps in the chi^2 minimization |
DATA ISTEPMAX/100/ !maximum number of steps in the chi^2 minimization |
41 |
* !the tracking procedure |
* !the tracking procedure |
42 |
DATA STEPMAX/100./ !maximum number of steps in the trackin gprocess |
DATA STEPMAX/100./ !maximum number of steps in the trackin gprocess |
43 |
|
|
44 |
c DATA ALMAX/inf,inf,inf,inf,0.25e2/ !limits on alpha vector components |
c DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components |
45 |
c DATA ALMIN/-inf,-inf,-inf,-inf,-0.25e2/ !" |
c DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !" |
46 |
DATA ALMAX/inf,inf,1.,inf,0.25e2/ !limits on alpha vector components |
DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components |
47 |
DATA ALMIN/-inf,-inf,-1.,-inf,-0.25e2/ !" |
DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !" |
|
|
|
48 |
|
|
49 |
DIMENSION DAL(5) !increment of vector alfa |
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 |
INTEGER IFLAG |
57 |
c-------------------------------------------------------- |
c-------------------------------------------------------- |
58 |
c IFLAG =1 ---- chi2 derivatives computed by using |
c IFLAG =1 ---- chi2 derivatives computed by using |
63 |
c NB: the two metods gives equivalent results BUT |
c NB: the two metods gives equivalent results BUT |
64 |
c method 2 is faster!! |
c method 2 is faster!! |
65 |
c-------------------------------------------------------- |
c-------------------------------------------------------- |
66 |
DATA IFLAG/2/ |
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 |
* define ALTOL(5) ---> tolerances on state vector |
104 |
* |
* |
105 |
* ---------------------------------------------------------- |
* ---------------------------------------------------------- |
106 |
FACT=10. !scale factor to define |
* changed in order to evaluate energy-dependent |
107 |
!tolerance on alfa |
* tolerances on all 5 parameters |
108 |
ALTOL(1)=RESX(1)/FACT !al(1) = x |
FACT=100. !scale factor to define tolerance on alfa |
109 |
ALTOL(2)=RESY(1)/FACT !al(2) = y |
c deflection error (see PDG) |
110 |
ALTOL(3)=DSQRT(RESX(1)**2 !al(3)=sin(theta) |
DELETA1 = 0.01/0.3/0.4/0.4451**2*SQRT(720./(6.+4.)) |
111 |
$ +RESY(1)**2)/44.51/FACT |
DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36) |
112 |
ALTOL(4)=ALTOL(3) !al(4)=phi |
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) |
c deflection error (see PDG) |
118 |
DELETA1=0.01*RESX(1)/0.3/0.4/0.4451**2*SQRT(720./(6.+4.)) |
c$$$ DELETA1 = 0.01*AVRESX/0.3/0.4/0.4451**2*SQRT(720./(6.+4.)) |
119 |
DELETA2=0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36) |
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 |
ISTEP=0 !num. steps to minimize chi^2 |
123 |
JFAIL=0 !error flag |
JFAIL=0 !error flag |
124 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
CHI2=0 |
125 |
IF(JFAIL.NE.0) THEN |
|
126 |
IFAIL=1 |
if(TRKDEBUG) print*,'guess: ',al |
127 |
if(DEBUG) |
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5) |
128 |
$ PRINT *,'mini_2 ===> error on CHISQ computation !!!' |
|
|
RETURN |
|
|
ENDIF |
|
129 |
* |
* |
130 |
* ----------------------- |
* ----------------------- |
131 |
* START MINIMIZATION LOOP |
* START MINIMIZATION LOOP |
132 |
* ----------------------- |
* ----------------------- |
133 |
10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !! |
10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !! |
|
CHI2_P=CHI2 |
|
|
|
|
|
c print*,'@@@@@ ',istep,' - ',al |
|
134 |
|
|
135 |
cost=1e-7 |
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
136 |
|
IF(JFAIL.NE.0) THEN |
137 |
|
IFAIL=1 |
138 |
|
CHI2=-9999. |
139 |
|
if(TRKVERBOSE) |
140 |
|
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
141 |
|
RETURN |
142 |
|
ENDIF |
143 |
|
|
144 |
|
COST=1e-5 |
145 |
DO I=1,5 |
DO I=1,5 |
146 |
DO J=1,5 |
DO J=1,5 |
147 |
CHI2DD(I,J)=CHI2DD(I,J)*COST |
CHI2DD(I,J)=CHI2DD(I,J)*COST |
148 |
ENDDO |
ENDDO |
149 |
CHI2D(I)=CHI2D(I)*COST |
CHI2D(I)=CHI2D(I)*COST |
150 |
ENDDO |
ENDDO |
151 |
|
|
152 |
|
IF(PFIXED.EQ.0.) THEN |
153 |
|
|
154 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
155 |
* track fitting with FREE deflection |
* track fitting with FREE deflection |
156 |
*------------------------------------------------------------* |
*------------------------------------------------------------* |
157 |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
158 |
IF(IFA.NE.0) THEN !not positive-defined |
IF(IFA.NE.0) THEN !not positive-defined |
159 |
if(DEBUG)then |
if(TRKVERBOSE)then |
160 |
PRINT *, |
PRINT *, |
161 |
$ 'MINI_HOUGH ==> '// |
$ '*** ERROR in mini ***'// |
162 |
$ '** ERROR ** on matrix inversion (not positive-defined)!!!' |
$ 'on matrix inversion (not pos-def)' |
163 |
$ ,DET |
$ ,DET |
164 |
endif |
endif |
165 |
IFAIL=1 |
IF(CHI2.EQ.0) CHI2=-9999. |
166 |
RETURN |
IF(CHI2.GT.0) CHI2=-CHI2 |
167 |
ENDIF |
IFAIL=1 |
168 |
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
RETURN |
169 |
|
ENDIF |
170 |
|
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
171 |
* ******************************************* |
* ******************************************* |
172 |
* find new value of AL-pha !* |
* find new value of AL-pha |
173 |
* !* |
* ******************************************* |
174 |
DO I=1,5 !* |
DO I=1,5 |
175 |
DAL(I)=0. !* |
DAL(I)=0. |
176 |
DO J=1,5 !* |
DO J=1,5 |
177 |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) !* |
DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J) |
178 |
COV(I,J)=CHI2DD(I,J) !* |
COV(I,J)=2.*COST*CHI2DD(I,J) |
179 |
ENDDO !* |
ENDDO |
180 |
ENDDO !* |
ENDDO |
181 |
DO I=1,5 !* |
DO I=1,5 |
182 |
AL(I)=AL(I)+DAL(I) !* |
AL(I)=AL(I)+DAL(I) |
183 |
ENDDO !* |
ENDDO |
184 |
|
*------------------------------------------------------------* |
185 |
|
* track fitting with FIXED deflection |
186 |
|
*------------------------------------------------------------* |
187 |
|
ELSE |
188 |
|
AL(5)=1./PFIXED |
189 |
|
DO I=1,4 |
190 |
|
CHI2D_R(I)=CHI2D(I) |
191 |
|
DO J=1,4 |
192 |
|
CHI2DD_R(I,J)=CHI2DD(I,J) |
193 |
|
ENDDO |
194 |
|
ENDDO |
195 |
|
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
196 |
|
IF(IFA.NE.0) THEN |
197 |
|
if(TRKVERBOSE)then |
198 |
|
PRINT *, |
199 |
|
$ '*** ERROR in mini ***'// |
200 |
|
$ 'on matrix inversion (not pos-def)' |
201 |
|
$ ,DET |
202 |
|
endif |
203 |
|
IF(CHI2.EQ.0) CHI2=-9999. |
204 |
|
IF(CHI2.GT.0) CHI2=-CHI2 |
205 |
|
IFAIL=1 |
206 |
|
RETURN |
207 |
|
ENDIF |
208 |
|
CALL DSFINV(4,CHI2DD_R,4) |
209 |
* ******************************************* |
* ******************************************* |
210 |
|
* find new value of AL-pha |
211 |
|
* ******************************************* |
212 |
|
DO I=1,4 |
213 |
|
DAL(I)=0. |
214 |
|
DO J=1,4 |
215 |
|
DAL(I)=DAL(I)-CHI2DD_R(I,J)*CHI2D_R(J) |
216 |
|
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
217 |
|
ENDDO |
218 |
|
ENDDO |
219 |
|
DAL(5)=0. |
220 |
|
DO I=1,4 |
221 |
|
AL(I)=AL(I)+DAL(I) |
222 |
|
ENDDO |
223 |
|
ENDIF |
224 |
|
|
225 |
|
if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5) |
226 |
|
|
227 |
|
*------------------------------------------------------------* |
228 |
|
* ---------------------------------------------------- * |
229 |
|
*------------------------------------------------------------* |
230 |
* check parameter bounds: |
* check parameter bounds: |
231 |
|
*------------------------------------------------------------* |
232 |
DO I=1,5 |
DO I=1,5 |
233 |
IF(AL(I).GT.ALMAX(I).OR.AL(I).LT.ALMIN(I))THEN |
IF(AL(I).GT.ALMAX(I).OR.AL(I).LT.ALMIN(I))THEN |
234 |
if(DEBUG)then |
if(TRKVERBOSE)then |
235 |
PRINT*,' **WARNING** ' |
PRINT*,' *** WARNING in mini *** ' |
236 |
PRINT*,'MINI_2 ==> AL(',I,') out of range' |
PRINT*,'MINI_2 ==> AL(',I,') out of range' |
237 |
PRINT*,' value: ',AL(I), |
PRINT*,' value: ',AL(I), |
238 |
$ ' limits: ',ALMIN(I),ALMAX(I) |
$ ' limits: ',ALMIN(I),ALMAX(I) |
239 |
print*,'istep ',istep |
print*,'istep ',istep |
240 |
endif |
endif |
241 |
|
IF(CHI2.EQ.0) CHI2=-9999. |
242 |
|
IF(CHI2.GT.0) CHI2=-CHI2 |
243 |
IFAIL=1 |
IFAIL=1 |
244 |
RETURN |
RETURN |
245 |
ENDIF |
ENDIF |
246 |
ENDDO |
ENDDO |
247 |
* new estimate of chi^2: |
*------------------------------------------------------------* |
|
JFAIL=0 !error flag |
|
|
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
|
|
IF(JFAIL.NE.0) THEN |
|
|
IFAIL=1 |
|
|
if(DEBUG) |
|
|
$ PRINT *,'mini_2: ===> error on CHISQ computation !!!' |
|
|
RETURN |
|
|
ENDIF |
|
248 |
* check number of steps: |
* check number of steps: |
249 |
IF(ISTEP.gt.ISTEPMAX) then |
*------------------------------------------------------------* |
250 |
IFAIL=1 |
IF(ISTEP.ge.ISTEPMAX) then |
251 |
if(DEBUG) |
c$$$ IFAIL=1 |
252 |
$ PRINT *,'mini_2: WARNING ===> ISTEP.GT.ISTEPMAX=',ISTEPMAX |
c$$$ if(TRKVERBOSE) |
253 |
|
c$$$ $ PRINT *,'*** WARNING in mini *** ISTEP.GT.ISTEPMAX=', |
254 |
|
c$$$ $ ISTEPMAX |
255 |
goto 11 |
goto 11 |
256 |
endif |
endif |
257 |
|
*------------------------------------------------------------* |
258 |
* --------------------------------------------- |
* --------------------------------------------- |
259 |
* evaluate deflection tolerance on the basis of |
* evaluate deflection tolerance on the basis of |
260 |
* estimated deflection |
* estimated deflection |
261 |
* --------------------------------------------- |
* --------------------------------------------- |
262 |
ALTOL(5)=DSQRT(DELETA1**2+DELETA2**2*AL(5)**2)/FACT |
*------------------------------------------------------------* |
263 |
|
c$$$ ALTOL(5) = DSQRT(DELETA1**2+DELETA2**2*AL(5)**2)/FACT |
264 |
|
ALTOL(5) = DSQRT((DELETA1*AVRESX)**2+DELETA2**2*AL(5)**2)/FACT |
265 |
|
ALTOL(1) = ALTOL(5)/DELETA1 |
266 |
|
ALTOL(2) = ALTOL(1) |
267 |
|
ALTOL(3) = DSQRT(ALTOL(1)**2+ALTOL(2)**2)/44.51 |
268 |
|
ALTOL(4) = ALTOL(3) |
269 |
|
|
270 |
*---- check tolerances: |
*---- check tolerances: |
271 |
|
c$$$ DO I=1,5 |
272 |
|
c$$$ if(TRKVERBOSE)print*,i,' -- ',DAL(I),ALTOL(I) !>>>> new step! |
273 |
|
c$$$ ENDDO |
274 |
|
c$$$ print*,'chi2 -- ',DCHI2 |
275 |
|
|
276 |
|
IF(ISTEP.LT.3) GOTO 10 ! ***PP*** |
277 |
DO I=1,5 |
DO I=1,5 |
278 |
IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step! |
IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step! |
279 |
ENDDO |
ENDDO |
280 |
|
|
281 |
|
* new estimate of chi^2: |
282 |
|
JFAIL=0 !error flag |
283 |
|
CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives |
284 |
|
IF(JFAIL.NE.0) THEN |
285 |
|
IFAIL=1 |
286 |
|
if(TRKVERBOSE)THEN |
287 |
|
CHI2=-9999. |
288 |
|
if(TRKVERBOSE) |
289 |
|
$ PRINT *,'*** ERROR in mini *** wrong CHISQ' |
290 |
|
ENDIF |
291 |
|
RETURN |
292 |
|
ENDIF |
293 |
|
COST=1e-7 |
294 |
|
DO I=1,5 |
295 |
|
DO J=1,5 |
296 |
|
CHI2DD(I,J)=CHI2DD(I,J)*COST |
297 |
|
ENDDO |
298 |
|
CHI2D(I)=CHI2D(I)*COST |
299 |
|
ENDDO |
300 |
|
IF(PFIXED.EQ.0.) THEN |
301 |
|
CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant |
302 |
|
IF(IFA.NE.0) THEN !not positive-defined |
303 |
|
if(TRKVERBOSE)then |
304 |
|
PRINT *, |
305 |
|
$ '*** ERROR in mini ***'// |
306 |
|
$ 'on matrix inversion (not pos-def)' |
307 |
|
$ ,DET |
308 |
|
endif |
309 |
|
IF(CHI2.EQ.0) CHI2=-9999. |
310 |
|
IF(CHI2.GT.0) CHI2=-CHI2 |
311 |
|
IFAIL=1 |
312 |
|
RETURN |
313 |
|
ENDIF |
314 |
|
CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion |
315 |
|
DO I=1,5 |
316 |
|
DAL(I)=0. |
317 |
|
DO J=1,5 |
318 |
|
COV(I,J)=2.*COST*CHI2DD(I,J) |
319 |
|
ENDDO |
320 |
|
ENDDO |
321 |
|
ELSE |
322 |
|
DO I=1,4 |
323 |
|
CHI2D_R(I)=CHI2D(I) |
324 |
|
DO J=1,4 |
325 |
|
CHI2DD_R(I,J)=CHI2DD(I,J) |
326 |
|
ENDDO |
327 |
|
ENDDO |
328 |
|
CALL DSFACT(4,CHI2DD_R,4,IFA,DET,JFA) |
329 |
|
IF(IFA.NE.0) THEN |
330 |
|
if(TRKVERBOSE)then |
331 |
|
PRINT *, |
332 |
|
$ '*** ERROR in mini ***'// |
333 |
|
$ 'on matrix inversion (not pos-def)' |
334 |
|
$ ,DET |
335 |
|
endif |
336 |
|
IF(CHI2.EQ.0) CHI2=-9999. |
337 |
|
IF(CHI2.GT.0) CHI2=-CHI2 |
338 |
|
IFAIL=1 |
339 |
|
RETURN |
340 |
|
ENDIF |
341 |
|
CALL DSFINV(4,CHI2DD_R,4) |
342 |
|
DO I=1,4 |
343 |
|
DAL(I)=0. |
344 |
|
DO J=1,4 |
345 |
|
COV(I,J)=2.*COST*CHI2DD_R(I,J) |
346 |
|
ENDDO |
347 |
|
ENDDO |
348 |
|
ENDIF |
349 |
|
***************************** |
350 |
|
|
351 |
* ------------------------------------ |
* ------------------------------------ |
352 |
* Number of Degree Of Freedom |
* Number of Degree Of Freedom |
356 |
$ +int(xgood(ip)) |
$ +int(xgood(ip)) |
357 |
$ +int(ygood(ip)) |
$ +int(ygood(ip)) |
358 |
enddo |
enddo |
359 |
ndof=ndof-5 |
if(pfixed.eq.0.) ndof=ndof-5 ! ***PP*** |
360 |
|
if(pfixed.ne.0.) ndof=ndof-4 ! ***PP*** |
361 |
|
if(ndof.le.0.) then |
362 |
|
ndof = 1 |
363 |
|
if(TRKVERBOSE) |
364 |
|
$ print*,'*** WARNING *** in mini n.dof = 0 (set to 1)' |
365 |
|
endif |
366 |
|
|
367 |
|
if(TRKDEBUG) print*,'mini2: -ok- ',istep,chi2,1./AL(5) |
368 |
|
|
369 |
* ------------------------------------ |
* ------------------------------------ |
370 |
* Reduced chi^2 |
* Reduced chi^2 |
371 |
CHI2 = CHI2/dble(ndof) |
CHI2 = CHI2/dble(ndof) |
372 |
|
|
373 |
|
c print*,'mini2: chi2 ',chi2 |
|
11 CONTINUE |
|
374 |
|
|
375 |
101 CONTINUE |
11 CONTINUE |
376 |
|
|
377 |
c print*,'END MINI' |
NSTEP=ISTEP ! ***PP*** |
378 |
|
|
379 |
RETURN |
RETURN |
380 |
END |
END |
401 |
DIMENSION XV2(nplanes),YV2(nplanes),XV1(nplanes),YV1(nplanes) |
DIMENSION XV2(nplanes),YV2(nplanes),XV1(nplanes),YV1(nplanes) |
402 |
$ ,XV0(nplanes),YV0(nplanes) |
$ ,XV0(nplanes),YV0(nplanes) |
403 |
DIMENSION AL_P(5) |
DIMENSION AL_P(5) |
404 |
|
|
405 |
|
c LOGICAL TRKVERBOSE |
406 |
|
c COMMON/TRKD/TRKVERBOSE |
407 |
|
LOGICAL TRKDEBUG,TRKVERBOSE |
408 |
|
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
409 |
* |
* |
410 |
* chi^2 computation |
* chi^2 computation |
411 |
* |
* |
415 |
JFAIL=0 !error flag |
JFAIL=0 !error flag |
416 |
CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes |
CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes |
417 |
IF(JFAIL.NE.0) THEN |
IF(JFAIL.NE.0) THEN |
418 |
PRINT *,'CHISQ ==> error from tracking routine POSXYZ !!' |
IF(TRKVERBOSE) |
419 |
|
$ PRINT *,'CHISQ ==> error from trk routine POSXYZ !!' |
420 |
IFAIL=1 |
IFAIL=1 |
421 |
RETURN |
RETURN |
422 |
ENDIF |
ENDIF |
468 |
+ *( XGOOD(I)*(1-YGOOD(I)) ) |
+ *( XGOOD(I)*(1-YGOOD(I)) ) |
469 |
+ +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2 |
+ +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2 |
470 |
+ *( (1-XGOOD(I))*YGOOD(I) ) |
+ *( (1-XGOOD(I))*YGOOD(I) ) |
471 |
|
c$$$ print*,(XV(I)-XM(I))**2/RESX(i)**2 *( XGOOD(I)*YGOOD(I) ) |
472 |
|
c$$$ print*,(YV(I)-YM(I))**2/RESY(i)**2 *( YGOOD(I)*XGOOD(I) ) |
473 |
|
c$$$ print*,((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESX(i)**2 |
474 |
|
c$$$ + *( XGOOD(I)*(1-YGOOD(I)) ) |
475 |
|
c$$$ print*,((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2 |
476 |
|
c$$$ + *( (1-XGOOD(I))*YGOOD(I) ) |
477 |
|
c$$$ print*,XV(I),XM(I),XGOOD(I) |
478 |
|
c$$$ print*,YV(I),YM(I),YGOOD(I) |
479 |
ENDDO |
ENDDO |
480 |
|
c$$$ print*,'CHISQ ',chi2 |
481 |
* ------------------------------------------------ |
* ------------------------------------------------ |
482 |
* |
* |
483 |
* calculation of derivatives (dX/dAL_fa and dY/dAL_fa) |
* calculation of derivatives (dX/dAL_fa and dY/dAL_fa) |
496 |
JFAIL=0 |
JFAIL=0 |
497 |
CALL POSXYZ(AL_P,JFAIL) |
CALL POSXYZ(AL_P,JFAIL) |
498 |
IF(JFAIL.NE.0) THEN |
IF(JFAIL.NE.0) THEN |
499 |
PRINT *,'CHISQ ==> error from tracking routine POSXYZ !!' |
IF(TRKVERBOSE) |
500 |
|
*23456789012345678901234567890123456789012345678901234567890123456789012 |
501 |
|
$ PRINT *,'CHISQ ==> error from trk routine POSXYZ' |
502 |
IFAIL=1 |
IFAIL=1 |
503 |
RETURN |
RETURN |
504 |
ENDIF |
ENDIF |
510 |
JFAIL=0 |
JFAIL=0 |
511 |
CALL POSXYZ(AL_P,JFAIL) |
CALL POSXYZ(AL_P,JFAIL) |
512 |
IF(JFAIL.NE.0) THEN |
IF(JFAIL.NE.0) THEN |
513 |
PRINT *,'CHISQ ==> error from tracking routine POSXYZ !!' |
IF(TRKVERBOSE) |
514 |
|
$ PRINT *,'CHISQ ==> error from trk routine POSXYZ' |
515 |
IFAIL=1 |
IFAIL=1 |
516 |
RETURN |
RETURN |
517 |
ENDIF |
ENDIF |
542 |
|
|
543 |
COSTHE=DSQRT(1.-AL(3)**2) |
COSTHE=DSQRT(1.-AL(3)**2) |
544 |
IF(COSTHE.EQ.0.) THEN |
IF(COSTHE.EQ.0.) THEN |
545 |
PRINT *,'=== WARNING ===> COSTHE=0' |
IF(TRKVERBOSE)PRINT *,'=== WARNING ===> COSTHE=0' |
546 |
STOP |
IFAIL=1 |
547 |
|
RETURN |
548 |
ENDIF |
ENDIF |
549 |
|
|
550 |
DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3 |
DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3 |
628 |
|
|
629 |
include 'commontracker.f' !tracker general common |
include 'commontracker.f' !tracker general common |
630 |
include 'common_mini_2.f' !common for the tracking procedure |
include 'common_mini_2.f' !common for the tracking procedure |
631 |
|
|
632 |
|
c LOGICAL TRKVERBOSE |
633 |
|
c COMMON/TRKD/TRKVERBOSE |
634 |
|
LOGICAL TRKDEBUG,TRKVERBOSE |
635 |
|
COMMON/TRKD/TRKDEBUG,TRKVERBOSE |
636 |
c |
c |
637 |
DIMENSION AL_P(5) |
DIMENSION AL_P(5) |
638 |
* |
* |
652 |
VOUT(6)=-1.*DSQRT(1.-AL_P(3)**2) |
VOUT(6)=-1.*DSQRT(1.-AL_P(3)**2) |
653 |
IF(AL_P(5).NE.0.) VOUT(7)=DABS(1./AL_P(5)) |
IF(AL_P(5).NE.0.) VOUT(7)=DABS(1./AL_P(5)) |
654 |
IF(AL_P(5).EQ.0.) VOUT(7)=1.E8 |
IF(AL_P(5).EQ.0.) VOUT(7)=1.E8 |
655 |
|
|
656 |
|
c$$$ print*,'POSXY (prima) ',vout |
657 |
|
|
658 |
DO I=1,nplanes |
DO I=1,nplanes |
659 |
step=vout(3)-zv(i) |
step=vout(3)-zv(i) |
660 |
10 DO J=1,7 |
10 DO J=1,7 |
665 |
CALL GRKUTA(CHARGE,STEP,VECT,VOUT) |
CALL GRKUTA(CHARGE,STEP,VECT,VOUT) |
666 |
IF(VOUT(3).GT.VECT(3)) THEN |
IF(VOUT(3).GT.VECT(3)) THEN |
667 |
IFAIL=1 |
IFAIL=1 |
668 |
PRINT *,'posxy (grkuta): WARNING ===> backward track!!' |
if(TRKVERBOSE) |
669 |
print*,'charge',charge |
$ PRINT *,'posxy (grkuta): WARNING ===> backward track!!' |
670 |
print*,'vect',vect |
c$$$ if(.TRUE.)print*,'charge',charge |
671 |
print*,'vout',vout |
c$$$ if(.TRUE.)print*,'vect',vect |
672 |
print*,'step',step |
c$$$ if(.TRUE.)print*,'vout',vout |
673 |
|
c$$$ if(.TRUE.)print*,'step',step |
674 |
|
if(TRKVERBOSE)print*,'charge',charge |
675 |
|
if(TRKVERBOSE)print*,'vect',vect |
676 |
|
if(TRKVERBOSE)print*,'vout',vout |
677 |
|
if(TRKVERBOSE)print*,'step',step |
678 |
RETURN |
RETURN |
679 |
ENDIF |
ENDIF |
680 |
Z=VOUT(3) |
Z=VOUT(3) |
688 |
GOTO 11 |
GOTO 11 |
689 |
ENDIF |
ENDIF |
690 |
|
|
691 |
|
|
692 |
* ----------------------------------------------- |
* ----------------------------------------------- |
693 |
* evaluate track coordinates |
* evaluate track coordinates |
694 |
100 XV(I)=VOUT(1) |
100 XV(I)=VOUT(1) |
700 |
|
|
701 |
ENDDO |
ENDDO |
702 |
|
|
703 |
|
c$$$ print*,'POSXY (dopo) ',vout |
704 |
|
|
705 |
|
|
706 |
RETURN |
RETURN |
707 |
END |
END |
708 |
|
|
747 |
|
|
748 |
return |
return |
749 |
end |
end |
750 |
|
|
751 |
|
|
752 |
|
*************************************************** |
753 |
|
* * |
754 |
|
* * |
755 |
|
* * |
756 |
|
* * |
757 |
|
* * |
758 |
|
* * |
759 |
|
************************************************** |
760 |
|
|
761 |
|
subroutine guess() |
762 |
|
|
763 |
|
c IMPLICIT DOUBLE PRECISION (A-H,O-Z) |
764 |
|
|
765 |
|
include 'commontracker.f' !tracker general common |
766 |
|
include 'common_mini_2.f' !common for the tracking procedure |
767 |
|
|
768 |
|
REAL*4 XP(NPLANES),ZP(NPLANES),AP(NPLANES),RP(NPLANES) |
769 |
|
REAL*4 CHI,XC,ZC,RADIUS |
770 |
|
* ---------------------------------------- |
771 |
|
* Y view |
772 |
|
* ---------------------------------------- |
773 |
|
* ---------------------------------------- |
774 |
|
* initial guess with a straigth line |
775 |
|
* ---------------------------------------- |
776 |
|
SZZ=0. |
777 |
|
SZY=0. |
778 |
|
SSY=0. |
779 |
|
SZ=0. |
780 |
|
S1=0. |
781 |
|
DO I=1,nplanes |
782 |
|
IF(YGOOD(I).EQ.1)THEN |
783 |
|
YY = YM(I) |
784 |
|
IF(XGOOD(I).EQ.0)THEN |
785 |
|
YY = (YM_A(I) + YM_B(I))/2 |
786 |
|
ENDIF |
787 |
|
SZZ=SZZ+ZM(I)*ZM(I) |
788 |
|
SZY=SZY+ZM(I)*YY |
789 |
|
SSY=SSY+YY |
790 |
|
SZ=SZ+ZM(I) |
791 |
|
S1=S1+1. |
792 |
|
ENDIF |
793 |
|
ENDDO |
794 |
|
DET=SZZ*S1-SZ*SZ |
795 |
|
AY=(SZY*S1-SZ*SSY)/DET |
796 |
|
BY=(SZZ*SSY-SZY*SZ)/DET |
797 |
|
Y0 = AY*ZINI+BY |
798 |
|
* ---------------------------------------- |
799 |
|
* X view |
800 |
|
* ---------------------------------------- |
801 |
|
* ---------------------------------------- |
802 |
|
* 1) initial guess with a circle |
803 |
|
* ---------------------------------------- |
804 |
|
NP=0 |
805 |
|
DO I=1,nplanes |
806 |
|
IF(XGOOD(I).EQ.1)THEN |
807 |
|
XX = XM(I) |
808 |
|
IF(YGOOD(I).EQ.0)THEN |
809 |
|
XX = (XM_A(I) + XM_B(I))/2 |
810 |
|
ENDIF |
811 |
|
NP=NP+1 |
812 |
|
XP(NP)=XX |
813 |
|
ZP(NP)=ZM(I) |
814 |
|
ENDIF |
815 |
|
ENDDO |
816 |
|
IFLAG=0 !no debug mode |
817 |
|
CALL TRICIRCLE(NP,XP,ZP,AP,RP,CHI,XC,ZC,RADIUS,IFLAG) |
818 |
|
c print*,' circle: ',XC,ZC,RADIUS,' --- ',CHI,IFLAG |
819 |
|
IF(IFLAG.NE.0)GOTO 10 !straigth fit |
820 |
|
if(CHI.gt.100)GOTO 10 !straigth fit |
821 |
|
ARG = RADIUS**2-(ZINI-ZC)**2 |
822 |
|
IF(ARG.LT.0)GOTO 10 !straigth fit |
823 |
|
DC = SQRT(ARG) |
824 |
|
IF(XC.GT.0)DC=-DC |
825 |
|
X0=XC+DC |
826 |
|
AX = -(ZINI-ZC)/DC |
827 |
|
DEF=100./(RADIUS*0.3*0.43) |
828 |
|
IF(XC.GT.0)DEF=-DEF |
829 |
|
|
830 |
|
IF(ABS(X0).GT.30)THEN |
831 |
|
c$$$ PRINT*,'STRANGE GUESS: XC,ZC,R ',XC,ZC,RADIUS |
832 |
|
c$$$ $ ,' - CHI ',CHI,' - X0,AX,DEF ',X0,AX,DEF |
833 |
|
GOTO 10 !straigth fit |
834 |
|
ENDIF |
835 |
|
GOTO 20 !guess is ok |
836 |
|
|
837 |
|
* ---------------------------------------- |
838 |
|
* 2) initial guess with a straigth line |
839 |
|
* - if circle does not intersect reference plane |
840 |
|
* - if bad chi**2 |
841 |
|
* ---------------------------------------- |
842 |
|
10 CONTINUE |
843 |
|
SZZ=0. |
844 |
|
SZX=0. |
845 |
|
SSX=0. |
846 |
|
SZ=0. |
847 |
|
S1=0. |
848 |
|
DO I=1,nplanes |
849 |
|
IF(XGOOD(I).EQ.1)THEN |
850 |
|
XX = XM(I) |
851 |
|
IF(YGOOD(I).EQ.0)THEN |
852 |
|
XX = (XM_A(I) + XM_B(I))/2 |
853 |
|
ENDIF |
854 |
|
SZZ=SZZ+ZM(I)*ZM(I) |
855 |
|
SZX=SZX+ZM(I)*XX |
856 |
|
SSX=SSX+XX |
857 |
|
SZ=SZ+ZM(I) |
858 |
|
S1=S1+1. |
859 |
|
ENDIF |
860 |
|
ENDDO |
861 |
|
DET=SZZ*S1-SZ*SZ |
862 |
|
AX=(SZX*S1-SZ*SSX)/DET |
863 |
|
BX=(SZZ*SSX-SZX*SZ)/DET |
864 |
|
DEF = 0 |
865 |
|
X0 = AX*ZINI+BX |
866 |
|
|
867 |
|
20 CONTINUE |
868 |
|
* ---------------------------------------- |
869 |
|
* guess |
870 |
|
* ---------------------------------------- |
871 |
|
|
872 |
|
AL(1) = X0 |
873 |
|
AL(2) = Y0 |
874 |
|
tath = sqrt(AY**2+AX**2) |
875 |
|
AL(3) = tath/sqrt(1+tath**2) |
876 |
|
c$$$ IF(AX.NE.0)THEN |
877 |
|
c$$$ AL(4)= atan(AY/AX) |
878 |
|
c$$$ ELSE |
879 |
|
c$$$ AL(4) = acos(-1.)/2 |
880 |
|
c$$$ IF(AY.LT.0)AL(4) = AL(4)+acos(-1.) |
881 |
|
c$$$ ENDIF |
882 |
|
c$$$ IF(AX.LT.0)AL(4)= acos(-1.)+ AL(4) |
883 |
|
c$$$ AL(4) = -acos(-1.) + AL(4) !from incidence direction to tracking ref.sys. |
884 |
|
|
885 |
|
c$$$ AL(4) = 0. |
886 |
|
c$$$ IF(AX.NE.0.AND.AY.NE.0)THEN |
887 |
|
c$$$ AL(4)= atan(AY/AX) |
888 |
|
c$$$ ELSEIF(AY.EQ.0)THEN |
889 |
|
c$$$ AL(4) = 0. |
890 |
|
c$$$ IF(AX.LT.0)AL(4) = AL(4)+acos(-1.) |
891 |
|
c$$$ ELSEIF(AX.EQ.0)THEN |
892 |
|
c$$$ AL(4) = acos(-1.)/2 |
893 |
|
c$$$ IF(AY.LT.0)AL(4) = AL(4)+acos(-1.) |
894 |
|
c$$$ ENDIF |
895 |
|
c$$$ IF(AX.LT.0)AL(4)= acos(-1.)+ AL(4) |
896 |
|
c$$$ AL(4) = -acos(-1.) + AL(4) !from incidence direction to tracking ref.sys. |
897 |
|
|
898 |
|
c$$$ AL(4)=0. |
899 |
|
c$$$ IF( AX.NE.0.OR.AY.NE.0. ) THEN |
900 |
|
c$$$ AL(4) = ASIN(AY/SQRT(AX**2+AY**2)) |
901 |
|
c$$$ IF(AX.LT.0.) AL(4) = ACOS(-1.0)-AL(4) |
902 |
|
c$$$ ENDIF |
903 |
|
|
904 |
|
AL(4)=0. |
905 |
|
IF( AX.NE.0.OR.AY.NE.0. ) THEN |
906 |
|
AL(4) = ASIN(AY/SQRT(AX**2+AY**2)) |
907 |
|
IF(AX.LT.0.AND.AY.GE.0) AL(4) = ACOS(-1.0)-AL(4) |
908 |
|
IF(AX.LT.0.AND.AY.LT.0) AL(4) = -ACOS(-1.0)-AL(4) |
909 |
|
ENDIF |
910 |
|
IF(AY.GT.0.) AL(4) = AL(4)-ACOS(-1.0) |
911 |
|
IF(AY.LE.0.) AL(4) = AL(4)+ACOS(-1.0) |
912 |
|
|
913 |
|
AL(5) = DEF |
914 |
|
|
915 |
|
c print*,' guess: ',(al(i),i=1,5) |
916 |
|
|
917 |
|
end |