C   06/03/80 205101418  MEMBER NAME  TFPAIR   (S)           FORTRAN
      SUBROUTINE TFPAIR(MCOSM)
C
      IMPLICIT INTEGER*2 (H)
      COMMON/SMPTOF/MTOF,TTOF(42),NTOF,HTOF(42),ZTOF(42)
      COMMON/TOFPAR/MPAIR,LTOF(2,10)
      COMMON/EVRUN/NRUN,IEV,ITYP,NEV,IMISS
      DIMENSION IHIT(42)
C
      DATA IBUG/0/
      IF(IENTRY.NE.0)  GOTO  19
      IENTRY = 1
      ZB = 10050
      ZA = 10150
      ZA = 10850
      ZB = 10950
      CALL HBOOK1(300,20HHITMAP             $,100,0.,100.)
      CALL HBOOK2(301,20HT1 T2              $, 40,-20.,20., 40,-20.,20.)
      CALL HBOOK1(302,20HTDT                $,100,-10.,15.)
      CALL HBOOK2(303,20HT VS TOFCOUNTER    $,100,-50.,50.,42,0.,42.)
      CALL HBOOK2(304,20HDTVS TOFCOUNTER    $,100,-25.,25.,22,0.,22.)
      CALL HBOOK2(305,20HNRUN TAUM          $,100,ZA,ZB,40,-20.,20.)
      CALL HBPROY(305)
      CALL HBOOK2(311,' Z1 Z2   $',100,-3000.,3000.,100,-3000.,3000.)
      CALL HBOOK1(312,20H DZ                $,100,-3000.,3000.)
   19 CONTINUE
C
      IBUG = IBUG + 1
      MPAIR = 0
      MCOSM = 0
      CALL SETSL(LTOF,0,20*4,0.)
      IF(NTOF.LT.2)  RETURN
C
C  FILL LATCH ARRAY IHIT
      NHIT = 0
      DO   30   I=1,42
      IF(HTOF(I).LE.0)  GOTO  30
      NHIT = NHIT + 1
      IHIT(NHIT) = I
      CALL HF1(300,FLOAT(I),1.)
   30 CONTINUE
      NH = NHIT
      IF(NHIT.GT.10) NH = 10
      CALL HF1(300,FLOAT(NH)+50.,1.)
C
      IBUG = IBUG + 1
      IF(IBUG.LE.10) PRINT 500,NHIT,NTOF,(IHIT(L),L=1,NHIT)
  500 FORMAT(' TFPAIT- NTOF ',11I5)
C
C FIND COPLANAR PAIRS OF TOF COUNTERS
C
      NA = NHIT-1
      DO   1   I=1,NA
      ITOF1 = IHIT(I)
      NB = I+1
      DO   2   J=NB,NHIT
      ITOF2 = IHIT(J)
      IDTOF = IABS(ITOF2-ITOF1)
      IF(IABS(IDTOF-21).GT.3)  GOTO  2
      IF(IBUG.LE.10) PRINT 500,I,J,ITOF1,ITOF2,IDTOF
      MPAIR = MPAIR + 1
      IF(MPAIR.GT.10)  GOTO  2
      LTOF(1,MPAIR) = ITOF1
      LTOF(2,MPAIR) = ITOF2
C
C   CHECK TOF DIFFERENCE
      T1 = TTOF(ITOF1)
      T2 = TTOF(ITOF2)
      IF(IBUG.LE.10) PRINT 501,ITOF1,ITOF2,T1,T2
  501 FORMAT(' TFPAIR- T1,T2',2I3,2F10.2)
C     IF(T1.LE.-20..OR.T2.LE.-20.)  GOTO  2
      DT = T2-T1
      IF(DT.GT.4.)  MCOSM = MCOSM + 1
      IF(IBUG.LE.10) PRINT 502,MCOSM,DT
  502 FORMAT(' TFPAIR- MCOSM,DT',I3,F10.2)
      CALL HFILL(301,T1,T2)
      CALL HF1(302,DT,1.)
      ZTOF1 = ZTOF(ITOF1)
      ZTOF2 = ZTOF(ITOF2)
      CALL HFILL(311,ZTOF1,ZTOF2)
      DZ = ZTOF1 + ZTOF2
      CALL HF1(312,DZ,1.)
    2 CONTINUE
    1 CONTINUE
C
      CALL HF1(300,FLOAT(MPAIR)+65.,1.)
      CALL HF1(300,FLOAT(MCOSM)+80.,1.)
      IF(MCOSM.GT.1) CALL HF1(300,FLOAT(NH)+95.,1.)
C/////////
      IF(MPAIR.NE.1) RETURN
      M = 1
      DO   50   I=1,2
      ITOF1 = LTOF(I,M)
      TOF1 = TTOF(ITOF1)
      CALL HFILL(303,TOF1,FLOAT(ITOF1))
      CALL HFILL(305,FLOAT(NRUN),TOF1)
   50 CONTINUE
      DT = TTOF(LTOF(2,1)) - TTOF(LTOF(1,1))
      CALL HFILL(304,DT,FLOAT(LTOF(1,1)))

       RETURN
       END
