StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
stage_2_202207.cxx
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <string.h>
4 
5 #include "fcs_trg_base.h"
6 #include "fcs_ecal_epd_mask.h"
7 
8 // Modifed from stage_2_JP5_202206.cxx
9 
10 namespace {
11  //version2 with top2 & bottom2 rows in trigger, missing far side column
12  static const int EtoHmap[15][9][2] = {
13  { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}},
14  { { 0, 0},{ 0, 1},{ 0, 1},{ 0, 2},{ 0, 2},{ 0, 3},{ 0, 4},{ 0, 4},{ 0, 4}},
15  { { 1, 0},{ 1, 1},{ 1, 1},{ 1, 2},{ 1, 2},{ 1, 3},{ 1, 4},{ 1, 4},{ 1, 4}},
16  { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}},
17  { { 2, 0},{ 2, 1},{ 2, 1},{ 2, 2},{ 2, 2},{ 2, 3},{ 2, 4},{ 2, 4},{ 2, 4}},
18  { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}},
19  { { 3, 0},{ 3, 1},{ 3, 1},{ 3, 2},{ 3, 2},{ 3, 3},{ 3, 4},{ 3, 4},{ 3, 4}},
20  { { 4, 0},{ 4, 1},{ 4, 1},{ 4, 2},{ 4, 2},{ 4, 3},{ 4, 4},{ 4, 4},{ 4, 4}},
21  { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}},
22  { { 5, 0},{ 5, 1},{ 5, 1},{ 5, 2},{ 5, 2},{ 5, 3},{ 5, 4},{ 5, 4},{ 5, 4}},
23  { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}},
24  { { 6, 0},{ 6, 1},{ 6, 1},{ 6, 2},{ 6, 2},{ 6, 3},{ 6, 4},{ 6, 4},{ 6, 4}},
25  { { 7, 0},{ 7, 1},{ 7, 1},{ 7, 2},{ 7, 2},{ 7, 3},{ 7, 4},{ 7, 4},{ 7, 4}},
26  { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}},
27  { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}}
28  } ;
29 
30  static const int EtoH3map[15][9][4] = {
31  {{-1,-1,-1, 0},{-1,-1, 0, 1},{-1,-1, 1, 2},{-1,-1, 1, 2},{-1,-1, 2, 3},{-1,-1, 2, 3},{-1,-1, 3, 4},{-1,-1, 4,-1},{-1,-1, 4,-1}},
32  {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}},
33  {{-1, 0,-1, 5},{ 0, 1, 5, 6},{ 1, 2, 6, 7},{ 1, 2, 6, 7},{ 2, 3, 7, 8},{ 2, 3, 7, 8},{ 3, 4, 8, 9},{ 4,-1, 9,-1},{ 4,-1, 9,-1}},
34  {{-1, 5,-1,10},{ 5, 6,10,11},{ 6, 7,11,12},{ 6, 7,11,12},{ 7, 8,12,13},{ 7, 8,12,13},{ 8, 9,13,14},{ 9,-1,14,-1},{ 9,-1,14,-1}},
35  {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}},
36  {{-1,10,-1,15},{10,11,15,16},{11,12,16,17},{11,12,16,17},{12,13,17,18},{12,13,17,18},{13,14,18,19},{14,-1,19,-1},{14,-1,19,-1}},
37  {{-1,15,-1,20},{15,16,20,21},{16,17,21,22},{16,17,21,22},{17,18,22,23},{17,18,22,23},{18,19,23,24},{19,-1,24,-1},{19,-1,24,-1}},
38  {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}},
39  {{-1,20,-1,25},{20,21,25,26},{21,22,26,27},{21,22,26,27},{22,23,27,28},{22,23,27,28},{23,24,28,29},{24,-1,29,-1},{24,-1,29,-1}},
40  {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}},
41  {{-1,25,-1,30},{25,26,30,31},{26,27,31,32},{26,27,31,32},{27,28,32,33},{27,28,32,33},{28,29,33,34},{29,-1,34,-1},{29,-1,34,-1}},
42  {{-1,30,-1,35},{30,31,35,36},{31,32,36,37},{31,32,36,37},{32,33,37,38},{32,33,37,38},{33,34,38,39},{34,-1,39,-1},{34,-1,39,-1}},
43  {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}},
44  {{-1,35,-1,40},{35,36,40,41},{36,37,41,42},{36,37,41,42},{37,38,42,43},{37,38,42,43},{38,39,43,44},{39,-1,44,-1},{39,-1,44,-1}},
45  {{-1,40,-1,-1},{40,41,-1,-1},{41,42,-1,-1},{41,42,-1,-1},{42,43,-1,-1},{42,43,-1,-1},{43,44,-1,-1},{44,-1,-1,-1},{44,-1,-1,-1}}
46  };
47 }
48 
49 void fcs_trg_base::stage_2_202207(link_t ecal[], link_t hcal[], link_t pres[], geom_t geo, link_t output[], u_short* s2_to_dsm)
50 {
51  int ns=geo.ns;
52  if(fcs_trgDebug>=2) printf("Stage2v1 ns=%d\n",ns);
53  static int first=0;
54  // creating 2x2 row/column address map when called first time
55  static u_int ETbTdep[16][10]; //DEP#
56  static u_int ETbTadr[16][10]; //Input Link data address
57  static u_int HTbTdep[10][6]; //DEP#
58  static u_int HTbTadr[10][6]; //Input Link data address
59  if(first==0){
60  first=1;
61  //making map of 2x2 Ecal Sums of [4][4]
62  for(int r=0; r<16; r++){
63  printf("Ecal r=%2d : ",r);
64  for(int c=0; c<10; c++){
65  ETbTdep[r][c]= c/2 + (r/4)*5;
66  ETbTadr[r][c]= c%2 + (r%4)*2;
67  printf("%2d-%1d ",ETbTdep[r][c],ETbTadr[r][c]);
68  }
69  printf("\n");
70  }
71  //making map of 2x2 Hcal sums of [10][6]
72  for(int r=0; r<10; r++){
73  printf("HCal r=%2d : ",r);
74  for(int c=0; c<6; c++){
75  if (r==0){
76  HTbTdep[r][c]= 6;
77  HTbTadr[r][c]= c;
78  }else if(r==9){
79  HTbTdep[r][c]= 7;
80  HTbTadr[r][c]= c;
81  }else{
82  HTbTdep[r][c]= c/2 + ((r-1)/4)*3;
83  HTbTadr[r][c]= c%2 + ((r-1)%4)*2;
84  }
85  printf("%2d-%1d ",HTbTdep[r][c],HTbTadr[r][c]);
86  }
87  printf("\n");
88  }
89  }
90 
91  // Ecal 2x2 "HT" trigger
92  int ecal_ht = 0 ;
93  for(int i=0;i<DEP_ECAL_TRG_COU;i++) {// 0..19
94  for(int j=0;j<8;j++) {
95  if(s2_ch_mask[geo.ns] & (1ll<<i)) {
96  ecal[i].d[j] = 0 ;
97  continue ;
98  }
99  if(ecal[i].d[j] > EHTTHR) ecal_ht |= 1 ;
100  }
101  }
102 
103  // Hcal 2x2 "HT" trigger
104  int hcal_ht = 0 ;
105  for(int i=0;i<DEP_HCAL_TRG_COU;i++) {// 20..27
106  for(int j=0;j<8;j++) {
107  if(s2_ch_mask[geo.ns] & (1ll<<(20+i))) {
108  hcal[i].d[j] = 0 ;
109  continue ;
110  }
111  if(hcal[i].d[j] > HHTTHR) hcal_ht |= 1 ;
112  }
113  }
114 
115  // Pres OR trigger
116  int fpre_or = 0 ;
117  for(int i=0;i<DEP_PRE_TRG_COU;i++) {// 28..32
118  for(int j=0;j<8;j++) {
119  if(s2_ch_mask[geo.ns] & (1ll<<(28+i))) {
120  pres[i].d[j] = 0 ;
121  continue ;
122  }
123  if(pres[i].d[j]) fpre_or |= 1 ;
124  }
125  }
126 
127  //mapped Ecal 2x2
128  for(int r=0; r<16; r++){
129  for(int c=0; c<10; c++){
130  e2x2[ns][r][c]=ecal[ETbTdep[r][c]].d[ETbTadr[r][c]];
131  }
132  }
133  //mapped Hcal 2x2
134  for(int r=0; r<10; r++){
135  for(int c=0; c<6; c++){
136  h2x2[ns][r][c]=hcal[HTbTdep[r][c]].d[HTbTadr[r][c]];
137  }
138  }
139 
140  //compute overlapping Hcal 4x4 sum of [9][5]
141  //u_int hsum[9][5];
142  for(int r=0; r<9; r++){
143  if(fcs_trgDebug>=2) printf("H4x4 ");
144  for(int c=0; c<5; c++){
145  hsum[ns][r][c]
146  = hcal[HTbTdep[r ][c ]].d[HTbTadr[r ][c ]]
147  + hcal[HTbTdep[r ][c+1]].d[HTbTadr[r ][c+1]]
148  + hcal[HTbTdep[r+1][c ]].d[HTbTadr[r+1][c ]]
149  + hcal[HTbTdep[r+1][c+1]].d[HTbTadr[r+1][c+1]];
150  //if(hsum[r][c] > 0xff) hsum[r][c]=0xff; //Tonko says no point to saturate at 8bit here
151  if(fcs_trgDebug>=2) printf("%5d ",hsum[ns][r][c]);
152  }
153  if(fcs_trgDebug>=2) printf("\n");
154  }
155 
156  //PRES for QA
157  if(fcs_trgDebug>0){
158  for(int dep=0; dep<6; dep++) {
159  for(int j=0; j<4; j++) {
160  for(int k=0; k<8; k++){
161  phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1;
162  }
163  }
164  }
165  }
166  if(fcs_trgDebug>=2){
167  for(int dep=0; dep<6; dep++) {
168  printf("PRES NS%1d DEP%1d : ",ns,dep);
169  for(int j=0; j<4; j++) {
170  for(int k=0; k<8; k++){
171  phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1;
172  printf("%1d", (pres[dep].d[j]>>k)&0x1);
173  }
174  printf(" ");
175  }
176  printf("\n");
177  }
178  }
179 
180  //compute overlapping Ecal 4x4 sums of [15][9]
181  //take ratio with the closest hcal 4x4
182  //u_int esum[15][9];
183  //u_int sum[15][9];
184  //float ratio[15][9];
185  u_int EM2 =0, EM1 =0, EM0=0, EM3=0;
186  u_int ELE2=0, ELE1=0, ELE0=0;
187  u_int HAD2=0, HAD1=0, HAD0=0;
188  u_int ETOT=0, HTOT=0;
189  for(int r=0; r<15; r++){
190  if(fcs_trgDebug>=2) printf("EM4x4 ");
191  for(int c=0; c<9; c++){
192  esum[ns][r][c]
193  = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]]
194  + ecal[ETbTdep[r ][c+1]].d[ETbTadr[r ][c+1]]
195  + ecal[ETbTdep[r+1][c ]].d[ETbTadr[r+1][c ]]
196  + ecal[ETbTdep[r+1][c+1]].d[ETbTadr[r+1][c+1]];
197  //if(esum[r][c] > 0xff) esum[r][c]=0xff; //Tonko says no point to saturate at 8bit here
198 
199  // locate the closest hcal
200  u_int h=hsum[ns][EtoHmap[r][c][0]][EtoHmap[r][c][1]];
201 
202  // locate the max 2x2 hcal
203  u_int hmax=0;
204  for(int iz=0; iz<4; iz++){
205  int iHCalID = EtoH3map[r][c][iz];
206  if(iHCalID < 0) continue;
207  int irow = iHCalID/5;
208  int icol = iHCalID%5;
209  if(hmax < hsum[ns][irow][icol]) hmax = hsum[ns][irow][icol];
210  }
211 
212  //if(h > 0 || hmax > 0) printf("Checking: %d, %d\n", h, hmax);
213 
214  // E+H sum
215  sum[ns][r][c] = esum[ns][r][c] + h;
216  summax[ns][r][c] = esum[ns][r][c] + hmax;
217 
218  //in VHDL we will do esum>hsum*threshold. Ratio is for human only
219  if(sum[ns][r][c]==0) {
220  ratio[ns][r][c]=0.0;
221  }else{
222  ratio[ns][r][c] = float(esum[ns][r][c]) / float(sum[ns][r][c]);
223  }
224  if(esum[ns][r][c]+hmax==0){
225  ratiomax[ns][r][c]=0.0;
226  }else{
227  ratiomax[ns][r][c]=float(esum[ns][r][c]) / float(summax[ns][r][c]);
228  }
229 
230  //check EPD hits using the mask
231  epdcoin[ns][r][c]=0;
232  for(int dep=0; dep<6; dep++){
233  int mask;
234  if(fcs_readPresMaskFromText==0){
235  mask = fcs_ecal_epd_mask[r][c][dep]; //from include file
236  }else{
237  mask = PRES_MASK[r][c][dep]; //from static which was from text file
238  }
239  for(int j=0; j<4; j++) {
240  for(int k=0; k<8; k++){
241  if( (mask >> (j*8 + k)) & 0x1) { //if this is 0, don't even put the logic in VHDL
242  epdcoin[ns][r][c] |= (pres[dep].d[j] >> k) & 0x1;
243  }
244  }
245  }
246  }
247 
248  // integer multiplication as in VHDL!
249  // ratio thresholds are in fixed point integer where 1.0==128
250  u_int h128 = h*128 ;
251  u_int hmax128 = hmax*128 ;
252 
253  if(hmax128 <= esum[ns][r][c] * EM_HERATIO_THR){
254  if(esum[ns][r][c] > EMTHR2) EM2 = 1;
255  if(esum[ns][r][c] > EMTHR1) EM1 = 1;
256  if(esum[ns][r][c] > EMTHR0) EM0 = 1;
257  if(esum[ns][r][c] > ELETHR2) EM3 = 1; //Using ELE Thr2
258  if(epdcoin[ns][r][c]==1){
259  if(esum[ns][r][c] > ELETHR2) ELE2 = 1;
260  if(esum[ns][r][c] > ELETHR1) ELE1 = 1;
261  if(esum[ns][r][c] > ELETHR0) ELE0 = 1;
262  }
263  }
264 
265  if(h128 > esum[ns][r][c] * HAD_HERATIO_THR){
266  if(sum[ns][r][c] > HADTHR0) HAD0 = 1;
267  if(sum[ns][r][c] > HADTHR1) HAD1 = 1;
268  if(sum[ns][r][c] > HADTHR2) HAD2 = 1;
269  }
270  if(fcs_trgDebug>=2) printf("%5d %1d %3.2f ",esum[ns][r][c],epdcoin[ns][r][c],ratiomax[ns][r][c]);
271  }
272  if(fcs_trgDebug>=2) printf("\n");
273  }
274  if(fcs_trgDebug>=2){
275  for(int r=0; r<15; r++){
276  printf("HAD4x4 ");
277  for(int c=0; c<9; c++){
278  printf("%5d %3.2f ",sum[ns][r][c],ratio[ns][r][c]);
279  }
280  printf("\n");
281  }
282  }
283 
284  //5 square JP
285  int e_col_start[5] = { 0, 0, 0, 3, 3}; //these are 2x2 row/col
286  int e_col_stop[5] = { 3, 6, 6, 9, 9};
287  int e_row_start[5] = { 3, 0, 5, 0, 5};
288  int e_row_stop[5] = {12,10,15,10,15};
289  int h_col_start[5] = { 0, 0, 0, 2, 2};
290  int h_col_stop[5] = { 2, 3, 3, 5, 5};
291  int h_row_start[5] = { 2, 0, 3, 0, 3};
292  int h_row_stop[5] = { 7, 6, 9, 6, 9};
293  int JP2[5] = {0,0,0,0,0};
294  int JP1[5] = {0,0,0,0,0};
295  int JP0[5] = {0,0,0,0,0};
296  int JPd[5] = {0,0,0,0,0};
297  for(int i=0; i<5; i++){
298  int ejet=0, hjet=0;
299  for(int c=e_col_start[i]; c<=e_col_stop[i]; c++){
300  for(int r=e_row_start[i]; r<=e_row_stop[i]; r++){
301  if((i==1 || i==2) && (c==0 || c==1) && (r>=5 && r<=10)) continue; //cutout
302  ejet += ecal[ETbTdep[r][c]].d[ETbTadr[r][c]];
303  }
304  }
305  for(int c=h_col_start[i]; c<=h_col_stop[i]; c++){
306  for(int r=h_row_start[i]; r<=h_row_stop[i]; r++){
307  if((i==1 || i==2) && (c==0) && (r>=3 && r<=6)) continue; //cutout
308  hjet += hcal[HTbTdep[r][c]].d[HTbTadr[r][c]];
309  }
310  }
311  jet[ns][i] = ejet + hjet;
312  //if(jet[ns][i]>=0xff) jet[ns][i]=0xff;
313  //int jet2 = ((ejet & 0x3ff) + (hjet & 0x3ff)) & 0x3ff;
314  //if(jet2>=0xff) jet2=0xff;
315  if(i==0){ //JPA
316  if(jet[ns][i]>JPATHR2) JP2[i] = 1;
317  if(jet[ns][i]>JPATHR1) JP1[i] = 1;
318  if(jet[ns][i]>JPATHR0) JP0[i] = 1;
319  }else if(i==1 || i==2){ //JPB and JPC
320  if(jet[ns][i]>JPBCTHR2) JP2[i] = 1;
321  if(jet[ns][i]>JPBCTHR1) JP1[i] = 1;
322  if(jet[ns][i]>JPBCTHR0) JP0[i] = 1;
323  if(jet[ns][i]>JPBCTHRD) JPd[i] = 1;
324  }else{ //JPD and JPE
325  if(jet[ns][i]>JPDETHR2) JP2[i] = 1;
326  if(jet[ns][i]>JPDETHR1) JP1[i] = 1;
327  if(jet[ns][i]>JPDETHR0) JP0[i] = 1;
328  if(jet[ns][i]>JPDETHRD) JPd[i] = 1;
329  }
330  }
331  if(fcs_trgDebug>=2) printf("JP5 (ns=%1d) = %3d %3d %3d %3d %3d\n",ns,jet[ns][0],jet[ns][1],jet[ns][2],jet[ns][3],jet[ns][4]);
332  if(fcs_trgDebug>=2) printf("JP5x(ns=%1d) = %3x %3x %3x %3x %3x\n",ns,jet[ns][0],jet[ns][1],jet[ns][2],jet[ns][3],jet[ns][4]);
333 
334  //Ecal sub-crate sum
335  u_int esub[4];
336  esub[0] = esum[ns][ 0][0]+esum[ns][ 0][2]+esum[ns][ 0][4]+esum[ns][ 0][6]+esum[ns][ 0][8]
337  + esum[ns][ 2][0]+esum[ns][ 2][2]+esum[ns][ 2][4]+esum[ns][ 2][6]+esum[ns][ 2][8];
338  esub[1] = esum[ns][ 4][0]+esum[ns][ 4][2]+esum[ns][ 4][4]+esum[ns][ 4][6]+esum[ns][ 4][8]
339  + esum[ns][ 6][0]+esum[ns][ 6][2]+esum[ns][ 6][4]+esum[ns][ 6][6]+esum[ns][ 6][8];
340  esub[2] = esum[ns][ 8][0]+esum[ns][ 8][2]+esum[ns][ 8][4]+esum[ns][ 8][6]+esum[ns][ 8][8]
341  + esum[ns][10][0]+esum[ns][10][2]+esum[ns][10][4]+esum[ns][10][6]+esum[ns][10][8];
342  esub[3] = esum[ns][12][0]+esum[ns][12][2]+esum[ns][12][4]+esum[ns][12][6]+esum[ns][12][8]
343  + esum[ns][14][0]+esum[ns][14][2]+esum[ns][14][4]+esum[ns][14][6]+esum[ns][14][8];
344  for(int i=0; i<4; i++) if(esub[i]>0xff) esub[i]=0xff;
345 
346  //Hcal sub-crate sum
347  u_int hsub[4];
348  hsub[0] = hsum[ns][ 1][0]+hsum[ns][ 1][2]+hsum[ns][ 1][4];
349  hsub[1] = hsum[ns][ 3][0]+hsum[ns][ 3][2]+hsum[ns][ 3][4];
350  hsub[2] = hsum[ns][ 5][0]+hsum[ns][ 5][2]+hsum[ns][ 5][4];
351  hsub[3] = hsum[ns][ 7][0]+hsum[ns][ 7][2]+hsum[ns][ 7][4];
352  for(int i=0; i<4; i++) if(hsub[i]>0xff) hsub[i]=0xff;
353 
354  //total ET
355  etot[ns] = esub[0] + esub[1] + esub[2] + esub[3];
356  htot[ns] = hsub[0] + hsub[1] + hsub[2] + hsub[3];
357  if(etot[ns]>ETOTTHR) ETOT=1;
358  if(htot[ns]>HTOTTHR) HTOT=1;
359  if(fcs_trgDebug>=2) printf("E/H Tot = %3d %3d\n",etot[ns],htot[ns]);
360 
361  //sending output bits
362  output[0].d[0] = (EM0<<0) + (EM1<<1) + (EM2<<2) + (EM3<<3) + (ELE0<<4) + (ELE1<<5) + (ELE2<<6) + (fpre_or<<7);
363  output[1].d[0] = (HAD0<<0) + (HAD1<<1) + (HAD2<<2) + (0<<3) + (ecal_ht<<4) + (hcal_ht<<5) + (ETOT<<6) + (HTOT<<7);
364  output[0].d[1] = (JP2[0]<<0) + (JP2[1]<<1) + (JP2[2]<<2) + (JP2[3]<<3) + (JP2[4]<<4);
365  output[1].d[1] = (JP1[0]<<0) + (JP1[1]<<1) + (JP1[2]<<2) + (JP1[3]<<3) + (JP1[4]<<4);
366  output[0].d[2] = (JP0[0]<<0) + (JP0[1]<<1) + (JP0[2]<<2) + (JP0[3]<<3) + (JP0[4]<<4);
367  output[1].d[2] = (JPd[0]<<0) + (JPd[1]<<1) + (JPd[2]<<2) + (JPd[3]<<3) + (JPd[4]<<4); //JPd[0]==0
368  output[0].d[3] = 0;
369  output[1].d[3] = 0;
370  output[1].d[4] = 0;
371  output[0].d[4] = 0;
372  output[0].d[5] = 0;
373  output[1].d[5] = 0;
374  output[0].d[6] = 0;
375  output[1].d[6] = 0;
376  output[0].d[7] = 0;
377  output[1].d[7] = 0;
378 
379  *s2_to_dsm = (ELE0<<0) + (ELE1<<1) + (ELE2<<2) + (EM3<<3)
380  + (ecal_ht<<4) + (hcal_ht<<5) + (ETOT<<6) + (HTOT<<7);
381 
382  if(fcs_trgDebug>=1){
383  printf("FCS STG2 NS=%1d output = %02x %02x %02x %02x %02x %02x TCU=%04x\n",
384  ns,
385  output[0].d[0],output[1].d[0],output[0].d[1],output[1].d[1],
386  output[0].d[2],output[1].d[2],*s2_to_dsm);
387  printf("emuout = %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x TCU=%04x\n",
388  output[1].d[0],output[0].d[0],
389  output[1].d[1],output[0].d[1],
390  output[1].d[2],output[0].d[2],
391  output[1].d[3],output[0].d[3],
392  output[1].d[4],output[0].d[4],
393  output[1].d[5],output[0].d[5],
394  output[1].d[6],output[0].d[6],
395  output[1].d[7],output[0].d[7],
396  *s2_to_dsm);
397  }
398 
399  return ;
400 }