# L2 W-algo for BTOW, p+p 500 GeV , 2009 run

This algorithm searches for energy depositions in the barrel, and will not run if BTOW is not in the run.

This algorithm reads in 2 ints and 2 floats from run control:

[i0] debug

[i1] Random Accept Prescale

[f0] Et threshold for seed

[f1] Et threshold for cluster

The logic is as follows:

For each tower with Et>f0, each 2x2 tower patch around it is summed.  As soon as one of these 2x2 patches has Et>f1, we accept the event.

The Random Accept Prescale value sets the prescale for random accept, described elsewhere.

if debug>0, various debug information will be printed.

```Run time params
2 int    dbg, randomAcceptPrescale
2 float  seedEtThres, clusterEtThres  (GeV)

This algo works only with BTOW ADCs

======== L2 W ALGO =======

1. Get list of towers w/ energy provided by the common L2 calib algo
2. Form smaller list of seed towers above seedTH
3. Loop over seed towers
a. Find the highest cluster ET out of 4 groups of 2x2 towers containing the seed tower
b. if Et > clusterET accept event, set trgBit=2, do not try any other cluster

4. try random accept
- set event counter at random start
- increment by 1 for every input event
- issue random accept if (eventCounter %  randomAcceptPrescale == 0)
- if accepted set trgBit=1
5. Accept event if trgBit is 1 or 2
6. Store information in the L2wResult[.] array
- seed eta-bin
- seed phi-bin
- seed ET
- cluster ET
- trgBits```

```  StMuEvent* muEve = mMuDstMaker->muDst()->event();

TArrayI& l2Array = muEve->L2Result();
unsigned int *l2res=(unsigned int *)l2Array.GetArray();
printf(" L2-jet online results below:\n");
int k;  for (k=0;k<32;k++) printf("k=%2d  val=0x%04x\n",k,l2res[k]);
const int BEMCW_off=20; // valid only for 2009 run
L2wResult2009 *out1= ( L2wResult2009 *) &l2res[BEMCW_off];
L2wResult2009_print(out1);

StMuTriggerIdCollection *tic=&(muEve->triggerIdCollection());
assert(tic);
const StTriggerId &l1=tic->l1();
vector idL=l1.triggerIds();   printf("nTrig=%d, trigID: ",idL.size());   for(unsigned int i=0;i```

# Simulation of L2-W-Algo for Filtered QCD & W events , LT=~10 /pb.

Used thresholds: seedET>9 GeV, clusterET>14 GeV

Fig 1. LT=10/pb. Left: W events, right: QCD events

Fig 2. Uniformity of L2-W trigger for accepted QCD events, LT=10/pb.
It is lower only at the physical edges of barrel at eta=+/-1 due to energy leak and smaller tower size.

Below you will find full set of L2 monitoring plots for both sets of events