      SUBROUTINE hec_trig_sheet
C
C-----------------------------------------
C
C   Author   :- RD33/TGT DAQ          17-SEP-1994
C
C=========================================
C
C   Purpose   : print runsheet
C   Inputs    :
C   Outputs   :
C
C=========================================
C +
C Declarations.
C -
      IMPLICIT NONE
c
      include'hec_par.inc'  ! shared parameters
c
c event header common
c
      include'hec_evth.inc'
c
c online mode common
c
      include'hec_online.inc'
c
c run header common
c
      include'hec_runh.inc'
c
      integer LUN 
      parameter (lun=66)
c
      INTEGER j, tmp_hits
      CHARACTER*20 PUname(0:15,1:4)
c
      integer i
      character*24 crun_start
c
      DATA PUname(15,1)/'15/15 pi/e*C Trig'/
      DATA PUname(14,1)/'15/14 pi/e   Trig'/
      DATA PUname(13,1)/'15/13 S random Tr'/
      DATA PUname(12,1)/'15/12 mu     Trig'/
      DATA PUname(11,1)/'15/11 MWPC   Trig'/
      DATA PUname(10,1)/'15/10 VM hole low'/
      DATA PUname(9,1)/'15/9  pi/e/mu  '/
      DATA PUname(8,1)/'15/8  '/
      DATA PUname(7,1)/'15/7  C1 8 major.'/
      DATA PUname(6,1)/'15/6  C1 7 major.'/
      DATA PUname(5,1)/'15/5  C1 6 major.'/
      DATA PUname(4,1)/'15/4  Early Pile up'/
      DATA PUname(3,1)/'15/3  H Random Trig'/
      DATA PUname(2,1)/'15/2  F pretrigger'/
      DATA PUname(1,1)/'15/1  VM hole up'/
      DATA PUname(0,1)/'15/0  all events'/
      DATA PUname(15,2)/'16/15 VM 12 c low'/
      DATA PUname(14,2)/'16/14 VM 11 left'/
      DATA PUname(13,2)/'16/13 VM 10'/
      DATA PUname(12,2)/'16/12 VM 9'/
      DATA PUname(11,2)/'16/11 VM 8'/
      DATA PUname(10,2)/'16/10 VM 7'/
      DATA PUname(9,2)/'16/9  VM 6 cent up'/
      DATA PUname(8,2)/'16/8  VM 5'/
      DATA PUname(7,2)/'16/7  VM 4'/
      DATA PUname(6,2)/'16/6  VM 3'/
      DATA PUname(5,2)/'16/5  VM 2'/
      DATA PUname(4,2)/'16/4  VM 1  right'/
      DATA PUname(3,2)/'16/3  M1 10 left'/
      DATA PUname(2,2)/'16/2  M1 9'/
      DATA PUname(1,2)/'16/1  M1 8'/
      DATA PUname(0,2)/'16/0  M1 7'/
      DATA PUname(15,3)/'17/15 M1 6'/
      DATA PUname(14,3)/'17/14 M1 5'/
      DATA PUname(13,3)/'17/13 M1 4'/
      DATA PUname(12,3)/'17/12 M1 3'/
      DATA PUname(11,3)/'17/11 M1 2'/
      DATA PUname(10,3)/'17/10 M1 1 right'/
      DATA PUname(9,3)/'17/9  M2 10 left'/
      DATA PUname(8,3)/'17/8  M2 9'/
      DATA PUname(7,3)/'17/7  M2 8'/
      DATA PUname(6,3)/'17/6  M2 7'/
      DATA PUname(5,3)/'17/5  M2 6'/
      DATA PUname(4,3)/'17/4  M2 5'/
      DATA PUname(3,3)/'17/3  M2 4'/
      DATA PUname(2,3)/'17/2  M2 3'/
      DATA PUname(1,3)/'17/1  M2 2'/
      DATA PUname(0,3)/'17/0  M2 1'/
      DATA PUname(15,4)/'18/15'/
      DATA PUname(14,4)/'18/14'/
      DATA PUname(13,4)/'18/13'/
      DATA PUname(12,4)/'18/12'/
      DATA PUname(11,4)/'18/11'/
      DATA PUname(10,4)/'18/10'/
      DATA PUname(9,4)/'18/9'/
      DATA PUname(8,4)/'18/8'/
      DATA PUname(7,4)/'18/7'/
      DATA PUname(6,4)/'18/6'/
      DATA PUname(5,4)/'18/5  '/
      DATA PUname(4,4)/'18/4  '/
      DATA PUname(3,4)/'18/3  '/
      DATA PUname(2,4)/'18/2  '/
      DATA PUname(1,4)/'18/1  '/
      DATA PUname(0,4)/'18/0  Late pile up'/
c
c translate run_start from unix binary bits to character
c
      call ctimef(run_start,crun_start)
c
c open file in which to write summary
c
      open(lun,file='runsheet.log',status='unknown')
C + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
C Entry Point.
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      WRITE(LUN,9000) run_no
      WRITE(LUN,'(T8,A)') crun_start
 9000 FORMAT(/,T8,'Run',I5)
      WRITE(LUN,9001) e_beam,i_part,real(x_cryo)*10.,real(y_tabl)*10.
 9001 FORMAT(/T8,'Momentum',I5,' GeV, particle type:',I3,
     &  ' Xcal=',f6.1,' Ycal=',f6.1)
      WRITE(LUN,9003) i_event,infname
 9003 FORMAT(T8,I5,' Events written to file ',A)
      WRITE(LUN,9004)
 9004 FORMAT(/T8,'Pattern unit statistics:')
      DO j=15,0,-1
        WRITE(LUN,9005) PUname(j,1),i_trigcnt(j+1),
     &    PUname(j,2),i_trigcnt(j+17)
      ENDDO
      WRITE(LUN,'()')
      DO j=15,0,-1
        WRITE(LUN,9005) PUname(j,3),i_trigcnt(j+33),
     &    PUname(j,4),i_trigcnt(j+49)
      ENDDO
 9005 FORMAT(T8,A20,I8,T40,A20,I8)
c
c Print MWPC efficientcy
c
      write(lun,*) '*************************************************'
      write(lun,*) 'Number of signal Hits on any MWPC     ',
     +              mwpc_signal_hit_count
c
c Total number of events - random triggers
c
      tmp_hits = i_trigcnt(1) - ( i_trigcnt(4) + i_trigcnt(14) )
      if (tmp_hits .ne. 0) then
         write(lun,*) 'Events used to calculate efficiencies ',tmp_hits
c
c start with chamber 2 because chamber 1 does not exist
c
         do i = 2, 5
            write(lun,'(a,i2,a,f5.1,a,a,f5.1,a)')
     +      ' Effciciency of MWPC ',i,
     +      ' in X is ',
     +     100.*real(mwpc_signal_xhit_count(i))/real(tmp_hits),' %',
     +      ' in Y is ',
     +     100.*real(mwpc_signal_yhit_count(i))/real(tmp_hits),' %'
         enddo
      else
         print *,'cannot judge mwpc efficiency....no physics triggers'
      endif
      write(lun,*) '*************************************************'
c
c print guestimate of number of electrons and pions
c
      write(lun,*) '*************************************************'
      write(lun,*) ' number of physics triggers    = ',phys_trig_count
      write(lun,*) ' estimated number of electrons = ',elec_count
      write(lun,*) ' estimated number of pions     = ',pion_count
      write(lun,*) ' NOTE: these numbers only include physics triggers'
      write(lun,*) ' chosen by the shift crew (ie. e pi or mu triggers '
      write(lun,*) ' could be requested) '
      write(lun,*) '*************************************************' 
c
c
      close(lun)
c
      END
