*
*=== Usreou ================= ==========================================*
*
      SUBROUTINE USREOU ( NOMORE )

*      INCLUDE 'dblprc.inc'
*      INCLUDE 'dimpar.inc'
*      INCLUDE 'iounit.inc'
*
*----------------------------------------------------------------------*
*                                                                      *
*     Copyright (C) 2003-2019:  CERN & INFN                            *
*     All Rights Reserved.                                             *
*                                                                      *
*     USeR Event OUtput: this routine is called at the end of each     *
*     event                                                            *
*                                                                      *
*     Created on 01 January 1991   by    Alfredo Ferrari & Paola Sala  *
*                                                   Infn - Milan       *
*                                                                      *
*       Input variables:                                               *
*                                                                      *
*              Nomore = if > 0 the run will be terminated              *
*                                                                      *
*----------------------------------------------------------------------*
*
*     INCLUDE 'detloc.inc'
*     INCLUDE 'detect.inc'


      INCLUDE '(DBLPRC)'
      INCLUDE '(DIMPAR)'
      INCLUDE '(IOUNIT)'
      INCLUDE '(DETLOC)'
      INCLUDE '(DETECT)'
      

      LOGICAL LSMOOTH

      PARAMETER (AA = 5.0D-5)
      PARAMETER (BB = 0.0D0)
      PARAMETER (CC = 0.0D0)

* Check if the event was smoothed or not
      IF (ACCUMN(NDTDET) .GE. ZERZER) THEN

         LSMOOTH = .FALSE.

         DO I=1,NDTDET-1
            IF (ACCUMP(I) .NE. ZERZER) THEN

               LSMOOTH = .TRUE.

               FWHM = AA + BB * SQRT(ACCUMP(I) + CC * ACCUMP(I)**2)
               CALL FLNRRN(RND)
*               WRITE(LUNOUT,*) "<< ACCUMP(",I,")=", ACCUMP(I)
               ACCUMP(I) = ACCUMP(I) + RND * FWHM / S2FWHM
*               WRITE(LUNOUT,*) ">> ACCUMP(",I,")=", ACCUMP(I),
*     &                         RND, RND*FWHM/S2FWHM

            END IF
         END DO

* Set to something negative not to redo in case of an empty event
         IF (LSMOOTH) THEN
            ACCUMN(NDTDET) = -999.0D0
            ACCUMP(NDTDET) = ZERZER
         END IF
      END IF 

      RETURN
*=== End of subroutine Usreou =========================================*
      END

