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 7, 4},{ 7, 4},{ 7, 4}},
31 { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}},
32 { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}}
39 if(fcs_trgDebug>=2) printf(
"Stage2v3 ns=%d\n",ns);
47 static u_int ETbTdep[16][10];
48 static u_int ETbTadr[16][10];
49 static u_int HTbTdep[10][6];
50 static u_int HTbTadr[10][6];
55 for(
int r=0; r<16; r++){
56 printf(
"Ecal r=%2d : ",r);
57 for(
int c=0; c<10; c++){
58 ETbTdep[r][c]= c/2 + (r/4)*5;
59 ETbTadr[r][c]= c%2 + (r%4)*2;
60 printf(
"%2d-%1d ",ETbTdep[r][c],ETbTadr[r][c]);
65 for(
int r=0; r<10; r++){
66 printf(
"HCal r=%2d : ",r);
67 for(
int c=0; c<6; c++){
75 HTbTdep[r][c]= c/2 + ((r-1)/4)*3;
76 HTbTadr[r][c]= c%2 + ((r-1)%4)*2;
78 printf(
"%2d-%1d ",HTbTdep[r][c],HTbTadr[r][c]);
86 for(
int i=0;i<DEP_ECAL_TRG_COU;i++) {
87 for(
int j=0;j<8;j++) {
88 if(s2_ch_mask[geo.ns] & (1ll<<i)) {
92 if(ecal[i].d[j] > EHTTHR) ecal_ht |= 1 ;
98 for(
int i=0;i<DEP_HCAL_TRG_COU;i++) {
99 for(
int j=0;j<8;j++) {
100 if(s2_ch_mask[geo.ns] & (1ll<<(20+i))) {
104 if(hcal[i].d[j] > HHTTHR) hcal_ht |= 1 ;
110 for(
int i=0;i<DEP_PRE_TRG_COU;i++) {
111 for(
int j=0;j<8;j++) {
112 if(s2_ch_mask[geo.ns] & (1ll<<(28+i))) {
117 if(pres[i].d[j]) fpre_or |= 1 ;
126 for(
int r=0; r<16; r++){
127 for(
int c=0; c<10; c++){
128 e2x2[ns][r][c]=ecal[ETbTdep[r][c]].d[ETbTadr[r][c]];
132 for(
int r=0; r<10; r++){
133 for(
int c=0; c<6; c++){
134 h2x2[ns][r][c]=hcal[HTbTdep[r][c]].d[HTbTadr[r][c]];
140 for(
int r=0; r<9; r++){
141 if(fcs_trgDebug>=2) printf(
"H4x4 ");
142 for(
int c=0; c<5; c++){
144 = hcal[HTbTdep[r ][c ]].d[HTbTadr[r ][c ]]
145 + hcal[HTbTdep[r ][c+1]].d[HTbTadr[r ][c+1]]
146 + hcal[HTbTdep[r+1][c ]].d[HTbTadr[r+1][c ]]
147 + hcal[HTbTdep[r+1][c+1]].d[HTbTadr[r+1][c+1]];
149 if(fcs_trgDebug>=2) printf(
"%5d ",hsum[ns][r][c]);
151 if(fcs_trgDebug>=2) printf(
"\n");
156 for(
int dep=0; dep<6; dep++) {
157 for(
int j=0; j<4; j++) {
158 for(
int k=0; k<8; k++){
159 phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1;
165 for(
int dep=0; dep<6; dep++) {
166 printf(
"PRES NS%1d DEP%1d : ",ns,dep);
167 for(
int j=0; j<4; j++) {
168 for(
int k=0; k<8; k++){
169 phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1;
170 printf(
"%1d", (pres[dep].d[j]>>k)&0x1);
183 u_int EM1 =0, EM2 =0, EM3=0;
184 u_int GAM1=0, GAM2=0, GAM3=0;
185 u_int ELE1=0, ELE2=0, ELE3=0;
186 u_int HAD1=0, HAD2=0, HAD3=0;
187 u_int ETOT=0, HTOT=0;
188 for(
int r=0; r<15; r++){
189 if(fcs_trgDebug>=2) printf(
"E4x4+H %2d ",r);
190 for(
int c=0; c<9; c++){
192 = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]]
193 + ecal[ETbTdep[r ][c+1]].d[ETbTadr[r ][c+1]]
194 + ecal[ETbTdep[r+1][c ]].d[ETbTadr[r+1][c ]]
195 + ecal[ETbTdep[r+1][c+1]].d[ETbTadr[r+1][c+1]];
199 u_int h=hsum[ns][EtoHmap[r][c][0]][EtoHmap[r][c][1]];
202 sum[ns][r][c] = esum[ns][r][c] + h;
203 if(sum[ns][r][c]>0xff) sum[ns][r][c]=0xff;
206 if(sum[ns][r][c]==0) {
209 ratio[ns][r][c] = float(esum[ns][r][c]) / float(esum[ns][r][c] + h);
214 for(
int dep=0; dep<6; dep++){
216 if(fcs_readPresMaskFromText==0){
217 mask = fcs_ecal_epd_mask[r][c][dep];
219 mask = PRES_MASK[r][c][dep];
221 for(
int j=0; j<4; j++) {
222 for(
int k=0; k<8; k++){
223 if( (mask >> (j*8 + k)) & 0x1) {
224 epdcoin[ns][r][c] |= (pres[dep].d[j] >> k) & 0x1;
238 if(h128 <= esum[ns][r][c] * EM_HERATIO_THR){
240 if(sum[ns][r][c] > EMTHR1){
242 if(epdcoin[ns][r][c]==0) {GAM1 = 1;}
245 if(sum[ns][r][c] > EMTHR2){
247 if(epdcoin[ns][r][c]==0) {GAM2 = 1;}
250 if(sum[ns][r][c] > EMTHR3){
252 if(epdcoin[ns][r][c]==0) {GAM3 = 1;}
256 if(h128 > esum[ns][r][c] * HAD_HERATIO_THR){
258 if(sum[ns][r][c] > HADTHR1) HAD1 = 1;
259 if(sum[ns][r][c] > HADTHR2) HAD2 = 1;
260 if(sum[ns][r][c] > HADTHR3) HAD3 = 1;
262 if(fcs_trgDebug>=2) printf(
"%5d %1d %3.2f ",sum[ns][r][c],epdcoin[ns][r][c],ratio[ns][r][c]);
264 if(fcs_trgDebug>=2) printf(
"\n");
269 esub[0] = esum[ns][ 0][0]+esum[ns][ 0][2]+esum[ns][ 0][4]+esum[ns][ 0][6]+esum[ns][ 0][8]
270 + esum[ns][ 2][0]+esum[ns][ 2][2]+esum[ns][ 2][4]+esum[ns][ 2][6]+esum[ns][ 2][8];
271 esub[1] = esum[ns][ 4][0]+esum[ns][ 4][2]+esum[ns][ 4][4]+esum[ns][ 4][6]+esum[ns][ 4][8]
272 + esum[ns][ 6][0]+esum[ns][ 6][2]+esum[ns][ 6][4]+esum[ns][ 6][6]+esum[ns][ 6][8];
273 esub[2] = esum[ns][ 8][0]+esum[ns][ 8][2]+esum[ns][ 8][4]+esum[ns][ 8][6]+esum[ns][ 8][8]
274 + esum[ns][10][0]+esum[ns][10][2]+esum[ns][10][4]+esum[ns][10][6]+esum[ns][10][8];
275 esub[3] = esum[ns][12][0]+esum[ns][12][2]+esum[ns][12][4]+esum[ns][12][6]+esum[ns][12][8]
276 + esum[ns][14][0]+esum[ns][14][2]+esum[ns][14][4]+esum[ns][14][6]+esum[ns][14][8];
277 for(
int i=0; i<4; i++) if(esub[i]>0xff) esub[i]=0xff;
281 hsub[0] = hsum[ns][ 1][0]+hsum[ns][ 1][2]+hsum[ns][ 1][4];
282 hsub[1] = hsum[ns][ 3][0]+hsum[ns][ 3][2]+hsum[ns][ 3][4];
283 hsub[2] = hsum[ns][ 5][0]+hsum[ns][ 5][2]+hsum[ns][ 5][4];
284 hsub[3] = hsum[ns][ 7][0]+hsum[ns][ 7][2]+hsum[ns][ 7][4];
285 for(
int i=0; i<4; i++) if(hsub[i]>0xff) hsub[i]=0xff;
290 jet[ns][0] = esub[0] + esub[1] + hsub[0] + hsub[1];
291 jet[ns][1] = esub[1] + esub[2] + hsub[1] + hsub[2];
292 jet[ns][2] = esub[2] + esub[3] + hsub[2] + hsub[3];
293 for(
int i=0; i<3; i++){
295 if(jet[ns][i]>JETTHR1) JP1 = 1;
296 if(jet[ns][i]>JETTHR2) JP2 = 1;
298 if(fcs_trgDebug>=2) printf(
"Jet = %3d %3d %3d\n",jet[ns][0],jet[ns][1],jet[ns][2]);
301 etot[ns] = esub[0] + esub[1] + esub[2] + esub[3];
302 htot[ns] = hsub[0] + hsub[1] + hsub[2] + hsub[3];
305 if(etot[ns]>ETOTTHR) ETOT=1;
306 if(htot[ns]>HTOTTHR) HTOT=1;
307 if(fcs_trgDebug>=2) printf(
"E/H Tot = %3d %3d\n",etot[ns],htot[ns]);
311 output[0].d[0] = EM1 + (EM2 <<1) + (EM3 <<2);
312 output[0].d[1] = ELE1 + (ELE2<<1) + (ELE3<<2);
313 output[0].d[2] = GAM1 + (GAM2<<1) + (GAM3<<2);
314 output[0].d[3] = HAD1 + (HAD2<<1) + (HAD3<<2);
315 output[0].d[4] = JP1 + (JP2 <<1);
316 output[0].d[5] = ETOT + (HTOT<<1);
317 output[0].d[6] = (fpre_or<<2) | (hcal_ht<<1) | (ecal_ht);
333 printf(
"STG2 NS%1d = %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x %02x%02x\n",
335 output[1].d[0],output[0].d[0],output[1].d[1],output[0].d[1],
336 output[1].d[2],output[0].d[2],output[1].d[3],output[0].d[3],
337 output[1].d[4],output[0].d[4],output[1].d[5],output[0].d[5],
338 output[1].d[6],output[0].d[6],output[1].d[7],output[0].d[7]);