******************************************************************
      SUBROUTINE GUSTEP
******************************************************************
*                                                                *
*     User routine called at the end of each tracking step       *
*                                                                *
******************************************************************
*
      IMPLICIT NONE
*
      INTEGER I, NPHE, ALIVE, PRFACE
      REAL DESTEPM, XX(6), XGIPMT, YGIPMT
      REAL ZOUT(6), TOUT
*
#include"geant321/gctrak.inc"
#include"geant321/gckine.inc"
#include"geant321/gcking.inc"
#include"geant321/gctmed.inc"
#include"geant321/gcvolu.inc"
#include"geant321/gctmed.inc"
#include"meguse.inc"
*
* *** Generates the scintillation photon cascade inside Lixe
*     (I prefer using MeV)
      DESTEPM =DESTEP * 1000.
*
      IF(NUMED.EQ.22.AND.DESTEPM.GT.0.) THEN
         NPHE=DESTEPM*LXPMTQE*LXLYELD
*
         DO I=1,3               ! only coordinates needed.
            XX(I)=VECT(I)
         ENDDO
*
         DO I=1,NPHE
*
* *** Track each scintillation photon till the surface.
           CALL LXPHO1(XX, 0., ZOUT, TOUT, ALIVE)
           IF (ALIVE.GT.0) THEN
*
* *** Fills histogram on the surface calling PROtotype Find PMultiplier
              CALL PROFPM( ZOUT, PRFACE, XGIPMT, YGIPMT)
*
* *** If PRFACE.GT.0 the photon hit some photomultiplier
              IF (PRFACE.GT.0) QSOMMA=QSOMMA+1
              IF (PRFACE.EQ.1) CALL HFILL( 101, XGIPMT, YGIPMT,  1.)
              IF (PRFACE.EQ.6) THEN
                 CALL HFILL( 201, XGIPMT, YGIPMT,  1.)
                 CALL HFILL( 102,-XGIPMT, YGIPMT, -1.)
              ENDIF
           ENDIF
         ENDDO
      ENDIF
*
* *** Store the created particles (for primary track only)
      IF (NGKINE.GT.0) CALL GSKING(0)
*
* *** Store track parameters
      CALL GSXYZ(0)
      RETURN
      END