StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
stage_1_202201.cxx
1 #include <stdio.h> // for debugging/logging
2 
3 #include "fcs_trg_base.h"
4 
5 // VERSION 0x1 (May 2020)
6 void fcs_trg_base::stage_1_202201(u_int s0[], geom_t geo, link_t *output)
7 {
8  u_char mrkr ; // marker
9 
10  if(fcs_trgDebug>=2) printf("Stage1v1 ns=%1d det=%1d dep=%2d\n",geo.ns,geo.det,geo.dep);
11 
12  // Tonko: I will run this basic "high-towerish" trigger always
13  u_char t[32] ;
14  u_int mask = 0 ;
15  u_int thr = ht_threshold[geo.det] ; // depends on detector
16 
17 
18 
19 
20  for(int i=0;i<32;i++) {
21 // if(s0[i]) printf("S1: %d:%d:%d: xing %d, ch %d = %d, thr %d\n",geo.det,geo.ns,geo.dep,dbg_xing,i,s0[i],thr) ;
22 
23  if(s0[i] > thr) {
24  mask |= (1<<i) ;
25  t[i] = 1 ;
26  self_trigger = 1 ;
27  }
28  else {
29  mask &= ~(1<<i) ;
30  t[i] = 0 ;
31  }
32  }
33 
34  // Tonko: new 16-Feb-21
35  // stage_params[0][2] overrides the algo
36 
37  // nah, not yet since stage_params doesn't know about DEPs
38  //if((stage_params[0][2]&0x3)==1) geo.det = 2 ; // force FPRE "high tower lookalike"
39 
40  // debugging marker in the stream, only for FPRE algo
41  if(stage_params[0][2]&4) {
42  mrkr = 0xAA ;
43  }
44  else mrkr = 0 ;
45 
46  // algorithm depends on detector
47  if(geo.det == 2) { // BASIC algo for fPRE
48  if(fcs_trgDebug>0){
49  for(int ch=0; ch<32; ch++) {
50  padc[geo.ns][geo.dep][ch]=s0[ch]; //keeping them for QA
51  }
52  }
53  output->d[0] = (t[ 7]<<7)|(t[ 6]<<6)|(t[ 5]<<5)|(t[ 4]<<4)|(t[ 3]<<3)|(t[ 2]<<2)|(t[ 1]<<1)|(t[ 0]<<0);
54  output->d[1] = (t[15]<<7)|(t[14]<<6)|(t[13]<<5)|(t[12]<<4)|(t[11]<<3)|(t[10]<<2)|(t[ 9]<<1)|(t[ 8]<<0);
55  output->d[2] = (t[23]<<7)|(t[22]<<6)|(t[21]<<5)|(t[20]<<4)|(t[19]<<3)|(t[18]<<2)|(t[17]<<1)|(t[16]<<0);
56  output->d[3] = (t[31]<<7)|(t[30]<<6)|(t[29]<<5)|(t[28]<<4)|(t[27]<<3)|(t[26]<<2)|(t[25]<<1)|(t[24]<<0);
57  output->d[4] = 0 ;
58  output->d[5] = 0 ;
59  output->d[6] = mrkr ; // marker 0xAA if params[2] & 4
60  output->d[7] = mask?0x80:0 ;
61  }
62  else { // BASIC algo for ECAL/HCAL
63  u_int sum[8] ;
64 
65  // Akio
66  sum[0] = s0[0] + s0[1] + s0[4] + s0[5] ;
67  sum[1] = s0[2] + s0[3] + s0[6] + s0[7] ;
68  sum[2] = s0[8] + s0[9] + s0[12] + s0[13] ;
69  sum[3] = s0[10] + s0[11] + s0[14] + s0[15] ;
70  sum[4] = s0[16] + s0[17] + s0[20] + s0[21] ;
71  sum[5] = s0[18] + s0[19] + s0[22] + s0[23] ;
72  sum[6] = s0[24] + s0[25] + s0[28] + s0[29] ;
73  sum[7] = s0[26] + s0[27] + s0[30] + s0[31] ;
74 
75  // outputs to stage_2
76  for(int i=0;i<8;i++) {
77  //fprintf(stderr,"SUM %d: %d: %d\n",i,sum[i],sum[i]>>7) ;
78 
79  //printf(" IN S1: ix %d: %d\n",i,sum[i]) ;
80 
81  //if(sum[i]>131071) output->d[i] = 0xFF ;
82  if(sum[i]>0x7FFF) output->d[i] = 0xFF ;
83  else output->d[i] = sum[i]>>7 ;
84 
85  // Tonko: Akio has a bug here because sum values between 132k and 32k
86  // will overflow the 8 bits.
87  // I fixed this to match the curreant VHDL:
88  //
89  // Akio - My original code was
90  // if(sum[i] > 0x7fff) sum[i]=0x7fff;
91  // output->d[i] = sum[i] >> 7;
92  // and where was the bug?
93  //
94  // 131071 is 0x1ffff and 131071>>7 is 0x3ff
95  // It seems to be inconsistent - akio
96 
97  output->d[i] &= 0xFF ;
98 
99  //printf(" IN S1: ix %d: %d out\n",i,output->d[i]) ;
100 
101  }
102  }
103 }