If...else... command (single sortword environment)}

The IF command allows conditional execution of statements1 or statements2 depending on the result of a test. If the result is true, then statements1 are executed, otherwise statements2 are executed (if specified). The various forms of the IF command are described below in more detail.

Validation test operator (VALID)

where VALID means `present in the event' or `set true by some previous statement in the sortfile', i.e. by an arithmetic assignment, EXTRACT, LOOPEXTRACT or CALL statement. For each such word, statements1 are executed.

Comparison operators (EQ,NE,GE,LE,GT,LT)

The first sortword or expression is compared with the second according to the operator specified,

Example

IF GAMA GT THRESHOLD {
    INC SPEC1(GAMA)
    INC SPEC2(TAC)
    }
ELSE  EVENTEND

In the above example, the spectrum increments are performed if the value of GAMA is greater than that of THRESHOLD. Otherwise event processing is terminated for that event (EVENTEND command).


Filtering operators (PASSES,FAILS)

where expressions may be used to define lower-limit and upper-limit. IF...PASSES is true if sortword or expression falls inside the gate defined by lower-limit and upper-limit inclusive,

Example

IF GAMA PASSES (100 , HLIMIT)    INC SPEC1(GAMB)

causes spectrum SPEC1 to be incremented if the value of sortword GAMA lies between 100 and the value of HLIMIT (inclusive).


If upper-limit is less than lower-limit then the IF test will always give the result FALSE.

where index is an integer expression which gives the array element number used to obtain a gate defined in gate-array-name. See gate-array command.

Example

EXTRACT GELIST INTO $G1
IF $G1.TAC PASSES TACLIST($G1) {
   ...

Conversely IF...FAILS is true only if sortword or expression is present in the event and falls outside the limits of the gate,

Example

IF GAMA FAILS (100 , HLIMIT) {
    DEC SPEC2(GAMB)
    DEC SPEC3(GAMC)
    }

causes spectra SPEC2 and SPEC3 to be decremented if sortword GAMA is outside the range defined by 100 and HLIMIT (inclusive).


Masking operator (MASKEDBY)

IF...MASKEDBY is true only if all the bits set in the 16-bit mask are present in the sortword or expression being tested,

Example

IF GAMA MASKEDBY %00110101    INC SPEC1(MB1)

causes SPEC1 to be incremented if all the bits set in GAMA are also set in the bit pattern %00110101.


This form of the command is true if there is a bit pattern in bitmask-set-name for which all the bits set are present in sortword or expression. The gate number of the bit pattern which satisfies this condition is placed in the reserved word GATE.

Gate-testing operator (GATEDBY)

IF...GATEDBY is true if the value or sortword or expression falls within the set of gates associated with gate-expression. The gate number passed is placed in the reserved variable GATE. This variable is only recognised within statements. See section group name for definition of gate limits.

Example

IF GAMTOT GATEDBY  GLIST1 {
    INC SPEC1(GAMTOT)
    INC SUMSPEC(SUMEN)
    }
ELSE  EVENTEND

where the spectra SPEC1 and SUMSPEC are incremented if sortword GAMTOT passes any of the 1D gates defined in the gate-map GLIST1. If no gates are passed then command processing is terminated for that event (EVENTEND command).


In the 2D gate test command the gate is passed if the coordinates given by exprx and expry fall within the set of 2D polygonal or elliptical gates specified in 2d-gate-expr. The intersection of two polygons is given the gate number of the later defined gate.

Example

IF EDELTE SUMEN GATEDBY  GREC1 {
    INC MASS1(GAMTOT)
    SELECT(GATE)
       ... commands dependent upon which gate passed ...
    }
ELSE {
    IF EDELTE SUMEN GATEDBY GREC2
        INC MASS2(GAMTOT)
    }

If EDELTE (x-coordinate) and SUMEN (y-coordinate) pass any of the gates defined in the gate-map GREC1 then the commands within the first set of braces will be executed, otherwise if they pass any of the gates defined in GREC2 then the commands within the second set of braces will be obeyed: