Projected Emittance

FORTRAN sample subroutine for
computing sigma of a beam profile

The following subroutine computes the beam center (XSP) and the 4sigma width (SIGMA) of a measured beam profile in millimeters. The digitized (12 bit ADC) profile data are stored in LBUF and some auxiliary data in IREC. The horizontal position is digitized with a 12-bit ADC ( 0 mm = 2048 units, ±2048 units are corresponding to ±50 mm). This code sample assumes, that there is not to much background noise ( <10% ) below the profile signal.


      SUBROUTINE COMPSIG(LBUF,IREC,XSP,SIGMA)
C
      IMPLICIT INTEGER*2 (I,J,K,L,M,N)
      INTEGER*2          REM1, REM2, REM3, YMAX, SUM, Y12
      INTEGER*2          LBUF(2), IREC(3)
C
      ANFL = IREC(1) ! start value in DAC units
      N    = IREC(2) ! number of data points in LBUF
      XINC = IREC(3) ! increment in DAC units
C
C     FIND MAXIMUM WITH SOME FILTERING
C
      YMAX    = 0
      REM1    = 0
      REM2    = 0
      DO 1 I  = 1, N
       REM3   = LBUF(I)
       SUM    = (REM1 + REM2 + REM3) / 3
       IF (SUM .GT. YMAX) THEN
         YMAX = SUM
         I0   = I
       ELSE
         REM1 = REM2
         REM2 = REM3
       ENDIF
    1 CONTINUE
C
C     FIND LEFT HALF HEIGHT
C
      Y12    = YMAX / 2
      REM1   = 0
      REM2   = 0
      DO 2 I = 1, N
       REM3  = LBUF(I)
       SUM   = (REM1 + REM2 + REM3) / 3
        IF (SUM. GE. Y12) GO TO 20
       REM1  = REM2
       REM2  = REM3
    2 CONTINUE
   20 I1     = I - 1
C
C     FIND RIGHT HALF HEIGHT
C
      REM1   = 0
      REM2   = 0
      DO 3 I = N, 1, -1
       REM3  = LBUF(I)
       SUM   = (REM1 + REM2 + REM3) / 3
        IF (SUM .GE. Y12) GO TO 30
       REM1  = REM2
       REM2  = REM3
    3 CONTINUE
   30 I2     = I + 1
C
C     GET REDUCED BOUNDARIES
C
      IDEL = MAX(1, IFIX(1.5 * FLOAT(I2 - I1)))
      I1   = I0 - IDEL
       IF (I1 .LT .1) I1 = 1
      I2   = I0 + IDEL
       IF (I2 .GT. N) I2 = N
C
C     COMPUTE THE SUMS WITH REDUCED BOUNDARIES
C
      SUM1    = 0.
      SUM2    = 0.
      SUM3    = 0.
      DO 40 I = I1, I2
        X     = I
        Y     = LBUF(I)
        XY    = X * Y
        XXY   = X * XY
        SUM1  = SUM1 + Y
        SUM2  = SUM2 + XY
        SUM3  = SUM3 + XXY
   40 CONTINUE
C
C     COMPUTE CENTER AND 4*SIGMA IN MM
C
      IF (SUM1 .GT. 0.0) THEN
       XSP   = SUM2 / SUM1
       SIGMA = SQRT(SUM3 / SUM1 - XSP**2)
       XSP   = ANFL - 2048. + XINC * (XSP - 1.)
       XSP   = XSP / 40.95
       SIGMA = 4. * XINC * SIGMA / 40.95
      ELSE
       XSP   = 0.
       SIGMA = 0.
      ENDIF
C
      RETURN
      END

Back to:About Monitors
Back to:Projected Emittance Computation
Last updated by Urs Rohrer on 1-Feb-2006