StRoot  1
stage_2_201900.cxx
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <string.h>
4
5 #include "fcs_trg_base.h"
6
7 //#include "fcs_trg_201901.h"
8
9 // Processing on the North or South DEP/IO flavoured board.
10 // Inputs are up to 32 links but I already organized them according to strawman.
11 // output is 1 link over the external OUT connector.
12 // Right now we assume we have 20 inputs from ECAL, 6 from HCAL and 4 from PRE.
13 // We also assume there is no need to know if this is North or South as
14 // the processing is exactly the same. Right??
15
17 {
18  static int first=0;
19  static u_int ETbTdep[4][4]; //DEP#
21  if(first==0){
22  first=1;
23  //making map of 2x2 Ecal Sums of [4][4]
24  for(int r=0; r<4; r++){
25  printf("Ecal r=%2d : ",r);
26  for(int c=0; c<4; c++){
27  ETbTdep[r][c]= c/2 + (r/4);
30  }
31  printf("\n");
32  }
33  }
34
35  //compute hcal 4x4 sum -- note d[1,3,5,7] are not used at the stage-1 DEP
36  u_int hsum=hcal[0].d[0]+hcal[0].d[2]+hcal[0].d[4]+hcal[0].d[6];
37  if(fcs_trgDebug>=2) printf("Hcal sum=%5d\n",hsum);
38
39  //compute ecal 4x4 sums of [3][3]
40  u_int esum[3][3];
41  float ratio[3][3];
42  u_int EM1 =0, EM2 =0;
43  u_int GAM1=0, GAM2=0;
44  u_int ELE1=0, ELE2=0;
46  u_int JP1 =0, JP2 =0;
47  for(int r=0; r<3; r++){
48  if(fcs_trgDebug>=2) printf("E4x4 ");
49  for(int c=0; c<3; c++){
50  esum[r][c]
51  = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]]
55
56 // Tonko: removed, no point in pegging at 0xFF since it's only 0x3FF
57 // if(esum[r][c] > 0xff) esum[r][c]=0xff;
58
59  //in VHDL we will do hsum > esum * threshold. Ratio is for human only
60  u_int h=hsum; //find closest hcal but 4x4... but we have only 1 in run19
61  u_int sum = esum[r][c] + h;
62  if(sum==0) {
63  ratio[r][c]=0.0;
64  }else{
65  ratio[r][c] = float(esum[r][c]) / float(sum); //doing with float in C;
66  }
67
68
69  // integer multiplication as in VHDL!
70  // ratio thresholds are in fixed point integer where 1.0==128
71  u_int h128 = h*128 ;
72
73  if(h128 < esum[r][c] * EM_HERATIO_THR){
74
75  if(sum > EMTHR1){
76  EM1 |= (1<<r);
77  if((pres[0].d[0] & (1<<r))==0) {GAM1 |= (1<<r);}
78  else {ELE1 |= (1<<r);}
79  }
80
81  if(sum > EMTHR2){
82  EM2 |= (1<<r);
83  if((pres[0].d[0] & (1<<r))==0) {GAM2 |= (1<<r);}
84  else {ELE2 |= (1<<r);}
85  }
86  }
87
88  if(h128 > esum[r][c] * HAD_HERATIO_THR){
91  }
92
93  if(fcs_trgDebug>=2) printf("%5d %3.2f ",esum[r][c],ratio[r][c]);
94  }
95  if(fcs_trgDebug>=2) printf("\n");
96  }
97
98  //Ecal total sum
99  u_int etot;
100  etot= esum[ 0][0]+esum[ 0][2]
101  + esum[ 2][0]+esum[ 2][2];
102
103  //Jet sum
104  u_int jet = hsum + etot;
105  if(etot > JETTHR1) JP1 = 1; //ecal only (pi0 trigger)
106  if(jet > JETTHR2) JP2 = 1; //ecal+hcal
107
108  if(fcs_trgDebug>=2) printf("Jet = %4d + %4d = %3d\n",etot,hsum,jet);
109
110  //sending output bits
111  output[0].d[0] = 0x80 | (EM1 + (EM2 <<3)); // Tonko: added last bit
112  output[0].d[1] = GAM1 + (GAM2<<3);
113  output[0].d[2] = ELE1 + (ELE2<<3);
115  output[0].d[4] = JP1 + (JP2 <<1);
116  output[0].d[5] = pres[0].d[0] ; // Tonko: added
117  output[0].d[6] = pres[0].d[1] ; // Tonko: added
118  output[0].d[7] = pres[0].d[7] ; // Tonko: added
119
120 #if 0
121  for(int i=0;i<4;i++) {
122  for(int j=0;j<8;j++) {
123  printf("PRES %d %d = 0x%X\n",i,j,pres[i].d[j]) ;
124  }}
125 #endif
126
127  if(fcs_trgDebug>=1){
128  printf("FCS STG2 NS=%1d output = %02x %02x %02x %02x %02x\n",
129  geo.ns,output[0].d[0],output[0].d[1],output[0].d[2],output[0].d[3],output[0].d[4]);
130  }
131
132  return ;
133 }
134