/[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.9 by mocchiut, Mon Feb 5 15:36:44 2007 UTC revision 1.17 by mocchiut, Fri Apr 18 18:55:55 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: claculation 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
30    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  mar-08 WM: Call to "newbeta" changed, now a flag tells the function if the
48    C             call comes from "tofl2com" or form "toftrack"
49    C  mar-08 WM: Bug found in dEdx if check_charge>1
50    C  apr-08 WM: Bug found in S22 artificial ADC, mismatch found between the track
51    C             length  from DOTRACK2 and "GetLength" method for 4 combinations
52  C****************************************************************************  C****************************************************************************
53        IMPLICIT NONE        IMPLICIT NONE
54  C      C
55        include  'input_tof.txt'        include  'input_tof.txt'
56        include  'output_tof.txt'        include  'output_tof.txt'
57        include  'tofcomm.txt'        include  'tofcomm.txt'
58  C      C
59          
60  c     =======================================  c     =======================================
61  c     variables for tracking routine  c     variables for tracking routine
62  c     =======================================  c     =======================================
# Line 58  c      REAL dx,dy,dr Line 81  c      REAL dx,dy,dr
81        REAL ds        REAL ds
82        REAL t1,t2,t3,t4        REAL t1,t2,t3,t4
83        REAL yhelp,xhelp,xhelp1,xhelp2        REAL yhelp,xhelp,xhelp1,xhelp2
84        REAL c1,c2,sw,sxw,w_i        REAL c1,c2
85        REAL dist,dl,F  C     REAL sw,sxw,w_i
86        INTEGER icount,ievent        REAL dist,dl,F
87        REAL xhelp_a,xhelp_t        INTEGER ievent
88    C      INTEGER icount
89        REAL beta_mean  C      REAL beta_mean
90          REAL btemp(12)
91        REAL hepratio        REAL hepratio
92          
93        INTEGER j        INTEGER j,hitvec(6)
94    
95          real atten,pc_adc,check_charge,newbeta
96    
97    
98        REAL theta,phi        REAL theta,phi
99  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
100        REAL tofarm12        REAL tofarm12
101        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69
102        REAL tofarm23                REAL tofarm23
103        PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92        PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92
104        REAL tofarm13        REAL tofarm13
105        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92
106    
107          
108        INTEGER ihelp        INTEGER ihelp
109        REAL xkorr,xpos        REAL xkorr,xpos
110    
111          INTEGER IZ
112          REAL k1corrA1,k1corrB1,k1corrC1
113    
114        REAL yl,yh,xl,xh        REAL yl,yh,xl,xh
115  C      C
116        REAL hmemor(9000000)        REAL hmemor(9000000)
117        INTEGER Iquest(100)        INTEGER Iquest(100)
118  C      C
119        DATA ievent / 0 /        DATA ievent / 0 /
120    
121          INTEGER ifst
122          DATA ifst /0/
123    
124        COMMON / pawcd / hmemor        COMMON / pawcd / hmemor
125        save / pawcd /        save / pawcd /
126  C      C
127        Common / QUESTd / Iquest        Common / QUESTd / Iquest
128        save / questd /        save / questd /
129  C      C
130  C     Begin !  C     Begin !
131  C      C
132        TOFTRK = 0        TOFTRK = 0
133    
134  *******************************************************************  *******************************************************************
135    
136        ievent = ievent +1         if (ifst.eq.0) then
137           ifst=1
138    
139  C  ratio helium to proton ca. 4  C  ratio helium to proton ca. 4
140        hepratio = 4.5        hepratio = 4.
141    
142        offset = 1        offset = 1
143        slope = 2        slope = 2
# Line 116  C  ratio helium to proton ca. 4 Line 150  C  ratio helium to proton ca. 4
150        itdc = 1        itdc = 1
151        iadc = 2        iadc = 2
152    
153    
154          k1corrA1 = 0.
155          k1corrB1 = -5.0
156          k1corrC1=  8.0
157    
158          ENDIF   ! ifst
159    
160    *******************************************************************
161    
162          ievent = ievent +1
163    
164        do i=1,13        do i=1,13
165           beta_a(i) = 100.           beta_a(i) = 100.
166        enddo        enddo
# Line 151  C  ratio helium to proton ca. 4 Line 196  C  ratio helium to proton ca. 4
196        THYOUT(j) = 0.        THYOUT(j) = 0.
197        enddo        enddo
198    
199          do j=1,6
200          xtr_tof(j) = 100.
201          ytr_tof(j) = 100.
202          enddo
203    
204    
205  C----------------------------------------------------------------------  C----------------------------------------------------------------------
206  C-------------------------get ToF data --------------------------------  C-------------------------get ToF data --------------------------------
207  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
208  C     manipulated (Time-walk, artificila ADc and TDC values using ToF  C     manipulated (Time-walk, artificila ADc and TDC values using ToF
209  C     standalone information  C     standalone information
210  C----------------------------------------------------------------------  C----------------------------------------------------------------------
 C     put the adc and tdc values from ntuple into tofxx(i,j,k) variables  
211    
212    c     put the adc and tdc values from ntuple into tofxx(i,j,k) variables
213    
214        do j=1,8        do j=1,8
215           tof11(1,j,2) = adc(ch11a(j),hb11a(j))           tof11(1,j,2) = pc_adc(adc(ch11a(j),hb11a(j)))
216           tof11(2,j,2) = adc(ch11b(j),hb11b(j))           tof11(2,j,2) = pc_adc(adc(ch11b(j),hb11b(j)))
217           tof11(1,j,1) = tdc(ch11a(j),hb11a(j))           tof11(1,j,1) = (tdc(ch11a(j),hb11a(j)))
218           tof11(2,j,1) = tdc(ch11b(j),hb11b(j))           tof11(2,j,1) = (tdc(ch11b(j),hb11b(j)))
219        enddo        enddo
220    
221    
222        do j=1,6        do j=1,6
223           tof12(1,j,2) = adc(ch12a(j),hb12a(j))           tof12(1,j,2) = pc_adc(adc(ch12a(j),hb12a(j)))
224           tof12(2,j,2) = adc(ch12b(j),hb12b(j))           tof12(2,j,2) = pc_adc(adc(ch12b(j),hb12b(j)))
225           tof12(1,j,1) = tdc(ch12a(j),hb12a(j))           tof12(1,j,1) = (tdc(ch12a(j),hb12a(j)))
226           tof12(2,j,1) = tdc(ch12b(j),hb12b(j))           tof12(2,j,1) = (tdc(ch12b(j),hb12b(j)))
227        enddo        enddo
228    
229        do j=1,2        do j=1,2
230           tof21(1,j,2) = adc(ch21a(j),hb21a(j))           tof21(1,j,2) = pc_adc(adc(ch21a(j),hb21a(j)))
231           tof21(2,j,2) = adc(ch21b(j),hb21b(j))           tof21(2,j,2) = pc_adc(adc(ch21b(j),hb21b(j)))
232           tof21(1,j,1) = tdc(ch21a(j),hb21a(j))           tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))
233           tof21(2,j,1) = tdc(ch21b(j),hb21b(j))           tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))
234        enddo        enddo
235    
236        do j=1,2        do j=1,2
237           tof22(1,j,2) = adc(ch22a(j),hb22a(j))           tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))
238           tof22(2,j,2) = adc(ch22b(j),hb22b(j))           tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))
239           tof22(1,j,1) = tdc(ch22a(j),hb22a(j))           tof22(1,j,1) = (tdc(ch22a(j),hb22a(j)))
240           tof22(2,j,1) = tdc(ch22b(j),hb22b(j))           tof22(2,j,1) = (tdc(ch22b(j),hb22b(j)))
241        enddo        enddo
242    
243        do j=1,3        do j=1,3
244           tof31(1,j,2) = adc(ch31a(j),hb31a(j))           tof31(1,j,2) = pc_adc(adc(ch31a(j),hb31a(j)))
245           tof31(2,j,2) = adc(ch31b(j),hb31b(j))           tof31(2,j,2) = pc_adc(adc(ch31b(j),hb31b(j)))
246           tof31(1,j,1) = tdc(ch31a(j),hb31a(j))           tof31(1,j,1) = (tdc(ch31a(j),hb31a(j)))
247           tof31(2,j,1) = tdc(ch31b(j),hb31b(j))           tof31(2,j,1) = (tdc(ch31b(j),hb31b(j)))
248        enddo        enddo
249    
250        do j=1,3        do j=1,3
251           tof32(1,j,2) = adc(ch32a(j),hb32a(j))           tof32(1,j,2) = pc_adc(adc(ch32a(j),hb32a(j)))
252           tof32(2,j,2) = adc(ch32b(j),hb32b(j))           tof32(2,j,2) = pc_adc(adc(ch32b(j),hb32b(j)))
253           tof32(1,j,1) = tdc(ch32a(j),hb32a(j))           tof32(1,j,1) = (tdc(ch32a(j),hb32a(j)))
254           tof32(2,j,1) = tdc(ch32b(j),hb32b(j))           tof32(2,j,1) = (tdc(ch32b(j),hb32b(j)))
255        enddo        enddo
256    
257  C----------------------------------------------------------------------  C----------------------------------------------------------------------
# Line 248  C--------------------------------------- Line 299  C---------------------------------------
299           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.
300        ENDDO        ENDDO
301    
302  C-------------------------------------------------------------------  C----------------------------------------------------------------------
303    
304  C------read  tracking routine  C------read  tracking routine
305  *     igoodevent = igoodevent+1  *     igoodevent = igoodevent+1
# Line 266  C     COPY THE ALFA VECTOR FROM AL_PP TO Line 317  C     COPY THE ALFA VECTOR FROM AL_PP TO
317  c      write(*,*) AL_P  c      write(*,*) AL_P
318    
319        if (al_p(5).eq.0.) THEN        if (al_p(5).eq.0.) THEN
320           PRINT *,' TOF - WARNING F77: track with R = 0, discarded'  c         PRINT *,' TOF - WARNING F77: track with R = 0, discarded'
321           GOTO 969           GOTO 969
322        ENDIF        ENDIF
323  *     -------- *** tracking routine *** --------  *     -------- *** tracking routine *** --------
# Line 274  c      write(*,*) AL_P Line 325  c      write(*,*) AL_P
325  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,AL_P,IFAIL)  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,AL_P,IFAIL)
326        call DOTRACK2(NPTOF,ZIN,XOUT,YOUT,THXOUT,THYOUT,TLOUT,AL_P,IFAIL)        call DOTRACK2(NPTOF,ZIN,XOUT,YOUT,THXOUT,THYOUT,TLOUT,AL_P,IFAIL)
327    
   
328  C     write(*,*) (TLOUT(i),i=1,6)  C     write(*,*) (TLOUT(i),i=1,6)
329    
330        if(IFAIL.ne.0)then        if(IFAIL.ne.0)then
331           print *,' TOF - WARNING F77: tracking failed '  c         print *,' TOF - WARNING F77: tracking failed '
332           goto 969           goto 969
333        endif        endif
334  *     ------------------------------------------  *     ------------------------------------------
335    
336   969  continue   969  continue
337    
338    C---  Fill xtr_tof  and ytr_tof: positions from tracker at ToF layers
339          do j=1,6
340          xtr_tof(j) = XOUT(j)
341          ytr_tof(j) = YOUT(j)
342          enddo
343    
344    
345  C---  convert  angles to radian  C---  convert  angles to radian
346        do j=1,6        do j=1,6
347        THXOUT(j) = 3.1415927*THXOUT(j)/180.        THXOUT(j) = 3.1415927*THXOUT(j)/180.
# Line 364  c     DATA tof21_y/  3.75,-3.75/  ! padd Line 421  c     DATA tof21_y/  3.75,-3.75/  ! padd
421  c     DATA tof22_x/ -4.5,4.5/  c     DATA tof22_x/ -4.5,4.5/
422  c     DATA tof31_x/ -6.0,0.,6.0/  c     DATA tof31_x/ -6.0,0.,6.0/
423  c     DATA tof32_y/ -5.0,0.0,5.0/  c     DATA tof32_y/ -5.0,0.0,5.0/
424  c      c
425  c     S11 8 paddles  33.0 x 5.1 cm  c     S11 8 paddles  33.0 x 5.1 cm
426  c     S12 6 paddles  40.8 x 5.5 cm  c     S12 6 paddles  40.8 x 5.5 cm
427  c     S21 2 paddles  18.0 x 7.5 cm  c     S21 2 paddles  18.0 x 7.5 cm
# Line 395  C--------------S11 --------------------- Line 452  C--------------S11 ---------------------
452  C--------------S12 --------------------------------------  C--------------S12 --------------------------------------
453    
454        tof12_i = none_find        tof12_i = none_find
455          
456        xl = -40.8/2.        xl = -40.8/2.
457        xh =  40.8/2.        xh =  40.8/2.
458    
# Line 412  C--------------S12 --------------------- Line 469  C--------------S12 ---------------------
469  C--------------S21 --------------------------------------  C--------------S21 --------------------------------------
470    
471        tof21_i = none_find        tof21_i = none_find
472          
473        xl = -18./2.        xl = -18./2.
474        xh =  18./2.        xh =  18./2.
475    
# Line 429  C--------------S21 --------------------- Line 486  C--------------S21 ---------------------
486  C--------------S22 --------------------------------------  C--------------S22 --------------------------------------
487    
488        tof22_i = none_find        tof22_i = none_find
489          
490        yl = -15./2.        yl = -15./2.
491        yh =  15./2.        yh =  15./2.
492    
# Line 446  C--------------S22 --------------------- Line 503  C--------------S22 ---------------------
503  C--------------S31 --------------------------------------  C--------------S31 --------------------------------------
504    
505        tof31_i = none_find        tof31_i = none_find
506          
507        yl = -15.0/2.        yl = -15.0/2.
508        yh =  15.0/2.        yh =  15.0/2.
509    
# Line 463  C--------------S31 --------------------- Line 520  C--------------S31 ---------------------
520  C--------------S32 --------------------------------------  C--------------S32 --------------------------------------
521    
522        tof32_i = none_find        tof32_i = none_find
523          
524        xl = -18.0/2.        xl = -18.0/2.
525        xh =  18.0/2.        xh =  18.0/2.
526    
# Line 480  C--------------S32 --------------------- Line 537  C--------------S32 ---------------------
537    
538  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
539    
540  C-----------------------------------------------------------------------         hitvec(1)=tof11_i
541  C--------------------Insert Artifical TDC Value  ---------------------         hitvec(2)=tof12_i
542  C     For each Paddle perform check:         hitvec(3)=tof21_i
543  C     if left paddle=4095  and right paddle OK => create TDC value left         hitvec(4)=tof22_i
544  C     if right paddle=4095  and left paddle OK => create TDC value right         hitvec(5)=tof31_i
545  C-----------------------------------------------------------------------         hitvec(6)=tof32_i
   
 C-----------------------S11 -----------------------------------------  
   
       IF (tof11_i.GT.none_find) THEN  
          xpos = yout(1)  
          i = tof11_i  
          if ((tof11(1,tof11_i,itdc).EQ.4095).AND.  
      &        (tof11(2,tof11_i,itdc).LT.4095)) THEN    
   
 c       write(*,*)'11lb4 ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  
   
             tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)  
      &           + 2*(y_coor_lin11(tof11_i,offset)  
      &           + xpos*y_coor_lin11(tof11_i,slope))  
   
 c       write(*,*)'11laf ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  
   
             tdcflag(ch11a(i),hb11a(i)) = 1  
     
         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)  
546    
547              tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)  c       write(*,*) 'toftrk ',
548       &           - 2*(y_coor_lin11(tof11_i,offset)  c     &  tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i
      &           + 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 -----------------------------------------  
549    
550        IF (tof21_i.GT.none_find) THEN  C----------------------------------------------------------------------
551           xpos = xout(3)  C--- check charge:
552           i = tof21_i  C--- if Z=2 we should use the attenuation curve for helium to
553           if ((tof21(1,tof21_i,itdc).EQ.4095).AND.  C--- fill the artificail ADC values and NOT divide by "hepratio"
554       &        (tof21(2,tof21_i,itdc).LT.4095)) THEN  C--- if Z>2 we should do a correction to
555              tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)  C--- the k1 constants in the beta calculation
556       &           + 2*(x_coor_lin21(tof21_i,offset)  C----------------------------------------------------------------------
      &           + 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  
557    
558  C-----------------------S31 -----------------------------------------         theta=0.  
559                 dist = ZTOF(1) - ZTOF(5)
560        IF (tof31_i.GT.none_find) THEN         dl = 0.
561           xpos = yout(5)         DO I=1,5
562           i = tof31_i           dl = dl + TLOUT(i)
563           if ((tof31(1,tof31_i,itdc).EQ.4095).AND.         ENDDO
564       &        (tof31(2,tof31_i,itdc).LT.4095)) THEN         F = dl/dist
565              tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)         theta = acos(1/F)
      &           + 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  
566    
567  C-----------------------S32 -----------------------------------------         iz = int(check_charge(theta,hitvec))
568    c       write(*,*) 'in toftrk',iz
       IF (tof32_i.GT.none_find) THEN  
          xpos = xout(6)  
          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  
569    
570  C--------------------------------------------------------------------  C--------------------------------------------------------------------
571  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  
572  C--------------------------------------------------------------------  C--------------------------------------------------------------------
573  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
574  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 642  C----------------------------S1 -------- Line 583  C----------------------------S1 --------
583        yhelp=yout(1)        yhelp=yout(1)
584        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
585           i = tof11_i           i = tof11_i
586           if (tof11(left,i,iadc).eq.4095) then           if ((tdc(ch11a(i),hb11a(i)).lt.4095).AND.
587         &       (adc(ch11a(i),hb11a(i)).eq.4095)) then
588              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
589              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
590              xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))              xkorr = atten(left,11,i,yhelp)
591              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
592              tof11(left,i,iadc)=xkorr/cos(theta)              tof11(left,i,iadc)=xkorr/cos(theta)
593              adcflag(ch11a(i),hb11a(i)) = 1              adcflag(ch11a(i),hb11a(i)) = 1
594           endif           endif
595           if (tof11(right,i,iadc).eq.4095) then           if ((tdc(ch11b(i),hb11b(i)).lt.4095).AND.
596         &       (adc(ch11b(i),hb11b(i)).eq.4095)) then
597              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
598              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
599              xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))              xkorr = atten(right,11,i,yhelp)
600              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
601              tof11(right,i,iadc)=xkorr/cos(theta)              tof11(right,i,iadc)=xkorr/cos(theta)
602              adcflag(ch11b(i),hb11b(i)) = 1              adcflag(ch11b(i),hb11b(i)) = 1
603           endif           endif
# Line 663  C----------------------------S1 -------- Line 606  C----------------------------S1 --------
606        xhelp=xout(2)        xhelp=xout(2)
607        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
608           i = tof12_i           i = tof12_i
609           if (tof12(left,i,iadc).eq.4095) then           if ((tdc(ch12a(i),hb12a(i)).lt.4095).AND.
610         &       (adc(ch12a(i),hb12a(i)).eq.4095)) then
611              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
612              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
613              xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))  c            xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))
614              xkorr=xkorr/hepratio                          xkorr = atten(left,12,i,xhelp)
615                if (iz.le.1) xkorr=xkorr/hepratio
616              tof12(left,i,iadc) = xkorr/cos(theta)              tof12(left,i,iadc) = xkorr/cos(theta)
617              adcflag(ch12a(i),hb12a(i)) = 1              adcflag(ch12a(i),hb12a(i)) = 1
618           endif           endif
619           if (tof12(right,i,iadc).eq.4095) then           if ((tdc(ch12b(i),hb12b(i)).lt.4095).AND.
620         &       (adc(ch12b(i),hb12b(i)).eq.4095)) then
621              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
622              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
623              xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))  c            xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))
624              xkorr=xkorr/hepratio                          xkorr = atten(right,12,i,xhelp)
625                if (iz.le.1) xkorr=xkorr/hepratio
626              tof12(right,i,iadc) = xkorr/cos(theta)              tof12(right,i,iadc) = xkorr/cos(theta)
627              adcflag(ch12b(i),hb12b(i)) = 1              adcflag(ch12b(i),hb12b(i)) = 1
628           endif           endif
# Line 686  C-----------------------------S2 ------- Line 633  C-----------------------------S2 -------
633        xhelp=xout(3)        xhelp=xout(3)
634        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
635           i = tof21_i           i = tof21_i
636           if (tof21(left,i,iadc).eq.4095) then           if ((tdc(ch21a(i),hb21a(i)).lt.4095).AND.
637         &       (adc(ch21a(i),hb21a(i)).eq.4095)) then
638              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
639              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
640              xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))  c            xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))
641              xkorr=xkorr/hepratio                          xkorr = atten(left,21,i,xhelp)
642                if (iz.le.1) xkorr=xkorr/hepratio
643              tof21(left,i,iadc) = xkorr/cos(theta)              tof21(left,i,iadc) = xkorr/cos(theta)
644              adcflag(ch21a(i),hb21a(i)) = 1              adcflag(ch21a(i),hb21a(i)) = 1
645           endif           endif
646           if (tof21(right,i,iadc).eq.4095) then           if ((tdc(ch21b(i),hb21b(i)).lt.4095).AND.
647         &       (adc(ch21b(i),hb21b(i)).eq.4095)) then
648              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
649              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
650              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))  c            xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))
651              xkorr=xkorr/hepratio                          xkorr = atten(right,21,i,xhelp)
652                if (iz.le.1) xkorr=xkorr/hepratio
653              tof21(right,i,iadc) = xkorr/cos(theta)              tof21(right,i,iadc) = xkorr/cos(theta)
654              adcflag(ch21b(i),hb21b(i)) = 1              adcflag(ch21b(i),hb21b(i)) = 1
655           endif           endif
# Line 708  C-----------------------------S2 ------- Line 659  C-----------------------------S2 -------
659        yhelp=yout(4)        yhelp=yout(4)
660        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
661           i = tof22_i           i = tof22_i
662           if (tof22(left,i,iadc).eq.4095) then           if ((tdc(ch22a(i),hb22a(i)).lt.4095).AND.
663         &       (adc(ch22a(i),hb22a(i)).eq.4095)) then
664              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
665              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
666              xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))  c            xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))
667              xkorr=xkorr/hepratio                          xkorr = atten(left,22,i,yhelp)
668                if (iz.le.1) xkorr=xkorr/hepratio
669              tof22(left,i,iadc) = xkorr/cos(theta)              tof22(left,i,iadc) = xkorr/cos(theta)
670              adcflag(ch22a(i),hb22a(i)) = 1              adcflag(ch22a(i),hb22a(i)) = 1
671           endif           endif
672           if (tof22(right,i,iadc).eq.4095) then           if ((tdc(ch22b(i),hb22b(i)).lt.4095).AND.
673         &       (adc(ch22b(i),hb22b(i)).eq.4095)) then
674              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
675              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
676              xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))  c            xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))
677              xkorr=xkorr/hepratio                          xkorr = atten(right,22,i,yhelp)
678                if (iz.le.1) xkorr=xkorr/hepratio
679              tof22(right,i,iadc) = xkorr/cos(theta)              tof22(right,i,iadc) = xkorr/cos(theta)
680              adcflag(ch22b(i),hb22b(i)) = 1              adcflag(ch22b(i),hb22b(i)) = 1
681           endif           endif
# Line 731  C-----------------------------S3 ------- Line 686  C-----------------------------S3 -------
686        yhelp=yout(5)        yhelp=yout(5)
687        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
688           i = tof31_i           i = tof31_i
689           if (tof31(left,i,iadc).eq.4095) then           if ((tdc(ch31a(i),hb31a(i)).lt.4095).AND.
690         &       (adc(ch31a(i),hb31a(i)).eq.4095)) then
691              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
692              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
693              xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))  c            xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))
694              xkorr=xkorr/hepratio                          xkorr = atten(left,31,i,yhelp)
695                if (iz.le.1) xkorr=xkorr/hepratio
696              tof31(left,i,iadc) = xkorr/cos(theta)              tof31(left,i,iadc) = xkorr/cos(theta)
697              adcflag(ch31a(i),hb31a(i)) = 1              adcflag(ch31a(i),hb31a(i)) = 1
698           endif           endif
699           if (tof31(right,i,iadc).eq.4095) then           if ((tdc(ch31b(i),hb31b(i)).lt.4095).AND.
700         &       (adc(ch31b(i),hb31b(i)).eq.4095)) then
701              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
702              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
703              xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))  c            xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))
704              xkorr=xkorr/hepratio                          xkorr = atten(right,31,i,yhelp)
705                if (iz.le.1) xkorr=xkorr/hepratio
706              tof31(right,i,iadc) = xkorr/cos(theta)              tof31(right,i,iadc) = xkorr/cos(theta)
707              adcflag(ch31b(i),hb31b(i)) = 1              adcflag(ch31b(i),hb31b(i)) = 1
708           endif           endif
# Line 753  C-----------------------------S3 ------- Line 712  C-----------------------------S3 -------
712        xhelp=xout(6)        xhelp=xout(6)
713        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
714           i = tof32_i           i = tof32_i
715           if (tof32(left,i,iadc).eq.4095) then           if ((tdc(ch32a(i),hb32a(i)).lt.4095).AND.
716         &       (adc(ch32a(i),hb32a(i)).eq.4095)) then
717              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
718              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
719              xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))  c            xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))
720              xkorr=xkorr/hepratio                          xkorr = atten(left,32,i,xhelp)
721                if (iz.le.1) xkorr=xkorr/hepratio
722              tof32(left,i,iadc) = xkorr/cos(theta)              tof32(left,i,iadc) = xkorr/cos(theta)
723              adcflag(ch32a(i),hb32a(i)) = 1              adcflag(ch32a(i),hb32a(i)) = 1
724           endif           endif
725           if (tof32(right,i,iadc).eq.4095) then           if ((tdc(ch32b(i),hb32b(i)).lt.4095).AND.
726         &       (adc(ch32b(i),hb32b(i)).eq.4095)) then
727              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
728              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
729              xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))  c            xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))
730              xkorr=xkorr/hepratio                          xkorr = atten(right,32,i,xhelp)
731                if (iz.le.1) xkorr=xkorr/hepratio
732              tof32(right,i,iadc) = xkorr/cos(theta)              tof32(right,i,iadc) = xkorr/cos(theta)
733              adcflag(ch32b(i),hb32b(i)) = 1              adcflag(ch32b(i),hb32b(i)) = 1
734           endif           endif
735        ENDIF        ENDIF
736    
737    C-------------------------------------------------------------------
738    C Now there is for each hitted paddle a TDC and ADC value, if the
739    C TDC was < 4095.
740    C There might be also TDC-ADC pairs in paddles not hitted
741    C Let's correct the raw TDC value with the time walk
742    C-------------------------------------------------------------------
743    C--------------------Time walk correction  -------------------------
744    C-------------------------------------------------------------------
745    
746          DO i=1,8
747             if ((tdc(ch11a(i),hb11a(i)).lt.4095).and.
748         &             (tof11(left,i,iadc).lt.3786)) THEN
749             xhelp = tw11(left,i)/(tof11(left,i,iadc)**0.5)
750             tof11(left,i,itdc) = tof11(left,i,itdc) + xhelp
751             tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)
752                                                  ENDIF
753    
754             if ((tdc(ch11b(i),hb11b(i)).lt.4095).and.
755         &             (tof11(right,i,iadc).lt.3786)) THEN
756             xhelp = tw11(right,i)/(tof11(right,i,iadc)**0.5)
757             tof11(right,i,itdc) = tof11(right,i,itdc) + xhelp
758             tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)
759                                                 ENDIF
760          ENDDO
761    
762    
763          DO i=1,6
764             if ((tdc(ch12a(i),hb12a(i)).lt.4095).and.
765         &             (tof12(left,i,iadc).lt.3786)) THEN
766             xhelp = tw12(left,i)/(tof12(left,i,iadc)**0.5)
767             tof12(left,i,itdc) = tof12(left,i,itdc) + xhelp
768             tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)
769                                                  ENDIF
770    
771             if ((tdc(ch12b(i),hb12b(i)).lt.4095).and.
772         &             (tof12(right,i,iadc).lt.3786)) THEN
773             xhelp = tw12(right,i)/(tof12(right,i,iadc)**0.5)
774             tof12(right,i,itdc) = tof12(right,i,itdc) + xhelp
775             tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)
776                                                 ENDIF
777          ENDDO
778    
779    C----
780          DO I=1,2
781             if ((tdc(ch21a(i),hb21a(i)).lt.4095).and.
782         &             (tof21(left,i,iadc).lt.3786)) THEN
783             xhelp = tw21(left,i)/(tof21(left,i,iadc)**0.5)
784             tof21(left,i,itdc) = tof21(left,i,itdc) + xhelp
785             tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)
786                                                  ENDIF
787    
788             if ((tdc(ch21b(i),hb21b(i)).lt.4095).and.
789         &             (tof21(right,i,iadc).lt.3786)) THEN
790             xhelp = tw21(right,i)/(tof21(right,i,iadc)**0.5)
791             tof21(right,i,itdc) = tof21(right,i,itdc) + xhelp
792             tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)
793                                                 ENDIF
794          ENDDO
795    
796          DO I=1,2
797             if ((tdc(ch22a(i),hb22a(i)).lt.4095).and.
798         &             (tof22(left,i,iadc).lt.3786)) THEN
799             xhelp = tw22(left,i)/(tof22(left,i,iadc)**0.5)
800             tof22(left,i,itdc) = tof22(left,i,itdc) + xhelp
801             tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)
802                                                  ENDIF
803    
804             if ((tdc(ch22b(i),hb22b(i)).lt.4095).and.
805         &             (tof22(right,i,iadc).lt.3786)) THEN
806             xhelp = tw22(right,i)/(tof22(right,i,iadc)**0.5)
807             tof22(right,i,itdc) = tof22(right,i,itdc) + xhelp
808             tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)
809                                                 ENDIF
810          ENDDO
811    
812    C----
813          DO I=1,3
814             if ((tdc(ch31a(i),hb31a(i)).lt.4095).and.
815         &             (tof31(left,i,iadc).lt.3786)) THEN
816             xhelp = tw31(left,i)/(tof31(left,i,iadc)**0.5)
817             tof31(left,i,itdc) = tof31(left,i,itdc) + xhelp
818             tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)
819                                                  ENDIF
820    
821             if ((tdc(ch31b(i),hb31b(i)).lt.4095).and.
822         &             (tof31(right,i,iadc).lt.3786)) THEN
823             xhelp = tw31(right,i)/(tof31(right,i,iadc)**0.5)
824             tof31(right,i,itdc) = tof31(right,i,itdc) + xhelp
825             tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)
826                                                 ENDIF
827          ENDDO
828    
829          DO I=1,3
830             if ((tdc(ch32a(i),hb32a(i)).lt.4095).and.
831         &             (tof32(left,i,iadc).lt.3786)) THEN
832             xhelp = tw32(left,i)/(tof32(left,i,iadc)**0.5)
833             tof32(left,i,itdc) = tof32(left,i,itdc) + xhelp
834             tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)
835                                                  ENDIF
836    
837             if ((tdc(ch32b(i),hb32b(i)).lt.4095).and.
838         &             (tof32(right,i,iadc).lt.3786)) THEN
839             xhelp = tw32(right,i)/(tof32(right,i,iadc)**0.5)
840             tof32(right,i,itdc) = tof32(right,i,itdc) + xhelp
841             tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)
842                                                 ENDIF
843          ENDDO
844    
845    
846    C-----------------------------------------------------------------------
847    C--------------------Insert Artifical TDC Value  ---------------------
848    C     For each Paddle perform check:
849    C     if left paddle=4095  and right paddle OK => create TDC value left
850    C     if right paddle=4095  and left paddle OK => create TDC value right
851    C-----------------------------------------------------------------------
852    
853    C-----------------------S11 -----------------------------------------
854    
855          IF (tof11_i.GT.none_find) THEN
856             xpos = yout(1)
857             i = tof11_i
858            if ((tdc(ch11a(i),hb11a(i)).EQ.4095).AND.
859         &          (tdc(ch11b(i),hb11b(i)).LT.4095)) THEN
860              tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)
861         &           + 2*(y_coor_lin11(tof11_i,offset)
862         &           + xpos*y_coor_lin11(tof11_i,slope))
863                tdcflag(ch11a(i),hb11a(i)) = 1
864            ENDIF
865    
866            if ((tdc(ch11b(i),hb11b(i)).EQ.4095).AND.
867         &          (tdc(ch11a(i),hb11a(i)).LT.4095)) THEN
868                tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)
869         &           - 2*(y_coor_lin11(tof11_i,offset)
870         &           + xpos*y_coor_lin11(tof11_i,slope))
871                tdcflag(ch11b(i),hb11b(i)) = 1
872             ENDIF
873    
874          ENDIF
875    
876    C-----------------------S12 -----------------------------------------
877    
878          IF (tof12_i.GT.none_find) THEN
879             xpos = xout(2)
880             i = tof12_i
881            if ((tdc(ch12a(i),hb12a(i)).EQ.4095).AND.
882         &          (tdc(ch12b(i),hb12b(i)).LT.4095)) THEN
883                tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)
884         &           + 2*(x_coor_lin12(tof12_i,offset)
885         &           + xpos*x_coor_lin12(tof12_i,slope))
886                tdcflag(ch12a(i),hb12a(i)) = 1
887             ENDIF
888    
889            if ((tdc(ch12b(i),hb12b(i)).EQ.4095).AND.
890         &          (tdc(ch12a(i),hb12a(i)).LT.4095)) THEN
891                tof12(2,tof12_i,itdc) = tof12(1,tof12_i,itdc)
892         &           - 2*(x_coor_lin12(tof12_i,offset)
893         &           + xpos*x_coor_lin12(tof12_i,slope))
894                tdcflag(ch12b(i),hb12b(i)) = 1
895             ENDIF
896          ENDIF
897    
898    C-----------------------S21 -----------------------------------------
899    
900          IF (tof21_i.GT.none_find) THEN
901             xpos = xout(3)
902             i = tof21_i
903            if ((tdc(ch21a(i),hb21a(i)).EQ.4095).AND.
904         &          (tdc(ch21b(i),hb21b(i)).LT.4095)) THEN
905                tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)
906         &           + 2*(x_coor_lin21(tof21_i,offset)
907         &           + xpos*x_coor_lin21(tof21_i,slope))
908                tdcflag(ch21a(i),hb21a(i)) = 1
909             ENDIF
910    
911            if ((tdc(ch21b(i),hb21b(i)).EQ.4095).AND.
912         &          (tdc(ch21a(i),hb21a(i)).LT.4095)) THEN
913                tof21(2,tof21_i,itdc) = tof21(1,tof21_i,itdc)
914         &           - 2*(x_coor_lin21(tof21_i,offset)
915         &           + xpos*x_coor_lin21(tof21_i,slope))
916                tdcflag(ch21b(i),hb21b(i)) = 1
917             ENDIF
918          ENDIF
919    
920    C-----------------------S22 -----------------------------------------
921    
922          IF (tof22_i.GT.none_find) THEN
923             xpos = yout(4)
924             i = tof22_i
925            if ((tdc(ch22a(i),hb22a(i)).EQ.4095).AND.
926         &          (tdc(ch22b(i),hb22b(i)).LT.4095)) THEN
927                tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)
928         &           + 2*(y_coor_lin22(tof22_i,offset)
929         &           + xpos*y_coor_lin22(tof22_i,slope))
930                tdcflag(ch22a(i),hb22a(i)) = 1
931             ENDIF
932    
933            if ((tdc(ch22b(i),hb22b(i)).EQ.4095).AND.
934         &          (tdc(ch22a(i),hb22a(i)).LT.4095)) THEN
935                tof22(2,tof22_i,itdc) = tof22(1,tof22_i,itdc)
936         &           - 2*(y_coor_lin22(tof22_i,offset)
937         &           + xpos*y_coor_lin22(tof22_i,slope))
938                tdcflag(ch22b(i),hb22b(i)) = 1
939             ENDIF
940          ENDIF
941    
942    C-----------------------S31 -----------------------------------------
943    
944          IF (tof31_i.GT.none_find) THEN
945             xpos = yout(5)
946             i = tof31_i
947            if ((tdc(ch31a(i),hb31a(i)).EQ.4095).AND.
948         &          (tdc(ch31b(i),hb31b(i)).LT.4095)) THEN
949                tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)
950         &           + 2*(y_coor_lin31(tof31_i,offset)
951         &           + xpos*y_coor_lin31(tof31_i,slope))
952                tdcflag(ch31a(i),hb31a(i)) = 1
953             ENDIF
954    
955            if ((tdc(ch31b(i),hb31b(i)).EQ.4095).AND.
956         &          (tdc(ch31a(i),hb31a(i)).LT.4095)) THEN
957                tof31(2,tof31_i,itdc) = tof31(1,tof31_i,itdc)
958         &           - 2*(y_coor_lin31(tof31_i,offset)
959         &           + xpos*y_coor_lin31(tof31_i,slope))
960                tdcflag(ch31b(i),hb31b(i)) = 1
961             ENDIF
962          ENDIF
963    
964    C-----------------------S32 -----------------------------------------
965    
966          IF (tof32_i.GT.none_find) THEN
967             xpos = xout(6)
968             i = tof32_i
969            if ((tdc(ch32a(i),hb32a(i)).EQ.4095).AND.
970         &          (tdc(ch32b(i),hb32b(i)).LT.4095)) THEN
971                tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)
972         &           + 2*(x_coor_lin32(tof32_i,offset)
973         &           + xpos*x_coor_lin32(tof32_i,slope))
974                tdcflag(ch32a(i),hb32a(i)) = 1
975             ENDIF
976    
977            if ((tdc(ch32b(i),hb32b(i)).EQ.4095).AND.
978         &          (tdc(ch32a(i),hb32a(i)).LT.4095)) THEN
979                tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)
980         &           - 2*(x_coor_lin32(tof32_i,offset)
981         &           + xpos*x_coor_lin32(tof32_i,slope))
982                tdcflag(ch32b(i),hb32b(i)) = 1
983             ENDIF
984          ENDIF
985    
986    
987  C------------------------------------------------------------------  C------------------------------------------------------------------
988  C---  calculate track position in paddle using timing difference  C---  calculate track position in paddle using timing difference
# Line 779  C--------------------------------------- Line 991  C---------------------------------------
991        do i=1,3        do i=1,3
992           xtofpos(i)=100.           xtofpos(i)=100.
993           ytofpos(i)=100.           ytofpos(i)=100.
994        enddo        enddo
995    
996  C-----------------------------S1 --------------------------------  C-----------------------------S1 --------------------------------
997          
998        IF (tof11_i.GT.none_find) THEN        IF (tof11_i.GT.none_find) THEN
999           IF ((tof11(1,tof11_i,itdc).NE.4095).AND.           IF ((tof11(1,tof11_i,itdc).NE.4095).AND.
1000       &       (tof11(2,tof11_i,itdc).NE.4095)) THEN       &       (tof11(2,tof11_i,itdc).NE.4095)) THEN
# Line 798  C-----------------------------S1 ------- Line 1011  C-----------------------------S1 -------
1011       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)
1012          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.
1013        endif        endif
1014        endif              endif
1015          
1016  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
1017          
1018        IF (tof21_i.GT.none_find) THEN        IF (tof21_i.GT.none_find) THEN
1019           IF ((tof21(1,tof21_i,itdc).NE.4095).AND.           IF ((tof21(1,tof21_i,itdc).NE.4095).AND.
1020       &       (tof21(2,tof21_i,itdc).NE.4095)) THEN       &       (tof21(2,tof21_i,itdc).NE.4095)) THEN
1021           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.
1022       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)
1023          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.
1024        endif        endif
1025        endif        endif
1026    
# Line 818  C-----------------------------S2 ------- Line 1031  C-----------------------------S2 -------
1031       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)
1032          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.
1033        endif        endif
1034        endif              endif
1035          
1036  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
1037          
1038        IF (tof31_i.GT.none_find) THEN        IF (tof31_i.GT.none_find) THEN
1039           IF ((tof31(1,tof31_i,itdc).NE.4095).AND.           IF ((tof31(1,tof31_i,itdc).NE.4095).AND.
1040       &       (tof31(2,tof31_i,itdc).NE.4095)) THEN       &       (tof31(2,tof31_i,itdc).NE.4095)) THEN
# Line 838  C-----------------------------S3 ------- Line 1051  C-----------------------------S3 -------
1051       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)
1052          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.
1053        endif        endif
1054        endif        endif
1055          
1056  c      do i=1,3  c      do i=1,3
1057  c         if (abs(xtofpos(i)).gt.100.) then  c         if (abs(xtofpos(i)).gt.100.) then
1058  c            xtofpos(i)=101.  c            xtofpos(i)=101.
# Line 847  c         endif Line 1060  c         endif
1060  c         if (abs(ytofpos(i)).gt.100.) then  c         if (abs(ytofpos(i)).gt.100.) then
1061  c            ytofpos(i)=101.  c            ytofpos(i)=101.
1062  c         endif  c         endif
1063  c      enddo  c      enddo
         
   
1064    
1065    
 C--------------------------------------------------------------------  
 C--------------------Time walk correction  -------------------------  
 C--------------------------------------------------------------------  
   
       DO i=1,8  
          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_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_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_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_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  
   
       DO i=1,3  
          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  
   
1066    
1067  C---------------------------------------------------------------------  C---------------------------------------------------------------------
1068  C--------------------Corrections on ADC-data -------------------------  C--------------------Corrections on ADC-data -------------------------
# Line 950  C-----------------------------S1 ------- Line 1078  C-----------------------------S1 -------
1078        IF (tof11_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof11_i.GT.none_find.AND.yhelp.lt.100) THEN
1079    
1080           i = tof11_i           i = tof11_i
1081            
1082           if (tof11(left,i,iadc).lt.4095) then           if (tof11(left,i,iadc).lt.3786) then
1083              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta)              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta)
1084              xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))              xkorr = atten(left,11,i,yhelp)
1085              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1086              adc_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr              adc_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr
1087           endif           endif
1088    
1089            
1090           if (tof11(right,i,iadc).lt.4095) then           if (tof11(right,i,iadc).lt.3786) then
1091              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta)              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta)
1092              xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))              xkorr = atten(right,11,i,yhelp)
1093              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1094              adc_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr              adc_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr
1095           endif           endif
1096        ENDIF        ENDIF
# Line 971  C-----------------------------S1 ------- Line 1099  C-----------------------------S1 -------
1099        xhelp=xout(2)        xhelp=xout(2)
1100        phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))        phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
1101        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  
1102    
1103          IF (tof12_i.GT.none_find.AND.xhelp.lt.100) THEN
1104           i = tof12_i           i = tof12_i
1105           if (tof12(left,i,iadc).lt.4095) then           if (tof12(left,i,iadc).lt.3786) then
1106              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta)              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta)
1107              xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))              xkorr = atten(left,12,i,xhelp)
1108              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1109              adc_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr              adc_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr
1110           endif           endif
1111    
1112           if (tof12(right,i,iadc).lt.4095) then           if (tof12(right,i,iadc).lt.3786) then
1113              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta)              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta)
1114              xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))              xkorr = atten(right,12,i,xhelp)
1115              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1116              adc_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr              adc_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr
1117           endif           endif
1118        ENDIF        ENDIF
# Line 995  C-----------------------------S2 ------- Line 1122  C-----------------------------S2 -------
1122        xhelp=xout(3)        xhelp=xout(3)
1123        phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))        phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
1124        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  
1125    
1126          IF (tof21_i.GT.none_find.AND.xhelp.lt.100) THEN
1127           i = tof21_i           i = tof21_i
1128           if (tof21(left,i,iadc).lt.4095) then           if (tof21(left,i,iadc).lt.3786) then
1129              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta)              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta)
1130              xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))              xkorr = atten(left,21,i,xhelp)
1131              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1132              adc_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr              adc_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr
1133           endif           endif
1134    
1135           if (tof21(right,i,iadc).lt.4095) then           if (tof21(right,i,iadc).lt.3786) then
1136              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta)              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta)
1137              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))              xkorr = atten(right,21,i,xhelp)
1138              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1139              adc_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr              adc_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr
1140           endif           endif
1141        ENDIF        ENDIF
# Line 1017  c      write(*,*) 'theta21 ',theta Line 1143  c      write(*,*) 'theta21 ',theta
1143        yhelp=yout(4)        yhelp=yout(4)
1144        phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))        phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
1145        theta = atan(tan(THXOUT(4))/cos(phi))        theta = atan(tan(THXOUT(4))/cos(phi))
 c      write(*,*) 'theta22 ',theta  
1146    
1147        IF (tof22_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof22_i.GT.none_find.AND.yhelp.lt.100) THEN
   
1148           i = tof22_i           i = tof22_i
1149           if (tof22(left,i,iadc).lt.4095) then           if (tof22(left,i,iadc).lt.3786) then
1150              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta)              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta)
1151              xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))              xkorr = atten(left,22,i,yhelp)
1152              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1153              adc_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr              adc_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr
1154           endif           endif
1155    
1156           if (tof22(right,i,iadc).lt.4095) then           if (tof22(right,i,iadc).lt.3786) then
1157              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta)              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta)
1158              xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))              xkorr = atten(right,22,i,yhelp)
1159              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1160              adc_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr              adc_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr
1161           endif           endif
1162        ENDIF        ENDIF
# Line 1042  C-----------------------------S3 ------- Line 1166  C-----------------------------S3 -------
1166        yhelp=yout(5)        yhelp=yout(5)
1167        phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))        phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
1168        theta = atan(tan(THXOUT(5))/cos(phi))        theta = atan(tan(THXOUT(5))/cos(phi))
1169  c      write(*,*) 'theta31 ',theta  
         
1170        IF (tof31_i.GT.none_find.AND.yhelp.lt.100) THEN        IF (tof31_i.GT.none_find.AND.yhelp.lt.100) THEN
1171    
1172           i = tof31_i           i = tof31_i
1173           if (tof31(left,i,iadc).lt.4095) then           if (tof31(left,i,iadc).lt.3786) then
1174              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta)              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta)
1175              xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))              xkorr = atten(left,31,i,yhelp)
1176              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1177              adc_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr              adc_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr
1178           endif           endif
1179    
1180           if (tof31(right,i,iadc).lt.4095) then           if (tof31(right,i,iadc).lt.3786) then
1181              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta)              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta)
1182              xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))              xkorr = atten(right,31,i,yhelp)
1183              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1184              adc_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr              adc_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr
1185           endif           endif
1186        ENDIF        ENDIF
# Line 1065  c      write(*,*) 'theta31 ',theta Line 1188  c      write(*,*) 'theta31 ',theta
1188        xhelp=xout(6)        xhelp=xout(6)
1189        phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))        phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
1190        theta = atan(tan(THXOUT(6))/cos(phi))        theta = atan(tan(THXOUT(6))/cos(phi))
 c      write(*,*) 'theta32 ',theta  
1191    
1192        IF (tof32_i.GT.none_find.AND.xhelp.lt.100) THEN        IF (tof32_i.GT.none_find.AND.xhelp.lt.100) THEN
   
1193           i = tof32_i           i = tof32_i
1194           if (tof32(left,i,iadc).lt.4095) then           if (tof32(left,i,iadc).lt.3786) then
1195              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta)              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta)
1196              xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))              xkorr = atten(left,32,i,xhelp)
1197              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1198              adc_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr              adc_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr
1199           endif           endif
1200    
1201           if (tof32(right,i,iadc).lt.4095) then           if (tof32(right,i,iadc).lt.3786) then
1202              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta)              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta)
1203              xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))              xkorr = atten(right,32,i,xhelp)
1204              xkorr=xkorr/hepratio                          xkorr=xkorr/hepratio
1205              adc_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr              adc_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr
1206           endif           endif
1207        ENDIF        ENDIF
1208    
1209    
1210  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
1211  C----------------------calculate Beta  ------------------------------  C----------------------calculate Beta  ------------------------------
1212  C-----------------------------------------------------------------------  C-----------------------------------------------------------------------
1213  C-------------------difference of sums  ---------------------------  C-------------------difference of sums  ---------------------------
1214  C      C
1215  C     DS = (t1+t2) - t3+t4)  C     DS = (t1+t2) - t3+t4)
1216  C     DS = c1 + c2/beta*cos(theta)  C     DS = c1 + c2/beta*cos(theta)
1217  C     c2 = 2d/c   gives c2 = 2d/(c*TDCresolution)  TDC=50ps/channel  C     c2 = 2d/c   gives c2 = 2d/(c*TDCresolution)  TDC=50ps/channel
1218  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
1219  C     since TDC resolution varies slightly c2 has to be calibrated  C     since TDC resolution varies slightly c2 has to be calibrated
1220  C     instead of cos(theta) use factor F:  C     instead of cos(theta) use factor F:
1221  C     F =  pathlength/d  C     F =  pathlength/d
1222  C     => beta = c2*F/(DS-c1))  C     => beta = c2*F/(DS-c1))
1223    
1224        dist = ZTOF(1) - ZTOF(5)        dist = ZTOF(1) - ZTOF(5)
# Line 1104  C     => beta = c2*F/(DS-c1)) Line 1226  C     => beta = c2*F/(DS-c1))
1226        DO I=1,5        DO I=1,5
1227           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1228        ENDDO        ENDDO
1229        F = dl/dist        F = dl/dist
1230    
1231  C     S11 - S31  C     S11 - S31
1232  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 1114  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1236  C      IF (tof11_i.GT.none_find.AND.tof3
1236           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1237           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1238           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1239           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1240       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1241              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1242              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1243              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1244              ihelp=(tof11_i-1)*3+tof31_i              ihelp=(tof11_i-1)*3+tof31_i
1245              c1 = k_S11S31(1,ihelp)              c1 = k_S11S31(1,ihelp)
1246              c2 = k_S11S31(2,ihelp)                      if (iz.gt.2) c1 = c1 + k1corrA1
1247                c2 = k_S11S31(2,ihelp)
1248              beta_a(1) = c2*F/(ds-c1)              beta_a(1) = c2*F/(ds-c1)
1249  C     write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)  c       write(*,*) 'S11-S31 ',c1,c2,F
1250    c       write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)
1251  C-------ToF Mask - S11 - S31  C-------ToF Mask - S11 - S31
1252    
1253              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
# Line 1133  C-------ToF Mask - S11 - S31 Line 1257  C-------ToF Mask - S11 - S31
1257    
1258              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1259       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1260              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1261       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1262    
1263           ENDIF           ENDIF
# Line 1144  C-------ToF Mask - S11 - S31 Line 1268  C-------ToF Mask - S11 - S31
1268        DO I=1,6        DO I=1,6
1269           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1270        ENDDO        ENDDO
1271        F = dl/dist        F = dl/dist
1272          
1273  C     S11 - S32  C     S11 - S32
1274  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
1275         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 1154  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1278  C      IF (tof11_i.GT.none_find.AND.tof3
1278           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1279           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1280           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1281           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1282       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1283              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1284              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1285              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1286              ihelp=(tof11_i-1)*3+tof32_i              ihelp=(tof11_i-1)*3+tof32_i
1287              c1 = k_S11S32(1,ihelp)              c1 = k_S11S32(1,ihelp)
1288              c2 = k_S11S32(2,ihelp)                      if (iz.gt.2) c1 = c1 + k1corrA1
1289                c2 = k_S11S32(2,ihelp)
1290              beta_a(2) = c2*F/(ds-c1)              beta_a(2) = c2*F/(ds-c1)
1291  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)
1292    
# Line 1174  C-------ToF Mask - S11 - S32 Line 1299  C-------ToF Mask - S11 - S32
1299    
1300              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1301       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1302              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1303       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1304    
1305  C-------  C-------
# Line 1188  C     S12 - S31 Line 1313  C     S12 - S31
1313        DO I=2,5        DO I=2,5
1314           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1315        ENDDO        ENDDO
1316        F = dl/dist        F = dl/dist
1317    
1318  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
1319         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 1197  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1322  C      IF (tof12_i.GT.none_find.AND.tof3
1322           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1323           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1324           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1325           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1326       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1327              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1328              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1329              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1330              ihelp=(tof12_i-1)*3+tof31_i              ihelp=(tof12_i-1)*3+tof31_i
1331              c1 = k_S12S31(1,ihelp)              c1 = k_S12S31(1,ihelp)
1332                if (iz.gt.2) c1 = c1 + k1corrA1
1333              c2 = k_S12S31(2,ihelp)              c2 = k_S12S31(2,ihelp)
1334              beta_a(3) = c2*F/(ds-c1)              beta_a(3) = c2*F/(ds-c1)
1335  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)
# Line 1217  C-------ToF Mask - S12 - S31 Line 1343  C-------ToF Mask - S12 - S31
1343    
1344              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1345       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1346              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1347       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1348    
1349  C-------  C-------
# Line 1232  C     S12 - S32 Line 1358  C     S12 - S32
1358        DO I=2,6        DO I=2,6
1359           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1360        ENDDO        ENDDO
1361        F = dl/dist        F = dl/dist
1362    
1363  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
1364         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 1241  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1367  C      IF (tof12_i.GT.none_find.AND.tof3
1367           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1368           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1369           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1370           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1371       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1372              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1373              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1374              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1375              ihelp=(tof12_i-1)*3+tof32_i              ihelp=(tof12_i-1)*3+tof32_i
1376              c1 = k_S12S32(1,ihelp)              c1 = k_S12S32(1,ihelp)
1377                if (iz.gt.2) c1 = c1 + k1corrA1
1378              c2 = k_S12S32(2,ihelp)              c2 = k_S12S32(2,ihelp)
1379              beta_a(4) = c2*F/(ds-c1)              beta_a(4) = c2*F/(ds-c1)
1380  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)
# Line 1261  C-------ToF Mask - S12 - S32 Line 1388  C-------ToF Mask - S12 - S32
1388    
1389              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1390       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1391              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1392       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1393    
1394  C-------  C-------
# Line 1276  C     S21 - S31 Line 1403  C     S21 - S31
1403        DO I=3,5        DO I=3,5
1404           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1405        ENDDO        ENDDO
1406        F = dl/dist        F = dl/dist
1407    
1408  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
1409         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 1285  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1412  C      IF (tof21_i.GT.none_find.AND.tof3
1412           t2 = tof21(2,tof21_i,itdc)           t2 = tof21(2,tof21_i,itdc)
1413           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1414           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1415           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1416       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1417              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1418              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1419              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1420              ihelp=(tof21_i-1)*3+tof31_i              ihelp=(tof21_i-1)*3+tof31_i
1421              c1 = k_S21S31(1,ihelp)              c1 = k_S21S31(1,ihelp)
1422                if (iz.gt.2) c1 = c1 + k1corrB1
1423              c2 = k_S21S31(2,ihelp)              c2 = k_S21S31(2,ihelp)
1424              beta_a(5) = c2*F/(ds-c1)              beta_a(5) = c2*F/(ds-c1)
1425    
# Line 1304  C-------ToF Mask - S21 - S31 Line 1432  C-------ToF Mask - S21 - S31
1432    
1433              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1434       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1435              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1436       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1437    
1438  C-------  C-------
# Line 1319  C     S21 - S32 Line 1447  C     S21 - S32
1447        DO I=3,6        DO I=3,6
1448           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1449        ENDDO        ENDDO
1450        F = dl/dist        F = dl/dist
1451    
1452  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
1453         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 1328  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1456  C      IF (tof21_i.GT.none_find.AND.tof3
1456           t2 = tof21(2,tof21_i,itdc)           t2 = tof21(2,tof21_i,itdc)
1457           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1458           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1459           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1460       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1461              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1462              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1463              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1464              ihelp=(tof21_i-1)*3+tof32_i              ihelp=(tof21_i-1)*3+tof32_i
1465              c1 = k_S21S32(1,ihelp)              c1 = k_S21S32(1,ihelp)
1466                if (iz.gt.2) c1 = c1 + k1corrB1
1467              c2 = k_S21S32(2,ihelp)              c2 = k_S21S32(2,ihelp)
1468              beta_a(6) = c2*F/(ds-c1)              beta_a(6) = c2*F/(ds-c1)
1469    
# Line 1347  C-------ToF Mask - S21 - S32 Line 1476  C-------ToF Mask - S21 - S32
1476    
1477              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1478       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1479              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1480       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1481    
1482  C-------  C-------
# Line 1362  C     S22 - S31 Line 1491  C     S22 - S31
1491        DO I=4,5        DO I=4,5
1492           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1493        ENDDO        ENDDO
1494        F = dl/dist        F = dl/dist
1495          
1496    C WM workaround
1497          dl = dl - 0.06*F
1498          F = dl/dist
1499    
1500  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
1501         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 1371  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1504  C      IF (tof22_i.GT.none_find.AND.tof3
1504           t2 = tof22(2,tof22_i,itdc)           t2 = tof22(2,tof22_i,itdc)
1505           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1506           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1507           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1508       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1509              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1510              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1511              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1512              ihelp=(tof22_i-1)*3+tof31_i              ihelp=(tof22_i-1)*3+tof31_i
1513              c1 = k_S22S31(1,ihelp)              c1 = k_S22S31(1,ihelp)
1514                if (iz.gt.2) c1 = c1 + k1corrB1
1515              c2 = k_S22S31(2,ihelp)              c2 = k_S22S31(2,ihelp)
1516              beta_a(7) = c2*F/(ds-c1)              beta_a(7) = c2*F/(ds-c1)
1517    
# Line 1390  C-------ToF Mask - S22 - S31 Line 1524  C-------ToF Mask - S22 - S31
1524    
1525              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1526       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1527              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1528       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1529    
1530  C-------  C-------
1531    
1532           ENDIF           ENDIF
1533        ENDIF        ENDIF
1534          
1535  C     S22 - S32  C     S22 - S32
1536    
1537        dist = ZTOF(4) - ZTOF(6)        dist = ZTOF(4) - ZTOF(6)
# Line 1405  C     S22 - S32 Line 1539  C     S22 - S32
1539        DO I=4,6        DO I=4,6
1540           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1541        ENDDO        ENDDO
1542        F = dl/dist        F = dl/dist
1543          
1544    C WM workaround      
1545          dl = dl - 0.06*F
1546          F = dl/dist
1547    
1548    
1549  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
1550         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 1414  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1553  C      IF (tof22_i.GT.none_find.AND.tof3
1553           t2 = tof22(2,tof22_i,itdc)           t2 = tof22(2,tof22_i,itdc)
1554           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1555           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1556           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1557       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1558              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1559              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1560              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1561              ihelp=(tof22_i-1)*3+tof32_i              ihelp=(tof22_i-1)*3+tof32_i
1562              c1 = k_S22S32(1,ihelp)              c1 = k_S22S32(1,ihelp)
1563                if (iz.gt.2) c1 = c1 + k1corrB1
1564              c2 = k_S22S32(2,ihelp)              c2 = k_S22S32(2,ihelp)
1565              beta_a(8) = c2*F/(ds-c1)              beta_a(8) = c2*F/(ds-c1)
1566    
# Line 1433  C-------ToF Mask - S22 - S32 Line 1573  C-------ToF Mask - S22 - S32
1573    
1574              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1575       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1576              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1577       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1578    
1579  C-------  C-------
# Line 1448  C     S11 - S21 Line 1588  C     S11 - S21
1588        DO I=1,3        DO I=1,3
1589           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1590        ENDDO        ENDDO
1591        F = dl/dist        F = dl/dist
1592    
1593    C WM workaround      
1594          dl = dl - 0.442*F
1595          F = dl/dist
1596    
1597  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
1598         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 1457  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1601  C      IF (tof11_i.GT.none_find.AND.tof2
1601           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1602           t3 = tof21(1,tof21_i,itdc)           t3 = tof21(1,tof21_i,itdc)
1603           t4 = tof21(2,tof21_i,itdc)           t4 = tof21(2,tof21_i,itdc)
1604           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1605       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1606              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1607              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1608              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1609              ihelp=(tof11_i-1)*2+tof21_i              ihelp=(tof11_i-1)*2+tof21_i
1610              c1 = k_S11S21(1,ihelp)              c1 = k_S11S21(1,ihelp)
1611                if (iz.gt.2) c1 = c1 + k1corrC1
1612              c2 = k_S11S21(2,ihelp)              c2 = k_S11S21(2,ihelp)
1613              beta_a(9) = c2*F/(ds-c1)              beta_a(9) = c2*F/(ds-c1)
1614    
# Line 1476  C-------ToF Mask - S11 - S21 Line 1621  C-------ToF Mask - S11 - S21
1621    
1622              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1623       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1624              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1625       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1626    
1627  C-------  C-------
1628    
1629           ENDIF           ENDIF
1630        ENDIF        ENDIF
1631          
1632  C     S11 - S22  C     S11 - S22
1633    
1634        dist = ZTOF(1) - ZTOF(4)        dist = ZTOF(1) - ZTOF(4)
# Line 1491  C     S11 - S22 Line 1636  C     S11 - S22
1636        DO I=1,4        DO I=1,4
1637           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1638        ENDDO        ENDDO
1639        F = dl/dist        F = dl/dist
1640    
1641  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
1642         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 1500  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1645  C      IF (tof11_i.GT.none_find.AND.tof2
1645           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1646           t3 = tof22(1,tof22_i,itdc)           t3 = tof22(1,tof22_i,itdc)
1647           t4 = tof22(2,tof22_i,itdc)           t4 = tof22(2,tof22_i,itdc)
1648           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1649       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1650              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1651              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1652              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1653              ihelp=(tof11_i-1)*2+tof22_i              ihelp=(tof11_i-1)*2+tof22_i
1654              c1 = k_S11S22(1,ihelp)              c1 = k_S11S22(1,ihelp)
1655                if (iz.gt.2) c1 = c1 + k1corrC1
1656              c2 = k_S11S22(2,ihelp)              c2 = k_S11S22(2,ihelp)
1657              beta_a(10) = c2*F/(ds-c1)              beta_a(10) = c2*F/(ds-c1)
1658    
# Line 1519  C-------ToF Mask - S11 - S22 Line 1665  C-------ToF Mask - S11 - S22
1665    
1666              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1667       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1668              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1669       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1670    
1671  C-------  C-------
# Line 1534  C     S12 - S21 Line 1680  C     S12 - S21
1680        DO I=2,3        DO I=2,3
1681           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1682        ENDDO        ENDDO
1683        F = dl/dist        F = dl/dist
1684    
1685    C  WM workaround
1686          dl = dl - 0.442*F
1687          F = dl/dist
1688    
1689  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
1690         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 1543  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1693  C      IF (tof12_i.GT.none_find.AND.tof2
1693           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1694           t3 = tof21(1,tof21_i,itdc)           t3 = tof21(1,tof21_i,itdc)
1695           t4 = tof21(2,tof21_i,itdc)           t4 = tof21(2,tof21_i,itdc)
1696           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1697       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1698              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1699              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1700              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1701              ihelp=(tof12_i-1)*2+tof21_i              ihelp=(tof12_i-1)*2+tof21_i
1702              c1 = k_S12S21(1,ihelp)              c1 = k_S12S21(1,ihelp)
1703                if (iz.gt.2) c1 = c1 + k1corrC1
1704              c2 = k_S12S21(2,ihelp)              c2 = k_S12S21(2,ihelp)
1705              beta_a(11) = c2*F/(ds-c1)              beta_a(11) = c2*F/(ds-c1)
1706    
# Line 1562  C-------ToF Mask - S12 - S21 Line 1713  C-------ToF Mask - S12 - S21
1713    
1714              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1715       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1716              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1717       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1718    
1719  C-------  C-------
# Line 1577  C     S12 - S22 Line 1728  C     S12 - S22
1728        DO I=2,4        DO I=2,4
1729           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1730        ENDDO        ENDDO
1731        F = dl/dist        F = dl/dist
1732    
1733  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
1734         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 1586  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1737  C      IF (tof12_i.GT.none_find.AND.tof2
1737           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1738           t3 = tof22(1,tof22_i,itdc)           t3 = tof22(1,tof22_i,itdc)
1739           t4 = tof22(2,tof22_i,itdc)           t4 = tof22(2,tof22_i,itdc)
1740           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1741       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1742              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1743              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1744              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1745              ihelp=(tof12_i-1)*2+tof22_i              ihelp=(tof12_i-1)*2+tof22_i
1746              c1 = k_S12S22(1,ihelp)              c1 = k_S12S22(1,ihelp)
1747                if (iz.gt.2) c1 = c1 + k1corrC1
1748              c2 = k_S12S22(2,ihelp)              c2 = k_S12S22(2,ihelp)
1749              beta_a(12) = c2*F/(ds-c1)              beta_a(12) = c2*F/(ds-c1)
1750    
# Line 1605  C-------ToF Mask - S12 - S22 Line 1757  C-------ToF Mask - S12 - S22
1757    
1758              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1759       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1760              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1761       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1762    
1763  C-------  C-------
1764    
1765           ENDIF           ENDIF
1766        ENDIF        ENDIF
1767          
1768  C-------  C-------
1769    C
1770    C      icount=0
1771    C      sw=0.
1772    C      sxw=0.
1773    C      beta_mean=100.
1774    C
1775    C      do i=1,12
1776    C         if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then
1777    C            icount= icount+1
1778    C            if (i.le.4) w_i=1./(0.13**2.)
1779    C            if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)
1780    C            if (i.ge.9) w_i=1./(0.25**2.) ! to be checked
1781    C            sxw=sxw + beta_a(i)*w_i
1782    C            sw =sw + w_i
1783    C         endif
1784    C      enddo
1785    C
1786    C      if (icount.gt.0) beta_mean=sxw/sw
1787    C      beta_a(13) = beta_mean
1788    C
1789    
1790    C-------  New mean beta  calculation
1791    
1792           do i=1,12
1793             btemp(i) =  beta_a(i)
1794           enddo
1795    
1796        icount=0         beta_a(13)=newbeta(2,btemp,hitvec,10.,10.,20.)
       sw=0.  
       sxw=0.  
       beta_mean=100.  
1797    
1798        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  
1799    
1800    
1801  c       IF (tof11_i.GT.none_find)  c       IF (tof11_i.GT.none_find)
1802  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)
1803  c       IF (tof12_i.GT.none_find)  c       IF (tof12_i.GT.none_find)
1804  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)
1805    
1806  c       IF (tof21_i.GT.none_find)  c       IF (tof21_i.GT.none_find)
1807  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)
1808  c       IF (tof22_i.GT.none_find)  c       IF (tof22_i.GT.none_find)
1809  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)
1810    
1811  c       IF (tof31_i.GT.none_find)  c       IF (tof31_i.GT.none_find)
1812  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)
1813  c       IF (tof32_i.GT.none_find)  c       IF (tof32_i.GT.none_find)
1814  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)
1815    
1816  c      write(*,*) xtofpos  c      write(*,*) xtofpos
1817  c      write(*,*) ytofpos  c      write(*,*) ytofpos
1818  c      write(*,*) beta_a  C      write(*,*)'toftrk beta', beta_a
1819  C      write(*,*) adcflagtof  C      write(*,*) adcflagtof
   
   
1820  C     write(*,*)'TOFTRK ',ievent,beta_a(1),beta_a(2),beta_a(3),beta_a(4)  C     write(*,*)'TOFTRK ',ievent,beta_a(1),beta_a(2),beta_a(3),beta_a(4)
1821    c      write(*,*) 'toftrk'
1822    c      write(*,*) xtofpos
1823    c      write(*,*) ytofpos
1824    c      write(*,*) xtr_tof
1825    c      write(*,*) ytr_tof
1826    
1827    
1828        RETURN        RETURN
1829        END        END
1830    
1831    
1832    
1833    
1834    C------------------------------------------------------------------
1835    
1836    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.23