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