******************************************************************************
*                                                                            *
*  File:  L_Tl_Np4.A40                                 Rev.   21-DEC-1995    *
*                                                                            *
*                                                                            *
*  "Meaningful" Register Usage                                               *
*  ---------------------------                                               *
*  R0  : TT Tot Et Data for n+4, phi center  Global                 Input    *
*  R1  : TT Tot Et Data for n+5, phi center  Global                 Input    *
*  R2  : Valid Object Counter                Global                 I/O      *
*  AR0 : Pointer to Rack #1 Tot Et TT Data                                   *
*        at phi = center + 1                 Global                 Input    *
*  AR1 : Pointer for Rack #2 Tot Et TT Data                                  *
*        at phi = center + 1                 Global                 Input    *
*  AR3 : Pointer for Object List             Global                 Output   *
*  BK  : Length of a TT Data Block           Global                 Input    *
*  R3  : 1x2 EM Et Sum                       Global                 Output   *
*  R5  : 3x3 Total Et Sum                    Global                 Output   *
*  R6  : 1x2 Total Et Sum                    Global                 Output   *
*  R7  : 5x5 Total Et Sum                    Global                 Output   *
*        (note that R6 and R7 have other uses  in the Scan Routine, but the  *
*         usage is non-overlapping with the usage here)                      *
*                                                                            *
*  "Destroyable" Register Usage                                              *
*  ----------------------------                                              *
*  R9, R10, R11, AR6, AR7                                                    *
*                                                                            *
*  Description of Module                                                     *
*  =====================                                                     *
*                                                                            *
*                                                                            *
*  This is the program section for the Tool Code for processing an event     *
*  with an  eta n+4  Trigger Tower over its Ref Set threshold.               *
*              -----                                                         *
*                                                                            *
*   This module is for Local Tool #4, the eWjj Tool.                         *
*                                                                            *
*   See the L_TL_NP2.A40 module for a description of the operation of this   *
*   Local Tool.                                                              *
*                                                                            *
*  Recall the arrangement of eta's in the racks:                             *
*                                                                            *
*                                                                            *
*    Rack                   Rack #1                   Rack #2                *
*    Signal           --------------------      ---------------------        *
*    Names            n    n+1   n+2   n+3      n+4   n+5   n+6   n+7        *
*                                                                            *
*    This DSP Node              --------------------------                   *
*    is Responsible              n+2   n+3      n+4   n+5                    *
*    for these eta's                                                         *
*                                               ^                            *
*                                               |                            *
*             We are processing this Trig Tower +                            *
*                                                                            *
*                                                                            *
*  NOTE that the "Eta Rings" are numbered in the same way,  i.e.  n : n+7    *
*                                                                            *
*                                                                            *
*  First lets understand the exact details about what things look like       *
*  at the time we enter this routine.                                        *
*                                                                            *
*  The data from the two racks looks like the following diagram.  Rack #1    *
*  Tot Et data is pointed to by AR0  and Rack #2 tot Et data is pointed to   *
*  by AR1.                                                                   *
*                                                                            *
*                                                                            *
*                          Rack #2                      Rack #1              *
*                --------------------------    -------------------------     *
*                 n+7    n+6    n+5    n+4      n+3    n+2    n+1    n+0     *
*                -----  -----  -----  -----    -----  -----  -----  -----    *
*                D   D  D   D  D   D  D   D    D   D  D   D  D   D  D   D    *
*                3   2  2   1  1   8  7   0    3   2  2   1  1   8  7   0    *
*                1   4  3   6  5               1   4  3   6  5               *
*                                                                            *
*                                                                            *
*                                                                            *
*                -----  -----  -----  -----    -----  -----  -----  -----    *
* phi center-2    n+7    n+6    n+5    n+4      n+3    n+2    n+1    n+0     *
*                -----  -----  -----  -----    -----  -----  -----  -----    *
* phi center-1    n+7    n+6    n+5    n+4      n+3    n+2    n+1    n+0     *
*                -----  -----  ----- +-----+   -----  -----  -----  -----    *
* phi center      n+7    n+6    n+5  | n+4 |    n+3    n+2    n+1    n+0     *
*                -----  -----  ----- +-----+   -----  -----  -----  -----    *
* phi center+1    n+7    n+6    n+5    n+4      n+3    n+2    n+1    n+0     *
*                -----  -----  -----  -----    -----  -----  -----  -----    *
* phi center+2    n+7    n+6    n+5    n+4      n+3    n+2    n+1    n+0     *
*                -----  -----  -----  -----    -----  -----  -----  -----    *
*                                                                            *
*                                                                            *
*  As we enter this routine:                                                 *
*                                                                            *
*     AR0 points to Rack #1 Tot Et data at "phi center + 1"   i.e. a phi     *
*     that is one greater than the phi address of the Trigger Tower that     *
*     we are processing.  This is true because it was incremented before     *
*     the delayed conditional branch was FETCHED (i.e. not due to the        *
*     delayed execution of the branch)                                       *
*                                                                            *
*     AR1 points to Rack #2 Tot Et data at "phi center + 1   i.e. a phi      *
*     that is one greater than the phi address of the Trigger Tower that     *
*     we are processing.  This is true because the three instructions        *
*     following the delayed conditional branch were all executed.            *
*                                                                            *
*     Register R1 is holding the Tot Et TT                                   *
*     data for:                               eta n+5  at "phi center"       *
*                                                                            *
*     Register R0 is holding the Tot Et TT                                   *
*     data for:                               eta n+4  at "phi center"       *
*                                                                            *
******************************************************************************

******************************************************************************
*         Include the       DSP Program-Specific Constant Definitions        *
******************************************************************************

         .include   "constant.inc"

******************************************************************************
*         Include the file that defines the symbols which show the           *
*         relative arrangement in C40 memory of the 4 blocks of TT data.     *
******************************************************************************

         .include     L_Tool.Inc

******************************************************************************
*         Load Code into the  .text  Section.                                *
******************************************************************************

         .text

Start_Tool_Ring_Nplus4:

         START_TOOL                        ; Insert the Start of Tool Macro
                                           ; with no parameters

******************************************************************************
*  This section of code forms the 1x2 EM Et Sum and 1x2 Total Et Sum         *
*                                                                            *
*   It first finds the "largest" of the 4 adjacent EM Et's (taking the eta-  *
*   specific Zero Offset into account).  It produces the pedestal-free EM    *
*   Et and Total Et, and delta-eta/delta-phi indices for this Tower          *
*                                                                            *
*   It then adds this "largest" neighboring EM Et to the central Tower's     *
*   EM Et (note that the Zero Offset for the central Tower must be removed)  *
*   to produce the pedestal-free 1x2 EM Et Sum.  This sum is built in R3.    *
*                                                                            *
*   It then adds the Total Et corresponding to the "largest" neighboring EM  *
*   Et to the central Tower's Total Et (note that the Zero Offset for the    *
*   central Tower must be removed) to produce the pedestal-free 1x2 Total    *
*   Et Sum.  This sum is built in R6.                                        *
*                                                                            *
*  Some notes on the scanning operation:                                     *
*                                                                            *
*  We will use Circular Modify indirect addressing so that we do not fall    *
*  off the "end" of the TT data.  The order of scanning the 4 adjacent       *
*  Trigger Towers is picked to leave AR0 and AR1 at the same values that     *
*  they had when we entered this Tool code routine.                          *
*                                                                            *
*  The order in which the 4 adjacent Towers are scanned is:                  *
*                                                                            *
*                          |eta|  |eta|  |eta|                               *
*                           n+5    n+4    n+3                                *
*                                (center)                                    *
*                                 -----                                      *
*         phi   center-1           3rd                                       *
*                          ----- +-----+ -----                               *
*         phi   center      2nd  |     |  4th                                *
*                          ----- +-----+ -----                               *
*         phi   center+1           1st                                       *
*                                 -----                                      *
*                                                                            *
*  As the scan begins, the 1st TT scanned is assumed to be the "largest"     *
*  (i.e. the one with maximum EM Et after its Zero Offset is removed).  The  *
*  2nd TT's EM Et (with Zero Offset removed) is compared to the "largest"    *
*  EM Et (using a SIGNED compare because once the Zero Offset is removed,    *
*  the EM Et may be NEGATIVE), and if it is larger, then it becomes the new  *
*  largest.  This processing is then repeated for the 3rd and 4th Trigger    *
*  Towers.                                                                   *
*                                                                            *
******************************************************************************

Make_Pointer_to_Total_Et_Data:

         SUBI3  Rack_1_Tot_Minus_EM_Value, AR0, AR6
                                           ; AR6 now points to EM    Et data
                                           ; for TT's   eta n:n+3
                                           ;           "phi center + 1"

         SUBI3  Rack_2_Tot_Minus_EM_Value, AR1, AR7
                                           ; AR7 now points to the EM   
                                           ; Et data for TT's eta n+4:n+7
                                           ;        "phi center + 1"

Find_Nplus4_Largest_EM_Neighbor:
                                                    ; First assume eta n+4,
                                                    ; phi center+1 is "largest"
                                                    ; EM Et.
                                                                   
Examine_Nplus4_Pplus1:

         LBU0   *AR7--(1)%, R3                      ; Assume eta n+4,
                                                    ; phi   center+1 is
                                                    ; "largest" EM Et.
                                                    ; Store this in R3.
                                                    ;   Set AR7 for phi center

         SUBI   @Eta_Nplus4_EM_Et_Zeresp_Loc, R3    ; Remove pedestal from
                                                    ; the "largest" EM Et
                                                    ; (to get true EM Et).

         LBU0   *AR1--(1)%, R6                      ; Assume eta n+4,
                                                    ; phi   center+1 is
                                                    ; "largest" EM Et.
                                                    ; Store its Total Et in R6
                                                    ;   Set AR1 for phi center

         SUBI   @Eta_Nplus4_Tot_Et_Zeresp_Loc, R6   ; Remove pedestal from
                                                    ; this Total Et
                                                    ; (to get true Total Et).

         LDI    Neighbor_1, R11                     ; Store a "key" to the
                                                    ; ID of the "largest"
                                                    ; neighbor (which we
                                                    ; have assumed to be
                                                    ; the 1st neighbor)
                                                    ; in R11

Store_Nplus4_Total_Et:                              ; Record the Total Et
                                                    ; of the "central"
                                                    ; Tower

         LBU0   *AR1, R5                            ; Store the "central"
                                                    ; Total Et in R5 (this
                                                    ; is temporary storage)
Store_Nplus4_EM_Et:                                            

         LBU0   *AR7, R7                            ; Store the "central"
                                                    ; EM Et in R7 (this 
                                                    ; is temporary storage)

Examine_Nplus5_Pplus0:                              ; Now see if eta n+5
                                                    ; phi center is new
                                                    ; "largest" EM Et


         LBU1   *AR7--(1)%, R10                     ; Load EM Et for eta n+5
                                                    ; phi center into a
                                                    ; temporary register (R10)
                                                    ;   Set AR7 for phi
                                                    ;   center-1

         SUBI   @Eta_Nplus5_EM_Et_Zeresp_Loc, R10   ; Remove pedestal to get
                                                    ; true EM Et

         LBU1   *AR1--(1)%, R9                      ; Load Tot for eta n+5
                                                    ; phi center into a
                                                    ; temporary register (R9)
                                                    ;   Set AR1 for phi
                                                    ;   center-1

         SUBI   @Eta_Nplus5_Tot_Et_Zeresp_Loc, R9   ; Remove pedestal to get
                                                    ; true Tot Et

         CMPI   R3, R10                             ; Compare the "current"
                                                    ; EM Et to the "largest"
                                                    ; EM Et

         LDIgt  R10, R3                             ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the "current"
                                                    ; EM Et into the "largest"
                                                    ; EM Et register (R3). 
                                                    ; NOTE that the condition
                                                    ; flags are unaffected.
                      
         LDIgt  R9, R6                              ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the "current"
                                                    ; TOTAL Et into the 
                                                    ; "largest" TOTAL Et
                                                    ; register (R6).
                                                    ; NOTE that the condition
                                                    ; flags are unaffected.

         LDIgt  Neighbor_2, R11                     ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the key to
                                                    ; the ID of the "current"
                                                    ; neighbor into R11


Examine_Nplus4_Pminus1:                             ; Now see if eta n+4
                                                    ; phi center-1 is new
                                                    ; "largest" EM Et


         LBU0   *AR7++(2)%, R10                     ; Load EM Et for eta n+4
                                                    ; phi center - 1 into a
                                                    ; temporary register (R10)
                                                    ;   Set AR7 for phi
                                                    ;   center + 1

         SUBI   @Eta_Nplus4_EM_Et_Zeresp_Loc, R10   ; Remove pedestal to get
                                                    ; true EM Et

         LBU0   *AR1++(2)%, R9                      ; Load Tot Et for eta n+4
                                                    ; phi center - 1 into a
                                                    ; temporary register (R9)
                                                    ;   Set AR1 for phi
                                                    ;   center + 1

         SUBI   @Eta_Nplus4_Tot_Et_Zeresp_Loc, R9   ; Remove pedestal to get
                                                    ; true Tot Et

         CMPI   R3, R10                             ; Compare the "current"
                                                    ; EM Et to the "largest"
                                                    ; EM Et.

         LDIgt  R10, R3                             ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the "current"
                                                    ; EM Et into the "largest"
                                                    ; EM Et register (R3). 
                                                    ; NOTE that the condition
                                                    ; flags are unaffected.

         LDIgt  R9, R6                              ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the "current"
                                                    ; TOTAL Et into the 
                                                    ; "largest" TOTAL Et
                                                    ; register (R6).
                                                    ; NOTE that the condition
                                                    ; flags are unaffected.

         LDIgt  Neighbor_3, R11                     ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the key to
                                                    ; the ID of the "current"
                                                    ; neighbor into R11


Examine_Nplus3_Pplus0:                              ; Now see if eta n+3
                                                    ; phi center   is new
                                                    ; "largest" EM Et

         LBU3   *AR6--(1)%, R10                     ; First get EM Et from
                                                    ; eta n+3 phi center+1.
                                                    ; We don't use this data
                                                    ; but this instruction
                                                    ; sets AR6 for phi
                                                    ; center.

         LBU3   *AR6++(1)%, R10                     ; Load EM Et for eta n+3
                                                    ; phi center into a
                                                    ; temporary register (R10)
                                                    ;   Set AR6 for phi
                                                    ;   center+1

         SUBI   @Eta_Nplus3_EM_Et_Zeresp_Loc, R10   ; Remove pedestal to get
                                                    ; true EM Et

         LBU3   *AR0--(1)%, R9                      ; First get Tot Et from
                                                    ; eta n+3 phi center+1.
                                                    ; We don't use this data
                                                    ; but this instruction
                                                    ; sets AR0 for phi
                                                    ; center.

         LBU3   *AR0++(1)%, R9                      ; Load Tot Et for eta n+3
                                                    ; phi center into a
                                                    ; temporary register (R9)
                                                    ;   Set AR0 for phi
                                                    ;   center+1

         SUBI   @Eta_Nplus3_Tot_Et_Zeresp_Loc, R9   ; Remove pedestal to get
                                                    ; true Tot Et

         CMPI   R3, R10                             ; Compare the "current"
                                                    ; EM Et to the "largest"
                                                    ; EM Et.

         LDIgt  R10, R3                             ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the "current"
                                                    ; EM Et into the "largest"
                                                    ; EM Et register (R3). 
                                                    ; NOTE that the condition
                                                    ; flags are unaffected.

         LDIgt  R9, R6                              ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the "current"
                                                    ; TOTAL Et into the 
                                                    ; "largest" TOTAL Et
                                                    ; register (R6).
                                                    ; NOTE that the condition
                                                    ; flags are unaffected.

         LDIgt  Neighbor_4, R11                     ; If the "current" EM Et
                                                    ; is strictly greater than
                                                    ; the "largest" EM Et
                                                    ; then load the key to
                                                    ; the ID of the "current"
                                                    ; neighbor into R11

         STI    R11, @Largest_Neighbor_ID_Loc       ; Put the key to the ID
                                                    ; of the "largest"
                                                    ; neighbor in memory.

                                                    ; Now we have the
                                                    ; (pedestal-free, signed)
                                                    ; "largest" EM Et in R3,
                                                    ; and a "key" of the ID
                                                    ; of the corresponding
                                                    ; Tower in memory

Calculate_Nplus4_EM_Et_Sum:

        SUBI    @Eta_Nplus4_EM_Et_Zeresp_Loc, R7    ; Remove the pedestal
                                                    ; from the "central"
                                                    ; EM Et (stored in R7)
                  
        STI     R7, @Seed_EM_Et_Loc                 ; record the Seed EM
                                                    ; Et (w/o pedestal)

        ADDI    R7, R3                              ; Form the 1x2 EM Et
                                                    ; Sum by adding the
                                                    ; "central" (R7) and
                                                    ; "largest" (R3) EM Et.
                                                    ; Store in R3.
Calculate_Nplus4_1x2_Tot_Et_Sum:

        SUBI    @Eta_Nplus4_Tot_Et_Zeresp_Loc, R5   ; Remove the pedestal
                                                    ; from the "central"
                                                    ; Total Et (stored in R5)

        STI     R5, @Seed_Tot_Et_Loc                ; record the Seed Tot
                                                    ; Et (w/o pedestal)

        ADDI    R5, R6                              ; Form the 1x2 Total Et
                                                    ; Sum by adding the 
                                                    ; "central" (R5) and
                                                    ; "largest" (R6) Total 
                                                    ; Et.  Store in R6

******************************************************************************
*  Register R3 now holds the (pedestal-free, signed) 1x2 EM Et Sum for this  *
*  seed.  Register R5 now holds the (pedestal-free, signed) 1x2 Total Et Sum *
*  for this seed.  Registers AR0 and AR1 have been returned to the values    *
*  that they held when we entered this routine.  Register AR6 points to the  *
*  EM    Et data for eta n+0:n+3 at phi "center + 1."  Register AR7 points   *
*  to the EM    Et data for eta n+4:n+7 at phi "center + 1."                 *
*                                                                            *
*  The Seed_EM_Et_ and Seed_Tot_Et (pedestal-free, signed) are stored in     *
*  memory for future reference.                                              *
******************************************************************************

******************************************************************************
*  Now we will build in R5 the sum of the 25 Total Et Trig Towers that are   *
*  centered around eta n+4 "phi center".  We will require Total Et data from *
*  both Rack #1 and Rack #2 to do this.  We will use register AR6 to point   *
*  to the Total Et data from Rack #1 and use register AR7 to point to the    *
*  Total Et data from Rack #2                                                *
*                                                                            *
*  The order in which the towers are added is:                               *
*                                                                            *
*                                 eta    eta    eta    eta    eta            *
*                                 n+6    n+5    n+4    n+3    n+2            *
*                                             (center)                       *
*                                                                            *
*                                -----  -----  -----  -----  -----           *
*         phi   center-2          25th   24th   23rd   22nd   21st           *
*                                -----  -----  -----  -----  -----           *
*         phi   center-1          20th   19th   18th   17th   16th           *
*                                -----  ----- +-----+ -----  -----           *
*         phi   center            15th   14th | 13th|  12th   11th           *
*                                -----  ----- +-----+ -----  -----           *
*         phi   center+1          5th    4th    3rd    2nd    1st            *
*                                -----  -----  -----  -----  -----           *
*         phi   center+2          10th   9th    8th    7th    6th            *
*                                -----  -----  -----  -----  -----           *
*                                                                            *
*  After the 25 Total TT Et's are summed the Total Zero Response of the 25   *
*  TT's is removed to generate the actual 5x5 Total Et Sum                   *
*                                                                            *
*  We also build in R7 the 3x3 Total Et sum, and remove the 3x3 Total Zero   *
*  Response.                                                                 *
******************************************************************************

Calculate_Nplus4_Total_Et_Sum:

         LDI    AR0, AR6                   ; AR6 now points to the Total
                                           ; Et data for TT's eta n:n+3
                                           ;        "phi center + 1"

         LDI    AR6, AR7                   ; AR7 now points to the Total  
                                           ; Et data for TT's eta n:n+3   
                                           ;        "phi center + 1"

         ADDI   Rack_2_Minus_Rack_1_Value,AR7
                                           ; AR7 now points to the Total  
                                           ; Et data for TT's eta n+4:n+7 
                                           ;        "phi center + 1"


                                           ; Now Add Total Et's from the 5 Trig
                                           ; Towers at  "phi center + 1".


         LBU2   *AR6,R11                   ; Get Tot eta n+2  "phi center + 1" 
                                           ;   AR6 stays at   "phi center + 1" 
         LDI    R11,R7                     ; Load this Tot TT into R7         
                                           ; ----

         LBU3   *AR6++(1)%,R11             ; Get Tot eta n+3  "phi center + 1" 
                                           ;   Set AR6 for    "phi center + 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         LDI    R11, R5                    ; Load this Tot TT into R5
                                           ; ----

         LBU0   *AR7,R11                   ; Get Tot eta n+4  "phi center + 1" 
                                           ;   AR7 stays at   "phi center + 1" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU1   *AR7,R11                   ; Get Tot eta n+5  "phi center + 1"
                                           ;   AR7 stays at   "phi center + 1" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU2   *AR7++(1)%,R11             ; Get Tot eta n+6  "phi center + 1"
                                           ;   Set AR7 for    "phi center + 2"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
 

                                           ; Now Add Total Et's from the 5 Trig
                                           ; Towers at  "phi center + 2".


         LBU2   *AR6,R11                   ; Get Tot eta n+2  "phi center + 2" 
                                           ;   AR6 stays at   "phi center + 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU3   *AR6--(2)%,R11             ; Get Tot eta n+3  "phi center + 2" 
                                           ;   Set AR6 for    "phi center"     
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU0   *AR7,R11                   ; Get Tot eta n+4  "phi center + 2" 
                                           ;   AR7 stays at   "phi center + 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU1   *AR7,R11                   ; Get Tot eta n+5  "phi center + 2"
                                           ;   AR7 stays at   "phi center + 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU2   *AR7--(2)%,R11             ; Get Tot eta n+6  "phi center + 2"
                                           ;   Set AR7 for    "phi center"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
 

                                           ; Now Add Total Et's from the 5 Trig
                                           ; Towers at  "phi center".


         LBU2   *AR6,R11                   ; Get Tot eta n+2  "phi center"     
                                           ;   AR6 stays at   "phi center"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU3   *AR6--(1)%,R11             ; Get Tot eta n+3  "phi center"
                                           ;   Set AR6 for    "phi center - 1" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU0   *AR7,R11                   ; Get Tot eta n+4  "phi center"
                                           ;   AR7 stays at   "phi center"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU1   *AR7,R11                   ; Get Tot eta n+5  "phi center"
                                           ;   AR7 stays at   "phi center"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU2   *AR7--(1)%,R11             ; Get Tot eta n+6  "phi center"
                                           ;   Set AR7 for    "phi center - 1"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 


                                           ; Now Add Total Et's from the 5 Trig
                                           ; Towers at  "phi center - 1".


         LBU2   *AR6,R11                   ; Get Tot eta n+2  "phi center - 1" 
                                           ;   AR6 stays at   "phi center - 1" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU3   *AR6--(1)%,R11             ; Get Tot eta n+3  "phi center - 1" 
                                           ;   Set AR6 for    "phi center - 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU0   *AR7,R11                   ; Get Tot eta n+4  "phi center - 1" 
                                           ;   AR7 stays at   "phi center - 1" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU1   *AR7,R11                   ; Get Tot eta n+5  "phi center - 1"
                                           ;   AR7 stays at   "phi center - 1" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 
         ADDI   R11, R5                    ; Add this Tot TT to the sum in R5

         LBU2   *AR7--(1)%,R11             ; Get Tot eta n+6  "phi center - 1"
                                           ;   Set AR7 for    "phi center - 2"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 


                                           ; Now Add Total Et's from the 5 Trig
                                           ; Towers at  "phi center - 2".


         LBU2   *AR6,R11                   ; Get Tot eta n+2  "phi center - 2" 
                                           ;   AR6 stays at   "phi center - 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU3   *AR6,R11                   ; Get Tot eta n+3  "phi center - 2" 
                                           ;   AR6 stays at   "phi center - 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU0   *AR7,R11                   ; Get Tot eta n+4  "phi center - 2" 
                                           ;   AR7 stays at   "phi center - 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU1   *AR7,R11                   ; Get Tot eta n+5  "phi center - 2"
                                           ;   AR7 stays at   "phi center - 2" 
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 

         LBU2   *AR7,R11                   ; Get Tot eta n+6  "phi center - 2"
                                           ;   AR7 stays at   "phi center - 2"
         ADDI   R11,R7                     ; Add this Tot TT to the sum in R7 


         SUBI   @Eta_Nplus4_5x5_Tot_Offset_Loc,R7       ; Remove the Zero
                                                        ; Response of the 25
                                                        ; Trigger Towers from
                                                        ; the 5x5 Tot Et Sum

         SUBI   @Eta_Nplus4_3x3_Tot_Offset_Loc, R5

******************************************************************************
*  Register R5 now holds the (pedestal-free, signed) 3x3 Total Et Sum for    *
*  this seed.  Register R7 now holds the (pfs) 5x5 Total Et Sum for this seed*
******************************************************************************

******************************************************************************
*  We have all of the "raw" information we need to perform rejection.        *
******************************************************************************

******************************************************************************
*   Now we need to evaluate the 4 Terms which this Tool is designed to       *
*   evaluate.  Recall that all 4 Terms are always evaluated.                 *
*   They are processed in the order: #0, #1, #2, #3.                         *
******************************************************************************

******************************************************************************
*       TERM #0                                                              *
******************************************************************************
                        
Term_0:

        LDI             @Term_Type_0_Loc, R11       ; EM or jet?

        CMPI            1, R11                      ; 1 = EM
                                                    
        Bne             Term_0_Is_Jet               ; if not EM, do jet tool

Term_0_Is_EM:                                       ; OK, it's EM

        EM_TOOL         0, Nplus4                   ; insert the EM_TOOL
                                                    ; macro

        BR              Term_1                      ; go to Term 1

Term_0_Is_Jet:                                      ; OK, it's jet
                                                                  
        JET_TOOL        0, Nplus4                   ; insert the JET_TOOL
                                                    ; macro

******************************************************************************
*       TERM #1                                                              *
******************************************************************************
                        
Term_1:

        LDI             @Term_Type_1_Loc, R11       ; EM or jet?

        CMPI            1, R11                      ; 1 = EM
                                                    
        Bne             Term_1_Is_Jet               ; if not EM, do jet tool

Term_1_Is_EM:                                       ; OK, it's EM

        EM_TOOL         1, Nplus4                   ; insert the EM_TOOL
                                                    ; macro

        BR              Term_2                      ; go to Term 2

Term_1_Is_Jet:                                      ; OK, it's jet
                                                                  
        JET_TOOL        1, Nplus4                   ; insert the JET_TOOL
                                                    ; macro

******************************************************************************
*       TERM #2                                                              *
******************************************************************************
                        
Term_2:

        LDI             @Term_Type_2_Loc, R11       ; EM or jet?

        CMPI            1, R11                      ; 1 = EM
                                                    
        Bne             Term_2_Is_Jet               ; if not EM, do jet tool

Term_2_Is_EM:                                       ; OK, it's EM

        EM_TOOL         2, Nplus4                   ; insert the EM_TOOL
                                                    ; macro

        BR              Term_3                      ; go to Term 3

Term_2_Is_Jet:                                      ; OK, it's jet
                                                                  
        JET_TOOL        2, Nplus4                   ; insert the JET_TOOL
                                                    ; macro

******************************************************************************
*       TERM #3                                                              *
******************************************************************************
                        
Term_3:

        LDI             @Term_Type_3_Loc, R11       ; EM or jet?

        CMPI            1, R11                      ; 1 = EM
                                                                       
        Bne             Term_3_Is_Jet               ; if not EM, do jet tool

Term_3_Is_EM:                                       ; OK, it's EM

        EM_TOOL         3, Nplus4                   ; insert the EM_TOOL
                                                    ; macro

        BR              Return_to_Scan_Routine_Np4  ; get out of here

Term_3_Is_Jet:                                      ; OK, it's jet
                                                                  
        JET_TOOL        3, Nplus4                   ; insert the JET_TOOL
                                                    ; macro

******************************************************************************
*   Now we should return to the Scan Routine.                                *
*                                                                            *
*   We will use the END_TOOL macro to perform this function                  *
******************************************************************************

Return_to_Scan_Routine_Np4:

        END_TOOL    Nplus4              ; Insert the END_TOOL macro
                                        ; with one argument indicating
                                        ; the Tool Ring

******************************************************************************
*  This is the Bulkhead.  This code should never be executed                 *
******************************************************************************

End_Of_L_Tl_Np4:                        ; These instructions should never be
                                        ; executed in the "normal" operation
         BR     End_Of_L_Tl_Np4         ; of the program.  If the program
                                        ; counter becomes corrupted or
         BR     End_Of_L_Tl_Np4         ; if we have a bug in the program
                                        ; we MAY try to execute these
         BR     End_Of_L_Tl_Np4         ; instructions.  If we get to these
                                        ; instructions the program will appear
         BR     End_Of_L_Tl_Np4         ; to halt.  We could also use a
                                        ; TRAP instruction here, and jump to
                                        ; a service routine.

******************************************************************************
*  Cross-References                                                          *
******************************************************************************

         .def    Start_Tool_Ring_Nplus4                 ; Symbols defined
                                                        ; in this module for
                                                        ; use in external
                                                        ; modules

         .ref    Tool_Number_Loc                        ; Symbols defined
         .ref    Object_Type_Loc                        ; in external
         .ref    Real_Data_Flag_Loc                     ; modules
         .ref    Mark_Force_Pass_Data_Flag_Loc


         .ref    Zero_Loc
         .ref    This_LDSP_ObjectList_Handle
         .ref    LDSP_Entries_per_List_Loc

         .ref    Term_Number_for_This_Tool_Loc

         .ref    Largest_Neighbor_ID_Loc

         .ref    EM_Et_1x2_Thresh_0_Loc
         .ref    Isolation_Ratio_Thresh_0_Loc 
         .ref    EM_Frac_Ratio_Thresh_0_Loc
         .ref    EM_Et_1x2_Thresh_1_Loc
         .ref    Isolation_Ratio_Thresh_1_Loc 
         .ref    EM_Frac_Ratio_Thresh_1_Loc
         .ref    EM_Et_1x2_Thresh_2_Loc
         .ref    Isolation_Ratio_Thresh_2_Loc 
         .ref    EM_Frac_Ratio_Thresh_2_Loc
         .ref    EM_Et_1x2_Thresh_3_Loc
         .ref    Isolation_Ratio_Thresh_3_Loc 
         .ref    EM_Frac_Ratio_Thresh_3_Loc

         .ref    Term_Type_0_Loc                ; new symbols defined 
         .ref    Seed_Min_EM_Et_Cut_0_Loc       ; in this module for
         .ref    Seed_Min_Tot_Et_Cut_0_Loc      ; the eWjj Tool
         .ref    Seed_Max_Eta_Cut_0_Loc
         .ref    Tot_Et_5x5_Thresh_0_Loc
         .ref    Term_Type_1_Loc
         .ref    Seed_Min_EM_Et_Cut_1_Loc
         .ref    Seed_Min_Tot_Et_Cut_1_Loc
         .ref    Seed_Max_Eta_Cut_1_Loc
         .ref    Tot_Et_5x5_Thresh_1_Loc
         .ref    Term_Type_2_Loc
         .ref    Seed_Min_EM_Et_Cut_2_Loc
         .ref    Seed_Min_Tot_Et_Cut_2_Loc
         .ref    Seed_Max_Eta_Cut_2_Loc
         .ref    Tot_Et_5x5_Thresh_2_Loc
         .ref    Term_Type_3_Loc
         .ref    Seed_Min_EM_Et_Cut_3_Loc
         .ref    Seed_Min_Tot_Et_Cut_3_Loc
         .ref    Seed_Max_Eta_Cut_3_Loc
         .ref    Tot_Et_5x5_Thresh_3_Loc
         .ref    Eta_Nplus2_5x5_Tot_Offset_Loc
         .ref    Eta_Nplus3_5x5_Tot_Offset_Loc
         .ref    Eta_Nplus4_5x5_Tot_Offset_Loc
         .ref    Eta_Nplus5_5x5_Tot_Offset_Loc
         

         .ref    Return_from_Tool_Ring_Nplus2
         .ref    Return_from_Tool_Ring_Nplus3
         .ref    Return_from_Tool_Ring_Nplus4
         .ref    Return_from_Tool_Ring_Nplus5

         .ref    Eta_Nplus1_EM_Et_Zeresp_Loc
         .ref    Eta_Nplus2_EM_Et_Zeresp_Loc
         .ref    Eta_Nplus3_EM_Et_Zeresp_Loc
         .ref    Eta_Nplus4_EM_Et_Zeresp_Loc
         .ref    Eta_Nplus5_EM_Et_Zeresp_Loc
         .ref    Eta_Nplus6_EM_Et_Zeresp_Loc

         .ref    Eta_Nplus1_Tot_Et_Zeresp_Loc
         .ref    Eta_Nplus2_Tot_Et_Zeresp_Loc
         .ref    Eta_Nplus3_Tot_Et_Zeresp_Loc
         .ref    Eta_Nplus4_Tot_Et_Zeresp_Loc
         .ref    Eta_Nplus5_Tot_Et_Zeresp_Loc
         .ref    Eta_Nplus6_Tot_Et_Zeresp_Loc

         .ref    Eta_Nplus2_3x3_Tot_Offset_Loc
         .ref    Eta_Nplus2_5x5_Tot_Offset_Loc
         .ref    Eta_Nplus2_Coord_Loc
         .ref    Eta_Nplus3_3x3_Tot_Offset_Loc
         .ref    Eta_Nplus3_5x5_Tot_Offset_Loc
         .ref    Eta_Nplus3_Coord_Loc
         .ref    Eta_Nplus4_3x3_Tot_Offset_Loc
         .ref    Eta_Nplus4_5x5_Tot_Offset_Loc
         .ref    Eta_Nplus4_Coord_Loc
         .ref    Eta_Nplus5_3x3_Tot_Offset_Loc
         .ref    Eta_Nplus5_5x5_Tot_Offset_Loc
         .ref    Eta_Nplus5_Coord_Loc

         .ref    Term_0_Object_Count_Loc
         .ref    Term_1_Object_Count_Loc
         .ref    Term_2_Object_Count_Loc
         .ref    Term_3_Object_Count_Loc      

         .ref    Term_0_Jet_Phi_Mask_Loc
         .ref    Term_1_Jet_Phi_Mask_Loc
         .ref    Term_2_Jet_Phi_Mask_Loc
         .ref    Term_3_Jet_Phi_Mask_Loc

         .ref    Wake_Up_Word_Loc

         .ref    Seed_EM_Et_Loc
         .ref    Seed_Tot_Et_Loc

******************************************************************************
*   End of this module                                                       *
******************************************************************************

         .end
