/[PAMELA software]/DarthVader/TrackerLevel2/src/F77/mini.f
ViewVC logotype

Annotation of /DarthVader/TrackerLevel2/src/F77/mini.f

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations) (download)
Mon Feb 19 16:28:39 2007 UTC (17 years, 9 months ago) by pam-fi
Branch: MAIN
Changes since 1.12: +7 -0 lines
added TRACKMOD parameter

1 mocchiut 1.1 ************************************************************************
2     *
3     * subroutine to evaluate the vector alfa (AL)
4     * which minimizes CHI^2
5     *
6     * - modified from mini.f in order to call differente chi^2 routine.
7     * The new one includes also single clusters: in this case
8     * the residual is defined as the distance between the track and the
9     * segment AB associated to the single cluster.
10     *
11     *
12     ************************************************************************
13    
14    
15 pam-fi 1.3 SUBROUTINE MINI2(ISTEP,IFAIL,IPRINT)
16 mocchiut 1.1
17     IMPLICIT DOUBLE PRECISION (A-H,O-Z)
18    
19     include 'commontracker.f' !tracker general common
20     include 'common_mini_2.f' !common for the tracking procedure
21    
22 pam-fi 1.2 c logical DEBUG
23     c common/dbg/DEBUG
24 mocchiut 1.1
25 pam-fi 1.4 parameter (dinf=1.d15) !just a huge number...
26 mocchiut 1.1 c------------------------------------------------------------------------
27     c variables used in the tracking procedure (mini and its subroutines)
28     c
29     c N.B.: in mini & C. (and in the following block of variables too)
30     c the plane ordering is reversed in respect of normal
31     c ordering, but they maintain their Z coordinates. so plane number 1 is
32     c the first one that a particle meets, and its Z coordinate is > 0
33     c------------------------------------------------------------------------
34 pam-fi 1.3 DATA ZINI/23.5/ !!! ***PP*** to be changed !z coordinate of the reference plane
35 mocchiut 1.1
36 pam-fi 1.3 c DATA XGOOD,YGOOD/nplanes*1.,nplanes*1./ !planes to be used in the tracking
37 mocchiut 1.1
38     DATA STEPAL/5*1.d-7/ !alpha vector step
39 pam-fi 1.7 DATA ISTEPMAX/100/ !maximum number of steps in the chi^2 minimization
40 mocchiut 1.1 DATA TOLL/1.d-8/ !tolerance in reaching the next plane during
41     * !the tracking procedure
42     DATA STEPMAX/100./ !maximum number of steps in the trackin gprocess
43    
44 pam-fi 1.8 c DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components
45     c DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !"
46 pam-fi 1.10 DATA ALMAX/dinf,dinf,1.,dinf,dinf/ !limits on alpha vector components
47     DATA ALMIN/-dinf,-dinf,-1.,-dinf,-dinf/ !"
48 mocchiut 1.1
49     DIMENSION DAL(5) !increment of vector alfa
50 pam-fi 1.3 DIMENSION CHI2DD_R(4,4),CHI2D_R(4) !hessiano e gradiente di chi2
51 pam-fi 1.4
52     c elena--------
53     REAL*8 AVRESX,AVRESY
54     c elena--------
55    
56 mocchiut 1.1 INTEGER IFLAG
57     c--------------------------------------------------------
58     c IFLAG =1 ---- chi2 derivatives computed by using
59     c incremental ratios and posxyz.f
60     c IFLAG =2 ---- the approximation of Golden is used
61     c (see chisq.f)
62     c
63     c NB: the two metods gives equivalent results BUT
64     c method 2 is faster!!
65     c--------------------------------------------------------
66 pam-fi 1.3 DATA IFLAG/2/
67    
68 pam-fi 1.4 c LOGICAL TRKDEBUG,TRKVERBOSE
69     c COMMON/TRKD/TRKDEBUG,TRKVERBOSE
70     LOGICAL TRKDEBUG,TRKVERBOSE
71     COMMON/TRKD/TRKDEBUG,TRKVERBOSE
72 pam-fi 1.3
73     IF(IPRINT.EQ.1) THEN
74 pam-fi 1.4 TRKVERBOSE = .TRUE.
75     TRKDEBUG = .FALSE.
76     ELSEIF(IPRINT.EQ.2)THEN
77     TRKVERBOSE = .TRUE.
78     TRKDEBUG = .TRUE.
79 pam-fi 1.3 ELSE
80 pam-fi 1.4 TRKVERBOSE = .FALSE.
81     TRKDEBUG = .FALSE.
82 pam-fi 1.3 ENDIF
83 mocchiut 1.1
84     * ----------------------------------------------------------
85 pam-fi 1.4 * 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 mocchiut 1.1 * define ALTOL(5) ---> tolerances on state vector
104     *
105     * ----------------------------------------------------------
106 pam-fi 1.4 * changed in order to evaluate energy-dependent
107     * tolerances on all 5 parameters
108     FACT=100. !scale factor to define tolerance on alfa
109 mocchiut 1.1 c deflection error (see PDG)
110 pam-fi 1.4 DELETA1 = 0.01/0.3/0.4/0.4451**2*SQRT(720./(6.+4.))
111     DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36)
112     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)
118     c$$$ DELETA1 = 0.01*AVRESX/0.3/0.4/0.4451**2*SQRT(720./(6.+4.))
119     c$$$ DELETA2 = 0.016/0.3/0.4/0.4451*SQRT(0.4451/9.36)
120 mocchiut 1.1 * ----------------------------------------------------------
121     *
122     ISTEP=0 !num. steps to minimize chi^2
123     JFAIL=0 !error flag
124 pam-fi 1.12 CHI2=0
125 pam-fi 1.4
126 pam-fi 1.5 if(TRKDEBUG) print*,'guess: ',al
127 pam-fi 1.4 if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5)
128    
129 pam-fi 1.3 *
130     * -----------------------
131     * START MINIMIZATION LOOP
132     * -----------------------
133     10 ISTEP=ISTEP+1 !<<<<<<<<<<<<<< NEW STEP !!
134    
135 mocchiut 1.1 CALL CHISQ(IFLAG,JFAIL) !chi^2 and its derivatives
136     IF(JFAIL.NE.0) THEN
137     IFAIL=1
138 pam-fi 1.3 CHI2=-9999.
139 pam-fi 1.4 if(TRKVERBOSE)
140 pam-fi 1.3 $ PRINT *,'*** ERROR in mini *** wrong CHISQ'
141 mocchiut 1.1 RETURN
142     ENDIF
143 pam-fi 1.3
144 pam-fi 1.10 COST=1e-5
145 mocchiut 1.1 DO I=1,5
146     DO J=1,5
147     CHI2DD(I,J)=CHI2DD(I,J)*COST
148     ENDDO
149     CHI2D(I)=CHI2D(I)*COST
150     ENDDO
151 pam-fi 1.3
152     IF(PFIXED.EQ.0.) THEN
153    
154 mocchiut 1.1 *------------------------------------------------------------*
155     * track fitting with FREE deflection
156     *------------------------------------------------------------*
157 pam-fi 1.3 CALL DSFACT(5,CHI2DD,5,IFA,DET,JFA) !CHI2DD matrix determinant
158 pam-fi 1.7 IF(IFA.NE.0) THEN !not positive-defined
159     if(TRKVERBOSE)then
160 pam-fi 1.3 PRINT *,
161     $ '*** ERROR in mini ***'//
162     $ 'on matrix inversion (not pos-def)'
163     $ ,DET
164 pam-fi 1.7 endif
165     IF(CHI2.EQ.0) CHI2=-9999.
166     IF(CHI2.GT.0) CHI2=-CHI2
167     IFAIL=1
168     RETURN
169 pam-fi 1.3 ENDIF
170     CALL DSFINV(5,CHI2DD,5) !CHI2DD matrix inversion
171     * *******************************************
172     * find new value of AL-pha
173 pam-fi 1.4 * *******************************************
174 pam-fi 1.3 DO I=1,5
175     DAL(I)=0.
176     DO J=1,5
177     DAL(I)=DAL(I)-CHI2DD(I,J)*CHI2D(J)
178     COV(I,J)=2.*COST*CHI2DD(I,J)
179     ENDDO
180     ENDDO
181     DO I=1,5
182     AL(I)=AL(I)+DAL(I)
183     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 pam-fi 1.4 if(TRKVERBOSE)then
198 pam-fi 1.3 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 pam-fi 1.4 * *******************************************
210     * find new value of AL-pha
211     * *******************************************
212 pam-fi 1.3 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 mocchiut 1.1 ENDIF
224 pam-fi 1.4
225     if(TRKDEBUG) print*,'mini2: step ',istep,chi2,1./AL(5)
226    
227 pam-fi 1.3 *------------------------------------------------------------*
228     * ---------------------------------------------------- *
229     *------------------------------------------------------------*
230 mocchiut 1.1 * check parameter bounds:
231 pam-fi 1.4 *------------------------------------------------------------*
232 mocchiut 1.1 DO I=1,5
233     IF(AL(I).GT.ALMAX(I).OR.AL(I).LT.ALMIN(I))THEN
234 pam-fi 1.4 if(TRKVERBOSE)then
235 pam-fi 1.3 PRINT*,' *** WARNING in mini *** '
236 mocchiut 1.1 PRINT*,'MINI_2 ==> AL(',I,') out of range'
237     PRINT*,' value: ',AL(I),
238     $ ' limits: ',ALMIN(I),ALMAX(I)
239     print*,'istep ',istep
240     endif
241 pam-fi 1.3 IF(CHI2.EQ.0) CHI2=-9999.
242     IF(CHI2.GT.0) CHI2=-CHI2
243 mocchiut 1.1 IFAIL=1
244     RETURN
245     ENDIF
246     ENDDO
247 pam-fi 1.4 *------------------------------------------------------------*
248 mocchiut 1.1 * check number of steps:
249 pam-fi 1.4 *------------------------------------------------------------*
250     IF(ISTEP.ge.ISTEPMAX) then
251 pam-fi 1.7 c$$$ IFAIL=1
252     c$$$ if(TRKVERBOSE)
253     c$$$ $ PRINT *,'*** WARNING in mini *** ISTEP.GT.ISTEPMAX=',
254     c$$$ $ ISTEPMAX
255 mocchiut 1.1 goto 11
256     endif
257 pam-fi 1.4 *------------------------------------------------------------*
258 mocchiut 1.1 * ---------------------------------------------
259     * evaluate deflection tolerance on the basis of
260     * estimated deflection
261     * ---------------------------------------------
262 pam-fi 1.4 *------------------------------------------------------------*
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 mocchiut 1.1 *---- check tolerances:
271 pam-fi 1.4 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 pam-fi 1.11 IF(ISTEP.LT.3) GOTO 10 ! ***PP***
277 mocchiut 1.1 DO I=1,5
278     IF(ABS(DAL(I)).GT.ALTOL(I))GOTO 10 !>>>> new step!
279     ENDDO
280    
281 pam-fi 1.3 * 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 pam-fi 1.4 if(TRKVERBOSE)THEN
287 pam-fi 1.3 CHI2=-9999.
288 pam-fi 1.4 if(TRKVERBOSE)
289 pam-fi 1.3 $ 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 pam-fi 1.4 if(TRKVERBOSE)then
304 pam-fi 1.3 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 pam-fi 1.4 if(TRKVERBOSE)then
331 pam-fi 1.3 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 mocchiut 1.1
351     * ------------------------------------
352     * Number of Degree Of Freedom
353     ndof=0
354     do ip=1,nplanes
355     ndof=ndof
356     $ +int(xgood(ip))
357     $ +int(ygood(ip))
358     enddo
359 pam-fi 1.3 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 pam-fi 1.4 if(TRKVERBOSE)
364 pam-fi 1.3 $ print*,'*** WARNING *** in mini n.dof = 0 (set to 1)'
365     endif
366 pam-fi 1.4
367     if(TRKDEBUG) print*,'mini2: -ok- ',istep,chi2,1./AL(5)
368    
369 mocchiut 1.1 * ------------------------------------
370     * Reduced chi^2
371     CHI2 = CHI2/dble(ndof)
372    
373 pam-fi 1.4 c print*,'mini2: chi2 ',chi2
374    
375 mocchiut 1.1 11 CONTINUE
376    
377 pam-fi 1.3 NSTEP=ISTEP ! ***PP***
378 mocchiut 1.1
379     RETURN
380     END
381    
382     ******************************************************************************
383     *
384     * routine to compute chi^2 and its derivatives
385     *
386     *
387     * (modified in respect to the previous one in order to include
388     * single clusters. In this case the residual is evaluated by
389     * calculating the distance between the track intersection and the
390     * segment AB associated to the single cluster)
391     *
392     ******************************************************************************
393    
394     SUBROUTINE CHISQ(IFLAG,IFAIL)
395    
396     IMPLICIT DOUBLE PRECISION (A-H,O-Z)
397    
398     include 'commontracker.f' !tracker general common
399     include 'common_mini_2.f' !common for the tracking procedure
400    
401     DIMENSION XV2(nplanes),YV2(nplanes),XV1(nplanes),YV1(nplanes)
402     $ ,XV0(nplanes),YV0(nplanes)
403     DIMENSION AL_P(5)
404 pam-fi 1.3
405 pam-fi 1.4 c LOGICAL TRKVERBOSE
406     c COMMON/TRKD/TRKVERBOSE
407     LOGICAL TRKDEBUG,TRKVERBOSE
408     COMMON/TRKD/TRKDEBUG,TRKVERBOSE
409 mocchiut 1.1 *
410     * chi^2 computation
411     *
412     DO I=1,5
413     AL_P(I)=AL(I)
414     ENDDO
415     JFAIL=0 !error flag
416     CALL POSXYZ(AL_P,JFAIL) !track intersection with tracking planes
417     IF(JFAIL.NE.0) THEN
418 pam-fi 1.4 IF(TRKVERBOSE)
419 pam-fi 1.3 $ PRINT *,'CHISQ ==> error from trk routine POSXYZ !!'
420 mocchiut 1.1 IFAIL=1
421     RETURN
422     ENDIF
423     DO I=1,nplanes
424     XV0(I)=XV(I)
425     YV0(I)=YV(I)
426     ENDDO
427     * ------------------------------------------------
428     c$$$ CHI2=0.
429     c$$$ DO I=1,nplanes
430     c$$$ CHI2=CHI2
431     c$$$ + +(XV(I)-XM(I))**2/RESX(i)**2 *XGOOD(I)*YGOOD(I)
432     c$$$ + +(YV(I)-YM(I))**2/RESY(i)**2 *YGOOD(I)*XGOOD(I)
433     c$$$ ENDDO
434     * ---------------------------------------------------------
435     * For planes with only a X or Y-cl included, instead of
436     * a X-Y couple, the residual for chi^2 calculation is
437     * evaluated by finding the point x-y, along the segment AB,
438     * closest to the track.
439     * The X or Y coordinate, respectivelly for X and Y-cl, is
440     * then assigned to XM or YM, which is then considered the
441     * measured position of the cluster.
442     * ---------------------------------------------------------
443     CHI2=0.
444     DO I=1,nplanes
445     IF(XGOOD(I).EQ.1.AND.YGOOD(I).EQ.0)THEN !X-cl
446     BETA = (XM_B(I)-XM_A(I))/(YM_B(I)-YM_A(I))
447     ALFA = XM_A(I) - BETA * YM_A(I)
448     YM(I) = ( YV(I) + BETA*XV(I) - BETA*ALFA )/(1+BETA**2)
449     if(YM(I).lt.dmin1(YM_A(I),YM_B(I)))
450     $ YM(I)=dmin1(YM_A(I),YM_B(I))
451     if(YM(I).gt.dmax1(YM_A(I),YM_B(I)))
452     $ YM(I)=dmax1(YM_A(I),YM_B(I))
453     XM(I) = ALFA + BETA * YM(I) !<<<< measured coordinates
454     ELSEIF(XGOOD(I).EQ.0.AND.YGOOD(I).EQ.1)THEN !Y-cl
455     BETA = (YM_B(I)-YM_A(I))/(XM_B(I)-XM_A(I))
456     ALFA = YM_A(I) - BETA * XM_A(I)
457     XM(I) = ( XV(I) + BETA*YV(I) - BETA*ALFA )/(1+BETA**2)
458     if(XM(I).lt.dmin1(XM_A(I),XM_B(I)))
459     $ XM(I)=dmin1(XM_A(I),XM_B(I))
460     if(XM(I).gt.dmax1(XM_A(I),XM_B(I)))
461     $ XM(I)=dmax1(XM_A(I),XM_B(I))
462     YM(I) = ALFA + BETA * XM(I) !<<<< measured coordinates
463     ENDIF
464     CHI2=CHI2
465     + +(XV(I)-XM(I))**2/RESX(i)**2 *( XGOOD(I)*YGOOD(I) )
466     + +(YV(I)-YM(I))**2/RESY(i)**2 *( YGOOD(I)*XGOOD(I) )
467     + +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESX(i)**2
468     + *( XGOOD(I)*(1-YGOOD(I)) )
469     + +((XV(I)-XM(I))**2+(YV(I)-YM(I))**2)/RESY(i)**2
470     + *( (1-XGOOD(I))*YGOOD(I) )
471 pam-fi 1.10 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 mocchiut 1.1 ENDDO
480 pam-fi 1.10 c$$$ print*,'CHISQ ',chi2
481 mocchiut 1.1 * ------------------------------------------------
482     *
483     * calculation of derivatives (dX/dAL_fa and dY/dAL_fa)
484     *
485     * //////////////////////////////////////////////////
486     * METHOD 1 -- incremental ratios
487     * //////////////////////////////////////////////////
488    
489     IF(IFLAG.EQ.1) THEN
490    
491     DO J=1,5
492     DO JJ=1,5
493     AL_P(JJ)=AL(JJ)
494     ENDDO
495     AL_P(J)=AL_P(J)+STEPAL(J)/2.
496     JFAIL=0
497     CALL POSXYZ(AL_P,JFAIL)
498     IF(JFAIL.NE.0) THEN
499 pam-fi 1.4 IF(TRKVERBOSE)
500 pam-fi 1.3 *23456789012345678901234567890123456789012345678901234567890123456789012
501     $ PRINT *,'CHISQ ==> error from trk routine POSXYZ'
502 mocchiut 1.1 IFAIL=1
503     RETURN
504     ENDIF
505     DO I=1,nplanes
506     XV2(I)=XV(I)
507     YV2(I)=YV(I)
508     ENDDO
509     AL_P(J)=AL_P(J)-STEPAL(J)
510     JFAIL=0
511     CALL POSXYZ(AL_P,JFAIL)
512     IF(JFAIL.NE.0) THEN
513 pam-fi 1.4 IF(TRKVERBOSE)
514 pam-fi 1.3 $ PRINT *,'CHISQ ==> error from trk routine POSXYZ'
515 mocchiut 1.1 IFAIL=1
516     RETURN
517     ENDIF
518     DO I=1,nplanes
519     XV1(I)=XV(I)
520     YV1(I)=YV(I)
521     ENDDO
522     DO I=1,nplanes
523     DXDAL(I,J)=(XV2(I)-XV1(I))/STEPAL(J)
524     DYDAL(I,J)=(YV2(I)-YV1(I))/STEPAL(J)
525     ENDDO
526     ENDDO
527    
528     ENDIF
529    
530     * //////////////////////////////////////////////////
531     * METHOD 2 -- Bob Golden
532     * //////////////////////////////////////////////////
533    
534     IF(IFLAG.EQ.2) THEN
535    
536     DO I=1,nplanes
537     DXDAL(I,1)=1.
538     DYDAL(I,1)=0.
539    
540     DXDAL(I,2)=0.
541     DYDAL(I,2)=1.
542    
543     COSTHE=DSQRT(1.-AL(3)**2)
544     IF(COSTHE.EQ.0.) THEN
545 pam-fi 1.4 IF(TRKVERBOSE)PRINT *,'=== WARNING ===> COSTHE=0'
546 pam-fi 1.3 IFAIL=1
547     RETURN
548 mocchiut 1.1 ENDIF
549    
550     DXDAL(I,3)=(ZINI-ZM(I))*DCOS(AL(4))/COSTHE**3
551     DYDAL(I,3)=(ZINI-ZM(I))*DSIN(AL(4))/COSTHE**3
552    
553     DXDAL(I,4)=-AL(3)*(ZINI-ZM(I))*DSIN(AL(4))/COSTHE
554     DYDAL(I,4)=AL(3)*(ZINI-ZM(I))*DCOS(AL(4))/COSTHE
555    
556     IF(AL(5).NE.0.) THEN
557     DXDAL(I,5)=
558     + (XV(I)-(AL(1)+AL(3)/COSTHE*(ZINI-ZM(I))
559     + *DCOS(AL(4))))/AL(5)
560     DYDAL(I,5)=
561     + (YV(I)-(AL(2)+AL(3)/COSTHE*(ZINI-ZM(I))
562     + *DSIN(AL(4))))/AL(5)
563     ELSE
564     DXDAL(I,5)=100.*( 0.25 *0.3*0.4*(0.01*(ZINI-ZM(I)))**2 )
565     DYDAL(I,5)=0.
566     ENDIF
567    
568     ENDDO
569     ENDIF
570     *
571     * x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x
572     * >>> CHI2D evaluation
573     *
574     DO J=1,5
575     CHI2D(J)=0.
576     DO I=1,nplanes
577     CHI2D(J)=CHI2D(J)
578     + +2.*(XV0(I)-XM(I))/RESX(i)**2*DXDAL(I,J) *XGOOD(I)
579     + +2.*(YV0(I)-YM(I))/RESY(i)**2*DYDAL(I,J) *YGOOD(I)
580     ENDDO
581     ENDDO
582     *
583     * >>> CHI2DD evaluation
584     *
585     DO I=1,5
586     DO J=1,5
587     CHI2DD(I,J)=0.
588     DO K=1,nplanes
589     CHI2DD(I,J)=CHI2DD(I,J)
590     + +2.*DXDAL(K,I)*DXDAL(K,J)/RESX(k)**2 *XGOOD(K)
591     + +2.*DYDAL(K,I)*DYDAL(K,J)/RESY(k)**2 *YGOOD(K)
592     ENDDO
593     ENDDO
594     ENDDO
595     * x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x
596    
597     RETURN
598     END
599    
600    
601     *****************************************************************
602     *
603     * Routine to compute the track intersection points
604     * on the tracking-system planes, given the track parameters
605     *
606     * The routine is based on GRKUTA, which computes the
607     * trajectory of a charged particle in a magnetic field
608     * by solving the equatins of motion with Runge-Kuta method.
609     *
610     * Variables that have to be assigned when the subroutine
611     * is called are:
612     *
613     * ZM(1,NPLANES) ----> z coordinates of the planes
614     * AL_P(1,5) ----> track-parameter vector
615     *
616     * -----------------------------------------------------------
617     * NB !!!
618     * The routine works properly only if the
619     * planes are numbered in descending order starting from the
620     * reference plane (ZINI)
621     * -----------------------------------------------------------
622     *
623     *****************************************************************
624    
625     SUBROUTINE POSXYZ(AL_P,IFAIL)
626    
627     IMPLICIT DOUBLE PRECISION (A-H,O-Z)
628    
629     include 'commontracker.f' !tracker general common
630     include 'common_mini_2.f' !common for the tracking procedure
631 pam-fi 1.3
632 pam-fi 1.4 c LOGICAL TRKVERBOSE
633     c COMMON/TRKD/TRKVERBOSE
634     LOGICAL TRKDEBUG,TRKVERBOSE
635     COMMON/TRKD/TRKDEBUG,TRKVERBOSE
636 mocchiut 1.1 c
637     DIMENSION AL_P(5)
638     *
639     DO I=1,nplanes
640     ZV(I)=ZM(I) !
641     ENDDO
642     *
643     * set parameters for GRKUTA
644     *
645     IF(AL_P(5).NE.0) CHARGE=AL_P(5)/DABS(AL_P(5))
646     IF(AL_P(5).EQ.0) CHARGE=1.
647     VOUT(1)=AL_P(1)
648     VOUT(2)=AL_P(2)
649     VOUT(3)=ZINI ! DBLE(Z0)-DBLE(ZSPEC)
650     VOUT(4)=AL_P(3)*DCOS(AL_P(4))
651     VOUT(5)=AL_P(3)*DSIN(AL_P(4))
652     VOUT(6)=-1.*DSQRT(1.-AL_P(3)**2)
653     IF(AL_P(5).NE.0.) VOUT(7)=DABS(1./AL_P(5))
654     IF(AL_P(5).EQ.0.) VOUT(7)=1.E8
655 pam-fi 1.5
656 pam-fi 1.10 c$$$ print*,'POSXY (prima) ',vout
657 pam-fi 1.5
658 mocchiut 1.1 DO I=1,nplanes
659     step=vout(3)-zv(i)
660     10 DO J=1,7
661     VECT(J)=VOUT(J)
662     VECTINI(J)=VOUT(J)
663     ENDDO
664     11 continue
665     CALL GRKUTA(CHARGE,STEP,VECT,VOUT)
666     IF(VOUT(3).GT.VECT(3)) THEN
667     IFAIL=1
668 pam-fi 1.4 if(TRKVERBOSE)
669 pam-fi 1.2 $ PRINT *,'posxy (grkuta): WARNING ===> backward track!!'
670 pam-fi 1.4 c$$$ if(.TRUE.)print*,'charge',charge
671     c$$$ if(.TRUE.)print*,'vect',vect
672     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 mocchiut 1.1 RETURN
679     ENDIF
680     Z=VOUT(3)
681     IF(Z.LE.ZM(I)+TOLL.AND.Z.GE.ZM(I)-TOLL) GOTO 100
682     IF(Z.GT.ZM(I)+TOLL) GOTO 10
683     IF(Z.LE.ZM(I)-TOLL) THEN
684     STEP=STEP*(ZM(I)-VECT(3))/(Z-VECT(3))
685     DO J=1,7
686     VECT(J)=VECTINI(J)
687     ENDDO
688     GOTO 11
689     ENDIF
690    
691 pam-fi 1.10
692 mocchiut 1.1 * -----------------------------------------------
693     * evaluate track coordinates
694     100 XV(I)=VOUT(1)
695     YV(I)=VOUT(2)
696     ZV(I)=VOUT(3)
697     AXV(I)=DATAN(VOUT(4)/VOUT(6))*180./ACOS(-1.)
698     AYV(I)=DATAN(VOUT(5)/VOUT(6))*180./ACOS(-1.)
699     * -----------------------------------------------
700    
701 pam-fi 1.13 IF(TRACKMODE.EQ.1) THEN
702     * -----------------------------------------------
703     * change of energy by bremsstrahlung for electrons
704     VOUT(7) = VOUT(7) * 0.997 !0.9968
705     * -----------------------------------------------
706     ENDIF
707    
708 mocchiut 1.1 ENDDO
709    
710 pam-fi 1.10 c$$$ print*,'POSXY (dopo) ',vout
711    
712    
713 mocchiut 1.1 RETURN
714     END
715    
716    
717    
718    
719    
720     * **********************************************************
721     * Some initialization routines
722     * **********************************************************
723    
724     * ----------------------------------------------------------
725     * Routine to initialize COMMON/TRACK/
726     *
727     subroutine track_init
728    
729     IMPLICIT DOUBLE PRECISION (A-H,O-Z)
730    
731     include 'commontracker.f' !tracker general common
732     include 'common_mini_2.f' !common for the tracking procedure
733     include 'common_mech.f'
734    
735     do i=1,5
736     AL(i) = 0.
737     enddo
738    
739     do ip=1,NPLANES
740     ZM(IP) = fitz(nplanes-ip+1) !init to mech. position
741     XM(IP) = -100. !0.
742     YM(IP) = -100. !0.
743     XM_A(IP) = -100. !0.
744     YM_A(IP) = -100. !0.
745     c ZM_A(IP) = 0
746     XM_B(IP) = -100. !0.
747     YM_B(IP) = -100. !0.
748     c ZM_B(IP) = 0
749     RESX(IP) = 1000. !3.d-4
750     RESY(IP) = 1000. !12.d-4
751     XGOOD(IP) = 0
752     YGOOD(IP) = 0
753     enddo
754    
755     return
756     end
757 pam-fi 1.4
758    
759     ***************************************************
760     * *
761     * *
762     * *
763     * *
764     * *
765     * *
766     **************************************************
767    
768     subroutine guess()
769    
770     c IMPLICIT DOUBLE PRECISION (A-H,O-Z)
771    
772     include 'commontracker.f' !tracker general common
773     include 'common_mini_2.f' !common for the tracking procedure
774    
775     REAL*4 XP(NPLANES),ZP(NPLANES),AP(NPLANES),RP(NPLANES)
776     REAL*4 CHI,XC,ZC,RADIUS
777     * ----------------------------------------
778     * Y view
779     * ----------------------------------------
780     * ----------------------------------------
781     * initial guess with a straigth line
782     * ----------------------------------------
783     SZZ=0.
784     SZY=0.
785     SSY=0.
786     SZ=0.
787     S1=0.
788     DO I=1,nplanes
789     IF(YGOOD(I).EQ.1)THEN
790     YY = YM(I)
791     IF(XGOOD(I).EQ.0)THEN
792     YY = (YM_A(I) + YM_B(I))/2
793     ENDIF
794     SZZ=SZZ+ZM(I)*ZM(I)
795     SZY=SZY+ZM(I)*YY
796     SSY=SSY+YY
797     SZ=SZ+ZM(I)
798     S1=S1+1.
799     ENDIF
800     ENDDO
801     DET=SZZ*S1-SZ*SZ
802     AY=(SZY*S1-SZ*SSY)/DET
803     BY=(SZZ*SSY-SZY*SZ)/DET
804     Y0 = AY*ZINI+BY
805     * ----------------------------------------
806     * X view
807     * ----------------------------------------
808     * ----------------------------------------
809     * 1) initial guess with a circle
810     * ----------------------------------------
811     NP=0
812     DO I=1,nplanes
813     IF(XGOOD(I).EQ.1)THEN
814     XX = XM(I)
815     IF(YGOOD(I).EQ.0)THEN
816     XX = (XM_A(I) + XM_B(I))/2
817     ENDIF
818     NP=NP+1
819     XP(NP)=XX
820     ZP(NP)=ZM(I)
821     ENDIF
822     ENDDO
823 pam-fi 1.9 IFLAG=0 !no debug mode
824 pam-fi 1.4 CALL TRICIRCLE(NP,XP,ZP,AP,RP,CHI,XC,ZC,RADIUS,IFLAG)
825 pam-fi 1.9 c print*,' circle: ',XC,ZC,RADIUS,' --- ',CHI,IFLAG
826 pam-fi 1.4 IF(IFLAG.NE.0)GOTO 10 !straigth fit
827 pam-fi 1.8 if(CHI.gt.100)GOTO 10 !straigth fit
828 pam-fi 1.4 ARG = RADIUS**2-(ZINI-ZC)**2
829     IF(ARG.LT.0)GOTO 10 !straigth fit
830     DC = SQRT(ARG)
831     IF(XC.GT.0)DC=-DC
832     X0=XC+DC
833     AX = -(ZINI-ZC)/DC
834     DEF=100./(RADIUS*0.3*0.43)
835     IF(XC.GT.0)DEF=-DEF
836 pam-fi 1.8
837     IF(ABS(X0).GT.30)THEN
838 pam-fi 1.10 c$$$ PRINT*,'STRANGE GUESS: XC,ZC,R ',XC,ZC,RADIUS
839     c$$$ $ ,' - CHI ',CHI,' - X0,AX,DEF ',X0,AX,DEF
840 pam-fi 1.8 GOTO 10 !straigth fit
841     ENDIF
842 pam-fi 1.4 GOTO 20 !guess is ok
843    
844     * ----------------------------------------
845     * 2) initial guess with a straigth line
846     * - if circle does not intersect reference plane
847     * - if bad chi**2
848     * ----------------------------------------
849     10 CONTINUE
850     SZZ=0.
851     SZX=0.
852     SSX=0.
853     SZ=0.
854     S1=0.
855     DO I=1,nplanes
856     IF(XGOOD(I).EQ.1)THEN
857     XX = XM(I)
858     IF(YGOOD(I).EQ.0)THEN
859     XX = (XM_A(I) + XM_B(I))/2
860     ENDIF
861     SZZ=SZZ+ZM(I)*ZM(I)
862     SZX=SZX+ZM(I)*XX
863     SSX=SSX+XX
864     SZ=SZ+ZM(I)
865     S1=S1+1.
866     ENDIF
867     ENDDO
868     DET=SZZ*S1-SZ*SZ
869     AX=(SZX*S1-SZ*SSX)/DET
870     BX=(SZZ*SSX-SZX*SZ)/DET
871     DEF = 0
872     X0 = AX*ZINI+BX
873    
874     20 CONTINUE
875     * ----------------------------------------
876     * guess
877     * ----------------------------------------
878    
879     AL(1) = X0
880     AL(2) = Y0
881     tath = sqrt(AY**2+AX**2)
882     AL(3) = tath/sqrt(1+tath**2)
883 pam-fi 1.10 c$$$ IF(AX.NE.0)THEN
884     c$$$ AL(4)= atan(AY/AX)
885     c$$$ ELSE
886     c$$$ AL(4) = acos(-1.)/2
887     c$$$ IF(AY.LT.0)AL(4) = AL(4)+acos(-1.)
888     c$$$ ENDIF
889     c$$$ IF(AX.LT.0)AL(4)= acos(-1.)+ AL(4)
890     c$$$ AL(4) = -acos(-1.) + AL(4) !from incidence direction to tracking ref.sys.
891    
892     c$$$ AL(4) = 0.
893     c$$$ IF(AX.NE.0.AND.AY.NE.0)THEN
894     c$$$ AL(4)= atan(AY/AX)
895     c$$$ ELSEIF(AY.EQ.0)THEN
896     c$$$ AL(4) = 0.
897     c$$$ IF(AX.LT.0)AL(4) = AL(4)+acos(-1.)
898     c$$$ ELSEIF(AX.EQ.0)THEN
899     c$$$ AL(4) = acos(-1.)/2
900     c$$$ IF(AY.LT.0)AL(4) = AL(4)+acos(-1.)
901     c$$$ ENDIF
902     c$$$ IF(AX.LT.0)AL(4)= acos(-1.)+ AL(4)
903     c$$$ AL(4) = -acos(-1.) + AL(4) !from incidence direction to tracking ref.sys.
904    
905     c$$$ AL(4)=0.
906     c$$$ IF( AX.NE.0.OR.AY.NE.0. ) THEN
907     c$$$ AL(4) = ASIN(AY/SQRT(AX**2+AY**2))
908     c$$$ IF(AX.LT.0.) AL(4) = ACOS(-1.0)-AL(4)
909     c$$$ ENDIF
910    
911     AL(4)=0.
912     IF( AX.NE.0.OR.AY.NE.0. ) THEN
913     AL(4) = ASIN(AY/SQRT(AX**2+AY**2))
914     IF(AX.LT.0.AND.AY.GE.0) AL(4) = ACOS(-1.0)-AL(4)
915     IF(AX.LT.0.AND.AY.LT.0) AL(4) = -ACOS(-1.0)-AL(4)
916 pam-fi 1.4 ENDIF
917 pam-fi 1.10 IF(AY.GT.0.) AL(4) = AL(4)-ACOS(-1.0)
918     IF(AY.LE.0.) AL(4) = AL(4)+ACOS(-1.0)
919    
920 pam-fi 1.4 AL(5) = DEF
921    
922     c print*,' guess: ',(al(i),i=1,5)
923    
924     end

  ViewVC Help
Powered by ViewVC 1.1.23