*      DATA ZTOF/55.,25.,-23/
*
*   TOF data
*   first index  : 1 = A, 2 = B
*   second index : 1.. number of paddle
*   third index  : 1 = TDC, 2 = ADC

c       INTEGER tof11(2,8,2),tof12(2,6,2)
c       INTEGER tof21(2,2,2),tof22(2,2,2)
c       INTEGER tof31(2,3,2),tof32(2,3,2)
       REAL tof11(2,8,2),tof12(2,6,2)
       REAL tof21(2,2,2),tof22(2,2,2)
       REAL tof31(2,3,2),tof32(2,3,2)

c      Normalized ADC value
       REAL adc_c(4,12)

c      k1 constans for calculation of beta
       REAL k1_s11s31(24),k1_s12s32(18),k1_S21S31(6),k1_S22S32(6)

c   middle y (or x) position of the upper and middle ToF-Paddle
c   to calculate theta-angle without track information
       REAL tof11_x(8), tof21_y(2), tof31_x(3)
       REAL tof12_y(6), tof22_x(2), tof32_y(3)

c   relation of time differences in a tof paddle and the location of the
c   passage of the particle
c   first index : 1... number of paddle
c   second index  : 1 = offset, 2 = slope
       REAL y_coor_lin11(8,2),x_coor_lin12(6,2)
       REAL x_coor_lin21(2,2),y_coor_lin22(2,2)
       REAL y_coor_lin31(3,2),x_coor_lin32(3,2)

c   ADC(x) - correction 
c   first index  : 1 = left, 2 = right
c   second index : 1..8 number of paddle
c   third index: parameter as follows
c   left: xkorr=par(1)*exp(-x/par(2))
c   right:xkorr=par(1)*exp(x/par(2))
c   then:adc(x,right/left)=adc(x,right/left)/xkorr
c   normalize to x=0 (middle of paddle)
       REAL adcx11(2,8,2),adcx12(2,6,2)
       REAL adcx21(2,2,2),adcx22(2,2,2)
       REAL adcx31(2,3,2),adcx32(2,3,2)


c   Time Walk - correction 
c   first index  : 1 = left, 2 = right
c   second index : 1..8 number of paddle
       REAL tw11(2,8),tw12(2,6)
       REAL tw21(2,2),tw22(2,2)
       REAL tw31(2,3),tw32(2,3)


c   value for status of each PM-data
c   first index  : 1 = left, 2 = right
c   second index : 1... number of paddle
       INTEGER tof11_event(2,8),tof12_event(2,6)
       INTEGER tof21_event(2,2),tof22_event(2,2)
       INTEGER tof31_event(2,3),tof32_event(2,3)

C----

       INTEGER left,right,top,bot,mid,itdc,iadc
       INTEGER tdc_ev, adc_ev, none_ev, none_find
       INTEGER offset, slope
       INTEGER tof11_i,tof21_i,tof31_i,tof11_j,tof21_j,tof31_j
       INTEGER tof12_i,tof22_i,tof32_i,tof12_j,tof22_j,tof32_j
*       REAL adcoff(4,2,52),a,b
c       REAL delta_x12,delta_y12,delta_x23,delta_y23,delta_x13,delta_y13
       REAL xtofpos(3),ytofpos(3)
       REAL xkorr, secure
       INTEGER i, j, ihelp
       LOGICAL check
       REAL theta12,theta13,theta23

       REAL beta_a(5)

       INTEGER  tof_i_flag(6),tof_j_flag(6)


       DATA TOFfst / 0/

       PARAMETER (tofarm23 = 45.)
       PARAMETER (tofarm13 = 81.)
       PARAMETER (c2_13=108.)  ! = 2.*tofarm13*0.01/(3.E08*50.E-12)
       PARAMETER (c2_23=60.)   ! = 2.*tofarm23*0.01/(3.E08*50.E-12)


*  S11 8 paddles  33.0 x 5.1 cm
*  S12 6 paddles  40.8 x 5.5 cm
*  S21 2 paddles  18.0 x 7.5 cm
*  S22 2 paddles  15.0 x 9.0 cm
*  S31 3 paddles  15.0 x 6.0 cm
*  S32 3 paddles  18.0 x 5.0 cm

       DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/
       DATA tof12_y/ -13.75,-8.25,-2.75,2.75,8.25,13.75/
       DATA tof21_y/ -3.75,3.75/
       DATA tof22_x/ -4.5,4.5/
       DATA tof31_x/ -6.0,0.,6.0/
       DATA tof32_y/ -5.0,0.0,5.0/

        integer  ch11a(8),hb11a(8),ch11b(8),hb11b(8)
        integer  ch12a(6),hb12a(6),ch12b(6),hb12b(6)
        integer  ch21a(2),hb21a(2),ch21b(2),hb21b(2)
        integer  ch22a(2),hb22a(2),ch22b(2),hb22b(2)
        integer  ch31a(3),hb31a(3),ch31b(3),hb31b(3)
        integer  ch32a(3),hb32a(3),ch32b(3),hb32b(3)


        data ch11a / 4, 4, 4, 4,  1,  1, 2, 2/
        data hb11a / 1, 3, 5, 7, 10, 12, 2, 4/
        data ch11b / 2, 2, 2, 2, 1, 1, 1, 1/
        data hb11b / 6, 8, 12, 10, 8, 6, 4, 2/

        data ch12a / 3, 3, 3, 3, 3, 3/
	data hb12a / 2, 4, 6, 8, 10, 12/
	data ch12b / 4, 4, 4, 4, 4,  4/
	data hb12b / 12, 10, 8, 6, 4, 2/

	data ch21a / 1, 1/
	data hb21a / 1, 5/
	data ch21b / 2, 1/
	data hb21b / 9, 7/

	data ch22a / 1, 1/
	data hb22a / 3, 9/
	data ch22b / 2, 1/
	data hb22b / 11, 11/

	data ch31a / 2, 3, 3/
	data hb31a / 7, 9, 11/
	data ch31b / 2, 2, 2/
	data hb31b / 5, 3, 1/

        data ch32a / 3, 3, 4/
        data hb32a / 1, 5, 9/
        data ch32b / 3, 3, 4/
        data hb32b / 3, 7, 11/

        common / tofcalc /k1_s11s31,k1_s12s32,k1_S21S31,
     &           k1_S22S32,beta_a,
     &           adcx11,adcx12,adcx21,adcx22,adcx31,adcx32,
     &           tw11,tw12,tw21,tw22,tw31,tw32,
     &           y_coor_lin11,x_coor_lin12,x_coor_lin21,
     &           y_coor_lin22,y_coor_lin31,x_coor_lin32,
     &           xtofpos,ytofpos,adc_c,tof_i_flag,tof_j_flag
