C   02/03/79 311301635  MEMBER NAME  ACTOF    (S)           FORTRAN
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
       SUBROUTINE ACTOF(P,R,TRL)
C      CHANGED IN NCNT PART ON 29/05/79   BY E.ELSEN
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
       DIMENSION P(10),R(3)
C
C      P(5)= MASS, P(6)= ABS(MOMENTUM), R= 3-VECOTR, TRL= PATH-LENGTH
C
C     GEOMETRICAL CONST
C
      COMMON/CGEO1/BKGAUS, RPIP,DRPIP,XRLPIP, RBPC,DRBPC,XRLBPC,
     *             RITNK,DRITNK,XRLTKI, R0ROH,DR0ROH,XR0ROH,
     *             R1ROH,DR1ROH,XR1ROH, R2ROH,DR2ROH,XR2ROH,
     *             R3ROH,DR3ROH,XR3ROH, ROTNK,DROTNK,XRLTKO,
     *             RTOF,DRTOF,XRTOF, RCOIL, DRCOIL, XRCOIL,
     *             ZJM,DZJM,XRZJM, ZJP,DZJP,XRZJP,
     *             ZTKM,DZTKM,XRZTKM, ZTKP,DZTKP,XRZTKP,
     *             ZBPPL,ZBPMI,ZTOFPL,ZTOFMI,
     *             XRJETC,
     *             RLG,ZLGPL,ZLGMI,OUTR2,CTLIMP,CTLIMM,DELFI,
     *             BLXY,BLZ,BLDEP,ZENDPL,ZENDMI,DEPEND,
     *             XHOL1,XHOL2,YHOL1,YHOL2,BLPHI
C
C    RTOF= 920.  ZTOFPL= 1500.  ZTOFMI= -1500.
C
       COMMON/CTWRK/IADC(2,42),ITDC(2,42)
C
        DATA PAI,CVEL,DUMP/ 3.1415927, 2.9979246E2, -1.4E-4/
        DATA TUNIT,  WM,   WP,  A0M,  A0P,  CM,  CP, TRAN/
     *       0.05, -50., -51., 200., 200., 40., 40., 162./
C
C---------  CHECK Z-POSITION ON THE TOF COUNTER
C
       Z= R(3)
       IF(ABS(Z).GT.ZTOFPL) RETURN
C
C----------  DEFINE THE HIT COUNTER NUMBER
C
       PHAI= ATAN2(R(2),R(1))
       IF(PHAI.LE.0.) PHAI= PHAI+2.*PAI
       DPAI= PAI/21.
       NCNT= ( PHAI + DPAI/2. ) / DPAI + 1
       IF(NCNT.GT.42) NCNT= 1
C------- TIME OF FLIGHT
       PMAS2= P(5)*P(5)
       DPMAS= P(5)/P(6)
       EGEV= SQRT(P(6)*P(6)+PMAS2)
       BETA= P(6)/EGEV
       VELO= BETA*CVEL
       TOF= TRL/VELO
C------- ADC COUNT
       ZDP= ZTOFPL-Z
       TPLUS= ZDP/TRAN
       ZDM= Z-ZTOFMI
       TMINS= ZDM/TRAN
       ADCA= 100.*(DPMAS+2.)
       ADCM= ADCA*(DUMP*ZDM+1.)
       ADCP= ADCA*(DUMP*ZDP+1.)
       IF(ADCM.GE.1024.) ADCM= 1024.1
       IF(ADCP.GE.1024.) ADCP= 1024.1
C-------- PULSE HEIGHT CORRECTION
        TCM= WM*(1./SQRT(A0M)-1./SQRT(ADCM))+CM
        TCP= WP*(1./SQRT(A0P)-1./SQRT(ADCP))+CP
C-------- TDC COUNT
        NPLUS= (TOF+TPLUS+TCP)/TUNIT + 0.5
        NMINS= (TOF+TMINS+TCM)/TUNIT + 0.5
        IF(NPLUS.GT.ITDC(2,NCNT)) GO TO 500
             ITDC(2,NCNT)= NPLUS
             IADC(2,NCNT)= ADCP
 500    IF(NMINS.GT.ITDC(1,NCNT)) GO TO 600
             ITDC(1,NCNT)= NMINS
             IADC(1,NCNT)= ADCM
 600    RETURN
       END
