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 7, 4},{ 7, 4},{ 7, 4}},
32 { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}},
33 { { 8, 0},{ 8, 1},{ 8, 1},{ 8, 2},{ 8, 2},{ 8, 3},{ 8, 4},{ 8, 4},{ 8, 4}}
40 if(fcs_trgDebug>=2) printf(
"Stage2v1 ns=%d\n",ns);
43 static u_int ETbTdep[16][10];
44 static u_int ETbTadr[16][10];
45 static u_int HTbTdep[10][6];
46 static u_int HTbTadr[10][6];
50 for(
int r=0; r<16; r++){
51 printf(
"Ecal r=%2d : ",r);
52 for(
int c=0; c<10; c++){
53 ETbTdep[r][c]= c/2 + (r/4)*5;
54 ETbTadr[r][c]= c%2 + (r%4)*2;
55 printf(
"%2d-%1d ",ETbTdep[r][c],ETbTadr[r][c]);
60 for(
int r=0; r<10; r++){
61 printf(
"HCal r=%2d : ",r);
62 for(
int c=0; c<6; c++){
70 HTbTdep[r][c]= c/2 + ((r-1)/4)*3;
71 HTbTadr[r][c]= c%2 + ((r-1)%4)*2;
73 printf(
"%2d-%1d ",HTbTdep[r][c],HTbTadr[r][c]);
81 for(
int r=0; r<9; r++){
82 if(fcs_trgDebug>=2) printf(
"H4x4 ");
83 for(
int c=0; c<5; c++){
85 = hcal[HTbTdep[r ][c ]].d[HTbTadr[r ][c ]]
86 + hcal[HTbTdep[r ][c+1]].d[HTbTadr[r ][c+1]]
87 + hcal[HTbTdep[r+1][c ]].d[HTbTadr[r+1][c ]]
88 + hcal[HTbTdep[r+1][c+1]].d[HTbTadr[r+1][c+1]];
90 if(fcs_trgDebug>=2) printf(
"%5d ",hsum[ns][r][c]);
92 if(fcs_trgDebug>=2) printf(
"\n");
97 for(
int dep=0; dep<6; dep++) {
98 for(
int j=0; j<4; j++) {
99 for(
int k=0; k<8; k++){
100 phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1;
106 for(
int dep=0; dep<6; dep++) {
107 printf(
"PRES NS%1d DEP%1d : ",ns,dep);
108 for(
int j=0; j<4; j++) {
109 for(
int k=0; k<8; k++){
110 phit[ns][dep][j*8+k] = (pres[dep].d[j] >> k) & 0x1;
111 printf(
"%1d", (pres[dep].d[j]>>k)&0x1);
124 u_int EM1 =0, EM2 =0, EM3=0;
125 u_int GAM1=0, GAM2=0, GAM3=0;
126 u_int ELE1=0, ELE2=0, ELE3=0;
127 u_int HAD1=0, HAD2=0, HAD3=0;
128 u_int ETOT=0, HTOT=0;
129 for(
int r=0; r<15; r++){
130 if(fcs_trgDebug>=2) printf(
"E4x4 ");
131 for(
int c=0; c<9; c++){
133 = ecal[ETbTdep[r ][c ]].d[ETbTadr[r ][c ]]
134 + ecal[ETbTdep[r ][c+1]].d[ETbTadr[r ][c+1]]
135 + ecal[ETbTdep[r+1][c ]].d[ETbTadr[r+1][c ]]
136 + ecal[ETbTdep[r+1][c+1]].d[ETbTadr[r+1][c+1]];
140 u_int h=hsum[ns][EtoHmap[r][c][0]][EtoHmap[r][c][1]];
143 sum[ns][r][c] = esum[ns][r][c] + h;
146 if(sum[ns][r][c]==0) {
149 ratio[ns][r][c] = float(esum[ns][r][c]) / float(sum[ns][r][c]);
154 for(
int dep=0; dep<6; dep++){
156 if(fcs_readPresMaskFromText==0){
157 mask = fcs_ecal_epd_mask[r][c][dep];
159 mask = PRES_MASK[r][c][dep];
161 for(
int j=0; j<4; j++) {
162 for(
int k=0; k<8; k++){
163 if( (mask >> (j*8 + k)) & 0x1) {
164 epdcoin[ns][r][c] |= (pres[dep].d[j] >> k) & 0x1;
173 if(h128 < esum[ns][r][c] * EM_HERATIO_THR){
174 if(sum[ns][r][c] > EMTHR1){
176 if(epdcoin[ns][r][c]==0) {GAM1 = 1;}
179 if(sum[ns][r][c] > EMTHR2){
181 if(epdcoin[ns][r][c]==0) {GAM2 = 1;}
184 if(sum[ns][r][c] > EMTHR3){
186 if(epdcoin[ns][r][c]==0) {GAM3 = 1;}
190 if(h128 > esum[ns][r][c] * HAD_HERATIO_THR){
191 if(sum[ns][r][c] > HADTHR1) HAD1 = 1;
192 if(sum[ns][r][c] > HADTHR2) HAD2 = 1;
193 if(sum[ns][r][c] > HADTHR3) HAD3 = 1;
195 if(fcs_trgDebug>=2) printf(
"%5d %1d %3.2f ",esum[ns][r][c],epdcoin[ns][r][c],ratio[ns][r][c]);
197 if(fcs_trgDebug>=2) printf(
"\n");
202 esub[0] = esum[ns][ 0][0]+esum[ns][ 0][2]+esum[ns][ 0][4]+esum[ns][ 0][6]+esum[ns][ 0][8]
203 + esum[ns][ 2][0]+esum[ns][ 2][2]+esum[ns][ 2][4]+esum[ns][ 2][6]+esum[ns][ 2][8];
204 esub[1] = esum[ns][ 4][0]+esum[ns][ 4][2]+esum[ns][ 4][4]+esum[ns][ 4][6]+esum[ns][ 4][8]
205 + esum[ns][ 6][0]+esum[ns][ 6][2]+esum[ns][ 6][4]+esum[ns][ 6][6]+esum[ns][ 6][8];
206 esub[2] = esum[ns][ 8][0]+esum[ns][ 8][2]+esum[ns][ 8][4]+esum[ns][ 8][6]+esum[ns][ 8][8]
207 + esum[ns][10][0]+esum[ns][10][2]+esum[ns][10][4]+esum[ns][10][6]+esum[ns][10][8];
208 esub[3] = esum[ns][12][0]+esum[ns][12][2]+esum[ns][12][4]+esum[ns][12][6]+esum[ns][12][8]
209 + esum[ns][14][0]+esum[ns][14][2]+esum[ns][14][4]+esum[ns][14][6]+esum[ns][14][8];
210 for(
int i=0; i<4; i++) if(esub[i]>0xff) esub[i]=0xff;
214 hsub[0] = hsum[ns][ 1][0]+hsum[ns][ 1][2]+hsum[ns][ 1][4];
215 hsub[1] = hsum[ns][ 3][0]+hsum[ns][ 3][2]+hsum[ns][ 3][4];
216 hsub[2] = hsum[ns][ 5][0]+hsum[ns][ 5][2]+hsum[ns][ 5][4];
217 hsub[3] = hsum[ns][ 7][0]+hsum[ns][ 7][2]+hsum[ns][ 7][4];
218 for(
int i=0; i<4; i++) if(hsub[i]>0xff) hsub[i]=0xff;
223 jet[ns][0] = esub[0] + esub[1] + hsub[0] + hsub[1];
224 jet[ns][1] = esub[1] + esub[2] + hsub[1] + hsub[2];
225 jet[ns][2] = esub[2] + esub[3] + hsub[2] + hsub[3];
226 for(
int i=0; i<3; i++){
227 if(jet[ns][i]>0xff) jet[ns][i]=0xff;
228 if(jet[ns][i]>JETTHR1) JP1 = 1;
229 if(jet[ns][i]>JETTHR2) JP2 = 1;
231 if(fcs_trgDebug>=2) printf(
"Jet = %3d %3d %3d\n",jet[ns][0],jet[ns][1],jet[ns][2]);
234 etot[ns] = esub[0] + esub[1] + esub[2] + esub[3];
235 htot[ns] = hsub[0] + hsub[1] + hsub[2] + hsub[3];
236 if(etot[ns]>ETOTTHR) ETOT=1;
237 if(htot[ns]>HTOTTHR) HTOT=1;
238 if(fcs_trgDebug>=2) printf(
"E/H Tot = %3d %3d\n",etot[ns],htot[ns]);
241 output[0].d[0] = EM1 + (EM2 <<1) + (EM3 <<2) + 0x80;
242 output[0].d[1] = ELE1 + (ELE2<<1) + (ELE3<<2);
243 output[0].d[2] = GAM1 + (GAM2<<1) + (GAM3<<2);
244 output[0].d[3] = HAD1 + (HAD2<<1) + (HAD3<<2);
245 output[0].d[4] = JP1 + (JP2 <<1);
246 output[0].d[5] = ETOT + (HTOT<<1);
247 output[0].d[6] = pres[0].d[1] ;
248 output[0].d[7] = pres[0].d[7] ;
251 printf(
"FCS STG2 NS=%1d output = %02x %02x %02x %02x %02x %02x %02x %02x\n",
253 output[0].d[0],output[0].d[1],output[0].d[2],output[0].d[3],
254 output[0].d[4],output[0].d[5],output[0].d[6],output[0].d[7]);