C   01/08/80 109291144  MEMBER NAME  MEWT3    (JADESR)      FORTRAN
      SUBROUTINE MEWT3(ISTF)
      IMPLICIT INTEGER*2 (H)
C-----------------------------------------------------------------------
C FLAGS EVENTS CONTAINING POSSIBLE MUON TRACKS USING THE T3 TRIGGER
C STREET/GROUP INFORMATION IN THE TRIGGER BANK.
C MIN. REQUIREMENT FOR POSSIBLE TRACK IN A STREET IS THAT
C 3/5 GROUPS IN THAT STREET HAVE GIVEN SIGNALS
C THE N3ST SUCH STREETS ARE STORED IN ILIS3.
C THE N4ST STREETS WITH >/= 4/5 GROUPS FIRED ARE STORED IN ILIS4
C NOISY STREETS CAN BE TREATED DIFFERENTLY BY SETTING THE FLAG
C 'NOISY' FOR A NOISY STREET. IN THIS CASE MIN REQUIRENEMT FOR THIS
C STREET IS 4/5 GROUPS FIRED.
C IF A GROUP CONTAINS 1 OR MORE DEAD CHAMBERS,FLAG KAPUT(GROUP,STREET)
C CAN BE SET TO TREAT THIS GROUP AS HAVING FIRED.
C IN THIS VERSION,FOR USE IN REDUC1, KAPUT IS ONLY SET IN THE ENDWALLS.
C
C RETURN FLAG  ISTF :
C                       = -1         NO TRIGGER BANK.
C                       = N4ST = 0,1,2,.....9 NUMBER OF ENDWALL STREETS
C                              WITH >/= 4/5 GROUPS FIRED.
C                              FOR N4ST.GT.9, N4ST IS SET TO 9 &
C                              A WARNING MESSAGE IS PRINTED
C                       = 130 + N4ST, ENDWALL QUADRANTS 1 & 3 EACH
C                         HAVE ONE OR MORE STREETS WITH >/= 3/5
C                         GROUPS FIRED
C                       = 240 + N4ST, ENDWALL QUADRANTS 2 & 4 EACH
C                         HAVE ONE OR MORE STREETS WITH >/= 3/5
C                         GROUPS FIRED
C                       = 400 + N4ST, ALL 4 ENDWALL QUADRANTS CONTAIN
C                         A STREET WITH >/= 3/5 GROUPS FIRED.
C-----------------------------------------------------------------------
#include "cdata.for"
      COMMON /CHEADR/HEAD(17),HRUN,HEV
      LOGICAL*1 NOISY(36)
      LOGICAL*1 KAPUT(5,36)
      LOGICAL*1 IFIR3(36)
      LOGICAL*1 IFIR4(36)
      LOGICAL*1 IQUAD1,IQUAD2,IQUAD3,IQUAD4
      DIMENSION ILIS3(36),ILIS4(36)
      DATA NGR1/3/,NGM1/3/,NGR2/4/,NGM2/4/
      DATA NOISY/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
     &           0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0/
      DATA KAPUT/0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
     &           0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
     &           0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
     &           0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
     &           0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
     &           0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
     &           0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
     &           0,0,0,0,0/
C
C..INITIALISE..
      DO 5 I=1,36
      IFIR3(I) = .FALSE.
      IFIR4(I) = .FALSE.
      ILIS3(I) = 0
      ILIS4(I) = 0
    5 CONTINUE
      ISTF = 0
      N3ST = 0
      N4ST = 0
      IQUAD1 = .FALSE.
      IQUAD2 = .FALSE.
      IQUAD3 = .FALSE.
      IQUAD4 = .FALSE.
C
C..FIND POINTER TO TRIGGER BANK..
      MTRIG1 = IDATA (IBLN('TRIG'))
      IF(MTRIG1.EQ.0) GOTO 999
      MTRIG2 = IDATA (MTRIG1 - 1)
      MTRIG3 = IDATA (MTRIG2 - 1)
C..HALF-WORD POINTERS..
      MHTRI1 = 2*MTRIG1
      MHTRI2 = 2*MTRIG2
      MHTRI3 = 2*MTRIG3
C
C..GET 1'ST I*2 T3 WORD..
      IT3 = MHTRI3 + 1
C
C..LOOP OVER T3 STREETS IN ENDWALLS..
      DO 100 IST = 21,36
      NG = 0
      NGG1 = 0
      NGG2 = 0
      ITEM = IT3 + IST
C
C..LOOP OVER GROUPS IN STREET IST..
      DO 40 IGR = 4,8
      IGROUP = 9 - IGR
      IF(KAPUT(IGR,IST)) GOTO 35
      IF(JBIT(HDATA(ITEM),IGR).NE.0) GOTO 40
   35 CONTINUE
      NG = NG + 1
      IF(IGROUP.GE.NGM1) NGG1 = NGG1 + 1
      IF(IGROUP.GE.NGM2) NGG2 = NGG2 + 1
   40 CONTINUE
      IF(NOISY(IST)) GOTO 45
      IF(NG.LT.NGR1.OR.NGG1.LE.0) GOTO 100
C..MIN REQUIREMENT SATISFIED FOR NORMAL STREET..
      N3ST = N3ST + 1
      IFIR3(IST) = .TRUE.
      ILIS3(N3ST) = IST
C
C..NOW SET UP FLAGS FOR ENDWALL QUADRANTS..
      IF(IST.GE.21.AND.IST.LE.24) IQUAD1 = .TRUE.
      IF(IST.GE.25.AND.IST.LE.28) IQUAD2 = .TRUE.
      IF(IST.GE.29.AND.IST.LE.32) IQUAD3 = .TRUE.
      IF(IST.GE.33.AND.IST.LE.36) IQUAD4 = .TRUE.
   45 CONTINUE
      IF(NG.LT.NGR2.OR.NGG2.LE.0) GOTO 100
      N4ST = N4ST + 1
      IFIR4(IST) = .TRUE.
      ILIS4(N4ST) = IST
  100 CONTINUE
      IF(N4ST.LT.10) GOTO 110
      WRITE(6,60) HRUN,HEV,N4ST
   60 FORMAT(1H ,/,' ***** MEWT3 : RUN ',I5,1X,'EVENT ',I5,
     &/,' !!!!! ',I3,' MUON STREETS WITH >/=4/5 GROUPS FIRED.SET TO 9')
      N4ST = 9
  110 CONTINUE
      ISTF = ISTF + N4ST
      IF(IQUAD1.AND.IQUAD4) ISTF = ISTF + 130
      IF(IQUAD2.AND.IQUAD3) ISTF = ISTF + 240
      IF(IQUAD1.AND.IQUAD2.AND.IQUAD3.AND.IQUAD4) ISTF = 400 + N4ST
      RETURN
  999 CONTINUE
      ISTF = -1
      RETURN
      END
