      SUBROUTINE GUKINE
C +SEQ, GCFLAG.
      COMMON/GCFLAG/IDEBUG,IDEMIN,IDEMAX,ITEST,IDRUN,IDEVT,IEORUN
     +        ,IEOTRI,IEVENT,ISWIT(10),IFINIT(20),NEVENT,NRNDM(2)
c      COMMON /GCFLAX/ BATCH, NOLOG
c      LOGICAL BATCH, NOLOG
C+SEQ, GCKINE.
c      COMMON /GCKINE/ IKINE,PKINE(10),ITRA,ISTAK,IVERT,IPART,ITRTYP,
c     +   NAPART(5),AMASS,CHARGE,TLIFE,VERT(3),PVERT(4),IPAOLD
c----------------------------------------------------------------------
      include 'ntpl.inc'
      include 'edep1.inc'
c----------------------------------------------------------------------
      real vertex(3,10), plab3(4,10), qp(10), pabs, am/0.000511/
      real sinth/0.025/, costh/0.999687/, py, pz, sigma/0.010/, u, v
      integer iout/0/, init/0/, i, j, np, nvert(10)
c
      if(init.eq.0) then
         open(11,file='esa.bin',form='UNFORMATTED')
         init = 1
      end if
c
      read(11,end=9999) np, (qp(i),(plab3(j,i),j=1,4),
     -                  (vertex(j,i),j=1,3),i=1,np)

c  Load vertex position onto GEANT stack

c      call gauss2d(u, v)
      do i=1, np
c         vertex(1,i) = vertex(1,i) + sigma * u
c         vertex(2,i) = vertex(2,i) + sigma * v
         call gsvert(vertex(1,i),0,0,dummy,0,nvert(i)) ! nvert returned
      end do

c
c  Load track onto GEANT stack
      do i=1, np
         kpart = 1
         if(qp(i).lt.0.) kpart = 3
         if(qp(i).gt.0.) kpart = 2
c         py = plab3(2,i) * costh + plab3(3,i) * sinth
c         pz = plab3(3,i) * costh - plab3(2,i) * sinth
c         plab3(2,i) = py
c         plab3(3,i) = pz
         call gskine(plab3(1,i),kpart,nvert(i),dummy,0,nt) ! nt returned
      end do
c

      call jbgtrk(2)

c---        save beam particle in ntuple
      nh = 0
      if(iout.eq.1) then
         nh = 3
      do i=1, 3
         xl(i) = 0.
         yl(i) = 0.
         zl(i) = 0.
         ql(i) = qp(i)
         el(i) = plab3(4,i)
         ul(i) = plab3(1,i)
         vl(i) = plab3(2,i)
         wl(i) = plab3(3,i)
      end do
      end if
c---
c      CALL GSVERT(PKINE,0,0,0,0,NVERT)
c      CALL GSKINE(PKINE(4),IKINE,NVERT,0,0,NT)

      IF (IDEBUG.NE.0) THEN
         CALL GPRINT('VERT',0)
         CALL GPRINT('KINE',0)
      ENDIF
      return

9999  continue

      ieorun = 1

      END




