/[PAMELA software]/DarthVader/ToFLevel2/src/toftrk.for
ViewVC logotype

Diff of /DarthVader/ToFLevel2/src/toftrk.for

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by pam-de, Mon Aug 20 14:22:33 2007 UTC revision 1.18 by pamelats, Thu Nov 27 13:49:13 2008 UTC
# Line 35  C             at ToF layers Line 35  C             at ToF layers
35  C  aug-07 WM: artificial ADC creation revised: Now an ADC value is created  C  aug-07 WM: artificial ADC creation revised: Now an ADC value is created
36  C             only if there is a TDC value (before ADC was created in ANY  C             only if there is a TDC value (before ADC was created in ANY
37  C             case)  C             case)
38  C  C  jan-08 WM: Major Update: Time Walk correction introduced
39    C             Additionally we use the information from the "check_charge"
40    C             function to fill artificial ADC values and make small corrections
41    C             to the k1-parameter (for Z>2)
42    C  feb-08 WM: Calculation of beta(13) changed: First a mean beta is calculated,
43    C             then in a second step we check the residuals of the single
44    C             measurements, reject if > 10 sigma, calculate chi2 and "quality"
45    C             beta is taken as good if chi2<20 and quality>10
46    C             The function "newbeta" is located in "tofl2com.for"
47    C  mar-08 WM: Call to "newbeta" changed, now a flag tells the function if the
48    C             call comes from "tofl2com" or form "toftrack"
49    C  mar-08 WM: Bug found in dEdx if check_charge>1
50    C  apr-08 WM: Bug found in S22 artificial ADC, mismatch found between the track
51    C             length  from DOTRACK2 and "GetLength" method for 4 combinations
52    C  oct-08 WM: New method to create artificial ADC values. Do NOT take the position
53    C             from the tracking, but the position from timing. This method gives a
54    C             better time resolution
55  C****************************************************************************  C****************************************************************************
56        IMPLICIT NONE        IMPLICIT NONE
57  C  C
# Line 68  c      REAL dx,dy,dr Line 84  c      REAL dx,dy,dr
84        REAL ds        REAL ds
85        REAL t1,t2,t3,t4        REAL t1,t2,t3,t4
86        REAL yhelp,xhelp,xhelp1,xhelp2        REAL yhelp,xhelp,xhelp1,xhelp2
87        REAL c1,c2,sw,sxw,w_i        REAL c1,c2
88    C     REAL sw,sxw,w_i
89        REAL dist,dl,F        REAL dist,dl,F
90        INTEGER icount,ievent        INTEGER ievent
91        REAL xhelp_a,xhelp_t  C      INTEGER icount
92    C      REAL beta_mean
93        REAL beta_mean        REAL btemp(12)
94        REAL hepratio        REAL hepratio
95    
96        INTEGER j        INTEGER j,hitvec(6)
97    
98        real atten,pc_adc        real atten,pc_adc,check_charge,newbeta
99    
100    
101        REAL theta,phi        REAL theta,phi
# Line 91  C--   DATA ZTOF/53.74,53.04,23.94,23.44, Line 108  C--   DATA ZTOF/53.74,53.04,23.94,23.44,
108        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92
109    
110    
111    C--- new
112          REAL xtofpre(3),ytofpre(3)
113    
114          REAL y_coor_lin11c(8,2),x_coor_lin12c(6,2)
115          REAL x_coor_lin21c(2,2),y_coor_lin22c(2,2)
116          REAL y_coor_lin31c(3,2),x_coor_lin32c(3,2)
117    
118          DATA y_coor_lin11c(1,1),y_coor_lin11c(1,2) /-20.66,-2.497/
119          DATA y_coor_lin11c(2,1),y_coor_lin11c(2,2) /-9.10, -2.52/
120          DATA y_coor_lin11c(3,1),y_coor_lin11c(3,2) /-24.07,-2.12/
121          DATA y_coor_lin11c(4,1),y_coor_lin11c(4,2) /-13.40,-2.47/
122          DATA y_coor_lin11c(5,1),y_coor_lin11c(5,2) /-31.07,-2.32/
123          DATA y_coor_lin11c(6,1),y_coor_lin11c(6,2) /-21.69,-2.63/
124          DATA y_coor_lin11c(7,1),y_coor_lin11c(7,2) /-12.37,-2.65/
125          DATA y_coor_lin11c(8,1),y_coor_lin11c(8,2) /-10.81,-3.15/
126    
127          DATA x_coor_lin12c(1,1),x_coor_lin12c(1,2) /12.96, -2.65/
128          DATA x_coor_lin12c(2,1),x_coor_lin12c(2,2) /17.12,-2.44/
129          DATA x_coor_lin12c(3,1),x_coor_lin12c(3,2) /7.26, -1.98/
130          DATA x_coor_lin12c(4,1),x_coor_lin12c(4,2) /-22.52,-2.27/
131          DATA x_coor_lin12c(5,1),x_coor_lin12c(5,2) /-18.54,-2.28/
132          DATA x_coor_lin12c(6,1),x_coor_lin12c(6,2) /-7.67,-2.15/
133    
134          DATA x_coor_lin21c(1,1),x_coor_lin21c(1,2) /22.56,-1.56/
135          DATA x_coor_lin21c(2,1),x_coor_lin21c(2,2) /13.94,-1.56/
136    
137          DATA y_coor_lin22c(1,1),y_coor_lin22c(1,2) /-24.24,-2.23/
138          DATA y_coor_lin22c(2,1),y_coor_lin22c(2,2) /-45.99,-1.68/
139    
140          DATA y_coor_lin31c(1,1),y_coor_lin31c(1,2) /-22.99,-3.54/
141          DATA y_coor_lin31c(2,1),y_coor_lin31c(2,2) /-42.28,-4.10/
142          DATA y_coor_lin31c(3,1),y_coor_lin31c(3,2) /-41.29,-3.69/
143    
144          DATA x_coor_lin32c(1,1),x_coor_lin32c(1,2) /0.961, -3.22/
145          DATA x_coor_lin32c(2,1),x_coor_lin32c(2,2) /4.98,-3.48/
146          DATA x_coor_lin32c(3,1),x_coor_lin32c(3,2) /-22.08,-3.37/
147    
148    C---
149    
150        INTEGER ihelp        INTEGER ihelp
151        REAL xkorr,xpos        REAL xkorr,xpos
152    
153          INTEGER IZ
154          REAL k1corrA1,k1corrB1,k1corrC1
155    
156        REAL yl,yh,xl,xh        REAL yl,yh,xl,xh
157  C  C
158        REAL hmemor(9000000)        REAL hmemor(9000000)
# Line 101  C Line 160  C
160  C  C
161        DATA ievent / 0 /        DATA ievent / 0 /
162    
163          INTEGER ifst
164          DATA ifst /0/
165    
166        COMMON / pawcd / hmemor        COMMON / pawcd / hmemor
167        save / pawcd /        save / pawcd /
168  C  C
# Line 113  C Line 175  C
175    
176  *******************************************************************  *******************************************************************
177    
178        ievent = ievent +1         if (ifst.eq.0) then
179           ifst=1
180    
181  C  ratio helium to proton ca. 4  C  ratio helium to proton ca. 4
182        hepratio = 4.        hepratio = 4.
# Line 129  C  ratio helium to proton ca. 4 Line 192  C  ratio helium to proton ca. 4
192        itdc = 1        itdc = 1
193        iadc = 2        iadc = 2
194    
195    
196          k1corrA1 = 0.
197          k1corrB1 = -5.0
198          k1corrC1=  8.0
199    
200          ENDIF   ! ifst
201    
202    *******************************************************************
203    
204          ievent = ievent +1
205    
206        do i=1,13        do i=1,13
207           beta_a(i) = 100.           beta_a(i) = 100.
208        enddo        enddo
# Line 169  C  ratio helium to proton ca. 4 Line 243  C  ratio helium to proton ca. 4
243        ytr_tof(j) = 100.        ytr_tof(j) = 100.
244        enddo        enddo
245    
246    
247  C----------------------------------------------------------------------  C----------------------------------------------------------------------
248  C-------------------------get ToF data --------------------------------  C-------------------------get ToF data --------------------------------
249  C     we cannot use the tofxx(x,x,x)  data  from tofl2com since it is  C     we cannot use the tofxx(x,x,x)  data  from tofl2com since it is
# Line 199  c     put the adc and tdc values from nt Line 274  c     put the adc and tdc values from nt
274           tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))           tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))
275           tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))           tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))
276        enddo        enddo
277    
278        do j=1,2        do j=1,2
279           tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))           tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))
280           tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))           tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))
# Line 282  C     COPY THE ALFA VECTOR FROM AL_PP TO Line 357  C     COPY THE ALFA VECTOR FROM AL_PP TO
357        enddo        enddo
358    
359  c      write(*,*) AL_P  c      write(*,*) AL_P
360    c      write(*,*) 'Rigidity ',(1./AL_P(5))
361    
362        if (al_p(5).eq.0.) THEN        if (al_p(5).eq.0.) THEN
363           PRINT *,' TOF - WARNING F77: track with R = 0, discarded'  c         PRINT *,' TOF - WARNING F77: track with R = 0, discarded'
364           GOTO 969           GOTO 969
365        ENDIF        ENDIF
366  *     -------- *** tracking routine *** --------  *     -------- *** tracking routine *** --------
# Line 295  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,A Line 371  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,A
371  C     write(*,*) (TLOUT(i),i=1,6)  C     write(*,*) (TLOUT(i),i=1,6)
372    
373        if(IFAIL.ne.0)then        if(IFAIL.ne.0)then
374           print *,' TOF - WARNING F77: tracking failed '  c         print *,' TOF - WARNING F77: tracking failed '
375           goto 969           goto 969
376        endif        endif
377  *     ------------------------------------------  *     ------------------------------------------
# Line 306  C---  Fill xtr_tof  and ytr_tof: positio Line 382  C---  Fill xtr_tof  and ytr_tof: positio
382        do j=1,6        do j=1,6
383        xtr_tof(j) = XOUT(j)        xtr_tof(j) = XOUT(j)
384        ytr_tof(j) = YOUT(j)        ytr_tof(j) = YOUT(j)
385    c      write(*,*) XOUT(j),YOUT(j)
386        enddo        enddo
387    
388    
# Line 396  c     S22 2 paddles  15.0 x 9.0 cm Line 473  c     S22 2 paddles  15.0 x 9.0 cm
473  c     S31 3 paddles  15.0 x 6.0 cm  c     S31 3 paddles  15.0 x 6.0 cm
474  c     S32 3 paddles  18.0 x 5.0 cm  c     S32 3 paddles  18.0 x 5.0 cm
475    
 c     write(*,*) xout(1),xout(2),xout(3),xout(4),xout(5),xout(6)  
 c     write(*,*) yout(1),yout(2),yout(3),yout(4),yout(5),yout(6)  
476    
477  C--------------S11 --------------------------------------  C--------------S11 --------------------------------------
478    
# Line 502  C--------------S32 --------------------- Line 577  C--------------S32 ---------------------
577        endif        endif
578    
579    
 C     write(*,*) tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i  
   
 C-----------------------------------------------------------------------  
 C--------------------Insert Artifical TDC Value  ---------------------  
 C     For each Paddle perform check:  
 C     if left paddle=4095  and right paddle OK => create TDC value left  
 C     if right paddle=4095  and left paddle OK => create TDC value right  
 C-----------------------------------------------------------------------  
   
 C-----------------------S11 -----------------------------------------  
   
       IF (tof11_i.GT.none_find) THEN  
          xpos = yout(1)  
          i = tof11_i  
          if ((tof11(1,tof11_i,itdc).EQ.4095).AND.  
      &        (tof11(2,tof11_i,itdc).LT.4095)) THEN  
580    
581  c       write(*,*)'11lb4 ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)         hitvec(1)=tof11_i
582           hitvec(2)=tof12_i
583           hitvec(3)=tof21_i
584           hitvec(4)=tof22_i
585           hitvec(5)=tof31_i
586           hitvec(6)=tof32_i
587    
             tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)  
      &           + 2*(y_coor_lin11(tof11_i,offset)  
      &           + xpos*y_coor_lin11(tof11_i,slope))  
588    
589  c       write(*,*)'11laf ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  C----------------------------------------------------------------------
590    C--- check charge:
591    C--- if Z=2 we should use the attenuation curve for helium to
592    C--- fill the artificail ADC values and NOT divide by "hepratio"
593    C--- if Z>2 we should do a correction to
594    C--- the k1 constants in the beta calculation
595    C----------------------------------------------------------------------
596    
597              tdcflag(ch11a(i),hb11a(i)) = 1         theta=0.  
598           dist = ZTOF(1) - ZTOF(5)
599           dl = 0.
600           DO I=1,5
601             dl = dl + TLOUT(i)
602           ENDDO
603           F = dl/dist
604           theta = acos(1/F)
605    
606           iz = int(check_charge(theta,hitvec))
607    c       write(*,*) 'in toftrk',iz
608    
         ENDIF  
          if ((tof11(2,tof11_i,itdc).EQ.4095).AND.  
      &        (tof11(1,tof11_i,itdc).LT.4095)) THEN  
609    
610  c       write(*,*)'11rb4 ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  C-------------------------------  new  ---------------------------
611    C--  calculate track position in paddle using timing difference
612    C--  this calculation is preliminary and uses some standard
613    C--  calibration values, but we need to find a rough position to
614    C--  be able to calculate artificial ADC values (needed for the
615    C--  timewalk...
616    C------------------------------------------------------------------
617    
618              tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)         do i=1,3
619       &           - 2*(y_coor_lin11(tof11_i,offset)           xtofpre(i)=100.
620       &           + xpos*y_coor_lin11(tof11_i,slope))           ytofpre(i)=100.
621  c       write(*,*)'11raf ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)         enddo
622    
623              tdcflag(ch11b(i),hb11b(i)) = 1  C-----------------------------S1 --------------------------------
          ENDIF  
       ENDIF  
624    
625  C-----------------------S12 -----------------------------------------        IF (tof11_i.GT.none_find) THEN
626          IF ((tof11(1,tof11_i,itdc).LT.2000).AND.
627         +                             (tof11(2,tof11_i,itdc).LT.2000))
628         +    ytofpre(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
629         +   -y_coor_lin11c(tof11_i,offset))/y_coor_lin11c(tof11_i,slope)
630          endif
631    
632        IF (tof12_i.GT.none_find) THEN        IF (tof12_i.GT.none_find) THEN
633           xpos = xout(2)        IF ((tof12(1,tof12_i,itdc).LT.2000).AND.
634           i = tof12_i       +                             (tof12(2,tof12_i,itdc).LT.2000))
635           if ((tof12(1,tof12_i,itdc).EQ.4095).AND.       +    xtofpre(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
636       &        (tof12(2,tof12_i,itdc).LT.4095)) THEN       +   -x_coor_lin12c(tof12_i,offset))/x_coor_lin12c(tof12_i,slope)
637              tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)        endif
      &           + 2*(x_coor_lin12(tof12_i,offset)  
      &           + xpos*x_coor_lin12(tof12_i,slope))  
             tdcflag(ch12a(i),hb12a(i)) = 1  
          ENDIF  
          if ((tof12(2,tof12_i,itdc).EQ.4095).AND.  
      &        (tof12(1,tof12_i,itdc).LT.4095)) THEN  
             tof12(2,tof12_i,itdc) = tof12(1,tof12_i,itdc)  
      &           - 2*(x_coor_lin12(tof12_i,offset)  
      &           + xpos*x_coor_lin12(tof12_i,slope))  
             tdcflag(ch12b(i),hb12b(i)) = 1  
          ENDIF  
       ENDIF  
638    
 C-----------------------S21 -----------------------------------------  
639    
640        IF (tof21_i.GT.none_find) THEN  C-----------------------------S2 --------------------------------
          xpos = xout(3)  
          i = tof21_i  
          if ((tof21(1,tof21_i,itdc).EQ.4095).AND.  
      &        (tof21(2,tof21_i,itdc).LT.4095)) THEN  
             tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)  
      &           + 2*(x_coor_lin21(tof21_i,offset)  
      &           + xpos*x_coor_lin21(tof21_i,slope))  
             tdcflag(ch21a(i),hb21a(i)) = 1  
          ENDIF  
          if ((tof21(2,tof21_i,itdc).EQ.4095).AND.  
      &        (tof21(1,tof21_i,itdc).LT.4095)) THEN  
             tof21(2,tof21_i,itdc) = tof21(1,tof21_i,itdc)  
      &           - 2*(x_coor_lin21(tof21_i,offset)  
      &           + xpos*x_coor_lin21(tof21_i,slope))  
             tdcflag(ch21b(i),hb21b(i)) = 1  
          ENDIF  
       ENDIF  
641    
642  C-----------------------S22 -----------------------------------------        IF (tof21_i.GT.none_find) THEN
643          IF ((tof21(1,tof21_i,itdc).LT.2000).AND.
644         +                             (tof21(2,tof21_i,itdc).LT.2000))
645         +    xtofpre(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
646         +    -x_coor_lin21c(tof21_i,offset))/x_coor_lin21c(tof21_i,slope)
647          endif
648    
649        IF (tof22_i.GT.none_find) THEN        IF (tof22_i.GT.none_find) THEN
650           xpos = yout(4)        IF ((tof22(1,tof22_i,itdc).LT.2000).AND.
651           i = tof22_i       +                             (tof22(2,tof22_i,itdc).LT.2000))
652           if ((tof22(1,tof22_i,itdc).EQ.4095).AND.       +    ytofpre(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
653       &        (tof22(2,tof22_i,itdc).LT.4095)) THEN       +    -y_coor_lin22c(tof22_i,offset))/y_coor_lin22c(tof22_i,slope)
654              tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)        endif
      &           + 2*(y_coor_lin22(tof22_i,offset)  
      &           + xpos*y_coor_lin22(tof22_i,slope))  
             tdcflag(ch22a(i),hb22a(i)) = 1  
          ENDIF  
          if ((tof22(2,tof22_i,itdc).EQ.4095).AND.  
      &        (tof22(1,tof22_i,itdc).LT.4095)) THEN  
             tof22(2,tof22_i,itdc) = tof22(1,tof22_i,itdc)  
      &           - 2*(y_coor_lin22(tof22_i,offset)  
      &           + xpos*y_coor_lin22(tof22_i,slope))  
             tdcflag(ch22b(i),hb22b(i)) = 1  
          ENDIF  
       ENDIF  
655    
 C-----------------------S31 -----------------------------------------  
656    
657        IF (tof31_i.GT.none_find) THEN  C-----------------------------S3 --------------------------------
          xpos = yout(5)  
          i = tof31_i  
          if ((tof31(1,tof31_i,itdc).EQ.4095).AND.  
      &        (tof31(2,tof31_i,itdc).LT.4095)) THEN  
             tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)  
      &           + 2*(y_coor_lin31(tof31_i,offset)  
      &           + xpos*y_coor_lin31(tof31_i,slope))  
             tdcflag(ch31a(i),hb31a(i)) = 1  
          ENDIF  
          if ((tof31(2,tof31_i,itdc).EQ.4095).AND.  
      &        (tof31(1,tof31_i,itdc).LT.4095)) THEN  
             tof31(2,tof31_i,itdc) = tof31(1,tof31_i,itdc)  
      &           - 2*(y_coor_lin31(tof31_i,offset)  
      &           + xpos*y_coor_lin31(tof31_i,slope))  
             tdcflag(ch31b(i),hb31b(i)) = 1  
          ENDIF  
       ENDIF  
658    
659  C-----------------------S32 -----------------------------------------        IF (tof31_i.GT.none_find) THEN
660          IF ((tof31(1,tof31_i,itdc).LT.2000).AND.
661         +                             (tof31(2,tof31_i,itdc).LT.2000))
662         +    ytofpre(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
663         +    -y_coor_lin31c(tof31_i,offset))/y_coor_lin31c(tof31_i,slope)
664          endif
665    
666        IF (tof32_i.GT.none_find) THEN        IF (tof32_i.GT.none_find) THEN
667           xpos = xout(6)        IF ((tof32(1,tof32_i,itdc).LT.2000).AND.
668           i = tof32_i       +                             (tof32(2,tof32_i,itdc).LT.2000))
669           if ((tof32(1,tof32_i,itdc).EQ.4095).AND.       +    xtofpre(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
670       &        (tof32(2,tof32_i,itdc).LT.4095)) THEN       +    -x_coor_lin32c(tof32_i,offset))/x_coor_lin32c(tof32_i,slope)
671              tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)        endif
672       &           + 2*(x_coor_lin32(tof32_i,offset)  
673       &           + xpos*x_coor_lin32(tof32_i,slope))  
674              tdcflag(ch32a(i),hb32a(i)) = 1  C--  restrict TDC measurements to physical paddle dimensions +/- 10 cm
675           ENDIF  
676           if ((tof32(2,tof32_i,itdc).EQ.4095).AND.          if (abs(xtofpre(1)).gt.31.)  xtofpre(1)=100.
677       &        (tof32(1,tof32_i,itdc).LT.4095)) THEN          if (abs(xtofpre(2)).gt.19.)  xtofpre(2)=100.
678              tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)          if (abs(xtofpre(3)).gt.19.)  xtofpre(3)=100.
679       &           - 2*(x_coor_lin32(tof32_i,offset)  
680       &           + xpos*x_coor_lin32(tof32_i,slope))          if (abs(ytofpre(1)).gt.26.)  ytofpre(1)=100.
681              tdcflag(ch32b(i),hb32b(i)) = 1          if (abs(ytofpre(2)).gt.18.)  ytofpre(2)=100.
682           ENDIF          if (abs(ytofpre(3)).gt.18.)  ytofpre(3)=100.
       ENDIF  
683    
684  C--------------------------------------------------------------------  C--------------------------------------------------------------------
685  C---- if paddle hit: if we have TDC value but no ADC, create ADC value  C---- if paddle hit: if we have TDC value but no ADC, create ADC value
686    C---- use the "pre" position if possible, since this gives better time
687    C---- resolution ... october 2008
688  C--------------------------------------------------------------------  C--------------------------------------------------------------------
689  c     middle y (or x) position of the upper and middle ToF-Paddle  c     middle y (or x) position of the upper and middle ToF-Paddle
690  c     DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/  c     DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/
# Line 662  c     DATA tof32_y/ -5.0,0.0,5.0/ Line 696  c     DATA tof32_y/ -5.0,0.0,5.0/
696    
697  C----------------------------S1 -------------------------------------  C----------------------------S1 -------------------------------------
698    
699        yhelp=yout(1)  c     yhelp=yout(1)
700        IF (tof11_i.GT.none_find.AND.abs(yout(1)).lt.100) THEN        yhelp = ytofpre(1)
701          if (yhelp.eq.100) yhelp=yout(1)
702    
703          IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
704           i = tof11_i           i = tof11_i
705           if ((tof11(left,tof11_i,itdc).LT.4095).AND.           if ((tdc(ch11a(i),hb11a(i)).lt.4095).AND.
706       &       (adc(ch11a(i),hb11a(i)).eq.4095)) then       &       (adc(ch11a(i),hb11a(i)).eq.4095)) then
707              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
708              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
 c            xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))  
709              xkorr = atten(left,11,i,yhelp)              xkorr = atten(left,11,i,yhelp)
710              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
711              tof11(left,i,iadc)=xkorr/cos(theta)              tof11(left,i,iadc)=xkorr/cos(theta)
712              adcflag(ch11a(i),hb11a(i)) = 1              adcflag(ch11a(i),hb11a(i)) = 1
713           endif           endif
714           if ((tof11(right,tof11_i,itdc).LT.4095).AND.           if ((tdc(ch11b(i),hb11b(i)).lt.4095).AND.
715       &       (adc(ch11b(i),hb11b(i)).eq.4095)) then       &       (adc(ch11b(i),hb11b(i)).eq.4095)) then
716              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
717              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
 c            xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))  
718              xkorr = atten(right,11,i,yhelp)              xkorr = atten(right,11,i,yhelp)
719              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
720              tof11(right,i,iadc)=xkorr/cos(theta)              tof11(right,i,iadc)=xkorr/cos(theta)
721              adcflag(ch11b(i),hb11b(i)) = 1              adcflag(ch11b(i),hb11b(i)) = 1
722           endif           endif
723        ENDIF        ENDIF
724    
725        xhelp=xout(2)  c      xhelp=xout(2)
726        IF (tof12_i.GT.none_find.AND.abs(xout(2)).lt.100) THEN        xhelp = xtofpre(1)
727          if (xhelp.eq.100) xhelp=xout(2)
728    
729          IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
730           i = tof12_i           i = tof12_i
731           if ((tof12(left,tof12_i,itdc).LT.4095).AND.           if ((tdc(ch12a(i),hb12a(i)).lt.4095).AND.
732       &       (adc(ch12a(i),hb12a(i)).eq.4095)) then       &       (adc(ch12a(i),hb12a(i)).eq.4095)) then
733              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
734              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
735  c            xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))  c            xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))
736              xkorr = atten(left,12,i,xhelp)              xkorr = atten(left,12,i,xhelp)
737              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
738              tof12(left,i,iadc) = xkorr/cos(theta)              tof12(left,i,iadc) = xkorr/cos(theta)
739              adcflag(ch12a(i),hb12a(i)) = 1              adcflag(ch12a(i),hb12a(i)) = 1
740           endif           endif
741           if ((tof12(right,tof12_i,itdc).LT.4095).AND.           if ((tdc(ch12b(i),hb12b(i)).lt.4095).AND.
742       &       (adc(ch12b(i),hb12b(i)).eq.4095)) then       &       (adc(ch12b(i),hb12b(i)).eq.4095)) then
743              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
744              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
745  c            xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))  c            xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))
746              xkorr = atten(right,12,i,xhelp)              xkorr = atten(right,12,i,xhelp)
747              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
748              tof12(right,i,iadc) = xkorr/cos(theta)              tof12(right,i,iadc) = xkorr/cos(theta)
749              adcflag(ch12b(i),hb12b(i)) = 1              adcflag(ch12b(i),hb12b(i)) = 1
750           endif           endif
# Line 714  c            xkorr=adcx12(right,i,1)*exp Line 752  c            xkorr=adcx12(right,i,1)*exp
752    
753  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
754    
755        xhelp=xout(3)  c      xhelp=xout(3)
756        IF (tof21_i.GT.none_find.AND.abs(xout(3)).lt.100) THEN        xhelp = xtofpre(2)
757          if (xhelp.eq.100) xhelp=xout(3)
758    
759          IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
760           i = tof21_i           i = tof21_i
761           if ((tof21(left,tof21_i,itdc).LT.4095).AND.           if ((tdc(ch21a(i),hb21a(i)).lt.4095).AND.
762       &       (adc(ch21a(i),hb21a(i)).eq.4095)) then       &       (adc(ch21a(i),hb21a(i)).eq.4095)) then
763              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
764              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
765  c            xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))  c            xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))
766              xkorr = atten(left,21,i,xhelp)              xkorr = atten(left,21,i,xhelp)
767              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
768              tof21(left,i,iadc) = xkorr/cos(theta)              tof21(left,i,iadc) = xkorr/cos(theta)
769              adcflag(ch21a(i),hb21a(i)) = 1              adcflag(ch21a(i),hb21a(i)) = 1
770           endif           endif
771           if ((tof21(right,tof21_i,itdc).LT.4095).AND.           if ((tdc(ch21b(i),hb21b(i)).lt.4095).AND.
772       &       (adc(ch21b(i),hb21b(i)).eq.4095)) then       &       (adc(ch21b(i),hb21b(i)).eq.4095)) then
773              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
774              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
775  c            xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))  c            xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))
776              xkorr = atten(right,21,i,xhelp)              xkorr = atten(right,21,i,xhelp)
777              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
778              tof21(right,i,iadc) = xkorr/cos(theta)              tof21(right,i,iadc) = xkorr/cos(theta)
779              adcflag(ch21b(i),hb21b(i)) = 1              adcflag(ch21b(i),hb21b(i)) = 1
780           endif           endif
781        ENDIF        ENDIF
782    
783    
784        yhelp=yout(4)  c      yhelp=yout(4)
785        IF (tof22_i.GT.none_find.AND.abs(yout(4)).lt.100) THEN        yhelp = ytofpre(2)
786          if (yhelp.eq.100) yhelp=yout(4)
787    
788          IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
789           i = tof22_i           i = tof22_i
790           if ((tof22(left,tof22_i,itdc).LT.4095).AND.           if ((tdc(ch22a(i),hb22a(i)).lt.4095).AND.
791       &       (adc(ch22a(i),hb22a(i)).eq.4095)) then       &       (adc(ch22a(i),hb22a(i)).eq.4095)) then
792              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
793              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
794  c            xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))  c            xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))
795              xkorr = atten(left,22,i,yhelp)              xkorr = atten(left,22,i,yhelp)
796              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
797              tof22(left,i,iadc) = xkorr/cos(theta)              tof22(left,i,iadc) = xkorr/cos(theta)
798              adcflag(ch22a(i),hb22a(i)) = 1              adcflag(ch22a(i),hb22a(i)) = 1
799           endif           endif
800           if ((tof22(right,tof22_i,itdc).LT.4095).AND.           if ((tdc(ch22b(i),hb22b(i)).lt.4095).AND.
801       &       (adc(ch22b(i),hb22b(i)).eq.4095)) then       &       (adc(ch22b(i),hb22b(i)).eq.4095)) then
802              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
803              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
804  c            xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))  c            xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))
805              xkorr = atten(right,22,i,yhelp)              xkorr = atten(right,22,i,yhelp)
806              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
807              tof22(right,i,iadc) = xkorr/cos(theta)              tof22(right,i,iadc) = xkorr/cos(theta)
808              adcflag(ch22b(i),hb22b(i)) = 1              adcflag(ch22b(i),hb22b(i)) = 1
809           endif           endif
# Line 767  c            xkorr=adcx22(right,i,1)*exp Line 811  c            xkorr=adcx22(right,i,1)*exp
811    
812  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
813    
814        yhelp=yout(5)  c      yhelp=yout(5)
815        IF (tof31_i.GT.none_find.AND.abs(yout(5)).lt.100) THEN        yhelp = ytofpre(3)
816          if (yhelp.eq.100) yhelp=yout(5)
817    
818          IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
819           i = tof31_i           i = tof31_i
820           if ((tof31(left,tof31_i,itdc).LT.4095).AND.           if ((tdc(ch31a(i),hb31a(i)).lt.4095).AND.
821       &       (adc(ch31a(i),hb31a(i)).eq.4095)) then       &       (adc(ch31a(i),hb31a(i)).eq.4095)) then
822              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
823              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
824  c            xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))  c            xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))
825              xkorr = atten(left,31,i,yhelp)              xkorr = atten(left,31,i,yhelp)
826              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
827              tof31(left,i,iadc) = xkorr/cos(theta)              tof31(left,i,iadc) = xkorr/cos(theta)
828              adcflag(ch31a(i),hb31a(i)) = 1              adcflag(ch31a(i),hb31a(i)) = 1
829           endif           endif
830           if ((tof31(right,tof31_i,itdc).LT.4095).AND.           if ((tdc(ch31b(i),hb31b(i)).lt.4095).AND.
831       &       (adc(ch31b(i),hb31b(i)).eq.4095)) then       &       (adc(ch31b(i),hb31b(i)).eq.4095)) then
832              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
833              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
834  c            xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))  c            xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))
835              xkorr = atten(right,31,i,yhelp)              xkorr = atten(right,31,i,yhelp)
836              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
837              tof31(right,i,iadc) = xkorr/cos(theta)              tof31(right,i,iadc) = xkorr/cos(theta)
838              adcflag(ch31b(i),hb31b(i)) = 1              adcflag(ch31b(i),hb31b(i)) = 1
839           endif           endif
840        ENDIF        ENDIF
841    
842    
843        xhelp=xout(6)  c      xhelp=xout(6)
844          xhelp = xtofpre(3)
845          if (xhelp.eq.100) xhelp=xout(6)
846    
847        IF (tof32_i.GT.none_find.AND.abs(xout(6)).lt.100) THEN        IF (tof32_i.GT.none_find.AND.abs(xout(6)).lt.100) THEN
848           i = tof32_i           i = tof32_i
849           if ((tof32(left,tof32_i,itdc).LT.4095).AND.           if ((tdc(ch32a(i),hb32a(i)).lt.4095).AND.
850       &       (adc(ch32a(i),hb32a(i)).eq.4095)) then       &       (adc(ch32a(i),hb32a(i)).eq.4095)) then
851              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
852              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
853  c            xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))  c            xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))
854              xkorr = atten(left,32,i,xhelp)              xkorr = atten(left,32,i,xhelp)
855              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
856              tof32(left,i,iadc) = xkorr/cos(theta)              tof32(left,i,iadc) = xkorr/cos(theta)
857              adcflag(ch32a(i),hb32a(i)) = 1              adcflag(ch32a(i),hb32a(i)) = 1
858           endif           endif
859           if ((tof32(right,tof32_i,itdc).LT.4095).AND.           if ((tdc(ch32b(i),hb32b(i)).lt.4095).AND.
860       &       (adc(ch32b(i),hb32b(i)).eq.4095)) then       &       (adc(ch32b(i),hb32b(i)).eq.4095)) then
861              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
862              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
863  c            xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))  c            xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))
864              xkorr = atten(right,32,i,xhelp)              xkorr = atten(right,32,i,xhelp)
865              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
866              tof32(right,i,iadc) = xkorr/cos(theta)              tof32(right,i,iadc) = xkorr/cos(theta)
867              adcflag(ch32b(i),hb32b(i)) = 1              adcflag(ch32b(i),hb32b(i)) = 1
868           endif           endif
869        ENDIF        ENDIF
870    
871    C-------------------------------------------------------------------
872    C Now there is for each hitted paddle a TDC and ADC value, if the
873    C TDC was < 4095.
874    C There might be also TDC-ADC pairs in paddles not hitted
875    C Let's correct the raw TDC value with the time walk
876    C-------------------------------------------------------------------
877    C--------------------Time walk correction  -------------------------
878    C-------------------------------------------------------------------
879    
880          DO i=1,8
881             if ((tdc(ch11a(i),hb11a(i)).lt.4095).and.
882         &             (tof11(left,i,iadc).lt.3786)) THEN
883             xhelp = tw11(left,i)/(tof11(left,i,iadc)**0.5)
884             tof11(left,i,itdc) = tof11(left,i,itdc) + xhelp
885             tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)
886                                                  ENDIF
887    
888             if ((tdc(ch11b(i),hb11b(i)).lt.4095).and.
889         &             (tof11(right,i,iadc).lt.3786)) THEN
890             xhelp = tw11(right,i)/(tof11(right,i,iadc)**0.5)
891             tof11(right,i,itdc) = tof11(right,i,itdc) + xhelp
892             tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)
893                                                 ENDIF
894          ENDDO
895    
896    
897          DO i=1,6
898             if ((tdc(ch12a(i),hb12a(i)).lt.4095).and.
899         &             (tof12(left,i,iadc).lt.3786)) THEN
900             xhelp = tw12(left,i)/(tof12(left,i,iadc)**0.5)
901             tof12(left,i,itdc) = tof12(left,i,itdc) + xhelp
902             tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)
903                                                  ENDIF
904    
905             if ((tdc(ch12b(i),hb12b(i)).lt.4095).and.
906         &             (tof12(right,i,iadc).lt.3786)) THEN
907             xhelp = tw12(right,i)/(tof12(right,i,iadc)**0.5)
908             tof12(right,i,itdc) = tof12(right,i,itdc) + xhelp
909             tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)
910                                                 ENDIF
911          ENDDO
912    
913    C----
914          DO I=1,2
915             if ((tdc(ch21a(i),hb21a(i)).lt.4095).and.
916         &             (tof21(left,i,iadc).lt.3786)) THEN
917             xhelp = tw21(left,i)/(tof21(left,i,iadc)**0.5)
918             tof21(left,i,itdc) = tof21(left,i,itdc) + xhelp
919             tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)
920                                                  ENDIF
921    
922             if ((tdc(ch21b(i),hb21b(i)).lt.4095).and.
923         &             (tof21(right,i,iadc).lt.3786)) THEN
924             xhelp = tw21(right,i)/(tof21(right,i,iadc)**0.5)
925             tof21(right,i,itdc) = tof21(right,i,itdc) + xhelp
926             tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)
927                                                 ENDIF
928          ENDDO
929    
930          DO I=1,2
931             if ((tdc(ch22a(i),hb22a(i)).lt.4095).and.
932         &             (tof22(left,i,iadc).lt.3786)) THEN
933             xhelp = tw22(left,i)/(tof22(left,i,iadc)**0.5)
934             tof22(left,i,itdc) = tof22(left,i,itdc) + xhelp
935             tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)
936                                                  ENDIF
937    
938             if ((tdc(ch22b(i),hb22b(i)).lt.4095).and.
939         &             (tof22(right,i,iadc).lt.3786)) THEN
940             xhelp = tw22(right,i)/(tof22(right,i,iadc)**0.5)
941             tof22(right,i,itdc) = tof22(right,i,itdc) + xhelp
942             tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)
943                                                 ENDIF
944          ENDDO
945    
946    C----
947          DO I=1,3
948             if ((tdc(ch31a(i),hb31a(i)).lt.4095).and.
949         &             (tof31(left,i,iadc).lt.3786)) THEN
950             xhelp = tw31(left,i)/(tof31(left,i,iadc)**0.5)
951             tof31(left,i,itdc) = tof31(left,i,itdc) + xhelp
952             tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)
953                                                  ENDIF
954    
955             if ((tdc(ch31b(i),hb31b(i)).lt.4095).and.
956         &             (tof31(right,i,iadc).lt.3786)) THEN
957             xhelp = tw31(right,i)/(tof31(right,i,iadc)**0.5)
958             tof31(right,i,itdc) = tof31(right,i,itdc) + xhelp
959             tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)
960                                                 ENDIF
961          ENDDO
962    
963          DO I=1,3
964             if ((tdc(ch32a(i),hb32a(i)).lt.4095).and.
965         &             (tof32(left,i,iadc).lt.3786)) THEN
966             xhelp = tw32(left,i)/(tof32(left,i,iadc)**0.5)
967             tof32(left,i,itdc) = tof32(left,i,itdc) + xhelp
968             tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)
969                                                  ENDIF
970    
971             if ((tdc(ch32b(i),hb32b(i)).lt.4095).and.
972         &             (tof32(right,i,iadc).lt.3786)) THEN
973             xhelp = tw32(right,i)/(tof32(right,i,iadc)**0.5)
974             tof32(right,i,itdc) = tof32(right,i,itdc) + xhelp
975             tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)
976                                                 ENDIF
977          ENDDO
978    
979    
980    C-----------------------------------------------------------------------
981    C--------------------Insert Artifical TDC Value  ---------------------
982    C     For each Paddle perform check:
983    C     if left paddle=4095  and right paddle OK => create TDC value left
984    C     if right paddle=4095  and left paddle OK => create TDC value right
985    C-----------------------------------------------------------------------
986    
987    C-----------------------S11 -----------------------------------------
988    
989          IF (tof11_i.GT.none_find) THEN
990             xpos = yout(1)
991             i = tof11_i
992            if ((tdc(ch11a(i),hb11a(i)).EQ.4095).AND.
993         &          (tdc(ch11b(i),hb11b(i)).LT.4095)) THEN
994              tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)
995         &           + 2*(y_coor_lin11(tof11_i,offset)
996         &           + xpos*y_coor_lin11(tof11_i,slope))
997                tdcflag(ch11a(i),hb11a(i)) = 1
998            ENDIF
999    
1000            if ((tdc(ch11b(i),hb11b(i)).EQ.4095).AND.
1001         &          (tdc(ch11a(i),hb11a(i)).LT.4095)) THEN
1002                tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)
1003         &           - 2*(y_coor_lin11(tof11_i,offset)
1004         &           + xpos*y_coor_lin11(tof11_i,slope))
1005                tdcflag(ch11b(i),hb11b(i)) = 1
1006             ENDIF
1007    
1008          ENDIF
1009    
1010    C-----------------------S12 -----------------------------------------
1011    
1012          IF (tof12_i.GT.none_find) THEN
1013             xpos = xout(2)
1014             i = tof12_i
1015            if ((tdc(ch12a(i),hb12a(i)).EQ.4095).AND.
1016         &          (tdc(ch12b(i),hb12b(i)).LT.4095)) THEN
1017                tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)
1018         &           + 2*(x_coor_lin12(tof12_i,offset)
1019         &           + xpos*x_coor_lin12(tof12_i,slope))
1020                tdcflag(ch12a(i),hb12a(i)) = 1
1021             ENDIF
1022    
1023            if ((tdc(ch12b(i),hb12b(i)).EQ.4095).AND.
1024         &          (tdc(ch12a(i),hb12a(i)).LT.4095)) THEN
1025                tof12(2,tof12_i,itdc) = tof12(1,tof12_i,itdc)
1026         &           - 2*(x_coor_lin12(tof12_i,offset)
1027         &           + xpos*x_coor_lin12(tof12_i,slope))
1028                tdcflag(ch12b(i),hb12b(i)) = 1
1029             ENDIF
1030          ENDIF
1031    
1032    C-----------------------S21 -----------------------------------------
1033    
1034          IF (tof21_i.GT.none_find) THEN
1035             xpos = xout(3)
1036             i = tof21_i
1037            if ((tdc(ch21a(i),hb21a(i)).EQ.4095).AND.
1038         &          (tdc(ch21b(i),hb21b(i)).LT.4095)) THEN
1039                tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)
1040         &           + 2*(x_coor_lin21(tof21_i,offset)
1041         &           + xpos*x_coor_lin21(tof21_i,slope))
1042                tdcflag(ch21a(i),hb21a(i)) = 1
1043             ENDIF
1044    
1045            if ((tdc(ch21b(i),hb21b(i)).EQ.4095).AND.
1046         &          (tdc(ch21a(i),hb21a(i)).LT.4095)) THEN
1047                tof21(2,tof21_i,itdc) = tof21(1,tof21_i,itdc)
1048         &           - 2*(x_coor_lin21(tof21_i,offset)
1049         &           + xpos*x_coor_lin21(tof21_i,slope))
1050                tdcflag(ch21b(i),hb21b(i)) = 1
1051             ENDIF
1052          ENDIF
1053    
1054    C-----------------------S22 -----------------------------------------
1055    
1056          IF (tof22_i.GT.none_find) THEN
1057             xpos = yout(4)
1058             i = tof22_i
1059            if ((tdc(ch22a(i),hb22a(i)).EQ.4095).AND.
1060         &          (tdc(ch22b(i),hb22b(i)).LT.4095)) THEN
1061                tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)
1062         &           + 2*(y_coor_lin22(tof22_i,offset)
1063         &           + xpos*y_coor_lin22(tof22_i,slope))
1064                tdcflag(ch22a(i),hb22a(i)) = 1
1065             ENDIF
1066    
1067            if ((tdc(ch22b(i),hb22b(i)).EQ.4095).AND.
1068         &          (tdc(ch22a(i),hb22a(i)).LT.4095)) THEN
1069                tof22(2,tof22_i,itdc) = tof22(1,tof22_i,itdc)
1070         &           - 2*(y_coor_lin22(tof22_i,offset)
1071         &           + xpos*y_coor_lin22(tof22_i,slope))
1072                tdcflag(ch22b(i),hb22b(i)) = 1
1073             ENDIF
1074          ENDIF
1075    
1076    C-----------------------S31 -----------------------------------------
1077    
1078          IF (tof31_i.GT.none_find) THEN
1079             xpos = yout(5)
1080             i = tof31_i
1081            if ((tdc(ch31a(i),hb31a(i)).EQ.4095).AND.
1082         &          (tdc(ch31b(i),hb31b(i)).LT.4095)) THEN
1083                tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)
1084         &           + 2*(y_coor_lin31(tof31_i,offset)
1085         &           + xpos*y_coor_lin31(tof31_i,slope))
1086                tdcflag(ch31a(i),hb31a(i)) = 1
1087             ENDIF
1088    
1089            if ((tdc(ch31b(i),hb31b(i)).EQ.4095).AND.
1090         &          (tdc(ch31a(i),hb31a(i)).LT.4095)) THEN
1091                tof31(2,tof31_i,itdc) = tof31(1,tof31_i,itdc)
1092         &           - 2*(y_coor_lin31(tof31_i,offset)
1093         &           + xpos*y_coor_lin31(tof31_i,slope))
1094                tdcflag(ch31b(i),hb31b(i)) = 1
1095             ENDIF
1096          ENDIF
1097    
1098    C-----------------------S32 -----------------------------------------
1099    
1100          IF (tof32_i.GT.none_find) THEN
1101             xpos = xout(6)
1102             i = tof32_i
1103            if ((tdc(ch32a(i),hb32a(i)).EQ.4095).AND.
1104         &          (tdc(ch32b(i),hb32b(i)).LT.4095)) THEN
1105                tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)
1106         &           + 2*(x_coor_lin32(tof32_i,offset)
1107         &           + xpos*x_coor_lin32(tof32_i,slope))
1108                tdcflag(ch32a(i),hb32a(i)) = 1
1109             ENDIF
1110    
1111            if ((tdc(ch32b(i),hb32b(i)).EQ.4095).AND.
1112         &          (tdc(ch32a(i),hb32a(i)).LT.4095)) THEN
1113                tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)
1114         &           - 2*(x_coor_lin32(tof32_i,offset)
1115         &           + xpos*x_coor_lin32(tof32_i,slope))
1116                tdcflag(ch32b(i),hb32b(i)) = 1
1117             ENDIF
1118          ENDIF
1119    
1120    
1121  C------------------------------------------------------------------  C------------------------------------------------------------------
1122  C---  calculate track position in paddle using timing difference  C---  calculate track position in paddle using timing difference
# Line 827  C--------------------------------------- Line 1126  C---------------------------------------
1126           xtofpos(i)=100.           xtofpos(i)=100.
1127           ytofpos(i)=100.           ytofpos(i)=100.
1128        enddo        enddo
1129    
1130  C-----------------------------S1 --------------------------------  C-----------------------------S1 --------------------------------
1131    
1132        IF (tof11_i.GT.none_find) THEN        IF (tof11_i.GT.none_find) THEN
# Line 835  C-----------------------------S1 ------- Line 1135  C-----------------------------S1 -------
1135           ytofpos(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.           ytofpos(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
1136       +        -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)       +        -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)
1137          if (abs(ytofpos(1)).gt.26.)  ytofpos(1)=101.          if (abs(ytofpos(1)).gt.26.)  ytofpos(1)=101.
1138          i=tof11_i
1139        endif        endif
1140        endif        endif
1141    
# Line 844  C-----------------------------S1 ------- Line 1145  C-----------------------------S1 -------
1145           xtofpos(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.           xtofpos(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
1146       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)
1147          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.
1148          i=tof12_i
1149        endif        endif
1150        endif        endif
1151    
# Line 855  C-----------------------------S2 ------- Line 1157  C-----------------------------S2 -------
1157           xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.           xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
1158       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)
1159          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.
1160          i=tof21_i
1161        endif        endif
1162        endif        endif
1163    
# Line 864  C-----------------------------S2 ------- Line 1167  C-----------------------------S2 -------
1167           ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.           ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
1168       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)
1169          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.
1170          i=tof22_i
1171        endif        endif
1172        endif        endif
1173    
# Line 875  C-----------------------------S3 ------- Line 1179  C-----------------------------S3 -------
1179           ytofpos(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.           ytofpos(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
1180       +        -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)       +        -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)
1181          if (abs(ytofpos(3)).gt.18.)  ytofpos(3)=101.          if (abs(ytofpos(3)).gt.18.)  ytofpos(3)=101.
1182          i=tof31_i
1183        endif        endif
1184        endif        endif
1185    
# Line 884  C-----------------------------S3 ------- Line 1189  C-----------------------------S3 -------
1189           xtofpos(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.           xtofpos(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
1190       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)
1191          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.
1192          i=tof32_i
1193        endif        endif
1194        endif        endif
1195    
# Line 898  c      enddo Line 1204  c      enddo
1204    
1205    
1206    
   
 C--------------------------------------------------------------------  
 C--------------------Time walk correction  -------------------------  
 C--------------------------------------------------------------------  
   
   
       DO i=1,8  
          xhelp= 0.  
          xhelp_a = tof11(left,i,iadc)  
          xhelp_t = tof11(left,i,itdc)  
           if (xhelp_a .eq.0) write (*,*) 'trk 11 ',i,xhelp_a  
   
          if(xhelp_a<3786) xhelp = tw11(left,i)/sqrt(xhelp_a)  
          tof11(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)  
          xhelp_a = tof11(right,i,iadc)  
          xhelp_t = tof11(right,i,itdc)  
          if(xhelp_a<3786) xhelp = tw11(right,i)/sqrt(xhelp_a)  
          tof11(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)  
       ENDDO  
   
       DO i=1,6  
          xhelp= 0.  
          xhelp_a = tof12(left,i,iadc)  
          xhelp_t = tof12(left,i,itdc)  
           if (xhelp_a .eq.0) write (*,*) 'trk 12 ',i,xhelp_a  
          if(xhelp_a<3786) xhelp = tw12(left,i)/sqrt(xhelp_a)  
          tof12(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)  
          xhelp_a = tof12(right,i,iadc)  
          xhelp_t = tof12(right,i,itdc)  
          if(xhelp_a<3786) xhelp = tw12(right,i)/sqrt(xhelp_a)  
          tof12(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)  
       ENDDO  
 C----  
       DO i=1,2  
          xhelp= 0.  
          xhelp_a = tof21(left,i,iadc)  
          xhelp_t = tof21(left,i,itdc)  
           if (xhelp_a .eq.0) write (*,*) ' trk 21 ',i,xhelp_a  
   
          if(xhelp_a<3786) xhelp = tw21(left,i)/sqrt(xhelp_a)  
          tof21(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)  
          xhelp_a = tof21(right,i,iadc)  
          xhelp_t = tof21(right,i,itdc)  
          if(xhelp_a<3786) xhelp = tw21(right,i)/sqrt(xhelp_a)  
          tof21(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)  
       ENDDO  
   
       DO i=1,2  
          xhelp= 0.  
          xhelp_a = tof22(left,i,iadc)  
          xhelp_t = tof22(left,i,itdc)  
           if (xhelp_a .eq.0) write (*,*) ' trk 22 ',i,xhelp_a  
          if(xhelp_a<3786) xhelp = tw22(left,i)/sqrt(xhelp_a)  
          tof22(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)  
          xhelp_a = tof22(right,i,iadc)  
          xhelp_t = tof22(right,i,itdc)  
          if(xhelp_a<3786) xhelp = tw22(right,i)/sqrt(xhelp_a)  
          tof22(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)  
       ENDDO  
 C----  
   
       DO i=1,3  
          xhelp= 0.  
          xhelp_a = tof31(left,i,iadc)  
          xhelp_t = tof31(left,i,itdc)  
           if (xhelp_a .eq.0) write (*,*) ' trk 31 ',i,xhelp_a  
   
          if(xhelp_a<3786) xhelp = tw31(left,i)/sqrt(xhelp_a)  
          tof31(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)  
          xhelp_a = tof31(right,i,iadc)  
          xhelp_t = tof31(right,i,itdc)  
          if(xhelp_a<3786) xhelp = tw31(right,i)/sqrt(xhelp_a)  
          tof31(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)  
       ENDDO  
   
       DO i=1,3  
          xhelp= 0.  
          xhelp_a = tof32(left,i,iadc)  
          xhelp_t = tof32(left,i,itdc)  
           if (xhelp_a .eq.0) write (*,*) ' trk 32 ',i,xhelp_a  
   
          if(xhelp_a<3786) xhelp = tw32(left,i)/sqrt(xhelp_a)  
          tof32(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)  
          xhelp_a = tof32(right,i,iadc)  
          xhelp_t = tof32(right,i,itdc)  
          if(xhelp_a<3786) xhelp = tw32(right,i)/sqrt(xhelp_a)  
          tof32(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)  
       ENDDO  
   
   
1207  C---------------------------------------------------------------------  C---------------------------------------------------------------------
1208  C--------------------Corrections on ADC-data -------------------------  C--------------------Corrections on ADC-data -------------------------
1209  C-----------------angle and ADC(x) correction -----------------------  C-----------------angle and ADC(x) correction -----------------------
# Line 1016  C-----------------------------S1 ------- Line 1220  C-----------------------------S1 -------
1220           i = tof11_i           i = tof11_i
1221    
1222           if (tof11(left,i,iadc).lt.3786) then           if (tof11(left,i,iadc).lt.3786) then
 c         if (adc(ch11a(i),hb11a(i)).lt.4095) then  
1223              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta)              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta)
 c            xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))  
1224              xkorr = atten(left,11,i,yhelp)              xkorr = atten(left,11,i,yhelp)
1225              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1226              adc_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr              adc_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr
# Line 1026  c            xkorr=adcx11(left,i,1)*exp( Line 1228  c            xkorr=adcx11(left,i,1)*exp(
1228    
1229    
1230           if (tof11(right,i,iadc).lt.3786) then           if (tof11(right,i,iadc).lt.3786) then
 c         if (adc(ch11b(i),hb11b(i)).lt.4095) then  
1231              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta)              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta)
 c            xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))  
1232              xkorr = atten(right,11,i,yhelp)              xkorr = atten(right,11,i,yhelp)
1233              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1234              adc_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr              adc_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr
# Line 1039  c            xkorr=adcx11(right,i,1)*exp Line 1239  c            xkorr=adcx11(right,i,1)*exp
1239        xhelp=xout(2)        xhelp=xout(2)
1240        phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))        phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
1241        theta = atan(tan(THXOUT(2))/cos(phi))        theta = atan(tan(THXOUT(2))/cos(phi))
 c      write(*,*) 'theta12 ',theta  
       IF (tof12_i.GT.none_find.AND.xhelp.lt.100) THEN  
1242    
1243          IF (tof12_i.GT.none_find.AND.xhelp.lt.100) THEN
1244           i = tof12_i           i = tof12_i
1245           if (tof12(left,i,iadc).lt.3786) then           if (tof12(left,i,iadc).lt.3786) then
 c         if (adc(ch12a(i),hb12a(i)).lt.4095) then  
1246              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta)              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta)
 c            xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))  
1247              xkorr = atten(left,12,i,xhelp)              xkorr = atten(left,12,i,xhelp)
1248              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1249              adc_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr              adc_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr
1250           endif           endif
1251    
1252           if (tof12(right,i,iadc).lt.3786) then           if (tof12(right,i,iadc).lt.3786) then
 c         if (adc(ch12b(i),hb12b(i)).lt.4095) then  
1253              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta)              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta)
 c            xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))  
1254              xkorr = atten(right,12,i,xhelp)              xkorr = atten(right,12,i,xhelp)
1255              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1256              adc_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr              adc_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr
# Line 1067  C-----------------------------S2 ------- Line 1262  C-----------------------------S2 -------
1262        xhelp=xout(3)        xhelp=xout(3)
1263        phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))        phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
1264        theta = atan(tan(THXOUT(3))/cos(phi))        theta = atan(tan(THXOUT(3))/cos(phi))
 c      write(*,*) 'theta21 ',theta  
       IF (tof21_i.GT.none_find.AND.xhelp.lt.100) THEN  
1265    
1266          IF (tof21_i.GT.none_find.AND.xhelp.lt.100) THEN
1267           i = tof21_i           i = tof21_i
1268           if (tof21(left,i,iadc).lt.3786) then           if (tof21(left,i,iadc).lt.3786) then
 c         if (adc(ch21a(i),hb21a(i)).lt.4095) then  
1269              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta)              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta)
 c            xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))  
1270              xkorr = atten(left,21,i,xhelp)              xkorr = atten(left,21,i,xhelp)
1271              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1272              adc_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr              adc_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr
1273           endif           endif
1274    
1275           if (tof21(right,i,iadc).lt.3786) then           if (tof21(right,i,iadc).lt.3786) then
 c         if (adc(ch21b(i),hb21b(i)).lt.4095) then  
1276              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta)              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta)
 c            xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))  
1277              xkorr = atten(right,21,i,xhelp)              xkorr = atten(right,21,i,xhelp)
1278              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1279              adc_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr              adc_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr
# Line 1093  c            xkorr=adcx21(right,i,1)*exp Line 1283  c            xkorr=adcx21(right,i,1)*exp
1283        yhelp=yout(4)        yhelp=yout(4)
1284        phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))        phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
1285        theta = atan(tan(THXOUT(4))/cos(phi))        theta = atan(tan(THXOUT(4))/cos(phi))
 c      write(*,*) 'theta22 ',theta  
1286    
1287        IF (tof22_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof22_i.GT.none_find.AND.yhelp.lt.100) THEN
   
1288           i = tof22_i           i = tof22_i
1289           if (tof22(left,i,iadc).lt.3786) then           if (tof22(left,i,iadc).lt.3786) then
 c         if (adc(ch22a(i),hb22a(i)).lt.4095) then  
1290              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta)              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta)
 c            xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))  
1291              xkorr = atten(left,22,i,yhelp)              xkorr = atten(left,22,i,yhelp)
1292              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1293              adc_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr              adc_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr
1294           endif           endif
1295    
1296           if (tof22(right,i,iadc).lt.3786) then           if (tof22(right,i,iadc).lt.3786) then
 c         if (adc(ch22b(i),hb22b(i)).lt.4095) then  
1297              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta)              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta)
 c            xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))  
1298              xkorr = atten(right,22,i,yhelp)              xkorr = atten(right,22,i,yhelp)
1299              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1300              adc_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr              adc_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr
# Line 1122  C-----------------------------S3 ------- Line 1306  C-----------------------------S3 -------
1306        yhelp=yout(5)        yhelp=yout(5)
1307        phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))        phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
1308        theta = atan(tan(THXOUT(5))/cos(phi))        theta = atan(tan(THXOUT(5))/cos(phi))
 c      write(*,*) 'theta31 ',theta  
1309    
1310        IF (tof31_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof31_i.GT.none_find.AND.yhelp.lt.100) THEN
1311    
1312           i = tof31_i           i = tof31_i
1313           if (tof31(left,i,iadc).lt.3786) then           if (tof31(left,i,iadc).lt.3786) then
 c         if (adc(ch31a(i),hb31a(i)).lt.4095) then  
1314              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta)              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta)
 c            xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))  
1315              xkorr = atten(left,31,i,yhelp)              xkorr = atten(left,31,i,yhelp)
1316              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1317              adc_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr              adc_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr
1318           endif           endif
1319    
1320           if (tof31(right,i,iadc).lt.3786) then           if (tof31(right,i,iadc).lt.3786) then
 c         if (adc(ch31b(i),hb31b(i)).lt.4095) then  
1321              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta)              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta)
 c            xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))  
1322              xkorr = atten(right,31,i,yhelp)              xkorr = atten(right,31,i,yhelp)
1323              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1324              adc_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr              adc_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr
# Line 1149  c            xkorr=adcx31(right,i,1)*exp Line 1328  c            xkorr=adcx31(right,i,1)*exp
1328        xhelp=xout(6)        xhelp=xout(6)
1329        phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))        phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
1330        theta = atan(tan(THXOUT(6))/cos(phi))        theta = atan(tan(THXOUT(6))/cos(phi))
 c      write(*,*) 'theta32 ',theta  
1331    
1332        IF (tof32_i.GT.none_find.AND.xhelp.lt.100) THEN        IF (tof32_i.GT.none_find.AND.xhelp.lt.100) THEN
   
1333           i = tof32_i           i = tof32_i
1334           if (tof32(left,i,iadc).lt.3786) then           if (tof32(left,i,iadc).lt.3786) then
 c         if (adc(ch32a(i),hb32a(i)).lt.4095) then  
1335              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta)              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta)
 c            xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))  
1336              xkorr = atten(left,32,i,xhelp)              xkorr = atten(left,32,i,xhelp)
1337              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1338              adc_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr              adc_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr
1339           endif           endif
1340    
1341           if (tof32(right,i,iadc).lt.3786) then           if (tof32(right,i,iadc).lt.3786) then
 c         if (adc(ch32b(i),hb32b(i)).lt.4095) then  
1342              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta)              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta)
 c            xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))  
1343              xkorr = atten(right,32,i,xhelp)              xkorr = atten(right,32,i,xhelp)
1344              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1345              adc_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr              adc_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr
1346           endif           endif
1347        ENDIF        ENDIF
1348    
1349    
1350  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
1351  C----------------------calculate Beta  ------------------------------  C----------------------calculate Beta  ------------------------------
1352  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
# Line 1209  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1383  C      IF (tof11_i.GT.none_find.AND.tof3
1383              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1384              ihelp=(tof11_i-1)*3+tof31_i              ihelp=(tof11_i-1)*3+tof31_i
1385              c1 = k_S11S31(1,ihelp)              c1 = k_S11S31(1,ihelp)
1386                if (iz.gt.2) c1 = c1 + k1corrA1
1387              c2 = k_S11S31(2,ihelp)              c2 = k_S11S31(2,ihelp)
1388              beta_a(1) = c2*F/(ds-c1)              beta_a(1) = c2*F/(ds-c1)
1389         write(*,*) 'S11-S31 ',c1,c2,F  c       write(*,*) 'S11-S31 ',c1,c2,F
1390         write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)  c       write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)
1391  C-------ToF Mask - S11 - S31  C-------ToF Mask - S11 - S31
1392    
1393              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
# Line 1250  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1425  C      IF (tof11_i.GT.none_find.AND.tof3
1425              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1426              ihelp=(tof11_i-1)*3+tof32_i              ihelp=(tof11_i-1)*3+tof32_i
1427              c1 = k_S11S32(1,ihelp)              c1 = k_S11S32(1,ihelp)
1428                if (iz.gt.2) c1 = c1 + k1corrA1
1429              c2 = k_S11S32(2,ihelp)              c2 = k_S11S32(2,ihelp)
1430              beta_a(2) = c2*F/(ds-c1)              beta_a(2) = c2*F/(ds-c1)
1431  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)
# Line 1293  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1469  C      IF (tof12_i.GT.none_find.AND.tof3
1469              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1470              ihelp=(tof12_i-1)*3+tof31_i              ihelp=(tof12_i-1)*3+tof31_i
1471              c1 = k_S12S31(1,ihelp)              c1 = k_S12S31(1,ihelp)
1472                if (iz.gt.2) c1 = c1 + k1corrA1
1473              c2 = k_S12S31(2,ihelp)              c2 = k_S12S31(2,ihelp)
1474              beta_a(3) = c2*F/(ds-c1)              beta_a(3) = c2*F/(ds-c1)
1475  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)
# Line 1337  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1514  C      IF (tof12_i.GT.none_find.AND.tof3
1514              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1515              ihelp=(tof12_i-1)*3+tof32_i              ihelp=(tof12_i-1)*3+tof32_i
1516              c1 = k_S12S32(1,ihelp)              c1 = k_S12S32(1,ihelp)
1517                if (iz.gt.2) c1 = c1 + k1corrA1
1518              c2 = k_S12S32(2,ihelp)              c2 = k_S12S32(2,ihelp)
1519              beta_a(4) = c2*F/(ds-c1)              beta_a(4) = c2*F/(ds-c1)
1520  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)
# Line 1381  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1559  C      IF (tof21_i.GT.none_find.AND.tof3
1559              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1560              ihelp=(tof21_i-1)*3+tof31_i              ihelp=(tof21_i-1)*3+tof31_i
1561              c1 = k_S21S31(1,ihelp)              c1 = k_S21S31(1,ihelp)
1562                if (iz.gt.2) c1 = c1 + k1corrB1
1563              c2 = k_S21S31(2,ihelp)              c2 = k_S21S31(2,ihelp)
1564              beta_a(5) = c2*F/(ds-c1)              beta_a(5) = c2*F/(ds-c1)
1565    
# Line 1424  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1603  C      IF (tof21_i.GT.none_find.AND.tof3
1603              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1604              ihelp=(tof21_i-1)*3+tof32_i              ihelp=(tof21_i-1)*3+tof32_i
1605              c1 = k_S21S32(1,ihelp)              c1 = k_S21S32(1,ihelp)
1606                if (iz.gt.2) c1 = c1 + k1corrB1
1607              c2 = k_S21S32(2,ihelp)              c2 = k_S21S32(2,ihelp)
1608              beta_a(6) = c2*F/(ds-c1)              beta_a(6) = c2*F/(ds-c1)
1609    
# Line 1452  C     S22 - S31 Line 1632  C     S22 - S31
1632           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1633        ENDDO        ENDDO
1634        F = dl/dist        F = dl/dist
1635          
1636    C WM workaround
1637          dl = dl - 0.06*F
1638          F = dl/dist
1639    
1640  C      IF (tof22_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof22_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1641         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
# Line 1467  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1651  C      IF (tof22_i.GT.none_find.AND.tof3
1651              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1652              ihelp=(tof22_i-1)*3+tof31_i              ihelp=(tof22_i-1)*3+tof31_i
1653              c1 = k_S22S31(1,ihelp)              c1 = k_S22S31(1,ihelp)
1654                if (iz.gt.2) c1 = c1 + k1corrB1
1655              c2 = k_S22S31(2,ihelp)              c2 = k_S22S31(2,ihelp)
1656              beta_a(7) = c2*F/(ds-c1)              beta_a(7) = c2*F/(ds-c1)
1657    
# Line 1495  C     S22 - S32 Line 1680  C     S22 - S32
1680           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1681        ENDDO        ENDDO
1682        F = dl/dist        F = dl/dist
1683          
1684    C WM workaround      
1685          dl = dl - 0.06*F
1686          F = dl/dist
1687    
1688    
1689  C      IF (tof22_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof22_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1690         IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1510  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1700  C      IF (tof22_i.GT.none_find.AND.tof3
1700              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1701              ihelp=(tof22_i-1)*3+tof32_i              ihelp=(tof22_i-1)*3+tof32_i
1702              c1 = k_S22S32(1,ihelp)              c1 = k_S22S32(1,ihelp)
1703                if (iz.gt.2) c1 = c1 + k1corrB1
1704              c2 = k_S22S32(2,ihelp)              c2 = k_S22S32(2,ihelp)
1705              beta_a(8) = c2*F/(ds-c1)              beta_a(8) = c2*F/(ds-c1)
1706    
# Line 1539  C     S11 - S21 Line 1730  C     S11 - S21
1730        ENDDO        ENDDO
1731        F = dl/dist        F = dl/dist
1732    
1733    C WM workaround      
1734          dl = dl - 0.442*F
1735          F = dl/dist
1736    
1737  C      IF (tof11_i.GT.none_find.AND.tof21_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof21_i.GT.none_find) THEN
1738         IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1739       &    (ytofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN       &    (ytofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
# Line 1553  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1748  C      IF (tof11_i.GT.none_find.AND.tof2
1748              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1749              ihelp=(tof11_i-1)*2+tof21_i              ihelp=(tof11_i-1)*2+tof21_i
1750              c1 = k_S11S21(1,ihelp)              c1 = k_S11S21(1,ihelp)
1751                if (iz.gt.2) c1 = c1 + k1corrC1
1752              c2 = k_S11S21(2,ihelp)              c2 = k_S11S21(2,ihelp)
1753              beta_a(9) = c2*F/(ds-c1)              beta_a(9) = c2*F/(ds-c1)
1754    
# Line 1596  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1792  C      IF (tof11_i.GT.none_find.AND.tof2
1792              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1793              ihelp=(tof11_i-1)*2+tof22_i              ihelp=(tof11_i-1)*2+tof22_i
1794              c1 = k_S11S22(1,ihelp)              c1 = k_S11S22(1,ihelp)
1795                if (iz.gt.2) c1 = c1 + k1corrC1
1796              c2 = k_S11S22(2,ihelp)              c2 = k_S11S22(2,ihelp)
1797              beta_a(10) = c2*F/(ds-c1)              beta_a(10) = c2*F/(ds-c1)
1798    
# Line 1625  C     S12 - S21 Line 1822  C     S12 - S21
1822        ENDDO        ENDDO
1823        F = dl/dist        F = dl/dist
1824    
1825    C  WM workaround
1826          dl = dl - 0.442*F
1827          F = dl/dist
1828    
1829  C      IF (tof12_i.GT.none_find.AND.tof21_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof21_i.GT.none_find) THEN
1830         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1831       &    (xtofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN       &    (xtofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
# Line 1639  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1840  C      IF (tof12_i.GT.none_find.AND.tof2
1840              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1841              ihelp=(tof12_i-1)*2+tof21_i              ihelp=(tof12_i-1)*2+tof21_i
1842              c1 = k_S12S21(1,ihelp)              c1 = k_S12S21(1,ihelp)
1843                if (iz.gt.2) c1 = c1 + k1corrC1
1844              c2 = k_S12S21(2,ihelp)              c2 = k_S12S21(2,ihelp)
1845              beta_a(11) = c2*F/(ds-c1)              beta_a(11) = c2*F/(ds-c1)
1846    
# Line 1682  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1884  C      IF (tof12_i.GT.none_find.AND.tof2
1884              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1885              ihelp=(tof12_i-1)*2+tof22_i              ihelp=(tof12_i-1)*2+tof22_i
1886              c1 = k_S12S22(1,ihelp)              c1 = k_S12S22(1,ihelp)
1887                if (iz.gt.2) c1 = c1 + k1corrC1
1888              c2 = k_S12S22(2,ihelp)              c2 = k_S12S22(2,ihelp)
1889              beta_a(12) = c2*F/(ds-c1)              beta_a(12) = c2*F/(ds-c1)
1890    
# Line 1703  C------- Line 1906  C-------
1906        ENDIF        ENDIF
1907    
1908  C-------  C-------
1909    C
1910    C      icount=0
1911    C      sw=0.
1912    C      sxw=0.
1913    C      beta_mean=100.
1914    C
1915    C      do i=1,12
1916    C         if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then
1917    C            icount= icount+1
1918    C            if (i.le.4) w_i=1./(0.13**2.)
1919    C            if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)
1920    C            if (i.ge.9) w_i=1./(0.25**2.) ! to be checked
1921    C            sxw=sxw + beta_a(i)*w_i
1922    C            sw =sw + w_i
1923    C         endif
1924    C      enddo
1925    C
1926    C      if (icount.gt.0) beta_mean=sxw/sw
1927    C      beta_a(13) = beta_mean
1928    C
1929    
1930        icount=0  C-------  New mean beta  calculation
       sw=0.  
       sxw=0.  
       beta_mean=100.  
1931    
1932        do i=1,12         do i=1,12
1933           if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then           btemp(i) =  beta_a(i)
1934              icount= icount+1         enddo
1935              if (i.le.4) w_i=1./(0.13**2.)  
1936              if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)         beta_a(13)=newbeta(2,btemp,hitvec,10.,10.,20.)
             if (i.ge.9) w_i=1./(0.25**2.) ! to be checked  
             sxw=sxw + beta_a(i)*w_i  
             sw =sw + w_i  
          endif  
       enddo  
1937    
1938        if (icount.gt.0) beta_mean=sxw/sw  C-------
       beta_a(13) = beta_mean  
1939    
1940    
1941  c       IF (tof11_i.GT.none_find)  c       IF (tof11_i.GT.none_find)
# Line 1750  c      write(*,*) ytofpos Line 1964  c      write(*,*) ytofpos
1964  c      write(*,*) xtr_tof  c      write(*,*) xtr_tof
1965  c      write(*,*) ytr_tof  c      write(*,*) ytr_tof
1966    
1967    c       write(*,*) '---------  end toftrk ----------'
1968    
1969        RETURN        RETURN
1970        END        END
# Line 1760  c      write(*,*) ytr_tof Line 1974  c      write(*,*) ytr_tof
1974    
1975  C------------------------------------------------------------------  C------------------------------------------------------------------
1976    
1977    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.23