StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
stage_1_201900.cxx
1 #include <stdio.h> // for debugging/logging
2 
3 #include "fcs_trg_base.h"
4 
5 // VERSION 0x0 (Apr 2, 2019)
6 void fcs_trg_base::stage_1_201900(u_int s0[], geom_t geo, link_t *output)
7 {
8 
9  // Tonko: I will run this basic "high-towerish" trigger always
10  u_char t[32] ;
11  u_int mask = 0 ;
12  u_int thr = ht_threshold[geo.det] ; // depends on detector
13 
14  for(int i=0;i<32;i++) {
15  if(s0[i] > thr) {
16  mask |= (1<<i) ;
17  t[i] = 1 ;
18  }
19  else {
20  mask &= ~(1<<i) ;
21  t[i] = 0 ;
22  }
23  }
24 
25  // algorithm depends on detector
26  if(geo.det == 2) { // BASIC algo for fPRE in FY19
27  u_char bit[3] ;
28 
29  bit[0] = t[0] | t[1] | t[2] | t[3] | t[4] ;
30  bit[1] = t[2] | t[3] | t[4] | t[5] | t[6] ;
31  bit[2] = t[4] | t[5] | t[6] | t[7] | t[8] ;
32 
33  // Akio
34  output->d[0] = (bit[2]<<2) | (bit[1]<<1) | (bit[0]<<0) ;
35 
36  // Tonko
37  output->d[1] = (t[7]<<7)|(t[6]<<6)|(t[5]<<5)|(t[4]<<4)|(t[3]<<3)|(t[2]<<2)|(t[1]<<1)|(t[0]<<0) ;
38  output->d[2] = (t[15]<<7)|(t[14]<<6)|(t[13]<<5)|(t[12]<<4)|(t[11]<<3)|(t[10]<<2)|(t[9]<<1)|(t[8]<<0) ;
39  output->d[3] = (t[23]<<7)|(t[22]<<6)|(t[21]<<5)|(t[20]<<4)|(t[19]<<3)|(t[18]<<2)|(t[17]<<1)|(t[16]<<0) ;
40  output->d[4] = (t[31]<<7)|(t[30]<<6)|(t[29]<<5)|(t[28]<<4)|(t[27]<<3)|(t[26]<<2)|(t[25]<<1)|(t[24]<<0) ;
41  output->d[5] = 0 ;
42  output->d[6] = 0 ;
43  output->d[7] = mask?0x80:0 ;
44  }
45  else { // BASIC algo for ECAL/HCAL
46  u_int sum[8] ;
47 
48  // Akio
49  sum[0] = s0[0] + s0[1] + s0[4] + s0[5] ;
50  sum[1] = s0[2] + s0[3] + s0[6] + s0[7] ;
51  sum[2] = s0[8] + s0[9] + s0[12] + s0[13] ;
52  sum[3] = s0[10] + s0[11] + s0[14] + s0[15] ;
53  sum[4] = s0[16] + s0[17] + s0[20] + s0[21] ;
54  sum[5] = s0[18] + s0[19] + s0[22] + s0[23] ;
55  sum[6] = s0[24] + s0[25] + s0[28] + s0[29] ;
56  sum[7] = s0[26] + s0[27] + s0[30] + s0[31] ;
57 
58  // outputs to stage_2
59  for(int i=0;i<8;i++) {
60  //fprintf(stderr,"SUM %d: %d: %d\n",i,sum[i],sum[i]>>7) ;
61 
62  if(sum[i]>131071) output->d[i] = 0xFF ;
63  else output->d[i] = sum[i]>>7 ;
64 
65  // Tonko: Akio has a bug here because sum values between 132k and 32k
66  // will overflow the 8 bits.
67  // I fixed this to match the current VHDL:
68 
69  output->d[i] &= 0xFF ;
70 
71  }
72  }
73 
74 
75 }