      subroutine anal3

c  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
c  This is a sample routine for finding a vertex using KWFIT
c  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

      implicit none

#include "seq/clinc/anlccd.inc"
#include "seq/clinc/anlclev.inc"

c     Local variables
      integer npi, listpi(mxtrak), nk, listk(mxtrak)
      integer dummy, error

      logical lerror
c  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

*     Clear the tracks from KWFIT at the start of the event
      call kset_clear

*     Get tracks... require at least 3 tracks for vertex finding
      call getcd
      if(ntrkcd .lt. 3) goto 1000

*     Put good pi+- and K+- tracks into KWFIT
      call make_kpi_list(.TRUE., npi, listpi, nk, listk)
      if(npi .lt. 3) goto 9999

*     Make primary vertex with selected pions
      call vtx_primary(npi, listpi, error)    !Make primary vertex
      if(error .ne. 0) goto 9999

*     Normal exit
 1000 continue
      return

*     Error in finding primary vertex
 9999 return
      end
