Quadsort

This example illustrates an offline double gated sort updating a 2D matrix. The update algorithm is designed to produce spikeless spectra when slices and projections of the matrix are made. The data has been compressed so that all groups have a single item represented the gain matched energy value. The tag bits have been preserved in the first 3 bits of each data word.

! compressed data sortfile
! double gates updating 2D matrix
!
*FORMATS
gam[1:134] (tag:3, e4:13)

*DATA

!! gates for energy=e4/2
GATEMAP 1D gates1 [2050]
( 672  680)  (1165 1175)  (1346 1358)
(1474 1486)  (1544 1556)  (1686 1698)
(1566 1578)  (2036 2048)  (998 1006)
(1239 1249)  (1433 1443)

*SPECTRA
!== sort spectra ======
mat2d   4096 2D

*COMMANDS

CREATELIST gamlist FROM gam

LOOPIF $c=gamlist.e4 VALID
   $c.e4=$c.e4/2

if (NUMBER(gamlist)) LT 4
   ENDEVENT

!! double gated 2D update
!!
!! Use LOOPIF to decide whether the event satisfies 2, 3 or 4 gates
!! Then loop over the appropriate words in event to update matrix
!!  and exit loop
!!
!! Update Algorithm:
!! For m-dim update and p gates, words which satisfy gates are g parameters,
!! all others are x parameters.  Have 3 possible cases:
!!  1. satisfy exactly p gates -- update m-tuples from x params
!!  2. satisfy at least p+m gates -- update m-tuples from g+x params
!!  3. satisfy p+k gates, k<= m -- update m-tuples which involve <= k g params
}
!!
!! for this case:
!!  1. satisfy exactly 2 gates -- update doubles from listp2
!!  2. satisfy at least 4 gates -- update doubles from gamlist
!!  3. satisfy exactly 3 gates -- update g params with singles from listp3
!!
LOOPIF gamlist.e4 GATEDBY gates1 NEWLISTX=listp1
   {
                                                            !! >=1 gate
   LOOPIF listp1.e4 GATEDBY gates1 NEWLISTX=listp2
      {
                                                            !! >=2 gates
      LOOPIF listp2.e4 GATEDBY gates1 NEWLISTX=listp3
         {
                                                            !! >=3 gates
         LOOPIF listp3.e4 GATEDBY gates1
            {
                                                            !! >=4 gates
!! ...at least 4 gates satisfied in gamlist -- update all parameters
            INC mat2d(gamlist.e4,gamlist.e4)
            GOTO endloop1
            }
         LOOPFAIL
            {
                                                            !! =3 gates
!! ...no gates satisfied in listp3
            LOOPIF $a=gamlist.e4 GATEDBY gates1
               {
               INC mat2d($a.e4,listp3.e4)
               INC mat2d(listp3.e4,$a.e4)
               }
            INC mat2d(listp3.e4,listp3.e4)
            GOTO endloop1
            }
         }
      LOOPFAIL
         {
                                                            !! =2 gates
!! ...no gates satisfied in listp2 so listp2 contains just the x parameters
         INC mat2d(listp2.e4,listp2.e4)
         GOTO endloop1
         }
      }
   }

LABEL endloop1

*RUNFILES
COMP1 RUN1
COMP1 RUN2
COMP2 RUN3

*FINISH