StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsBitCheckMaker.cxx
1 #include "StFmsBitCheckMaker.h"
2 #include "StFmsTriggerMaker.h"
3 #include "StTriggerData.h"
4 
5 enum {MAXD=MAXPP*2, MAXDT=MAXD*2+1};
6 
7 unsigned short TCU;
9 static int PRINTLEVEL;
10 
11 static int NPRE,NPOST;
12 static unsigned int N0[12][MAXDT][4][32][4];
13 static unsigned int N1[4][MAXDT][4][32][4];
14 static unsigned int N2[MAXDT][4][32][4];
15 static unsigned int N3[16][4];
16 static float MM[MAXDT][18];
17 
18 void printMismatch(int run){
19  printf("Run Mismatch% = FM001 FM002 FM003 FM004 FM005 FM006 FM007 FM008 FM009 FM010 FM011 FM012 | FM101 FM102 FM03 FM104 | FP201 | TCU | Average\n");
20  printf("%8d mismatch\% = ",run);
21  float ave=0.0;
22  for(int id=0; id<18; id++) {
23  ave+=MM[MAXD][id];
24  printf("%6.3f ",MM[MAXD][id]);
25  if(id==11 || id==15 || id==16) printf("| ");
26  }
27  printf("| ave=%6.3f\n",ave/18.0);
28  printf("%8.4f AVGMM\n",ave/18.0);
29 }
30 
31 void printCount(int id, const char* name, unsigned int n[MAXDT][4][32][4], int run, int layer2=0){
32  int dmin,dmax;
33  dmin=-(NPRE+NPOST); dmax=NPRE+NPOST;
34  // if(layer2==0){ dmin=-(NPRE+NPOST); dmax=NPRE+NPOST; }
35  //else { dmin=-NPRE; dmax=NPOST; }
36  int nt[MAXDT];
37  int ng[MAXDT];
38  memset(nt,0,sizeof(nt));
39  memset(ng,0,sizeof(ng));
40  for(int dt=0; dt<MAXDT; dt++){
41  int d=dt-MAXD;
42  if(d<dmin || d>dmax) continue;
43  printf("%8d %15s : %2d ",run,name,d);
44  for(int i=0; i<4; i++){
45  for(int j=31; j>=0; j--){
46  char a[2];
47  int n00=n[dt][i][j][0];
48  int n01=n[dt][i][j][1];
49  int n10=n[dt][i][j][2];
50  int n11=n[dt][i][j][3];
51  nt[dt]+=n00+n01+n10+n11;
52  ng[dt]+=n00+n11;
53  if(n01==0 && n10==0) {
54  sprintf(a,".");
55  }else{
56  float r = float(n00+n11)/float(n00+n01+n10+n11)*10.0;
57  sprintf(a,"%1d",(int)r);
58  if(n00==0 && n01==0) sprintf(a,"!");
59  if(n10==0 && n11==0) sprintf(a,"o");
60  }
61  printf("%1s",a);
62  }
63  printf(" ");
64  }
65  printf("\n");
66  }
67  printf("%8d %15s MMdeltaT\% = ",run,name);
68  for(int dt=0; dt<MAXDT; dt++){
69  int d=dt-MAXD;
70  if(d<dmin || d>dmax) continue;
71  float mm=float(nt[dt]-ng[dt])/float(nt[dt])*100.0;
72  printf("%6.3f ",mm);
73  MM[dt][id]=mm;
74  }
75  printf("\n");
76  printf("%8d %15s Mismatch\% = ",run,name);
77  int dt=MAXD;
78  int d=dt-MAXD;
79  float mm=float(nt[dt]-ng[dt])/float(nt[dt])*100.0;
80  printf("%6.3f ",mm);
81  MM[dt][id]=mm;
82  printf("\n");
83 }
84 
85 void printCount3(int id, const char* name, unsigned int n[32][4], int run){
86  int nt=0,ng=0;
87  printf("%8d %15s : 0 ",run,name);
88  for(int j=15; j>=0; j--){
89  char a[2];
90  int n00=n[j][0];
91  int n01=n[j][1];
92  int n10=n[j][2];
93  int n11=n[j][3];
94  nt+=n00+n01+n10+n11;
95  ng+=n00+n11;
96  if(n01==0 && n10==0) {
97  sprintf(a,".");
98  }else{
99  float r = float(n00+n11)/float(n00+n01+n10+n11)*10.0;
100  sprintf(a,"%1d",(int)r);
101  if(n00==0 && n01==0) sprintf(a,"!");
102  if(n10==0 && n11==0) sprintf(a,"o");
103  }
104  printf("%1s",a);
105  }
106  printf("\n");
107  float mm=float(nt-ng)/float(nt)*100.0;
108  printf("%8d %15s Mismatch\% = %6.3f\n",run,name,mm);
109  MM[MAXD][id]=mm;
110 }
111 
112 void Count(int d1, int d2, int d3, int d4, int s1, int s2, int s3, int s4, unsigned int n[4][32][4]){
113  int c;
114  for(int i=0; i<32; i++){
115  c = ((d1>>i) & 0x1)*2 + ((s1>>i) & 0x1); n[0][i][c]++;
116  c = ((d2>>i) & 0x1)*2 + ((s2>>i) & 0x1); n[1][i][c]++;
117  c = ((d3>>i) & 0x1)*2 + ((s3>>i) & 0x1); n[2][i][c]++;
118  c = ((d4>>i) & 0x1)*2 + ((s4>>i) & 0x1); n[3][i][c]++;
119  }
120 }
121 
122 void Count3(int d1, int s1, unsigned int n[32][4]){
123  int c;
124  for(int i=0; i<16; i++){
125  c = ((d1>>i) & 0x1)*2 + ((s1>>i) & 0x1); n[i][c]++;
126  }
127 }
128 
129 void Comp0(const char* name, int slot, int num, int t1, int t2, int run){
130  int x1=t1-MAXPP;
131  int x2=t2-MAXPP;
132  /*
133  unsigned int d1=getDSM(slot,0);
134  unsigned int d2=getDSM(slot,1);
135  unsigned int d3=getDSM(slot,2);
136  unsigned int d4=getDSM(slot,3);
137  */
138  unsigned int d1=SIM->FM0xxdata(num,0,t1);
139  unsigned int d2=SIM->FM0xxdata(num,1,t1);
140  unsigned int d3=SIM->FM0xxdata(num,2,t1);
141  unsigned int d4=SIM->FM0xxdata(num,3,t1);
142  unsigned int s1=SIM->FM0xxinput(num,0,t2);
143  unsigned int s2=SIM->FM0xxinput(num,1,t2);
144  unsigned int s3=SIM->FM0xxinput(num,2,t2);
145  unsigned int s4=SIM->FM0xxinput(num,3,t2);
146  if(PRINTLEVEL>0){
147  printf("%8d %15s | %2d %2d %2d | %08x %08x %08x %08x | %08x %08x %08x %08x | %08x %08x %08x %08x\n",
148  run,name,x1-x2,x1,x2,
149  d1,d2,d3,d4,
150  s1,s2,s3,s4,
151  d1^s1, d2^s2, d3^s3, d4^s4);
152  }
153  Count(d1,d2,d3,d4,s1,s2,s3,s4,N0[num-1][x1-x2+MAXD]);
154 }
155 
156 void Comp1(const char* name, int slot, int num, int t1, int t2, int run){
157  int x1=t1-MAXPP;
158  int x2=t2-MAXPP;
159  /*
160  unsigned int d1=getDSM(slot,0);
161  unsigned int d2=getDSM(slot,1);
162  unsigned int d3=getDSM(slot,2);
163  unsigned int d4=getDSM(slot,3);
164  */
165  unsigned int d1=SIM->FM1xxdata(num,0,t1);
166  unsigned int d2=SIM->FM1xxdata(num,1,t1);
167  unsigned int d3=SIM->FM1xxdata(num,2,t1);
168  unsigned int d4=SIM->FM1xxdata(num,3,t1);
169  unsigned int s1=SIM->FM1xxinput(num,0,t2);
170  unsigned int s2=SIM->FM1xxinput(num,1,t2);
171  unsigned int s3=SIM->FM1xxinput(num,2,t2);
172  unsigned int s4=SIM->FM1xxinput(num,3,t2);
173  if(PRINTLEVEL>0)
174  printf("%8d %15s | %2d %2d %2d | %08x %08x %08x %08x | %08x %08x %08x %08x | %08x %08x %08x %08x\n",
175  run,name,x1-x2,x1,x2,
176  d1,d2,d3,d4,
177  s1,s2,s3,s4,
178  d1^s1, d2^s2, d3^s3, d4^s4);
179  Count(d1,d2,d3,d4,s1,s2,s3,s4,N1[num-1][x1-x2+MAXD]);
180 }
181 
182 void Comp2(const char* name, int t2, int run){
183  int x1=0;
184  int x2=t2-MAXPP;
185  /*
186  unsigned int d1=getDSM(16,0);
187  unsigned int d2=getDSM(16,1);
188  unsigned int d3=getDSM(16,2);
189  unsigned int d4=getDSM(16,3);
190  */
191  unsigned int d1=SIM->FP201data(0);
192  unsigned int d2=SIM->FP201data(1);
193  unsigned int d3=SIM->FP201data(2);
194  unsigned int d4=SIM->FP201data(3);
195  unsigned int s1=SIM->FP201input(0,t2);
196  unsigned int s2=SIM->FP201input(1,t2);
197  unsigned int s3=SIM->FP201input(2,t2);
198  unsigned int s4=SIM->FP201input(3,t2);
199  if(PRINTLEVEL>0)
200  printf("%8d %15s | %2d %2d %2d | %08x %08x %08x %08x | %08x %08x %08x %08x | %08x %08x %08x %08x\n",
201  run,name,x1-x2,x1,x2,
202  d1,d2,d3,d4,
203  s1,s2,s3,s4,
204  d1^s1, d2^s2, d3^s3, d4^s4);
205  Count(d1,d2,d3,d4,s1,s2,s3,s4,N2[x1-x2+MAXD]);
206 }
207 
208 void Comp3(const char* name, int run){
209  unsigned int d1=TCU;
210  unsigned int s1=SIM->FP201output();
211  int jp0=SIM->FP201userdata(1);
212  if(PRINTLEVEL>0) {
213  printf("%8d %15s | %04x / %04x | %04x DiJp=",
214  run,name,
215  d1,s1,d1^s1);
216  for(int i=5; i>=0; i--) printf("%1x",(jp0>>i)&0x1);
217  printf("\n");
218  }
219  Count3(d1,s1,N3);
220 }
221 
222 ClassImp(StFmsBitCheckMaker);
223 
224 StFmsBitCheckMaker::StFmsBitCheckMaker(const char* name): StMaker(name), mPrint(0) {
225 }
226 
227 void StFmsBitCheckMaker::Clear(Option_t* option){
228 }
229 
230 int StFmsBitCheckMaker::Init(){
231  memset(N0,0,sizeof(N0));
232  memset(N1,0,sizeof(N1));
233  memset(N2,0,sizeof(N2));
234  memset(N3,0,sizeof(N3));
235  PRINTLEVEL=mPrint;
236  return kStOk;
237 }
238 
239 int StFmsBitCheckMaker::InitRun(int runNumber){
240  return kStOK;
241 }
242 
244  printf("Run Name Mismatch% Data Xing - Previous layer&Emulation xing\n");
245  printCount(0,"QT1/DCBA=>FM001",N0[0],mRun);
246  printCount(1,"QT2/DCBA=>FM002",N0[1],mRun);
247  printCount(2,"QT3/DCBA=>FM003",N0[2],mRun);
248  printCount(3,"QT4/DCBA=>FM004",N0[3],mRun);
249  printCount(4,"QT1/JIHG=>FM005",N0[4],mRun);
250  printCount(5,"QT1/FE =>FM006",N0[5],mRun);
251  printCount(6,"QT2/JIHG=>FM007",N0[6],mRun);
252  printCount(7,"QT2/FE =>FM008",N0[7],mRun);
253  printCount(8,"QT3/JIHG=>FM009",N0[8],mRun);
254  printCount(9,"QT3/FE =>FM010",N0[9],mRun);
255  printCount(10,"QT4/JIHG=>FM011",N0[10],mRun);
256  printCount(11,"QT4/FE =>FM012",N0[11],mRun);
257  printCount(12,"FM001/2 =>FM101", N1[0],mRun);
258  printCount(13,"FM003/4 =>FM102", N1[1],mRun);
259  printCount(14,"FM005/8 =>FM103", N1[2],mRun);
260  printCount(15,"FM09/12 =>FM104", N1[3],mRun);
261  printCount(16,"FM101/4 =>FP201", N2,mRun,1);
262  printCount3(17,"FP201 =>TCU ",N3,mRun);
263  printMismatch(mRun);
264 }
265 
267  StTriggerData *td = (StTriggerData*)GetDataSet("StTriggerData")->GetObject();
268  if(!td) {printf("No StTriggerData found\n"); return kStErr;}
269  SIM=(StFmsTriggerMaker*)GetMaker("fmstrigger");
270  if(!SIM) {printf("No StFmsTriggerMaker found\n"); return kStErr;}
271 
272  //unsigned int detmask=td->getTrgDetMask();
273  unsigned int cratemask=td->getTrgCrateMask();
274  //printf("TrgDetMask=%8x TrgCrateMask=%8x\n",detmask,cratemask);
275  //if((cratemask>>FMS_CONF_NUM) & 0x1) printf("FMS ");
276  //if((cratemask>>QT1_CONF_NUM) & 0x1) printf("QT1 ");
277  //if((cratemask>>QT2_CONF_NUM) & 0x1) printf("QT2 ");
278  //if((cratemask>>QT3_CONF_NUM) & 0x1) printf("QT3 ");
279  //if((cratemask>>QT4_CONF_NUM) & 0x1) printf("QT4 ");
280  //printf("\n");
281  if(! (cratemask>>FMS_CONF_NUM) & 0x1) return kStOK;
282  if(! (cratemask>>QT1_CONF_NUM) & 0x1) return kStOK;
283  if(! (cratemask>>QT2_CONF_NUM) & 0x1) return kStOK;
284  if(! (cratemask>>QT3_CONF_NUM) & 0x1) return kStOK;
285  if(! (cratemask>>QT4_CONF_NUM) & 0x1) return kStOK;
286 
287  static int dbc0 = -999;
288  unsigned long long bxinghi,bxing1,bxinglo,bx,bxdiff;
289  bxinghi = td->bcData(3);
290  bxing1 = td->bcData(10);
291  bxinglo = (bxing1 << 16) + td->bcData(11);
292  bx = (bxinghi << 32) + bxinglo;
293  int bunchid7 = td->bunchId7Bit();
294  int bunchid48 = td->bunchId48Bit();
295  if(bx%120 != bunchid48)
296  printf("BC48 check : (BX from BCdata)\%120=%d is not consistent with bunchId48Bit=%d\n",bx%120,bunchid48);
297  int dbc = bunchid7-bunchid48;
298  if(dbc<0) dbc+=120;
299  if(dbc0==-999) dbc0=dbc;
300  int dd=dbc-dbc0;
301  int bc48c=bunchid48+dbc0; if(bc48c<0) bc48c+=120; if(bc48c>119)bc48c-=120;
302  if(dd!=0)
303  printf("BC7: bc7=%3d bc48%120=%3d bc48corr=%3d D=%3d D0=%3d DD=%3d BC48=%llx\n",bunchid7,bunchid48,bc48c,dbc,dbc0,dd,bx);
304  //if(td->bcData(1)>0)
305  if(td->bcData(12)&0x1==1 && bunchid7!=1) {
306  //if(bunchid7<4 || bunchid7>117)
307  printf("Revtick : bc7=%3d %3d RT1=%x %x %x %x %x %x RT2=%1d BC48=%llx\n",
308  bunchid7,td->bcData(2)&0x7f,
309  td->bcData(1),
310  td->bcData(0),
311  td->bcData(4),
312  td->bcData(5),
313  td->bcData(6),
314  td->bcData(7),
315  td->bcData(12)&0x1,bx);
316  }
317 
318  //FMS=td->getDsm_FMS();
319  //for(int i=0; i<8; i++) {FP201[i]=td->fpdLayer2DSMRaw(i);} // printf("FP201 %d %d\n",i,td->fpdLayer2DSMRaw(i));}
320  TCU = td->lastDSM(5);
321  NPRE=td->numberOfPreXing();
322  NPOST=td->numberOfPostXing();
323 
324  //QT -> layer0
325  for(int t1=0; t1<MAXT; t1++){ //data xing loop
326  int x1=t1-MAXPP;
327  if(-x1>NPRE || x1>NPOST) continue;
328  for(int t2=0; t2<MAXT; t2++){ //sim xing loop
329  int x2=t2-MAXPP;
330  if(-x2>NPRE || x2>NPOST) continue;
331  Comp0("QT1/DCBA=>FM001",0,1,t1,t2,mRun);
332  Comp0("QT2/DCBA=>FM002",1,2,t1,t2,mRun);
333  Comp0("QT3/DCBA=>FM003",3,3,t1,t2,mRun);
334  Comp0("QT4/DCBA=>FM004",4,4,t1,t2,mRun);
335  Comp0("QT1/JIHG=>FM005",6,5,t1,t2,mRun);
336  Comp0("QT1/FE =>FM006",7,6,t1,t2,mRun);
337  Comp0("QT2/JIHG=>FM007",8,7,t1,t2,mRun);
338  Comp0("QT2/FE =>FM008",9,8,t1,t2,mRun);
339  Comp0("QT3/JIHG=>FM009",11,9,t1,t2,mRun);
340  Comp0("QT3/FE =>FM010",12,10,t1,t2,mRun);
341  Comp0("QT4/JIHG=>FM011",13,11,t1,t2,mRun);
342  Comp0("QT4/FE =>FM012",14,12,t1,t2,mRun);
343 
344  //Layer0->Layer1
345  Comp1("FM001/2 =>FM101", 2,1,t1,t2,mRun);
346  Comp1("FM003/4 =>FM102", 5,2,t1,t2,mRun);
347  Comp1("FM005/8 =>FM103",10,3,t1,t2,mRun);
348  Comp1("FM09/12 =>FM104",15,4,t1,t2,mRun);
349 
350  //Layer1->Layer2
351  if(t1==MAXPP) Comp2("FM101/4 =>FP201",t2,mRun);
352 
353  //Layer2->TCU
354  if(t1==MAXPP && t2==MAXPP) Comp3("FP201 =>TCU",mRun);
355  }
356  }
357  PRINTLEVEL--;
358  return kStOk;
359 }
360 
void Clear(Option_t *option="")
User defined functions.
Definition: TCU.hh:18
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:40
Definition: Stypes.h:44
Definition: Stypes.h:41