      subroutine hec_his_pass1
c
c pass 1 over data set to fill some system histograms
c
      implicit none
c
      include'hec_par.inc'      !shared parameters
      include'hec_datacard.inc' !datacard values
      include'hec_evth.inc'     !event header
      include'hec_search.inc'   !search
c
c local variable declaration
c
      logical hec_nextevt
      external hec_nextevt
      logical again
c
      print *, ' '
      print *, ' *** starting pass 1 for system histogram filling'
c
c initialise data io for pass
c
      call hec_io_pass_ini
c
c loop over events
c
      i_event = 1
      again = .true.

      do while (i_event .le. n_evtmax .and. again)
c
c check on end of epio file and/or errors
c
         again = hec_nextevt()

         if(again)then
 
            if (mod(i_event, 1000) .eq. 0 .or. i_event .eq. 1) then
               print *, ' *** starting event number ', i_event
            endif
c
c process event
c
            call hec_evt
c
c call special routine to book and fill mwpc histos
c
            if( mk_beam .ge. 1) call hec_online_mwpc
c
c system histogram analysis for a given event
c
            call hec_his_evt1
c
c handle end of event data io
c
            call hec_io_pass_evt
c
            i_event = i_event + 1
c
         endif
c
      enddo                     ! enddo over events
c
      i_event = i_event - 1
c
      print *, ' *** events processed      ', i_event
c
c system histogram analysis at end of event loop
c
      call hec_his_book_ana
      call hec_his_ana1
      call hec_his_fit
c
c handle data io at pass end
c
      call hec_io_pass_ter
c
      print *, ' *** pass 1 done for system histogram filling'
c
      end

 
              
            
          



