StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsTrgQaMaker.cxx
1 #include "StFmsTrgQaMaker.h"
2 #include "StFmsTriggerMaker.h"
3 #include "StTriggerData.h"
4 
5 static const char* BSname[68]={
6  "ST_A","ST_B","ST_BC","ST_C","ST_CD","ST_D",
7  "SM_DD",
8  "SB_D","SB_CD","SB_C","SB_BC","SB_B","SB_A",
9  "NB_A","NB_B","NB_BC","NB_C","NB_CD","NB_D",
10  "NM_DD",
11  "NT_D","NT_CD","NT_C","NT_BC","NT_B","NT_A",
12  "ST_E","ST_EF","ST_F","ST_G","ST_GH","ST_H","ST_HI","ST_I","ST_IJ","ST_J",
13  "SM_JJ",
14  "SB_J","SB_IJ","SB_I","SB_HI","SB_H","SB_GH","SB_G","SB_F","SB_EF","SB_E",
15  "NB_E","NB_EF","NB_F","NB_G","NB_GH","NB_H","NB_HI","NB_I","NB_IJ","NB_J",
16  "NM_JJ",
17  "NT_J","NT_IJ","NT_I","NT_HI","NT_H","NT_GH","NT_G","NT_F","NT_EF","NT_E"};
18 
19 static const char* JPname[6]={"STop","SMid","SBot","NBot","NMid","NTop"};
20 
21 static const int BSGRP[68]={0,1,1,1,1,1,
22  1,
23  1,1,1,1,1,2,
24  3,4,4,4,4,4,
25  4,
26  4,4,4,4,4,5,
27  6,6,7,7,7,7,7,7,7,7,
28  7,
29  7,7,7,7,7,7,7,7,8,8,
30  9,9,10,10,10,10,10,10,10,10,
31  10,
32  10,10,10,10,10,10,10,10,11,11};
33 
34 inline int bt(int x, int pos) { return x >> pos & 1; }
35 
36 ClassImp(StFmsTrgQaMaker);
37 
38 StFmsTrgQaMaker::StFmsTrgQaMaker(const char* name): StMaker(name), mRun(0), mPrint(0) {}
39 
40 void StFmsTrgQaMaker::Clear(Option_t* option){}
41 
42 int StFmsTrgQaMaker::Init(){
43  int yday=mRun/1000;
44  sprintf(mFilename,"%d/fmstrg.%d.root",yday,mRun);
45  printf("StFpsQaMaker::Init - Opening %s\n",mFilename);
46  mFile=new TFile(mFilename,"RECREATE");
47  mBS[0]=new TH1F("BS3","BS3",NBS,0.0,float(NBS));
48  mBS[1]=new TH1F("BS2","BS2",NBS,0.0,float(NBS));
49  mBS[2]=new TH1F("BS1","BS1",NBS,0.0,float(NBS));
50  mJP[0]=new TH1F("JP2","JP2",NJP,0.0,float(NJP));
51  mJP[1]=new TH1F("JP1","JP1",NJP,0.0,float(NJP));
52  mJP[2]=new TH1F("JP0","JP0",NJP,0.0,float(NJP));
53  mDIBSg=new TH2F("DiBSg","DiBSg",NBSG,0.0,float(NBSG),NBSG,0.0,float(NBSG));
54  mDIBS=new TH2F("DiBS","DiBS",NBS,0.0,float(NBS),NBS,0.0,float(NBS));
55  mDIJP=new TH2F("DiJP","DiJP",NJP,0.0,float(NJP),NJP,0.0,float(NJP));
56  for(int i=0; i<NBS; i++){ hBS[i]=new TH1F(BSname[i],BSname[i],256,0.0,4096.0); }
57  for(int i=0; i<NJP; i++){ hJP[i]=new TH1F(JPname[i],JPname[i],64,0.0,256.0); }
58  readtrgid();
59  return kStOk;
60 }
61 
63  printf("Nevent=%d NFMStriggeredEvent=%d NFSMtrg=%d overlap=%f\n",
64  count[0],count[1],count[2],float(count[2])/float(count[1]));
65  mFile->Write();
66  mFile->Close();
67  printf("StFmsTrgQaMaker::Finish - Closing %s\n",mFilename);
68  return kStOK;
69 }
70 
72  mSIM=(StFmsTriggerMaker*)GetMaker("fmstrigger");
73  if(!mSIM) { printf("No StFmsTriggerMaker found\n"); return kStErr;}
74  mTrgd=(StTriggerData*)GetDataSet("StTriggerData")->GetObject();
75  if(!mTrgd) { printf("No StTriggerData found\n"); return kStErr;}
76 
77  int npre=mTrgd->numberOfPreXing();
78  int npost=mTrgd->numberOfPostXing();
79  //printf("Npre/Npost=%2d/%2d ",npre,npost); printTriggers();
80 
81  countOverlap();
82  if(isTrg("FMS-LED")) return kStOK;
83  fillBS();
84  fillJP();
85  fillBSsum();
86  fillJPsum();
87  fillDiBS();
88  fillDiJp();
89  return kStOK;
90 }
91 
92 void StFmsTrgQaMaker::fillDiBS(){
93  if(isTrg("FMS-DiBS")){
94  char BSbit[NBS];
95  memset(BSbit,0,sizeof(BSbit));
96  int k=-1, i=2;
97  for(int j=0; j<6; j++){ k++; if(bt(mSIM->FM0xxuserdata( 1,i+7),j)) {BSbit[k]=1;}}
98  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 1,i+7),j)) {BSbit[k]=1;}}
99  for(int j=5; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 2,i+7),j)) {BSbit[k]=1;}}
100 
101  for(int j=0; j<6 ; j++){ k++; if(bt(mSIM->FM0xxuserdata( 4,i+7),j)) {BSbit[k]=1;}}
102  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 2,i+7),j)) {BSbit[k]=1;}}
103  for(int j=5; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 3,i+7),j)) {BSbit[k]=1;}}
104 
105  for(int j=0; j<3; j++){ k++; if(bt(mSIM->FM0xxuserdata( 6,i+7),j)) {BSbit[k]=1;}}
106  for(int j=0; j<7; j++){ k++; if(bt(mSIM->FM0xxuserdata( 5,i+7),j)) {BSbit[k]=1;}}
107  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 3,i+7),j)) {BSbit[k]=1;}}
108  for(int j=6; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 7,i+7),j)) {BSbit[k]=1;}}
109  for(int j=2; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 8,i+7),j)) {BSbit[k]=1;}}
110 
111  for(int j=0; j<3; j++){ k++; if(bt(mSIM->FM0xxuserdata(12,i+7),j)) {BSbit[k]=1;}}
112  for(int j=0; j<7; j++){ k++; if(bt(mSIM->FM0xxuserdata(11,i+7),j)) {BSbit[k]=1;}}
113  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 4,i+7),j)) {BSbit[k]=1;}}
114  for(int j=6; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 9,i+7),j)) {BSbit[k]=1;}}
115  for(int j=2; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata(10,i+7),j)) {BSbit[k]=1;}}
116 
117  union u_t{
118  int INT[36];
119  char DBS[NBSG][NBSG];
120  } u;
121  for(int i=0; i<36; i++) u.INT[i]=mSIM->FP201userdata(10+i);
122  for(int j=0; j<NBSG; j++){
123  if(mPrint) printf("** DiBSg ");
124  for(int i=0; i<NBSG; i++){
125  if(mPrint) printf(" %1s", u.DBS[j][i]?"1":"0");
126  if(u.DBS[j][i]) {
127  float w=1.0;
128  if(i==7 && j==10) w=0.2;
129  mDIBSg->Fill(float(i),float(NBSG-j-1),w);
130  //printf("BSbit=");
131  for(int jj=0; jj<NBS; jj++){
132  //printf("%1d",BSbit[jj]); if(BSGRP[jj]!=BSGRP[jj+1]) printf(" ");}
133  if(BSGRP[jj]==j && BSbit[jj]==1){
134  for(int ii=0; ii<NBS; ii++){
135  if(BSGRP[ii]==i && BSbit[ii]==1){
136  mDIBS->Fill(float(ii),float(NBS-jj-1));
137  }
138  }
139  }
140  }
141  //printf("\n");
142  }
143  }
144  if(mPrint) printf("\n");
145  }
146  }
147 }
148 
149 void StFmsTrgQaMaker::fillDiJp(){
150  if(isTrg("FMS-DiJP")){
151  union u_t{
152  int INT[9];
153  char DJp[NJP][NJP];
154  } u;
155  for(int i=0; i<9; i++) u.INT[i]=mSIM->FP201userdata(50+i);
156  for(int j=0; j<NJP; j++){
157  if(mPrint) printf("** DiJp ");
158  for(int i=0; i<NJP; i++){
159  if(mPrint) printf(" %1s", u.DJp[j][i]?"1":"0");
160  if(u.DJp[j][i]) mDIJP->Fill(float(i),float(NJP-j-1));
161  }
162  if(mPrint) printf("\n");
163  }
164  }
165 }
166 
167 void StFmsTrgQaMaker::fillJP(){
168  char trg[20];
169  for(int i=0; i<NTHR; i++){
170  sprintf(trg,"FMS-JP%1d",2-i);
171  if(isTrg(trg)){
172  for(int j=0; j<NJP; j++){
173  int b= ((mSIM->FP201userdata(i+7)) >> j) & 0x1;
174  if(b) mJP[i]->Fill(float(j));
175  }
176  }
177  }
178 }
179 
180 void StFmsTrgQaMaker::fillBS(){
181  char trg[20];
182  int k;
183  for(int i=0; i<NTHR; i++){
184  sprintf(trg,"FMS-sm-bs%1d",3-i);
185  if(isTrg(trg)){
186  k=-1;
187  for(int j=0; j<6; j++){ k++; if(bt(mSIM->FM0xxuserdata( 1,i+7),j)) {mBS[i]->Fill(float(k));}}
188  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 1,i+7),j)) {mBS[i]->Fill(float(k));}}
189  for(int j=5; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 2,i+7),j)) {mBS[i]->Fill(float(k));}}
190 
191  for(int j=0; j<6 ; j++){ k++; if(bt(mSIM->FM0xxuserdata( 4,i+7),j)) {mBS[i]->Fill(float(k));}}
192  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 2,i+7),j)) {mBS[i]->Fill(float(k));}}
193  for(int j=5; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 3,i+7),j)) {mBS[i]->Fill(float(k));}}
194  }
195 
196  sprintf(trg,"FMS-lg-bs%1d",3-i);
197  if(isTrg(trg)){
198  k=25;
199  for(int j=0; j<3; j++){ k++; if(bt(mSIM->FM0xxuserdata( 6,i+7),j)) {mBS[i]->Fill(float(k));}}
200  for(int j=0; j<7; j++){ k++; if(bt(mSIM->FM0xxuserdata( 5,i+7),j)) {mBS[i]->Fill(float(k));}}
201  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 3,i+7),j)) {mBS[i]->Fill(float(k));}}
202  for(int j=6; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 7,i+7),j)) {mBS[i]->Fill(float(k));}}
203  for(int j=2; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 8,i+7),j)) {mBS[i]->Fill(float(k));}}
204 
205  for(int j=0; j<3; j++){ k++; if(bt(mSIM->FM0xxuserdata(12,i+7),j)) {mBS[i]->Fill(float(k));}}
206  for(int j=0; j<7; j++){ k++; if(bt(mSIM->FM0xxuserdata(11,i+7),j)) {mBS[i]->Fill(float(k));}}
207  for(int j=0; j<1; j++){ k++; if(bt(mSIM->FM1xxuserdata( 4,i+7),j)) {mBS[i]->Fill(float(k));}}
208  for(int j=6; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata( 9,i+7),j)) {mBS[i]->Fill(float(k));}}
209  for(int j=2; j>=0; j--){ k++; if(bt(mSIM->FM0xxuserdata(10,i+7),j)) {mBS[i]->Fill(float(k));}}
210  }
211  }
212 }
213 
214 void StFmsTrgQaMaker::fillJPsum(){
215  int sum[NJP];
216  sum[ 0]=mSIM->FP201userdata(0);
217  sum[ 1]=mSIM->FP201userdata(1);
218  sum[ 2]=mSIM->FP201userdata(2);
219  sum[ 3]=mSIM->FP201userdata(3);
220  sum[ 4]=mSIM->FP201userdata(4);
221  sum[ 5]=mSIM->FP201userdata(5);
222  for(int i=0; i<NJP; i++){
223  hJP[i]->Fill(float(sum[i]));
224  }
225  return;
226 }
227 
228 void StFmsTrgQaMaker::fillBSsum(){
229  int sum[NBS];
230  sum[ 0]=mSIM->FM0xxuserdata( 1,0); //ST-A
231  sum[ 1]=mSIM->FM0xxuserdata( 1,1); //ST-B
232  sum[ 2]=mSIM->FM0xxuserdata( 1,2); //ST-BC
233  sum[ 3]=mSIM->FM0xxuserdata( 1,3); //ST-C
234  sum[ 4]=mSIM->FM0xxuserdata( 1,4); //ST-CD
235  sum[ 5]=mSIM->FM0xxuserdata( 1,5); //ST-D
236  sum[ 6]=mSIM->FM1xxuserdata( 1,0); //SM-DD
237  sum[ 7]=mSIM->FM0xxuserdata( 2,5); //SB-D
238  sum[ 8]=mSIM->FM0xxuserdata( 2,4); //SB-CD
239  sum[ 9]=mSIM->FM0xxuserdata( 2,3); //SB-C
240  sum[10]=mSIM->FM0xxuserdata( 2,2); //SB-BC
241  sum[11]=mSIM->FM0xxuserdata( 2,1); //SB-B
242  sum[12]=mSIM->FM0xxuserdata( 2,0); //SB-A
243 
244  sum[13]=mSIM->FM0xxuserdata( 4,0); //NB-A
245  sum[14]=mSIM->FM0xxuserdata( 4,1); //NB-B
246  sum[15]=mSIM->FM0xxuserdata( 4,2); //NB-BC
247  sum[16]=mSIM->FM0xxuserdata( 4,3); //NB-C
248  sum[17]=mSIM->FM0xxuserdata( 4,4); //NB-CD
249  sum[18]=mSIM->FM0xxuserdata( 4,5); //NB-D
250  sum[19]=mSIM->FM1xxuserdata( 2,0); //NM-DD
251  sum[20]=mSIM->FM0xxuserdata( 3,5); //NT-D
252  sum[21]=mSIM->FM0xxuserdata( 3,4); //NT-CD
253  sum[22]=mSIM->FM0xxuserdata( 3,3); //NT-C
254  sum[23]=mSIM->FM0xxuserdata( 3,2); //NT-BC
255  sum[24]=mSIM->FM0xxuserdata( 3,1); //NT-B
256  sum[25]=mSIM->FM0xxuserdata( 3,0); //NT-A
257 
258  sum[26]=mSIM->FM0xxuserdata( 6,0); //ST-E
259  sum[27]=mSIM->FM0xxuserdata( 6,1); //ST-EF
260  sum[28]=mSIM->FM0xxuserdata( 6,2); //ST-F
261  sum[29]=mSIM->FM0xxuserdata( 5,0); //ST-G
262  sum[30]=mSIM->FM0xxuserdata( 5,1); //ST-GH
263  sum[31]=mSIM->FM0xxuserdata( 5,2); //ST-H
264  sum[32]=mSIM->FM0xxuserdata( 5,3); //ST-HI
265  sum[33]=mSIM->FM0xxuserdata( 5,4); //ST-I
266  sum[34]=mSIM->FM0xxuserdata( 5,5); //ST-IJ
267  sum[35]=mSIM->FM0xxuserdata( 5,6); //ST-J
268  sum[36]=mSIM->FM1xxuserdata( 3,0); //SM-JJ
269  sum[37]=mSIM->FM0xxuserdata( 7,6); //SB-J
270  sum[38]=mSIM->FM0xxuserdata( 7,5); //SB-IJ
271  sum[39]=mSIM->FM0xxuserdata( 7,4); //SB-I
272  sum[40]=mSIM->FM0xxuserdata( 7,3); //SB-HI
273  sum[41]=mSIM->FM0xxuserdata( 7,2); //SB-H
274  sum[42]=mSIM->FM0xxuserdata( 7,1); //SB-GH
275  sum[43]=mSIM->FM0xxuserdata( 7,0); //SB-G
276  sum[44]=mSIM->FM0xxuserdata( 8,2); //SB-F
277  sum[45]=mSIM->FM0xxuserdata( 8,1); //SB-EF
278  sum[46]=mSIM->FM0xxuserdata( 8,0); //SB-E
279 
280  sum[47]=mSIM->FM0xxuserdata(12,0); //NB-E
281  sum[48]=mSIM->FM0xxuserdata(12,1); //NB-EF
282  sum[49]=mSIM->FM0xxuserdata(12,2); //NB-F
283  sum[50]=mSIM->FM0xxuserdata(11,0); //NB-G
284  sum[51]=mSIM->FM0xxuserdata(11,1); //NB-GH
285  sum[52]=mSIM->FM0xxuserdata(11,2); //NB-H
286  sum[53]=mSIM->FM0xxuserdata(11,3); //NB-HI
287  sum[54]=mSIM->FM0xxuserdata(11,4); //NB-I
288  sum[55]=mSIM->FM0xxuserdata(11,5); //NB-IJ
289  sum[56]=mSIM->FM0xxuserdata(11,6); //NB-J
290  sum[57]=mSIM->FM1xxuserdata( 4,0); //NM-JJ
291  sum[58]=mSIM->FM0xxuserdata( 9,6); //NT-J
292  sum[59]=mSIM->FM0xxuserdata( 9,5); //NT-IJ
293  sum[60]=mSIM->FM0xxuserdata( 9,4); //NT-I
294  sum[61]=mSIM->FM0xxuserdata( 9,3); //NT-HI
295  sum[62]=mSIM->FM0xxuserdata( 9,2); //NT-H
296  sum[63]=mSIM->FM0xxuserdata( 9,1); //NT-GH
297  sum[64]=mSIM->FM0xxuserdata( 9,0); //NT-G
298  sum[65]=mSIM->FM0xxuserdata(10,2); //NT-F
299  sum[66]=mSIM->FM0xxuserdata(10,1); //NT-EF
300  sum[67]=mSIM->FM0xxuserdata(10,0); //NT-E
301  for(int i=0; i<NBS; i++){
302  hBS[i]->Fill(float(sum[i]));
303  }
304 }
305 
306 void StFmsTrgQaMaker::readtrgid(){
307  int i,yearday=mRun/1000;
308  char filename[200],trgn[200];
309  sprintf(filename,"%d/%d.trgid",yearday,mRun);
310  FILE* fp=fopen(filename,"r");
311  if(!fp) {printf("Cannot open %s\n",filename); return; }
312  while(!feof(fp)) {
313  fscanf(fp,"%d %s",&i,trgn);
314  printf("%d %s\n",i,trgn);
315  trgname[i]=trgn;
316  }
317  fclose(fp);
318 }
319 
320 int StFmsTrgQaMaker::isTrg(const char* trgn){
321  int id=-1;
322  unsigned long long one=1;
323  /*
324  printf("l2sum=%x TRG=",mTrgd->l2sum());
325  for(int i=0; i<64; i++){
326  if(mTrgd->l2sum() & (one << i)) printf("%s ",trgname[i].Data());
327  }
328  printf("\n");
329  */
330  for(int i=0; i<64; i++){
331  if( trgname[i].EqualTo(trgn) ) {id=i; break;}
332  }
333  if(id==-1) return 0;
334  unsigned long long flag=(mTrgd->l2sum() & (one << id));
335  //if(flag) printf("Yes triggered by %s\n",trgn);
336  if(flag>0) return 1;
337  return 0;
338 }
339 
340 void StFmsTrgQaMaker::printTriggers(){
341  int id=-1;
342  unsigned long long one=1;
343  printf("l2sum=%16llx TRG=",mTrgd->l2sum());
344  for(int i=0; i<64; i++){
345  if(mTrgd->l2sum() & (one << i)) printf("%s ",trgname[i].Data());
346  }
347  printf("\n");
348  return;
349 }
350 
351 void StFmsTrgQaMaker::countOverlap(){
352  static const int NTRG=11;
353  const char* tname[NTRG]={"FMS-sm-bs1","FMS-sm-bs2","FMS-sm-bs3",
354  "FMS-lg-bs1","FMS-lg-bs2","FMS-lg-bs3",
355  "FMS-JP0","FMS-JP1","FMS-JP2",
356  "FMS-DiBS","FMS-DiJP"};
357  int flag=0;
358  for(int i=0; i<NTRG; i++){
359  if(isTrg(tname[i])) {count[2]++; flag=1;}
360  }
361  if(flag==1) count[1]++;
362  count[0]++;
363 }
364 
void Clear(Option_t *option="")
User defined functions.
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