/[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.10 by mocchiut, Wed Feb 7 08:17:17 2007 UTC revision 1.15 by mocchiut, Mon Mar 3 09:51:04 2008 UTC
# Line 7  C     Changed to use DOTRACK2 Line 7  C     Changed to use DOTRACK2
7  C     Beta calculation: now the flightpath (instead of cos(theta)) is used  C     Beta calculation: now the flightpath (instead of cos(theta)) is used
8  C     Beta calculation: all 4 TDV measurements must be < 4095 (in the old  C     Beta calculation: all 4 TDV measurements must be < 4095 (in the old
9  C     routine it was (t1+t2)<8000  C     routine it was (t1+t2)<8000
10  C      C
11  C     08-12-06 WM:  C     08-12-06 WM:
12  C     adc_c-bug :  The raw ADC value was multiplied with cos(theta)  C     adc_c-bug :  The raw ADC value was multiplied with cos(theta)
13  C     and AFTER that there was an if statement "if tof32(right,i,iadc) < 4095"  C     and AFTER that there was an if statement "if tof32(right,i,iadc) < 4095"
14  C      C
15  C  jan-07 GF: ADC/TDCflags(4,12) inserted to flag artificial ADC/TDC  C  jan-07 GF: ADC/TDCflags(4,12) inserted to flag artificial ADC/TDC
16  C             values  C             values
17  C  jan-07 WM: artificial ADC values created using attenuation calibration  C  jan-07 WM: artificial ADC values created using attenuation calibration
18  C  jan-07 WM: artificial TDC values created using xy_coor calibration  C  jan-07 WM: artificial TDC values created using xy_coor calibration
# Line 20  C  jan-07 WM: modified xtofpos flag "101 Line 20  C  jan-07 WM: modified xtofpos flag "101
20  C             dimension of the paddle +/- 10 cm  C             dimension of the paddle +/- 10 cm
21  C  jan-07 WM: if xtofpos=101 then this paddle is not used for beta  C  jan-07 WM: if xtofpos=101 then this paddle is not used for beta
22  C             calculation  C             calculation
23  C  jan-07 WM: in the xtofpos calculation a check for TDC.ne.4095 was  C  jan-07 WM: in the xtofpos calculation a check for TDC.ne.4095 was
24  C             inserted. In the old code one would still calculate a  C             inserted. In the old code one would still calculate a
25  C             xtofpos-value even if the TDC information was missing  C             xtofpos-value even if the TDC information was missing
26  C  jan-07 WM: flag for PMTs #10 and #35 added, TDC=819 due to bit-shift  C  jan-07 WM: flag for PMTs #10 and #35 added, TDC=819 due to bit-shift
27  C  jan-05 WM: bug fixed: calculation of zenith angles using DOTRACK2  C  jan-05 WM: bug fixed: calculation of zenith angles using DOTRACK2
28  C             was incorrect  C             was incorrect
29  C  jan-07 WM: bug fixed: in some cases tdc_tw was calculated due to a  C  jan-07 WM: bug fixed: in some cases tdc_tw was calculated due to a
30  C             leftover "xhelp" value  C             leftover "xhelp" value
31    C  apr-07 WM: attenuation fit curve is now a double exponential fit
32    C             conversion from raw ADC to pC using calibration function
33    C             new variables xtr_tof(6) and ytr_tof(6) give track position
34    C             at ToF layers
35    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
37    C             case)
38    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
48  C****************************************************************************  C****************************************************************************
49        IMPLICIT NONE        IMPLICIT NONE
50  C      C
51        include  'input_tof.txt'        include  'input_tof.txt'
52        include  'output_tof.txt'        include  'output_tof.txt'
53        include  'tofcomm.txt'        include  'tofcomm.txt'
54  C      C
55          
56  c     =======================================  c     =======================================
57  c     variables for tracking routine  c     variables for tracking routine
58  c     =======================================  c     =======================================
# Line 60  c      REAL dx,dy,dr Line 77  c      REAL dx,dy,dr
77        REAL ds        REAL ds
78        REAL t1,t2,t3,t4        REAL t1,t2,t3,t4
79        REAL yhelp,xhelp,xhelp1,xhelp2        REAL yhelp,xhelp,xhelp1,xhelp2
80        REAL c1,c2,sw,sxw,w_i        REAL c1,c2
81        REAL dist,dl,F  C     REAL sw,sxw,w_i
82        INTEGER icount,ievent        REAL dist,dl,F
83        REAL xhelp_a,xhelp_t        INTEGER ievent
84    C      INTEGER icount
85        REAL beta_mean  C      REAL beta_mean
86          REAL btemp(12)
87        REAL hepratio        REAL hepratio
88          
89        INTEGER j        INTEGER j,hitvec(6)
90    
91          real atten,pc_adc,check_charge,newbeta
92    
93    
94        REAL theta,phi        REAL theta,phi
95  C--   DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006  C--   DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006
96        REAL tofarm12        REAL tofarm12
97        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69
98        REAL tofarm23                REAL tofarm23
99        PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92        PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92
100        REAL tofarm13        REAL tofarm13
101        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92
102    
103          
104        INTEGER ihelp        INTEGER ihelp
105        REAL xkorr,xpos        REAL xkorr,xpos
106    
107          INTEGER IZ
108          REAL k1corrA1,k1corrB1,k1corrC1
109    
110        REAL yl,yh,xl,xh        REAL yl,yh,xl,xh
111  C      C
112        REAL hmemor(9000000)        REAL hmemor(9000000)
113        INTEGER Iquest(100)        INTEGER Iquest(100)
114  C      C
115        DATA ievent / 0 /        DATA ievent / 0 /
116    
117          INTEGER ifst
118          DATA ifst /0/
119    
120        COMMON / pawcd / hmemor        COMMON / pawcd / hmemor
121        save / pawcd /        save / pawcd /
122  C      C
123        Common / QUESTd / Iquest        Common / QUESTd / Iquest
124        save / questd /        save / questd /
125  C      C
126  C     Begin !  C     Begin !
127  C      C
128        TOFTRK = 0        TOFTRK = 0
129    
130  *******************************************************************  *******************************************************************
131    
132        ievent = ievent +1         if (ifst.eq.0) then
133           ifst=1
134    
135  C  ratio helium to proton ca. 4  C  ratio helium to proton ca. 4
136        hepratio = 4.5        hepratio = 4.
137    
138        offset = 1        offset = 1
139        slope = 2        slope = 2
# Line 118  C  ratio helium to proton ca. 4 Line 146  C  ratio helium to proton ca. 4
146        itdc = 1        itdc = 1
147        iadc = 2        iadc = 2
148    
149    
150          k1corrA1 = 0.
151          k1corrB1 = -5.0
152          k1corrC1=  8.0
153    
154          ENDIF   ! ifst
155    
156    *******************************************************************
157    
158          ievent = ievent +1
159    
160        do i=1,13        do i=1,13
161           beta_a(i) = 100.           beta_a(i) = 100.
162        enddo        enddo
# Line 153  C  ratio helium to proton ca. 4 Line 192  C  ratio helium to proton ca. 4
192        THYOUT(j) = 0.        THYOUT(j) = 0.
193        enddo        enddo
194    
195          do j=1,6
196          xtr_tof(j) = 100.
197          ytr_tof(j) = 100.
198          enddo
199    
200    
201  C----------------------------------------------------------------------  C----------------------------------------------------------------------
202  C-------------------------get ToF data --------------------------------  C-------------------------get ToF data --------------------------------
203  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
204  C     manipulated (Time-walk, artificila ADc and TDC values using ToF  C     manipulated (Time-walk, artificila ADc and TDC values using ToF
205  C     standalone information  C     standalone information
206  C----------------------------------------------------------------------  C----------------------------------------------------------------------
 C     put the adc and tdc values from ntuple into tofxx(i,j,k) variables  
207    
208    c     put the adc and tdc values from ntuple into tofxx(i,j,k) variables
209    
210        do j=1,8        do j=1,8
211           tof11(1,j,2) = adc(ch11a(j),hb11a(j))           tof11(1,j,2) = pc_adc(adc(ch11a(j),hb11a(j)))
212           tof11(2,j,2) = adc(ch11b(j),hb11b(j))           tof11(2,j,2) = pc_adc(adc(ch11b(j),hb11b(j)))
213           tof11(1,j,1) = tdc(ch11a(j),hb11a(j))           tof11(1,j,1) = (tdc(ch11a(j),hb11a(j)))
214           tof11(2,j,1) = tdc(ch11b(j),hb11b(j))           tof11(2,j,1) = (tdc(ch11b(j),hb11b(j)))
215        enddo        enddo
216    
217    
218        do j=1,6        do j=1,6
219           tof12(1,j,2) = adc(ch12a(j),hb12a(j))           tof12(1,j,2) = pc_adc(adc(ch12a(j),hb12a(j)))
220           tof12(2,j,2) = adc(ch12b(j),hb12b(j))           tof12(2,j,2) = pc_adc(adc(ch12b(j),hb12b(j)))
221           tof12(1,j,1) = tdc(ch12a(j),hb12a(j))           tof12(1,j,1) = (tdc(ch12a(j),hb12a(j)))
222           tof12(2,j,1) = tdc(ch12b(j),hb12b(j))           tof12(2,j,1) = (tdc(ch12b(j),hb12b(j)))
223        enddo        enddo
224    
225        do j=1,2        do j=1,2
226           tof21(1,j,2) = adc(ch21a(j),hb21a(j))           tof21(1,j,2) = pc_adc(adc(ch21a(j),hb21a(j)))
227           tof21(2,j,2) = adc(ch21b(j),hb21b(j))           tof21(2,j,2) = pc_adc(adc(ch21b(j),hb21b(j)))
228           tof21(1,j,1) = tdc(ch21a(j),hb21a(j))           tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))
229           tof21(2,j,1) = tdc(ch21b(j),hb21b(j))           tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))
230        enddo        enddo
231    
232        do j=1,2        do j=1,2
233           tof22(1,j,2) = adc(ch22a(j),hb22a(j))           tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))
234           tof22(2,j,2) = adc(ch22b(j),hb22b(j))           tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))
235           tof22(1,j,1) = tdc(ch22a(j),hb22a(j))           tof22(1,j,1) = (tdc(ch22a(j),hb22a(j)))
236           tof22(2,j,1) = tdc(ch22b(j),hb22b(j))           tof22(2,j,1) = (tdc(ch22b(j),hb22b(j)))
237        enddo        enddo
238    
239        do j=1,3        do j=1,3
240           tof31(1,j,2) = adc(ch31a(j),hb31a(j))           tof31(1,j,2) = pc_adc(adc(ch31a(j),hb31a(j)))
241           tof31(2,j,2) = adc(ch31b(j),hb31b(j))           tof31(2,j,2) = pc_adc(adc(ch31b(j),hb31b(j)))
242           tof31(1,j,1) = tdc(ch31a(j),hb31a(j))           tof31(1,j,1) = (tdc(ch31a(j),hb31a(j)))
243           tof31(2,j,1) = tdc(ch31b(j),hb31b(j))           tof31(2,j,1) = (tdc(ch31b(j),hb31b(j)))
244        enddo        enddo
245    
246        do j=1,3        do j=1,3
247           tof32(1,j,2) = adc(ch32a(j),hb32a(j))           tof32(1,j,2) = pc_adc(adc(ch32a(j),hb32a(j)))
248           tof32(2,j,2) = adc(ch32b(j),hb32b(j))           tof32(2,j,2) = pc_adc(adc(ch32b(j),hb32b(j)))
249           tof32(1,j,1) = tdc(ch32a(j),hb32a(j))           tof32(1,j,1) = (tdc(ch32a(j),hb32a(j)))
250           tof32(2,j,1) = tdc(ch32b(j),hb32b(j))           tof32(2,j,1) = (tdc(ch32b(j),hb32b(j)))
251        enddo        enddo
252    
253  C----------------------------------------------------------------------  C----------------------------------------------------------------------
# Line 250  C--------------------------------------- Line 295  C---------------------------------------
295           if (abs(tof32(2,i,iadc)).gt.10000.) tof32(2,i,iadc)= 10000.           if (abs(tof32(2,i,iadc)).gt.10000.) tof32(2,i,iadc)= 10000.
296        ENDDO        ENDDO
297    
298  C-------------------------------------------------------------------  C----------------------------------------------------------------------
299    
300  C------read  tracking routine  C------read  tracking routine
301  *     igoodevent = igoodevent+1  *     igoodevent = igoodevent+1
# Line 268  C     COPY THE ALFA VECTOR FROM AL_PP TO Line 313  C     COPY THE ALFA VECTOR FROM AL_PP TO
313  c      write(*,*) AL_P  c      write(*,*) AL_P
314    
315        if (al_p(5).eq.0.) THEN        if (al_p(5).eq.0.) THEN
316           PRINT *,' TOF - WARNING F77: track with R = 0, discarded'  c         PRINT *,' TOF - WARNING F77: track with R = 0, discarded'
317           GOTO 969           GOTO 969
318        ENDIF        ENDIF
319  *     -------- *** tracking routine *** --------  *     -------- *** tracking routine *** --------
# Line 276  c      write(*,*) AL_P Line 321  c      write(*,*) AL_P
321  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,AL_P,IFAIL)  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,AL_P,IFAIL)
322        call DOTRACK2(NPTOF,ZIN,XOUT,YOUT,THXOUT,THYOUT,TLOUT,AL_P,IFAIL)        call DOTRACK2(NPTOF,ZIN,XOUT,YOUT,THXOUT,THYOUT,TLOUT,AL_P,IFAIL)
323    
   
324  C     write(*,*) (TLOUT(i),i=1,6)  C     write(*,*) (TLOUT(i),i=1,6)
325    
326        if(IFAIL.ne.0)then        if(IFAIL.ne.0)then
327           print *,' TOF - WARNING F77: tracking failed '  c         print *,' TOF - WARNING F77: tracking failed '
328           goto 969           goto 969
329        endif        endif
330  *     ------------------------------------------  *     ------------------------------------------
331    
332   969  continue   969  continue
333    
334    C---  Fill xtr_tof  and ytr_tof: positions from tracker at ToF layers
335          do j=1,6
336          xtr_tof(j) = XOUT(j)
337          ytr_tof(j) = YOUT(j)
338          enddo
339    
340    
341  C---  convert  angles to radian  C---  convert  angles to radian
342        do j=1,6        do j=1,6
343        THXOUT(j) = 3.1415927*THXOUT(j)/180.        THXOUT(j) = 3.1415927*THXOUT(j)/180.
# Line 366  c     DATA tof21_y/  3.75,-3.75/  ! padd Line 417  c     DATA tof21_y/  3.75,-3.75/  ! padd
417  c     DATA tof22_x/ -4.5,4.5/  c     DATA tof22_x/ -4.5,4.5/
418  c     DATA tof31_x/ -6.0,0.,6.0/  c     DATA tof31_x/ -6.0,0.,6.0/
419  c     DATA tof32_y/ -5.0,0.0,5.0/  c     DATA tof32_y/ -5.0,0.0,5.0/
420  c      c
421  c     S11 8 paddles  33.0 x 5.1 cm  c     S11 8 paddles  33.0 x 5.1 cm
422  c     S12 6 paddles  40.8 x 5.5 cm  c     S12 6 paddles  40.8 x 5.5 cm
423  c     S21 2 paddles  18.0 x 7.5 cm  c     S21 2 paddles  18.0 x 7.5 cm
# Line 397  C--------------S11 --------------------- Line 448  C--------------S11 ---------------------
448  C--------------S12 --------------------------------------  C--------------S12 --------------------------------------
449    
450        tof12_i = none_find        tof12_i = none_find
451          
452        xl = -40.8/2.        xl = -40.8/2.
453        xh =  40.8/2.        xh =  40.8/2.
454    
# Line 414  C--------------S12 --------------------- Line 465  C--------------S12 ---------------------
465  C--------------S21 --------------------------------------  C--------------S21 --------------------------------------
466    
467        tof21_i = none_find        tof21_i = none_find
468          
469        xl = -18./2.        xl = -18./2.
470        xh =  18./2.        xh =  18./2.
471    
# Line 431  C--------------S21 --------------------- Line 482  C--------------S21 ---------------------
482  C--------------S22 --------------------------------------  C--------------S22 --------------------------------------
483    
484        tof22_i = none_find        tof22_i = none_find
485          
486        yl = -15./2.        yl = -15./2.
487        yh =  15./2.        yh =  15./2.
488    
# Line 448  C--------------S22 --------------------- Line 499  C--------------S22 ---------------------
499  C--------------S31 --------------------------------------  C--------------S31 --------------------------------------
500    
501        tof31_i = none_find        tof31_i = none_find
502          
503        yl = -15.0/2.        yl = -15.0/2.
504        yh =  15.0/2.        yh =  15.0/2.
505    
# Line 465  C--------------S31 --------------------- Line 516  C--------------S31 ---------------------
516  C--------------S32 --------------------------------------  C--------------S32 --------------------------------------
517    
518        tof32_i = none_find        tof32_i = none_find
519          
520        xl = -18.0/2.        xl = -18.0/2.
521        xh =  18.0/2.        xh =  18.0/2.
522    
# Line 482  C--------------S32 --------------------- Line 533  C--------------S32 ---------------------
533    
534  C     write(*,*) tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i  C     write(*,*) tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i
535    
536  C-----------------------------------------------------------------------         hitvec(1)=tof11_i
537  C--------------------Insert Artifical TDC Value  ---------------------         hitvec(2)=tof12_i
538  C     For each Paddle perform check:         hitvec(3)=tof21_i
539  C     if left paddle=4095  and right paddle OK => create TDC value left         hitvec(4)=tof22_i
540  C     if right paddle=4095  and left paddle OK => create TDC value right         hitvec(5)=tof31_i
541  C-----------------------------------------------------------------------         hitvec(6)=tof32_i
   
 C-----------------------S11 -----------------------------------------  
542    
543        IF (tof11_i.GT.none_find) THEN  c       write(*,*) 'toftrk ',
544           xpos = yout(1)  c     &  tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i
          i = tof11_i  
          if ((tof11(1,tof11_i,itdc).EQ.4095).AND.  
      &        (tof11(2,tof11_i,itdc).LT.4095)) THEN    
   
 c       write(*,*)'11lb4 ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  
545    
546              tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)  C----------------------------------------------------------------------
547       &           + 2*(y_coor_lin11(tof11_i,offset)  C--- check charge:
548       &           + xpos*y_coor_lin11(tof11_i,slope))  C--- if Z=2 we should use the attenuation curve for helium to
549    C--- fill the artificail ADC values and NOT divide by "hepratio"
550  c       write(*,*)'11laf ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  C--- if Z>2 we should do a correction to
551    C--- the k1 constants in the beta calculation
552              tdcflag(ch11a(i),hb11a(i)) = 1  C----------------------------------------------------------------------
     
         ENDIF  
          if ((tof11(2,tof11_i,itdc).EQ.4095).AND.  
      &        (tof11(1,tof11_i,itdc).LT.4095)) THEN    
   
 c       write(*,*)'11rb4 ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  
   
             tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)  
      &           - 2*(y_coor_lin11(tof11_i,offset)  
      &           + xpos*y_coor_lin11(tof11_i,slope))  
 c       write(*,*)'11raf ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  
   
             tdcflag(ch11b(i),hb11b(i)) = 1  
          ENDIF      
       ENDIF  
   
 C-----------------------S12 -----------------------------------------  
   
       IF (tof12_i.GT.none_find) THEN  
          xpos = xout(2)  
          i = tof12_i  
          if ((tof12(1,tof12_i,itdc).EQ.4095).AND.  
      &        (tof12(2,tof12_i,itdc).LT.4095)) THEN  
             tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)  
      &           + 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  
         
 C-----------------------S21 -----------------------------------------  
   
       IF (tof21_i.GT.none_find) THEN  
          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  
   
 C-----------------------S22 -----------------------------------------  
   
       IF (tof22_i.GT.none_find) THEN  
          xpos = yout(4)  
          i = tof22_i  
          if ((tof22(1,tof22_i,itdc).EQ.4095).AND.  
      &        (tof22(2,tof22_i,itdc).LT.4095)) THEN  
             tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)  
      &           + 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  
   
 C-----------------------S31 -----------------------------------------  
         
       IF (tof31_i.GT.none_find) THEN  
          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  
553    
554  C-----------------------S32 -----------------------------------------         theta=0.  
555           dist = ZTOF(1) - ZTOF(5)
556           dl = 0.
557           DO I=1,5
558             dl = dl + TLOUT(i)
559           ENDDO
560           F = dl/dist
561           theta = acos(1/F)
562    
563        IF (tof32_i.GT.none_find) THEN         iz = int(check_charge(theta,hitvec))
564           xpos = xout(6)  c       write(*,*) 'in toftrk',iz
          i = tof32_i  
          if ((tof32(1,tof32_i,itdc).EQ.4095).AND.  
      &        (tof32(2,tof32_i,itdc).LT.4095)) THEN  
             tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)  
      &           + 2*(x_coor_lin32(tof32_i,offset)  
      &           + xpos*x_coor_lin32(tof32_i,slope))  
             tdcflag(ch32a(i),hb32a(i)) = 1  
          ENDIF  
          if ((tof32(2,tof32_i,itdc).EQ.4095).AND.  
      &        (tof32(1,tof32_i,itdc).LT.4095)) THEN  
             tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)  
      &           - 2*(x_coor_lin32(tof32_i,offset)  
      &           + xpos*x_coor_lin32(tof32_i,slope))  
             tdcflag(ch32b(i),hb32b(i)) = 1  
          ENDIF  
       ENDIF  
565    
566  C--------------------------------------------------------------------  C--------------------------------------------------------------------
567  C---- if TDCleft.and.TDCright and NO ADC insert artificial ADC  C---- if paddle hit: if we have TDC value but no ADC, create ADC value
 C---- values  
568  C--------------------------------------------------------------------  C--------------------------------------------------------------------
569  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
570  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 644  C----------------------------S1 -------- Line 579  C----------------------------S1 --------
579        yhelp=yout(1)        yhelp=yout(1)
580        IF (tof11_i.GT.none_find.AND.abs(yout(1)).lt.100) THEN        IF (tof11_i.GT.none_find.AND.abs(yout(1)).lt.100) THEN
581           i = tof11_i           i = tof11_i
582           if (tof11(left,i,iadc).eq.4095) then           if ((tdc(ch11a(i),hb11a(i)).lt.4095).AND.
583         &       (adc(ch11a(i),hb11a(i)).eq.4095)) then
584              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
585              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
586              xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))              xkorr = atten(left,11,i,yhelp)
587              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
588              tof11(left,i,iadc)=xkorr/cos(theta)              tof11(left,i,iadc)=xkorr/cos(theta)
589              adcflag(ch11a(i),hb11a(i)) = 1              adcflag(ch11a(i),hb11a(i)) = 1
590           endif           endif
591           if (tof11(right,i,iadc).eq.4095) then           if ((tdc(ch11b(i),hb11b(i)).lt.4095).AND.
592         &       (adc(ch11b(i),hb11b(i)).eq.4095)) then
593              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
594              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
595              xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))              xkorr = atten(right,11,i,yhelp)
596              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
597              tof11(right,i,iadc)=xkorr/cos(theta)              tof11(right,i,iadc)=xkorr/cos(theta)
598              adcflag(ch11b(i),hb11b(i)) = 1              adcflag(ch11b(i),hb11b(i)) = 1
599           endif           endif
# Line 665  C----------------------------S1 -------- Line 602  C----------------------------S1 --------
602        xhelp=xout(2)        xhelp=xout(2)
603        IF (tof12_i.GT.none_find.AND.abs(xout(2)).lt.100) THEN        IF (tof12_i.GT.none_find.AND.abs(xout(2)).lt.100) THEN
604           i = tof12_i           i = tof12_i
605           if (tof12(left,i,iadc).eq.4095) then           if ((tdc(ch12a(i),hb12a(i)).lt.4095).AND.
606         &       (adc(ch12a(i),hb12a(i)).eq.4095)) then
607              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
608              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
609              xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))  c            xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))
610              xkorr=xkorr/hepratio                          xkorr = atten(left,12,i,xhelp)
611                if (iz.le.1) xkorr=xkorr/hepratio
612              tof12(left,i,iadc) = xkorr/cos(theta)              tof12(left,i,iadc) = xkorr/cos(theta)
613              adcflag(ch12a(i),hb12a(i)) = 1              adcflag(ch12a(i),hb12a(i)) = 1
614           endif           endif
615           if (tof12(right,i,iadc).eq.4095) then           if ((tdc(ch12b(i),hb12b(i)).lt.4095).AND.
616         &       (adc(ch12b(i),hb12b(i)).eq.4095)) then
617              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
618              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
619              xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))  c            xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))
620              xkorr=xkorr/hepratio                          xkorr = atten(right,12,i,xhelp)
621                if (iz.le.1) xkorr=xkorr/hepratio
622              tof12(right,i,iadc) = xkorr/cos(theta)              tof12(right,i,iadc) = xkorr/cos(theta)
623              adcflag(ch12b(i),hb12b(i)) = 1              adcflag(ch12b(i),hb12b(i)) = 1
624           endif           endif
# Line 688  C-----------------------------S2 ------- Line 629  C-----------------------------S2 -------
629        xhelp=xout(3)        xhelp=xout(3)
630        IF (tof21_i.GT.none_find.AND.abs(xout(3)).lt.100) THEN        IF (tof21_i.GT.none_find.AND.abs(xout(3)).lt.100) THEN
631           i = tof21_i           i = tof21_i
632           if (tof21(left,i,iadc).eq.4095) then           if ((tdc(ch21a(i),hb21a(i)).lt.4095).AND.
633         &       (adc(ch21a(i),hb21a(i)).eq.4095)) then
634              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
635              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
636              xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))  c            xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))
637              xkorr=xkorr/hepratio                          xkorr = atten(left,21,i,xhelp)
638                if (iz.le.1) xkorr=xkorr/hepratio
639              tof21(left,i,iadc) = xkorr/cos(theta)              tof21(left,i,iadc) = xkorr/cos(theta)
640              adcflag(ch21a(i),hb21a(i)) = 1              adcflag(ch21a(i),hb21a(i)) = 1
641           endif           endif
642           if (tof21(right,i,iadc).eq.4095) then           if ((tdc(ch21b(i),hb21b(i)).lt.4095).AND.
643         &       (adc(ch21b(i),hb21b(i)).eq.4095)) then
644              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
645              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
646              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))  c            xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))
647              xkorr=xkorr/hepratio                          xkorr = atten(right,21,i,xhelp)
648                if (iz.le.1) xkorr=xkorr/hepratio
649              tof21(right,i,iadc) = xkorr/cos(theta)              tof21(right,i,iadc) = xkorr/cos(theta)
650              adcflag(ch21b(i),hb21b(i)) = 1              adcflag(ch21b(i),hb21b(i)) = 1
651           endif           endif
# Line 710  C-----------------------------S2 ------- Line 655  C-----------------------------S2 -------
655        yhelp=yout(4)        yhelp=yout(4)
656        IF (tof22_i.GT.none_find.AND.abs(yout(4)).lt.100) THEN        IF (tof22_i.GT.none_find.AND.abs(yout(4)).lt.100) THEN
657           i = tof22_i           i = tof22_i
658           if (tof22(left,i,iadc).eq.4095) then           if ((tdc(ch22a(i),hb22a(i)).lt.4095).AND.
659         &       (adc(ch22a(i),hb22a(i)).eq.4095)) then
660              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
661              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
662              xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))  c            xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))
663              xkorr=xkorr/hepratio                          xkorr = atten(left,22,i,yhelp)
664                if (iz.le.1) xkorr=xkorr/hepratio
665              tof22(left,i,iadc) = xkorr/cos(theta)              tof22(left,i,iadc) = xkorr/cos(theta)
666              adcflag(ch22a(i),hb22a(i)) = 1              adcflag(ch22a(i),hb22a(i)) = 1
667           endif           endif
668           if (tof22(right,i,iadc).eq.4095) then           if ((tdc(ch22a(i),hb22b(i)).lt.4095).AND.
669         &       (adc(ch22b(i),hb22b(i)).eq.4095)) then
670              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
671              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
672              xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))  c            xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))
673              xkorr=xkorr/hepratio                          xkorr = atten(right,22,i,yhelp)
674                if (iz.le.1) xkorr=xkorr/hepratio
675              tof22(right,i,iadc) = xkorr/cos(theta)              tof22(right,i,iadc) = xkorr/cos(theta)
676              adcflag(ch22b(i),hb22b(i)) = 1              adcflag(ch22b(i),hb22b(i)) = 1
677           endif           endif
# Line 733  C-----------------------------S3 ------- Line 682  C-----------------------------S3 -------
682        yhelp=yout(5)        yhelp=yout(5)
683        IF (tof31_i.GT.none_find.AND.abs(yout(5)).lt.100) THEN        IF (tof31_i.GT.none_find.AND.abs(yout(5)).lt.100) THEN
684           i = tof31_i           i = tof31_i
685           if (tof31(left,i,iadc).eq.4095) then           if ((tdc(ch31a(i),hb31a(i)).lt.4095).AND.
686         &       (adc(ch31a(i),hb31a(i)).eq.4095)) then
687              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
688              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
689              xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))  c            xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))
690              xkorr=xkorr/hepratio                          xkorr = atten(left,31,i,yhelp)
691                if (iz.le.1) xkorr=xkorr/hepratio
692              tof31(left,i,iadc) = xkorr/cos(theta)              tof31(left,i,iadc) = xkorr/cos(theta)
693              adcflag(ch31a(i),hb31a(i)) = 1              adcflag(ch31a(i),hb31a(i)) = 1
694           endif           endif
695           if (tof31(right,i,iadc).eq.4095) then           if ((tdc(ch31b(i),hb31b(i)).lt.4095).AND.
696         &       (adc(ch31b(i),hb31b(i)).eq.4095)) then
697              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
698              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
699              xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))  c            xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))
700              xkorr=xkorr/hepratio                          xkorr = atten(right,31,i,yhelp)
701                if (iz.le.1) xkorr=xkorr/hepratio
702              tof31(right,i,iadc) = xkorr/cos(theta)              tof31(right,i,iadc) = xkorr/cos(theta)
703              adcflag(ch31b(i),hb31b(i)) = 1              adcflag(ch31b(i),hb31b(i)) = 1
704           endif           endif
# Line 755  C-----------------------------S3 ------- Line 708  C-----------------------------S3 -------
708        xhelp=xout(6)        xhelp=xout(6)
709        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
710           i = tof32_i           i = tof32_i
711           if (tof32(left,i,iadc).eq.4095) then           if ((tdc(ch32a(i),hb32a(i)).lt.4095).AND.
712         &       (adc(ch32a(i),hb32a(i)).eq.4095)) then
713              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
714              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
715              xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))  c            xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))
716              xkorr=xkorr/hepratio                          xkorr = atten(left,32,i,xhelp)
717                if (iz.le.1) xkorr=xkorr/hepratio
718              tof32(left,i,iadc) = xkorr/cos(theta)              tof32(left,i,iadc) = xkorr/cos(theta)
719              adcflag(ch32a(i),hb32a(i)) = 1              adcflag(ch32a(i),hb32a(i)) = 1
720           endif           endif
721           if (tof32(right,i,iadc).eq.4095) then           if ((tdc(ch32b(i),hb32b(i)).lt.4095).AND.
722         &       (adc(ch32b(i),hb32b(i)).eq.4095)) then
723              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
724              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
725              xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))  c            xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))
726              xkorr=xkorr/hepratio                          xkorr = atten(right,32,i,xhelp)
727                if (iz.le.1) xkorr=xkorr/hepratio
728              tof32(right,i,iadc) = xkorr/cos(theta)              tof32(right,i,iadc) = xkorr/cos(theta)
729              adcflag(ch32b(i),hb32b(i)) = 1              adcflag(ch32b(i),hb32b(i)) = 1
730           endif           endif
731        ENDIF        ENDIF
732    
733    C-------------------------------------------------------------------
734    C Now there is for each hitted paddle a TDC and ADC value, if the
735    C TDC was < 4095.
736    C There might be also TDC-ADC pairs in paddles not hitted
737    C Let's correct the raw TDC value with the time walk
738    C-------------------------------------------------------------------
739    C--------------------Time walk correction  -------------------------
740    C-------------------------------------------------------------------
741    
742          DO i=1,8
743             if ((tdc(ch11a(i),hb11a(i)).lt.4095).and.
744         &             (tof11(left,i,iadc).lt.3786)) THEN
745             xhelp = tw11(left,i)/(tof11(left,i,iadc)**0.5)
746             tof11(left,i,itdc) = tof11(left,i,itdc) + xhelp
747             tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)
748                                                  ENDIF
749    
750             if ((tdc(ch11b(i),hb11b(i)).lt.4095).and.
751         &             (tof11(right,i,iadc).lt.3786)) THEN
752             xhelp = tw11(right,i)/(tof11(right,i,iadc)**0.5)
753             tof11(right,i,itdc) = tof11(right,i,itdc) + xhelp
754             tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)
755                                                 ENDIF
756          ENDDO
757    
758    
759          DO i=1,6
760             if ((tdc(ch12a(i),hb12a(i)).lt.4095).and.
761         &             (tof12(left,i,iadc).lt.3786)) THEN
762             xhelp = tw12(left,i)/(tof12(left,i,iadc)**0.5)
763             tof12(left,i,itdc) = tof12(left,i,itdc) + xhelp
764             tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)
765                                                  ENDIF
766    
767             if ((tdc(ch12b(i),hb12b(i)).lt.4095).and.
768         &             (tof12(right,i,iadc).lt.3786)) THEN
769             xhelp = tw12(right,i)/(tof12(right,i,iadc)**0.5)
770             tof12(right,i,itdc) = tof12(right,i,itdc) + xhelp
771             tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)
772                                                 ENDIF
773          ENDDO
774    
775    C----
776          DO I=1,2
777             if ((tdc(ch21a(i),hb21a(i)).lt.4095).and.
778         &             (tof21(left,i,iadc).lt.3786)) THEN
779             xhelp = tw21(left,i)/(tof21(left,i,iadc)**0.5)
780             tof21(left,i,itdc) = tof21(left,i,itdc) + xhelp
781             tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)
782                                                  ENDIF
783    
784             if ((tdc(ch21b(i),hb21b(i)).lt.4095).and.
785         &             (tof21(right,i,iadc).lt.3786)) THEN
786             xhelp = tw21(right,i)/(tof21(right,i,iadc)**0.5)
787             tof21(right,i,itdc) = tof21(right,i,itdc) + xhelp
788             tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)
789                                                 ENDIF
790          ENDDO
791    
792          DO I=1,2
793             if ((tdc(ch22a(i),hb22a(i)).lt.4095).and.
794         &             (tof22(left,i,iadc).lt.3786)) THEN
795             xhelp = tw22(left,i)/(tof22(left,i,iadc)**0.5)
796             tof22(left,i,itdc) = tof22(left,i,itdc) + xhelp
797             tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)
798                                                  ENDIF
799    
800             if ((tdc(ch22b(i),hb22b(i)).lt.4095).and.
801         &             (tof22(right,i,iadc).lt.3786)) THEN
802             xhelp = tw22(right,i)/(tof22(right,i,iadc)**0.5)
803             tof22(right,i,itdc) = tof22(right,i,itdc) + xhelp
804             tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)
805                                                 ENDIF
806          ENDDO
807    
808    C----
809          DO I=1,3
810             if ((tdc(ch31a(i),hb31a(i)).lt.4095).and.
811         &             (tof31(left,i,iadc).lt.3786)) THEN
812             xhelp = tw31(left,i)/(tof31(left,i,iadc)**0.5)
813             tof31(left,i,itdc) = tof31(left,i,itdc) + xhelp
814             tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)
815                                                  ENDIF
816    
817             if ((tdc(ch31b(i),hb31b(i)).lt.4095).and.
818         &             (tof31(right,i,iadc).lt.3786)) THEN
819             xhelp = tw31(right,i)/(tof31(right,i,iadc)**0.5)
820             tof31(right,i,itdc) = tof31(right,i,itdc) + xhelp
821             tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)
822                                                 ENDIF
823          ENDDO
824    
825          DO I=1,3
826             if ((tdc(ch32a(i),hb32a(i)).lt.4095).and.
827         &             (tof32(left,i,iadc).lt.3786)) THEN
828             xhelp = tw32(left,i)/(tof32(left,i,iadc)**0.5)
829             tof32(left,i,itdc) = tof32(left,i,itdc) + xhelp
830             tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)
831                                                  ENDIF
832    
833             if ((tdc(ch32b(i),hb32b(i)).lt.4095).and.
834         &             (tof32(right,i,iadc).lt.3786)) THEN
835             xhelp = tw32(right,i)/(tof32(right,i,iadc)**0.5)
836             tof32(right,i,itdc) = tof32(right,i,itdc) + xhelp
837             tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)
838                                                 ENDIF
839          ENDDO
840    
841    
842    C-----------------------------------------------------------------------
843    C--------------------Insert Artifical TDC Value  ---------------------
844    C     For each Paddle perform check:
845    C     if left paddle=4095  and right paddle OK => create TDC value left
846    C     if right paddle=4095  and left paddle OK => create TDC value right
847    C-----------------------------------------------------------------------
848    
849    C-----------------------S11 -----------------------------------------
850    
851          IF (tof11_i.GT.none_find) THEN
852             xpos = yout(1)
853             i = tof11_i
854            if ((tdc(ch11a(i),hb11a(i)).EQ.4095).AND.
855         &          (tdc(ch11b(i),hb11b(i)).LT.4095)) THEN
856              tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)
857         &           + 2*(y_coor_lin11(tof11_i,offset)
858         &           + xpos*y_coor_lin11(tof11_i,slope))
859                tdcflag(ch11a(i),hb11a(i)) = 1
860            ENDIF
861    
862            if ((tdc(ch11b(i),hb11b(i)).EQ.4095).AND.
863         &          (tdc(ch11a(i),hb11a(i)).LT.4095)) THEN
864                tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)
865         &           - 2*(y_coor_lin11(tof11_i,offset)
866         &           + xpos*y_coor_lin11(tof11_i,slope))
867                tdcflag(ch11b(i),hb11b(i)) = 1
868             ENDIF
869    
870          ENDIF
871    
872    C-----------------------S12 -----------------------------------------
873    
874          IF (tof12_i.GT.none_find) THEN
875             xpos = xout(2)
876             i = tof12_i
877            if ((tdc(ch12a(i),hb12a(i)).EQ.4095).AND.
878         &          (tdc(ch12b(i),hb12b(i)).LT.4095)) THEN
879                tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)
880         &           + 2*(x_coor_lin12(tof12_i,offset)
881         &           + xpos*x_coor_lin12(tof12_i,slope))
882                tdcflag(ch12a(i),hb12a(i)) = 1
883             ENDIF
884    
885            if ((tdc(ch12b(i),hb12b(i)).EQ.4095).AND.
886         &          (tdc(ch12a(i),hb12a(i)).LT.4095)) THEN
887                tof12(2,tof12_i,itdc) = tof12(1,tof12_i,itdc)
888         &           - 2*(x_coor_lin12(tof12_i,offset)
889         &           + xpos*x_coor_lin12(tof12_i,slope))
890                tdcflag(ch12b(i),hb12b(i)) = 1
891             ENDIF
892          ENDIF
893    
894    C-----------------------S21 -----------------------------------------
895    
896          IF (tof21_i.GT.none_find) THEN
897             xpos = xout(3)
898             i = tof21_i
899            if ((tdc(ch21a(i),hb21a(i)).EQ.4095).AND.
900         &          (tdc(ch21b(i),hb21b(i)).LT.4095)) THEN
901                tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)
902         &           + 2*(x_coor_lin21(tof21_i,offset)
903         &           + xpos*x_coor_lin21(tof21_i,slope))
904                tdcflag(ch21a(i),hb21a(i)) = 1
905             ENDIF
906    
907            if ((tdc(ch21b(i),hb21b(i)).EQ.4095).AND.
908         &          (tdc(ch21a(i),hb21a(i)).LT.4095)) THEN
909                tof21(2,tof21_i,itdc) = tof21(1,tof21_i,itdc)
910         &           - 2*(x_coor_lin21(tof21_i,offset)
911         &           + xpos*x_coor_lin21(tof21_i,slope))
912                tdcflag(ch21b(i),hb21b(i)) = 1
913             ENDIF
914          ENDIF
915    
916    C-----------------------S22 -----------------------------------------
917    
918          IF (tof22_i.GT.none_find) THEN
919             xpos = yout(4)
920             i = tof22_i
921            if ((tdc(ch22a(i),hb22a(i)).EQ.4095).AND.
922         &          (tdc(ch22b(i),hb22b(i)).LT.4095)) THEN
923                tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)
924         &           + 2*(y_coor_lin22(tof22_i,offset)
925         &           + xpos*y_coor_lin22(tof22_i,slope))
926                tdcflag(ch22a(i),hb22a(i)) = 1
927             ENDIF
928    
929            if ((tdc(ch22b(i),hb22b(i)).EQ.4095).AND.
930         &          (tdc(ch22a(i),hb22a(i)).LT.4095)) THEN
931                tof22(2,tof22_i,itdc) = tof22(1,tof22_i,itdc)
932         &           - 2*(y_coor_lin22(tof22_i,offset)
933         &           + xpos*y_coor_lin22(tof22_i,slope))
934                tdcflag(ch22b(i),hb22b(i)) = 1
935             ENDIF
936          ENDIF
937    
938    C-----------------------S31 -----------------------------------------
939    
940          IF (tof31_i.GT.none_find) THEN
941             xpos = yout(5)
942             i = tof31_i
943            if ((tdc(ch31a(i),hb31a(i)).EQ.4095).AND.
944         &          (tdc(ch31b(i),hb31b(i)).LT.4095)) THEN
945                tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)
946         &           + 2*(y_coor_lin31(tof31_i,offset)
947         &           + xpos*y_coor_lin31(tof31_i,slope))
948                tdcflag(ch31a(i),hb31a(i)) = 1
949             ENDIF
950    
951            if ((tdc(ch31b(i),hb31b(i)).EQ.4095).AND.
952         &          (tdc(ch31a(i),hb31a(i)).LT.4095)) THEN
953                tof31(2,tof31_i,itdc) = tof31(1,tof31_i,itdc)
954         &           - 2*(y_coor_lin31(tof31_i,offset)
955         &           + xpos*y_coor_lin31(tof31_i,slope))
956                tdcflag(ch31b(i),hb31b(i)) = 1
957             ENDIF
958          ENDIF
959    
960    C-----------------------S32 -----------------------------------------
961    
962          IF (tof32_i.GT.none_find) THEN
963             xpos = xout(6)
964             i = tof32_i
965            if ((tdc(ch32a(i),hb32a(i)).EQ.4095).AND.
966         &          (tdc(ch32b(i),hb32b(i)).LT.4095)) THEN
967                tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)
968         &           + 2*(x_coor_lin32(tof32_i,offset)
969         &           + xpos*x_coor_lin32(tof32_i,slope))
970                tdcflag(ch32a(i),hb32a(i)) = 1
971             ENDIF
972    
973            if ((tdc(ch32b(i),hb32b(i)).EQ.4095).AND.
974         &          (tdc(ch32a(i),hb32a(i)).LT.4095)) THEN
975                tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)
976         &           - 2*(x_coor_lin32(tof32_i,offset)
977         &           + xpos*x_coor_lin32(tof32_i,slope))
978                tdcflag(ch32b(i),hb32b(i)) = 1
979             ENDIF
980          ENDIF
981    
982    
983  C------------------------------------------------------------------  C------------------------------------------------------------------
984  C---  calculate track position in paddle using timing difference  C---  calculate track position in paddle using timing difference
# Line 781  C--------------------------------------- Line 987  C---------------------------------------
987        do i=1,3        do i=1,3
988           xtofpos(i)=100.           xtofpos(i)=100.
989           ytofpos(i)=100.           ytofpos(i)=100.
990        enddo        enddo
991    
992  C-----------------------------S1 --------------------------------  C-----------------------------S1 --------------------------------
993          
994        IF (tof11_i.GT.none_find) THEN        IF (tof11_i.GT.none_find) THEN
995           IF ((tof11(1,tof11_i,itdc).NE.4095).AND.           IF ((tof11(1,tof11_i,itdc).NE.4095).AND.
996       &       (tof11(2,tof11_i,itdc).NE.4095)) THEN       &       (tof11(2,tof11_i,itdc).NE.4095)) THEN
# Line 800  C-----------------------------S1 ------- Line 1007  C-----------------------------S1 -------
1007       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)
1008          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.
1009        endif        endif
1010        endif              endif
1011          
1012  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
1013          
1014        IF (tof21_i.GT.none_find) THEN        IF (tof21_i.GT.none_find) THEN
1015           IF ((tof21(1,tof21_i,itdc).NE.4095).AND.           IF ((tof21(1,tof21_i,itdc).NE.4095).AND.
1016       &       (tof21(2,tof21_i,itdc).NE.4095)) THEN       &       (tof21(2,tof21_i,itdc).NE.4095)) THEN
1017           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.
1018       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)
1019          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.
1020        endif        endif
1021        endif        endif
1022    
# Line 820  C-----------------------------S2 ------- Line 1027  C-----------------------------S2 -------
1027       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)
1028          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.
1029        endif        endif
1030        endif              endif
1031          
1032  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
1033          
1034        IF (tof31_i.GT.none_find) THEN        IF (tof31_i.GT.none_find) THEN
1035           IF ((tof31(1,tof31_i,itdc).NE.4095).AND.           IF ((tof31(1,tof31_i,itdc).NE.4095).AND.
1036       &       (tof31(2,tof31_i,itdc).NE.4095)) THEN       &       (tof31(2,tof31_i,itdc).NE.4095)) THEN
# Line 840  C-----------------------------S3 ------- Line 1047  C-----------------------------S3 -------
1047       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)
1048          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.
1049        endif        endif
1050        endif        endif
1051          
1052  c      do i=1,3  c      do i=1,3
1053  c         if (abs(xtofpos(i)).gt.100.) then  c         if (abs(xtofpos(i)).gt.100.) then
1054  c            xtofpos(i)=101.  c            xtofpos(i)=101.
# Line 849  c         endif Line 1056  c         endif
1056  c         if (abs(ytofpos(i)).gt.100.) then  c         if (abs(ytofpos(i)).gt.100.) then
1057  c            ytofpos(i)=101.  c            ytofpos(i)=101.
1058  c         endif  c         endif
1059  c      enddo  c      enddo
         
   
   
   
 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<4095) 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<4095) 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<4095) 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<4095) 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<4095) 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<4095) 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<4095) 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<4095) 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<4095) 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<4095) 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  
1060    
       DO i=1,3  
          xhelp= 0.  
          xhelp_a = tof32(left,i,iadc)  
          xhelp_t = tof32(left,i,itdc)  
          if(xhelp_a<4095) 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<4095) 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  
1061    
1062    
1063  C---------------------------------------------------------------------  C---------------------------------------------------------------------
# Line 959  C-----------------------------S1 ------- Line 1074  C-----------------------------S1 -------
1074        IF (tof11_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof11_i.GT.none_find.AND.yhelp.lt.100) THEN
1075    
1076           i = tof11_i           i = tof11_i
1077            
1078           if (tof11(left,i,iadc).lt.4095) then           if (tof11(left,i,iadc).lt.3786) then
1079              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta)              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta)
1080              xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))              xkorr = atten(left,11,i,yhelp)
1081              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
1082              adc_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr              adc_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr
1083           endif           endif
1084    
1085            
1086           if (tof11(right,i,iadc).lt.4095) then           if (tof11(right,i,iadc).lt.3786) then
1087              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta)              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta)
1088              xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))              xkorr = atten(right,11,i,yhelp)
1089              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1090              adc_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr              adc_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr
1091           endif           endif
1092        ENDIF        ENDIF
# Line 980  C-----------------------------S1 ------- Line 1095  C-----------------------------S1 -------
1095        xhelp=xout(2)        xhelp=xout(2)
1096        phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))        phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
1097        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  
1098    
1099          IF (tof12_i.GT.none_find.AND.xhelp.lt.100) THEN
1100           i = tof12_i           i = tof12_i
1101           if (tof12(left,i,iadc).lt.4095) then           if (tof12(left,i,iadc).lt.3786) then
1102              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta)              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta)
1103              xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))              xkorr = atten(left,12,i,xhelp)
1104              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1105              adc_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr              adc_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr
1106           endif           endif
1107    
1108           if (tof12(right,i,iadc).lt.4095) then           if (tof12(right,i,iadc).lt.3786) then
1109              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta)              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta)
1110              xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))              xkorr = atten(right,12,i,xhelp)
1111              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1112              adc_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr              adc_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr
1113           endif           endif
1114        ENDIF        ENDIF
# Line 1004  C-----------------------------S2 ------- Line 1118  C-----------------------------S2 -------
1118        xhelp=xout(3)        xhelp=xout(3)
1119        phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))        phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
1120        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  
1121    
1122          IF (tof21_i.GT.none_find.AND.xhelp.lt.100) THEN
1123           i = tof21_i           i = tof21_i
1124           if (tof21(left,i,iadc).lt.4095) then           if (tof21(left,i,iadc).lt.3786) then
1125              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta)              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta)
1126              xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))              xkorr = atten(left,21,i,xhelp)
1127              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1128              adc_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr              adc_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr
1129           endif           endif
1130    
1131           if (tof21(right,i,iadc).lt.4095) then           if (tof21(right,i,iadc).lt.3786) then
1132              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta)              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta)
1133              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))              xkorr = atten(right,21,i,xhelp)
1134              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1135              adc_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr              adc_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr
1136           endif           endif
1137        ENDIF        ENDIF
# Line 1026  c      write(*,*) 'theta21 ',theta Line 1139  c      write(*,*) 'theta21 ',theta
1139        yhelp=yout(4)        yhelp=yout(4)
1140        phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))        phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
1141        theta = atan(tan(THXOUT(4))/cos(phi))        theta = atan(tan(THXOUT(4))/cos(phi))
 c      write(*,*) 'theta22 ',theta  
1142    
1143        IF (tof22_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof22_i.GT.none_find.AND.yhelp.lt.100) THEN
   
1144           i = tof22_i           i = tof22_i
1145           if (tof22(left,i,iadc).lt.4095) then           if (tof22(left,i,iadc).lt.3786) then
1146              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta)              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta)
1147              xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))              xkorr = atten(left,22,i,yhelp)
1148              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1149              adc_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr              adc_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr
1150           endif           endif
1151    
1152           if (tof22(right,i,iadc).lt.4095) then           if (tof22(right,i,iadc).lt.3786) then
1153              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta)              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta)
1154              xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))              xkorr = atten(right,22,i,yhelp)
1155              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1156              adc_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr              adc_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr
1157           endif           endif
1158        ENDIF        ENDIF
# Line 1051  C-----------------------------S3 ------- Line 1162  C-----------------------------S3 -------
1162        yhelp=yout(5)        yhelp=yout(5)
1163        phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))        phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
1164        theta = atan(tan(THXOUT(5))/cos(phi))        theta = atan(tan(THXOUT(5))/cos(phi))
1165  c      write(*,*) 'theta31 ',theta  
         
1166        IF (tof31_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof31_i.GT.none_find.AND.yhelp.lt.100) THEN
1167    
1168           i = tof31_i           i = tof31_i
1169           if (tof31(left,i,iadc).lt.4095) then           if (tof31(left,i,iadc).lt.3786) then
1170              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta)              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta)
1171              xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))              xkorr = atten(left,31,i,yhelp)
1172              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1173              adc_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr              adc_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr
1174           endif           endif
1175    
1176           if (tof31(right,i,iadc).lt.4095) then           if (tof31(right,i,iadc).lt.3786) then
1177              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta)              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta)
1178              xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))              xkorr = atten(right,31,i,yhelp)
1179              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1180              adc_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr              adc_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr
1181           endif           endif
1182        ENDIF        ENDIF
# Line 1074  c      write(*,*) 'theta31 ',theta Line 1184  c      write(*,*) 'theta31 ',theta
1184        xhelp=xout(6)        xhelp=xout(6)
1185        phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))        phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
1186        theta = atan(tan(THXOUT(6))/cos(phi))        theta = atan(tan(THXOUT(6))/cos(phi))
 c      write(*,*) 'theta32 ',theta  
1187    
1188        IF (tof32_i.GT.none_find.AND.xhelp.lt.100) THEN        IF (tof32_i.GT.none_find.AND.xhelp.lt.100) THEN
   
1189           i = tof32_i           i = tof32_i
1190           if (tof32(left,i,iadc).lt.4095) then           if (tof32(left,i,iadc).lt.3786) then
1191              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta)              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta)
1192              xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))              xkorr = atten(left,32,i,xhelp)
1193              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1194              adc_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr              adc_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr
1195           endif           endif
1196    
1197           if (tof32(right,i,iadc).lt.4095) then           if (tof32(right,i,iadc).lt.3786) then
1198              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta)              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta)
1199              xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))              xkorr = atten(right,32,i,xhelp)
1200              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
1201              adc_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr              adc_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr
1202           endif           endif
1203        ENDIF        ENDIF
1204    
1205    
1206  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
1207  C----------------------calculate Beta  ------------------------------  C----------------------calculate Beta  ------------------------------
1208  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
1209  C-------------------difference of sums  ---------------------------  C-------------------difference of sums  ---------------------------
1210  C      C
1211  C     DS = (t1+t2) - t3+t4)  C     DS = (t1+t2) - t3+t4)
1212  C     DS = c1 + c2/beta*cos(theta)  C     DS = c1 + c2/beta*cos(theta)
1213  C     c2 = 2d/c   gives c2 = 2d/(c*TDCresolution)  TDC=50ps/channel  C     c2 = 2d/c   gives c2 = 2d/(c*TDCresolution)  TDC=50ps/channel
1214  C     =>  c2 =  ca.60 for  0.45 m    c2 = ca.109  for 0.81 m  C     =>  c2 =  ca.60 for  0.45 m    c2 = ca.109  for 0.81 m
1215  C     since TDC resolution varies slightly c2 has to be calibrated  C     since TDC resolution varies slightly c2 has to be calibrated
1216  C     instead of cos(theta) use factor F:  C     instead of cos(theta) use factor F:
1217  C     F =  pathlength/d  C     F =  pathlength/d
1218  C     => beta = c2*F/(DS-c1))  C     => beta = c2*F/(DS-c1))
1219    
1220        dist = ZTOF(1) - ZTOF(5)        dist = ZTOF(1) - ZTOF(5)
# Line 1113  C     => beta = c2*F/(DS-c1)) Line 1222  C     => beta = c2*F/(DS-c1))
1222        DO I=1,5        DO I=1,5
1223           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1224        ENDDO        ENDDO
1225        F = dl/dist        F = dl/dist
1226    
1227  C     S11 - S31  C     S11 - S31
1228  C      IF (tof11_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
# Line 1123  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1232  C      IF (tof11_i.GT.none_find.AND.tof3
1232           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1233           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1234           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1235           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1236       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1237              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1238              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1239              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1240              ihelp=(tof11_i-1)*3+tof31_i              ihelp=(tof11_i-1)*3+tof31_i
1241              c1 = k_S11S31(1,ihelp)              c1 = k_S11S31(1,ihelp)
1242              c2 = k_S11S31(2,ihelp)                      if (iz.gt.2) c1 = c1 + k1corrA1
1243                c2 = k_S11S31(2,ihelp)
1244              beta_a(1) = c2*F/(ds-c1)              beta_a(1) = c2*F/(ds-c1)
1245  C     write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)  c       write(*,*) 'S11-S31 ',c1,c2,F
1246    c       write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)
1247  C-------ToF Mask - S11 - S31  C-------ToF Mask - S11 - S31
1248    
1249              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
# Line 1142  C-------ToF Mask - S11 - S31 Line 1253  C-------ToF Mask - S11 - S31
1253    
1254              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1255       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1256              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1257       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1258    
1259           ENDIF           ENDIF
# Line 1153  C-------ToF Mask - S11 - S31 Line 1264  C-------ToF Mask - S11 - S31
1264        DO I=1,6        DO I=1,6
1265           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1266        ENDDO        ENDDO
1267        F = dl/dist        F = dl/dist
1268          
1269  C     S11 - S32  C     S11 - S32
1270  C      IF (tof11_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1271         IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1163  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1274  C      IF (tof11_i.GT.none_find.AND.tof3
1274           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1275           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1276           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1277           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1278       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1279              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1280              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1281              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1282              ihelp=(tof11_i-1)*3+tof32_i              ihelp=(tof11_i-1)*3+tof32_i
1283              c1 = k_S11S32(1,ihelp)              c1 = k_S11S32(1,ihelp)
1284              c2 = k_S11S32(2,ihelp)                      if (iz.gt.2) c1 = c1 + k1corrA1
1285                c2 = k_S11S32(2,ihelp)
1286              beta_a(2) = c2*F/(ds-c1)              beta_a(2) = c2*F/(ds-c1)
1287  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)
1288    
# Line 1183  C-------ToF Mask - S11 - S32 Line 1295  C-------ToF Mask - S11 - S32
1295    
1296              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1297       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1298              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1299       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1300    
1301  C-------  C-------
# Line 1197  C     S12 - S31 Line 1309  C     S12 - S31
1309        DO I=2,5        DO I=2,5
1310           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1311        ENDDO        ENDDO
1312        F = dl/dist        F = dl/dist
1313    
1314  C      IF (tof12_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1315         IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
# Line 1206  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1318  C      IF (tof12_i.GT.none_find.AND.tof3
1318           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1319           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1320           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1321           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1322       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1323              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1324              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1325              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1326              ihelp=(tof12_i-1)*3+tof31_i              ihelp=(tof12_i-1)*3+tof31_i
1327              c1 = k_S12S31(1,ihelp)              c1 = k_S12S31(1,ihelp)
1328                if (iz.gt.2) c1 = c1 + k1corrA1
1329              c2 = k_S12S31(2,ihelp)              c2 = k_S12S31(2,ihelp)
1330              beta_a(3) = c2*F/(ds-c1)              beta_a(3) = c2*F/(ds-c1)
1331  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)
# Line 1226  C-------ToF Mask - S12 - S31 Line 1339  C-------ToF Mask - S12 - S31
1339    
1340              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1341       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1342              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1343       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1344    
1345  C-------  C-------
# Line 1241  C     S12 - S32 Line 1354  C     S12 - S32
1354        DO I=2,6        DO I=2,6
1355           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1356        ENDDO        ENDDO
1357        F = dl/dist        F = dl/dist
1358    
1359  C      IF (tof12_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1360         IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1250  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1363  C      IF (tof12_i.GT.none_find.AND.tof3
1363           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1364           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1365           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1366           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1367       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1368              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1369              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1370              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1371              ihelp=(tof12_i-1)*3+tof32_i              ihelp=(tof12_i-1)*3+tof32_i
1372              c1 = k_S12S32(1,ihelp)              c1 = k_S12S32(1,ihelp)
1373                if (iz.gt.2) c1 = c1 + k1corrA1
1374              c2 = k_S12S32(2,ihelp)              c2 = k_S12S32(2,ihelp)
1375              beta_a(4) = c2*F/(ds-c1)              beta_a(4) = c2*F/(ds-c1)
1376  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)
# Line 1270  C-------ToF Mask - S12 - S32 Line 1384  C-------ToF Mask - S12 - S32
1384    
1385              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1386       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1387              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1388       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1389    
1390  C-------  C-------
# Line 1285  C     S21 - S31 Line 1399  C     S21 - S31
1399        DO I=3,5        DO I=3,5
1400           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1401        ENDDO        ENDDO
1402        F = dl/dist        F = dl/dist
1403    
1404  C      IF (tof21_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof21_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1405         IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
# Line 1294  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1408  C      IF (tof21_i.GT.none_find.AND.tof3
1408           t2 = tof21(2,tof21_i,itdc)           t2 = tof21(2,tof21_i,itdc)
1409           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1410           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1411           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1412       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1413              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1414              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1415              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1416              ihelp=(tof21_i-1)*3+tof31_i              ihelp=(tof21_i-1)*3+tof31_i
1417              c1 = k_S21S31(1,ihelp)              c1 = k_S21S31(1,ihelp)
1418                if (iz.gt.2) c1 = c1 + k1corrB1
1419              c2 = k_S21S31(2,ihelp)              c2 = k_S21S31(2,ihelp)
1420              beta_a(5) = c2*F/(ds-c1)              beta_a(5) = c2*F/(ds-c1)
1421    
# Line 1313  C-------ToF Mask - S21 - S31 Line 1428  C-------ToF Mask - S21 - S31
1428    
1429              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1430       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1431              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1432       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1433    
1434  C-------  C-------
# Line 1328  C     S21 - S32 Line 1443  C     S21 - S32
1443        DO I=3,6        DO I=3,6
1444           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1445        ENDDO        ENDDO
1446        F = dl/dist        F = dl/dist
1447    
1448  C      IF (tof21_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof21_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1449         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1337  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1452  C      IF (tof21_i.GT.none_find.AND.tof3
1452           t2 = tof21(2,tof21_i,itdc)           t2 = tof21(2,tof21_i,itdc)
1453           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1454           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1455           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1456       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1457              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1458              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1459              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1460              ihelp=(tof21_i-1)*3+tof32_i              ihelp=(tof21_i-1)*3+tof32_i
1461              c1 = k_S21S32(1,ihelp)              c1 = k_S21S32(1,ihelp)
1462                if (iz.gt.2) c1 = c1 + k1corrB1
1463              c2 = k_S21S32(2,ihelp)              c2 = k_S21S32(2,ihelp)
1464              beta_a(6) = c2*F/(ds-c1)              beta_a(6) = c2*F/(ds-c1)
1465    
# Line 1356  C-------ToF Mask - S21 - S32 Line 1472  C-------ToF Mask - S21 - S32
1472    
1473              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1474       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1475              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1476       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1477    
1478  C-------  C-------
# Line 1371  C     S22 - S31 Line 1487  C     S22 - S31
1487        DO I=4,5        DO I=4,5
1488           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1489        ENDDO        ENDDO
1490        F = dl/dist        F = dl/dist
1491    
1492  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
1493         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 1380  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1496  C      IF (tof22_i.GT.none_find.AND.tof3
1496           t2 = tof22(2,tof22_i,itdc)           t2 = tof22(2,tof22_i,itdc)
1497           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1498           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1499           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1500       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1501              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1502              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1503              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1504              ihelp=(tof22_i-1)*3+tof31_i              ihelp=(tof22_i-1)*3+tof31_i
1505              c1 = k_S22S31(1,ihelp)              c1 = k_S22S31(1,ihelp)
1506                if (iz.gt.2) c1 = c1 + k1corrB1
1507              c2 = k_S22S31(2,ihelp)              c2 = k_S22S31(2,ihelp)
1508              beta_a(7) = c2*F/(ds-c1)              beta_a(7) = c2*F/(ds-c1)
1509    
# Line 1399  C-------ToF Mask - S22 - S31 Line 1516  C-------ToF Mask - S22 - S31
1516    
1517              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1518       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1519              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1520       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1521    
1522  C-------  C-------
1523    
1524           ENDIF           ENDIF
1525        ENDIF        ENDIF
1526          
1527  C     S22 - S32  C     S22 - S32
1528    
1529        dist = ZTOF(4) - ZTOF(6)        dist = ZTOF(4) - ZTOF(6)
# Line 1414  C     S22 - S32 Line 1531  C     S22 - S32
1531        DO I=4,6        DO I=4,6
1532           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1533        ENDDO        ENDDO
1534        F = dl/dist        F = dl/dist
1535    
1536  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
1537         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 1423  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1540  C      IF (tof22_i.GT.none_find.AND.tof3
1540           t2 = tof22(2,tof22_i,itdc)           t2 = tof22(2,tof22_i,itdc)
1541           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1542           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1543           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1544       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1545              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1546              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1547              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1548              ihelp=(tof22_i-1)*3+tof32_i              ihelp=(tof22_i-1)*3+tof32_i
1549              c1 = k_S22S32(1,ihelp)              c1 = k_S22S32(1,ihelp)
1550                if (iz.gt.2) c1 = c1 + k1corrB1
1551              c2 = k_S22S32(2,ihelp)              c2 = k_S22S32(2,ihelp)
1552              beta_a(8) = c2*F/(ds-c1)              beta_a(8) = c2*F/(ds-c1)
1553    
# Line 1442  C-------ToF Mask - S22 - S32 Line 1560  C-------ToF Mask - S22 - S32
1560    
1561              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1562       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1563              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1564       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1565    
1566  C-------  C-------
# Line 1457  C     S11 - S21 Line 1575  C     S11 - S21
1575        DO I=1,3        DO I=1,3
1576           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1577        ENDDO        ENDDO
1578        F = dl/dist        F = dl/dist
1579    
1580  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
1581         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.
# Line 1466  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1584  C      IF (tof11_i.GT.none_find.AND.tof2
1584           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1585           t3 = tof21(1,tof21_i,itdc)           t3 = tof21(1,tof21_i,itdc)
1586           t4 = tof21(2,tof21_i,itdc)           t4 = tof21(2,tof21_i,itdc)
1587           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1588       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1589              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1590              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1591              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1592              ihelp=(tof11_i-1)*2+tof21_i              ihelp=(tof11_i-1)*2+tof21_i
1593              c1 = k_S11S21(1,ihelp)              c1 = k_S11S21(1,ihelp)
1594                if (iz.gt.2) c1 = c1 + k1corrC1
1595              c2 = k_S11S21(2,ihelp)              c2 = k_S11S21(2,ihelp)
1596              beta_a(9) = c2*F/(ds-c1)              beta_a(9) = c2*F/(ds-c1)
1597    
# Line 1485  C-------ToF Mask - S11 - S21 Line 1604  C-------ToF Mask - S11 - S21
1604    
1605              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1606       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1607              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1608       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1609    
1610  C-------  C-------
1611    
1612           ENDIF           ENDIF
1613        ENDIF        ENDIF
1614          
1615  C     S11 - S22  C     S11 - S22
1616    
1617        dist = ZTOF(1) - ZTOF(4)        dist = ZTOF(1) - ZTOF(4)
# Line 1500  C     S11 - S22 Line 1619  C     S11 - S22
1619        DO I=1,4        DO I=1,4
1620           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1621        ENDDO        ENDDO
1622        F = dl/dist        F = dl/dist
1623    
1624  C      IF (tof11_i.GT.none_find.AND.tof22_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof22_i.GT.none_find) THEN
1625         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
# Line 1509  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1628  C      IF (tof11_i.GT.none_find.AND.tof2
1628           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1629           t3 = tof22(1,tof22_i,itdc)           t3 = tof22(1,tof22_i,itdc)
1630           t4 = tof22(2,tof22_i,itdc)           t4 = tof22(2,tof22_i,itdc)
1631           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1632       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1633              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1634              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1635              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1636              ihelp=(tof11_i-1)*2+tof22_i              ihelp=(tof11_i-1)*2+tof22_i
1637              c1 = k_S11S22(1,ihelp)              c1 = k_S11S22(1,ihelp)
1638                if (iz.gt.2) c1 = c1 + k1corrC1
1639              c2 = k_S11S22(2,ihelp)              c2 = k_S11S22(2,ihelp)
1640              beta_a(10) = c2*F/(ds-c1)              beta_a(10) = c2*F/(ds-c1)
1641    
# Line 1528  C-------ToF Mask - S11 - S22 Line 1648  C-------ToF Mask - S11 - S22
1648    
1649              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1650       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1651              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1652       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1653    
1654  C-------  C-------
# Line 1543  C     S12 - S21 Line 1663  C     S12 - S21
1663        DO I=2,3        DO I=2,3
1664           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1665        ENDDO        ENDDO
1666        F = dl/dist        F = dl/dist
1667    
1668  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
1669         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.
# Line 1552  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1672  C      IF (tof12_i.GT.none_find.AND.tof2
1672           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1673           t3 = tof21(1,tof21_i,itdc)           t3 = tof21(1,tof21_i,itdc)
1674           t4 = tof21(2,tof21_i,itdc)           t4 = tof21(2,tof21_i,itdc)
1675           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1676       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1677              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1678              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1679              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1680              ihelp=(tof12_i-1)*2+tof21_i              ihelp=(tof12_i-1)*2+tof21_i
1681              c1 = k_S12S21(1,ihelp)              c1 = k_S12S21(1,ihelp)
1682                if (iz.gt.2) c1 = c1 + k1corrC1
1683              c2 = k_S12S21(2,ihelp)              c2 = k_S12S21(2,ihelp)
1684              beta_a(11) = c2*F/(ds-c1)              beta_a(11) = c2*F/(ds-c1)
1685    
# Line 1571  C-------ToF Mask - S12 - S21 Line 1692  C-------ToF Mask - S12 - S21
1692    
1693              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1694       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1695              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1696       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1697    
1698  C-------  C-------
# Line 1586  C     S12 - S22 Line 1707  C     S12 - S22
1707        DO I=2,4        DO I=2,4
1708           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1709        ENDDO        ENDDO
1710        F = dl/dist        F = dl/dist
1711    
1712  C      IF (tof12_i.GT.none_find.AND.tof22_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof22_i.GT.none_find) THEN
1713         IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
# Line 1595  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1716  C      IF (tof12_i.GT.none_find.AND.tof2
1716           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1717           t3 = tof22(1,tof22_i,itdc)           t3 = tof22(1,tof22_i,itdc)
1718           t4 = tof22(2,tof22_i,itdc)           t4 = tof22(2,tof22_i,itdc)
1719           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1720       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1721              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1722              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1723              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1724              ihelp=(tof12_i-1)*2+tof22_i              ihelp=(tof12_i-1)*2+tof22_i
1725              c1 = k_S12S22(1,ihelp)              c1 = k_S12S22(1,ihelp)
1726                if (iz.gt.2) c1 = c1 + k1corrC1
1727              c2 = k_S12S22(2,ihelp)              c2 = k_S12S22(2,ihelp)
1728              beta_a(12) = c2*F/(ds-c1)              beta_a(12) = c2*F/(ds-c1)
1729    
# Line 1614  C-------ToF Mask - S12 - S22 Line 1736  C-------ToF Mask - S12 - S22
1736    
1737              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1738       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1739              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1740       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1741    
1742  C-------  C-------
1743    
1744           ENDIF           ENDIF
1745        ENDIF        ENDIF
1746          
1747  C-------  C-------
1748    C
1749    C      icount=0
1750    C      sw=0.
1751    C      sxw=0.
1752    C      beta_mean=100.
1753    C
1754    C      do i=1,12
1755    C         if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then
1756    C            icount= icount+1
1757    C            if (i.le.4) w_i=1./(0.13**2.)
1758    C            if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)
1759    C            if (i.ge.9) w_i=1./(0.25**2.) ! to be checked
1760    C            sxw=sxw + beta_a(i)*w_i
1761    C            sw =sw + w_i
1762    C         endif
1763    C      enddo
1764    C
1765    C      if (icount.gt.0) beta_mean=sxw/sw
1766    C      beta_a(13) = beta_mean
1767    C
1768    C-------  New mean beta  calculation
1769    
1770           do i=1,12
1771             btemp(i) =  beta_a(i)
1772           enddo
1773    
1774        icount=0         beta_a(13)=newbeta(btemp,hitvec,10.,10.,20.)
       sw=0.  
       sxw=0.  
       beta_mean=100.  
1775    
1776        do i=1,12  C-------
          if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then  
             icount= icount+1  
             if (i.le.4) w_i=1./(0.13**2.)  
             if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)  
             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  
         
       if (icount.gt.0) beta_mean=sxw/sw  
       beta_a(13) = beta_mean  
1777    
1778    
1779  c       IF (tof11_i.GT.none_find)  c       IF (tof11_i.GT.none_find)
1780  c     &  write(*,*) '11 ',tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  c     &  write(*,*) '11 ',tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)
1781  c       IF (tof12_i.GT.none_find)  c       IF (tof12_i.GT.none_find)
1782  c     &  write(*,*) '12 ',tof12(1,tof12_i,itdc),tof12(2,tof12_i,itdc)  c     &  write(*,*) '12 ',tof12(1,tof12_i,itdc),tof12(2,tof12_i,itdc)
1783    
1784  c       IF (tof21_i.GT.none_find)  c       IF (tof21_i.GT.none_find)
1785  c     &  write(*,*) '21 ',tof21(1,tof21_i,itdc),tof21(2,tof21_i,itdc)  c     &  write(*,*) '21 ',tof21(1,tof21_i,itdc),tof21(2,tof21_i,itdc)
1786  c       IF (tof22_i.GT.none_find)  c       IF (tof22_i.GT.none_find)
1787  c     &  write(*,*) '22 ',tof22(1,tof22_i,itdc),tof22(2,tof22_i,itdc)  c     &  write(*,*) '22 ',tof22(1,tof22_i,itdc),tof22(2,tof22_i,itdc)
1788    
1789  c       IF (tof31_i.GT.none_find)  c       IF (tof31_i.GT.none_find)
1790  c     &  write(*,*) '31 ',tof31(1,tof31_i,itdc),tof31(2,tof31_i,itdc)  c     &  write(*,*) '31 ',tof31(1,tof31_i,itdc),tof31(2,tof31_i,itdc)
1791  c       IF (tof32_i.GT.none_find)  c       IF (tof32_i.GT.none_find)
1792  c     &  write(*,*) '32 ',tof32(1,tof32_i,itdc),tof32(2,tof32_i,itdc)  c     &  write(*,*) '32 ',tof32(1,tof32_i,itdc),tof32(2,tof32_i,itdc)
1793    
1794  c      write(*,*) xtofpos  c      write(*,*) xtofpos
1795  c      write(*,*) ytofpos  c      write(*,*) ytofpos
1796  c      write(*,*) beta_a  C      write(*,*)'toftrk beta', beta_a
1797  C      write(*,*) adcflagtof  C      write(*,*) adcflagtof
1798    C     write(*,*)'TOFTRK ',ievent,beta_a(1),beta_a(2),beta_a(3),beta_a(4)
1799    c      write(*,*) 'toftrk'
1800    c      write(*,*) xtofpos
1801    c      write(*,*) ytofpos
1802    c      write(*,*) xtr_tof
1803    c      write(*,*) ytr_tof
1804    
1805    
 C     write(*,*)'TOFTRK ',ievent,beta_a(1),beta_a(2),beta_a(3),beta_a(4)  
1806    
1807        RETURN        RETURN
1808        END        END
1809    
1810    
1811    
1812    
1813    C------------------------------------------------------------------
1814    

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.23