*$ CREATE USIMBS.FOR
*COPY USIMBS
*
*=== Usimbs ===========================================================*
*
      SUBROUTINE USIMBS ( MREG, NEWREG, FIMP )

      INCLUDE '(DBLPRC)'
      INCLUDE '(DIMPAR)'
      INCLUDE '(IOUNIT)'
*
*----------------------------------------------------------------------*
*                                                                      *
*     Copyright (C) 2001-2008      by    Alfredo Ferrari & Paola Sala  *
*     All Rights Reserved.                                             *
*                                                                      *
*                                                                      *
*     USer defined IMportance BiaSing:                                 *
*                                                                      *
*     Created on   02 july 2001    by    Alfredo Ferrari & Paola Sala  *
*                                                   Infn - Milan       *
*                                                                      *
*     Last change on 30-oct-08     by    Alfredo Ferrari               *
*                                                                      *
*     Input variables:                                                 *
*                Mreg = region at the beginning of the step            *
*              Newreg = region at the end of the step                  *
*     (thru common TRACKR):                                            *
*              Jtrack = particle id. (Paprop numbering)                *
*              Etrack = particle total energy (GeV)                    *
*       X,Y,Ztrack(0) = position at the beginning of the step          *
*  X,Y,Ztrack(Ntrack) = position at the end of the step                *
*                                                                      *
*    Output variable:                                                  *
*                Fimp = importance ratio (new position/original one)   *
*                                                                      *
*----------------------------------------------------------------------*
*
      INCLUDE '(TRACKR)'
**
      YSTART = YTRACK(0)
      ZSTART = ZTRACK(0)
      IF(YSTRAT <=450.0 .AND. YSTART > 0.0) THEN
      FYSTART = 2 * (INT((450.0-YSTART)/225.0) + 1)
      ELSEIF(YSTRAT >=1750.0 .AND. YSTART < 2025.0) THEN
      FYSTART = 2 * (INT((YSTART-1750.0)/275.0) + 1)
      ELSEIF(YSTART <= 0.0) THEN
      FYSTART = 4
      ELSEIF(YSTART >= 2025.0) THEN
      FYSTART = 4
      ELSE
      FYSTART = 1
      ENDIF
**
      IF(ZSTRAT <=1072.0 .AND. ZSTART > 300.0) THEN
      FZSTART = 2 * (INT((1072.0-ZSTART)/193.0) + 1)
      ELSEIF(ZSTRAT >=2920.0 .AND. ZSTART < 3370.0) THEN
      FZSTART = 2 * (INT((ZSTART-2920.0)/225.0) + 1)
      ELSEIF(ZSTART <= 300.0) THEN
      FZSTART = 8
      ELSEIF(ZSTART >= 3370.0) THEN
      FZSTART = 4
      ELSE
      FZSTART = 1
      ENDIF
**
      FSTART = FYSTART * FZSTART
**
      YEND = YTRACK(NTRACK)
      ZEND = ZTRACK(NTRACK)
      IF(YEND <=450.0 .AND. YEND > 0.0) THEN
      FYEND = 2 * (INT((450.0-YEND)/225.0) + 1)
      ELSEIF(YEND >=1750.0 .AND. YEND < 2025.0) THEN
      FYEND = 2 * (INT((YEND-1750.0)/275.0) + 1)
      ELSEIF(YEND <= 0.0) THEN
      FYEND = 4
      ELSEIF(YEND >= 2025.0) THEN
      FYEND = 4
      ELSE
      FYEND = 1
      ENDIF
**
      IF(ZEND <=1072.0 .AND. ZEND > 300.0) THEN
      FZEND = 2 * (INT((1072.0-ZEND)/193.0) + 1)
      ELSEIF(ZEND >=2920.0 .AND. ZEND < 3370.0) THEN
      FZEND = 2 * (INT((ZEND-2920.0)/225.0) + 1)
      ELSEIF(ZEND <= 300.0) THEN
      FZEND = 8
      ELSEIF(ZEND >= 3370.0) THEN
      FZEND = 4
      ELSE
      FZEND = 1
      ENDIF
**
      FEND = FYEND * FZEND
**
      FIMP   = FEND / FSTART
      RETURN
*
*======================================================================*
*                                                                      *
*     Entry USIMST:                                                    *
*                                                                      *
*     Input variables:                                                 *
*                Mreg = region at the beginning of the step            *
*                Step = length of the particle next step               *
*                                                                      *
*    Output variable:                                                  *
*                Step = possibly reduced step suggested by the user    *
*                                                                      *
*======================================================================*
*
      ENTRY USIMST ( MREG, STEP )
*
      IF ( STEP .GT. ONEONE ) STEP = HLFHLF * STEP
      RETURN
*=== End of subroutine Usimbs =========================================*
      END

