StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFcsTrgQaMaker.cxx
1 
2 /*
3  *
4  * \class StFcsTrgQaMaker
5  *
6  */
7 
8 #include "StFcsTrgQaMaker.h"
9 
10 #include "StMessMgr.h"
11 //#include "Stypes.h"
12 #include "StEvent/StEventTypes.h"
13 #include "StEvent/StTriggerData.h"
14 #include "StEvent/StFcsCollection.h"
15 #include "StEvent/StFcsHit.h"
16 #include "StEvent/StFcsCluster.h"
17 #include "StFcsDbMaker/StFcsDb.h"
18 #include "StSpinPool/StFcsTriggerSimMaker/StFcsTriggerSimMaker.h"
19 
20 #include "RTS/src/TRG_FCS/fcs_trg_base.h"
21 
22 #include "TH1F.h"
23 #include "TH2F.h"
24 #include "TString.h"
25 #include "TFile.h"
26 
27 #include <string.h>
28 #include <time.h>
29 
30 StFcsTrgQaMaker::StFcsTrgQaMaker(const Char_t* name) : StMaker(name) {};
31 
32 StFcsTrgQaMaker::~StFcsTrgQaMaker(){};
33 
34 Int_t StFcsTrgQaMaker::Init(){
35  mFcsDb = static_cast< StFcsDb*>(GetDataSet("fcsDb"));
36  if(!mFcsDb){
37  LOG_FATAL << "Error finding StFcsDb"<< endm;
38  return kStFatal;
39  }
40  mFcsTrgSimMkr = static_cast< StFcsTriggerSimMaker*>(GetMaker("FcsTrgSim"));
41  if(!mFcsTrgSimMkr){
42  LOG_FATAL << "Error finding StFcsTrgSimMaker"<< endm;
43  return kStFatal;
44  }
45  fcs_trg_base* trg=mFcsTrgSimMkr->getTriggerEmu();
46  if(!trg){
47  LOG_FATAL << "Error finding fcs_trg_base from StFcsTrgSimMaker"<< endm;
48  return kStFatal;
49  }
50 
51  if(mRun>0){
52  int yday=mRun/1000;
53  sprintf(mFilename,"%d/%d.trgQa.root",yday,mRun);
54  }else if(mFilename==0){
55  char* fname = "fcs.trgqa.root";
56  mFilename=fname;
57  }
58  printf("StFcsTrgQaMaker::Init - Opening %s\n",mFilename);
59  mFile=new TFile(mFilename,"RECREATE");
60 
61  const char* NS[2]={"N","S"};
62  const char* JP[5]={"A","B","C","D","E"};
63 
64  mTow[0] = new TH2F("ETow","Ecal; +-col; -row",22*2+1,-22.5,22.5,34,-34.5,-0.5);
65  mTow[1] = new TH2F("HTow","Hcal; +-col; -row",13*2+1,-13.5,13.5,20,-20.5,-0.5);
66 
67  mETot[0] = new TH1F("ETotN", "ETotN", 256,0,512);
68  mETot[1] = new TH1F("ETotS", "ETotS", 256,0,512);
69  mHTot[0] = new TH1F("HTotN", "HTotN", 256,0,256);
70  mHTot[1] = new TH1F("HTotS", "HTotS", 256,0,256);
71 
72  mEHT[0] = new TH1F("EHTN" ,"MAX EHT", 256,0,256);
73  mEHT[1] = new TH1F("EHTS" ,"MAX EHT", 256,0,256);
74  mEHTMap = new TH2F("EHTMap","MAX E2x2Map",21,-10.5,10.5,16,-16.5,-0.5);
75  mHHT[0] = new TH1F("HHTN" ,"MAX HHT", 256,0,256);
76  mHHT[1] = new TH1F("HHTS" ,"MAX HHT", 256,0,256);
77  mHHTMap = new TH2F("HHTMap","MAX H2x2Map",13,-6.5,6.5,10,-10.5,-0.5);
78 
79  for(int ns=0; ns<2; ns++){
80  for(int j=0; j<5; j++){
81  mJP[ns][j] = new TH1F(Form("JP%1s_%1s",JP[j],NS[ns]),
82  Form("JP%1s_%1s",JP[j],NS[ns]),256,0,512);
83  }
84  }
85  mJPMap[0] = new TH1F("JP2",Form("JP2 THR A=%d,BC=%d,DE=%d",trg->JPATHR2,trg->JPBCTHR2,trg->JPDETHR2),11,-5.5,5.5);
86  mJPMap[1] = new TH1F("JP1",Form("JP1 THR A=%d,BC=%d,DE=%d",trg->JPATHR1,trg->JPBCTHR1,trg->JPDETHR1),11,-5.5,5.5);
87  mJPMap[2] = new TH1F("JP0",Form("JP0 THR A=%d,BC=%d,DE=%d",trg->JPATHR0,trg->JPBCTHR0,trg->JPDETHR0),11,-5.5,5.5);
88 
89  mE4x4 = new TH1F("E4x4", "MAX E4x4", 256,0,256);
90  mEM4x4 = new TH1F("EM4x4", "MAX EM4x4", 256,0,256);
91  mELE4x4 = new TH1F("ELE4x4", "MAX ELE4x4", 256,0,256);
92  mERatio = new TH1F("EMRatio", "MAX EM Ratio=E/(E+Hmax)", 64,0,1.05);
93  mELERatio = new TH1F("ELERatio","MAX ELE Ratio=E/(E+Hmax)", 64,0,1.05);
94 
95  mH4x4 = new TH1F("H4x4", "MAX H4x4", 256,0,256);
96  mEH4x4 = new TH1F("EH4x4", "MAX E+H4x4", 256,0,256);
97  mHAD4x4 = new TH1F("HAD4x4", "MAX Had4x4", 256,0,256);
98  mHRatio = new TH1F("HRatio", "MAX E+H Ratio=E/(E+H)", 64,0,1.05);
99  mHADRatio = new TH1F("HADRatio","MAX Had Ratio=E/(E+H)", 64,0,1.05);
100 
101  mE4x4Map[0] = new TH2F("EM4x4MapEM2", Form("EM EM2=%d",trg->EMTHR2), 19,-9.5,9.5,15,-15.5,-0.5);
102  mE4x4Map[1] = new TH2F("EM4x4MapEM1", Form("EM EM1=%d",trg->EMTHR1), 19,-9.5,9.5,15,-15.5,-0.5);
103  mE4x4Map[2] = new TH2F("EM4x4MapEM0", Form("EM EM0=%d",trg->EMTHR0), 19,-9.5,9.5,15,-15.5,-0.5);
104  mE4x4Map[3] = new TH2F("EM4x4MapELE2", Form("EM ELE2=%d",trg->ELETHR2),19,-9.5,9.5,15,-15.5,-0.5);
105 
106  mELE4x4Map[0] = new TH2F("ELE4x4MapELE2",Form("ELE ELE2=%d",trg->ELETHR2), 19,-9.5,9.5,15,-15.5,-0.5);
107  mELE4x4Map[1] = new TH2F("ELE4x4MapELE1",Form("ELE ELE1=%d",trg->ELETHR1), 19,-9.5,9.5,15,-15.5,-0.5);
108 
109  mEH4x4Map[0] = new TH2F("EHMapHAD2", Form("E+H HAD2=%d",trg->HADTHR2), 19,-9.5,9.5,15,-15.5,-0.5);
110  mEH4x4Map[1] = new TH2F("EHMapHAD1", Form("E+H HAD1=%d",trg->HADTHR1), 19,-9.5,9.5,15,-15.5,-0.5);
111  mEH4x4Map[2] = new TH2F("EHMapHAD0", Form("E+H HAD0=%d",trg->HADTHR0), 19,-9.5,9.5,15,-15.5,-0.5);
112 
113  mDsmOut = new TH1F("DsmOut","DsmOut",33,0,33);
114  mDepOut = new TH1F("DepOut","DepOut",33,0,33);
115  mTcuBit = new TH1F("TcuBit","TcuBit",33,0,33);
116  mTcuDep = new TH1F("TcuDep","TcuDepMismatch",33,0,33);
117  mSimDep = new TH1F("SimDep","SimDepMismatch",33,0,33);
118 
119  const float maxadc=500;
120  mAdc[0]=new TH2F("EN_Id_Adc","EcalNorth; Id; ADC",mFcsDb->maxId(0),0.0,mFcsDb->maxId(0),500,0.0,maxadc);
121  mAdc[1]=new TH2F("ES_Id_Adc","EcalSouth; Id; ADC",mFcsDb->maxId(1),0.0,mFcsDb->maxId(1),500,0.0,maxadc);
122  mAdc[2]=new TH2F("HN_Id_Adc","HcalNorth; Id; ADC",mFcsDb->maxId(2),0.0,mFcsDb->maxId(2),500,0.0,maxadc);
123  mAdc[3]=new TH2F("HS_Id_Adc","HcalSouth; Id; ADC",mFcsDb->maxId(3),0.0,mFcsDb->maxId(3),500,0.0,maxadc);
124  mAdc[4]=new TH2F("PN_Id_Adc","PresNorth; Id; ADC",mFcsDb->maxId(4),0.0,mFcsDb->maxId(4),500,0.0,maxadc);
125  mAdc[5]=new TH2F("PS_Id_Adc","PresSouth; Id; ADC",mFcsDb->maxId(5),0.0,mFcsDb->maxId(5),500,0.0,maxadc);
126 
127  return kStOK;
128 };
129 
131  fcs_trg_base* trg=mFcsTrgSimMkr->getTriggerEmu();
132  if(!trg){
133  LOG_FATAL << "Error finding fcs_trg_base from StFcsTrgSimMaker"<< endm;
134  return kStFatal;
135  }
136 
137  //Getting StEvent and FcsCollection
138  StEvent* event=0;
139  event = static_cast<StEvent*>(GetInputDS("StEvent"));
140 
141  StFcsCollection *fcs = 0;
142  if(!event) {
143  LOG_INFO << "No StEvent found" << endm;
144  }else{
145  fcs=event->fcsCollection();
146  }
147  if(!fcs){
148  LOG_INFO << "No StFcsCollection found" << endm;
149  return kStErr;
150  }
151  if(fcs->isDataExist()==0) {
152  LOG_INFO << "No FCS data in this event" << endm;
153  return kStOk;
154  }
155  //Getting Trigger Data
156  StTriggerData* trgd = event->triggerData();
157  if(!trgd){
158  TObjectSet *os = (TObjectSet*)GetDataSet("StTriggerData");
159  if(os){
160  trgd = (StTriggerData*)os->GetObject();
161  if(trgd){
162  //LOG_INFO << "got StTriggerData addr="<<trgd<<endm;
163  }else{
164  LOG_ERROR << "could not get StTriggerData from DataSet."<<endm;
165  return kStErr;
166  }
167  }else{
168  LOG_ERROR << "could not get StTriggerData DataSet."<<endm;
169  return kStErr;
170  }
171  }
172  unsigned int tcubit = trgd->lastDSM(2) + (trgd->lastDSM(5)<<16);
173 
174  //TCU bits
175  for(int i=0; i<32; i++) if((tcubit >> i) & 0x1) mTcuBit->Fill(i);
176 
177  //DSM out
178  unsigned int dsmout=trg->dsmout;
179  for(int i=0; i<32; i++) if((dsmout >> i) & 0x1) mDsmOut->Fill(i);
180  mDsmOut->Fill(32);
181 
182  //DEP out
183  int depout=0;
184  int det=6; //access DEPIO
185  int nhit=fcs->numberOfHits(det);
186  StSPtrVecFcsHit& hits = fcs->hits(det);
187  //printf("DEP TRG data n = %d\n",nhit);
188  for (int i=0; i<nhit; i++){
189  int ehp = hits[i]->ehp();
190  int ns = hits[i]->ns();
191  int dep = hits[i]->dep();
192  int ch = hits[i]->channel();
193  if(ehp!=3) continue; //DEPIO boards only
194  if(dep==0 && (ch==4 || ch==5) ){ //stage3 DEP to TCU
195  int ntb = hits[i]->nTimeBin();
196  for(int j=0; j<ntb; j++){
197  int adc = hits[i]->adc(j);
198  unsigned short tb = hits[i]->timebin(j);
199  //printf("DEPIO3 data = ehp%1d ns%1d dep%2d ch%2d tb%3d 0x%x\n",ehp,ns,dep,ch,tb,adc);
200  if(tb!=mS3off) continue;
201  if(ch==4) depout += adc;
202  if(ch==5) depout += (adc << 8);
203  }
204  }
205  if(dep==1 && ch==36){ //stage2 north/south DEP to TCU
206  int ntb = hits[i]->nTimeBin();
207  for(int j=0; j<ntb; j++){
208  int adc = hits[i]->adc(j);
209  unsigned short tb = hits[i]->timebin(j);
210  //printf("DEPIO2 data = ehp%1d ns%1d dep%02d ch%02d tb%03d 0x%x\n",ehp,ns,dep,ch,tb,adc);
211  if(tb!=mS2off) continue;
212  if(ns==0) depout += (adc&0xff) << 16;
213  if(ns==1) depout += (adc&0xff) << 24;
214  }
215  }
216  }
217  for(int i=0; i<32; i++) if((depout >> i) & 0x1) mDepOut->Fill(i);
218 
219  const char* BIT[32]={"HAD0","HAD1","HAD2",
220  "EM0","EM1","EM2",
221  "JP2","JPA1","JPBC1","JPDE1","JPA0","JPBC0","JPDE0",
222  "DiJP","DiJPAsy","DiELEA",
223  "ELE0-N","ELE1-N","ELE2-N","EM3-N","EHT-N","HHT-N","ETOT-N","HTOT-N",
224  "ELE0-S","ELE1-S","ELE2-S","EM3-S","EHT-S","HHT-S","ETOT-S","HTOT-S"};
225  if(GetDebug()){
226  LOG_INFO << Form("FCSBits SIM = %08x ",dsmout);
227  for(int i=0; i<32; i++){ if((dsmout>>i)&1) {LOG_INFO << BIT[i] << " ";} } LOG_INFO<<endm;
228  LOG_INFO << Form("FCSBits DEP = %08x ",depout);
229  for(int i=0; i<32; i++){ if((depout>>i)&1) {LOG_INFO << BIT[i] << " ";} } LOG_INFO<<endm;
230  LOG_INFO << Form("FCSBits TCU = %08x ",tcubit);
231  for(int i=0; i<32; i++){ if((tcubit>>i)&1) {LOG_INFO << BIT[i] << " ";} } LOG_INFO<<endm;
232  }
233 
234  //Mismatch
235  LOG_INFO << Form("FCSBitsMM DEP-TCU Mismatch ");
236  for(int i=0; i<32; i++) if(((depout>> i)&1) != ((tcubit>>i)&1)) {mTcuDep->Fill(i); LOG_INFO << BIT[i] << " ";}
237  LOG_INFO<<endm;
238  LOG_INFO << Form("FCSBitsMM SIM-DEP Mismatch ");
239  for(int i=0; i<32; i++) if(((dsmout >>i)&1) != ((depout>>i)&1)) {mSimDep->Fill(i); LOG_INFO << BIT[i] << " ";}
240  LOG_INFO<<endm;
241 
242  //Tower
243  for(int det=0; det<4; det++){
244  int nhit=fcs->numberOfHits(det);
245  StSPtrVecFcsHit& hits = fcs->hits(det);
246  for (int i=0; i<nhit; i++){
247  int id = hits[i]->id();
248  int ehp = hits[i]->ehp();
249  int ns = hits[i]->ns();
250  int c = mFcsDb->getColumnNumber(det,id);
251  int r = mFcsDb->getRowNumber(det,id);
252  float cc = c * (ns*2-1);
253  float rr = - r;
254  mTow[ehp]->Fill(cc,rr,hits[i]->energy());
255  }
256  }
257 
258  unsigned int max;
259  int maxns,maxc,maxr;
260  int maxns2,maxc2,maxr2;
261  int maxns3,maxc3,maxr3;
262  int maxns4,maxc4,maxr4;
263  int maxns5,maxc5,maxr5;
264  //Ecal HT 2x2
265  for(int ns=0; ns<kFcsNorthSouth; ns++){
266  max=0;
267  for(int c=0; c<kFcsEcal4x4NCol+1; c++){
268  for(int r=0; r<kFcsEcal4x4NRow+1; r++){
269  if(trg->e2x2[ns][r][c]>max){ //find max Ecal 2x2
270  max=trg->e2x2[ns][r][c]; maxr=r; maxc=c;
271  }
272  }
273  }
274  if(max>0){
275  mEHT[ns]->Fill(max);
276  mEHTMap->Fill((maxc+1)*(ns*2-1),-maxr-1);
277  }
278  }
279 
280  //Hcal HT 2x2
281  for(int ns=0; ns<kFcsNorthSouth; ns++){
282  max=0;
283  for(int c=0; c<kFcsHcal4x4NCol+1; c++){
284  for(int r=0; r<kFcsHcal4x4NRow+1; r++){
285  if(trg->h2x2[ns][r][c]>max){ //find max Hcal 2x2
286  max=trg->h2x2[ns][r][c]; maxr=r; maxc=c;
287  }
288  }
289  }
290  if(max>0){
291  mHHT[ns]->Fill(max);
292  mHHTMap->Fill((maxc+1)*(ns*2-1),-maxr-1);
293  }
294  }
295 
296  //Ecal Tot
297  mETot[0]->Fill(trg->etot[0]);
298  mETot[1]->Fill(trg->etot[1]);
299 
300  //Hcal Tot
301  mHTot[0]->Fill(trg->htot[0]);
302  mHTot[1]->Fill(trg->htot[1]);
303 
304  //JP
305  for(int ns=0; ns<kFcsNorthSouth; ns++){
306  for(int j=0; j<5; j++){
307  if(trg->jet[ns][j]>max){ //find max JP
308  mJP[ns][j]->Fill(trg->jet[ns][j]);
309  if((trg->d_out.s2[ns].s2_to_s3[0].d[1]>>j)&0x1) mJPMap[0]->Fill((j+1)*(ns*2-1));
310  if((trg->d_out.s2[ns].s2_to_s3[1].d[1]>>j)&0x1) mJPMap[1]->Fill((j+1)*(ns*2-1));
311  if((trg->d_out.s2[ns].s2_to_s3[0].d[2]>>j)&0x1) mJPMap[2]->Fill((j+1)*(ns*2-1));
312  }
313  }
314  }
315 
316  //Ecal 4x4
317  for(int ns=0; ns<kFcsNorthSouth; ns++){
318  max=0;
319  int emmax=0, elemax=0, summax=0, hadmax=0;
320  for(int c=0; c<kFcsEcal4x4NCol; c++){
321  for(int r=0; r<kFcsEcal4x4NRow; r++){
322  int esum=trg->esum[ns][r][c];
323  int sum=trg->sum[ns][r][c];
324  if(esum>max){ //find max Ecal 4x4
325  max=esum; maxns=ns; maxr=r; maxc=c;
326  }
327  if(esum>emmax && trg->ratiomax[ns][r][c] > 1.0/(1.0+(float)trg->EM_HERATIO_THR/128)){
328  emmax=esum; maxns2=ns; maxr2=r; maxc2=c;
329  }
330  if(esum>elemax && trg->ratiomax[ns][r][c] > 1.0/(1.0+(float)trg->EM_HERATIO_THR/128) && trg->epdcoin[ns][r][c]){
331  elemax=esum; maxns3=ns; maxr3=r; maxc3=c;
332  }
333  if(sum>summax){
334  summax=sum; maxns4=ns; maxr4=r; maxc4=c;
335  }
336  if(sum>hadmax && trg->ratio[ns][r][c] < 1.0/(1.0+(float)trg->HAD_HERATIO_THR/128)){
337  hadmax=sum; maxns5=ns; maxr5=r; maxc5=c;
338  }
339  int cc=(c+1)*(ns*2-1);
340  int rr=-r-1;
341  if(esum > trg->EMTHR2) mE4x4Map[0]->Fill(cc,rr);
342  if(esum > trg->EMTHR1) mE4x4Map[1]->Fill(cc,rr);
343  if(esum > trg->EMTHR0) mE4x4Map[2]->Fill(cc,rr);
344  if(esum > trg->ELETHR2) mE4x4Map[3]->Fill(cc,rr);
345  if(trg->epdcoin[ns][r][c]){
346  if(esum > trg->ELETHR2) mELE4x4Map[0]->Fill(cc,rr);
347  if(esum > trg->ELETHR1) mELE4x4Map[1]->Fill(cc,rr);
348  }
349  if(sum > trg->HADTHR2) mEH4x4Map[0]->Fill(cc,rr);
350  if(sum > trg->HADTHR1) mEH4x4Map[1]->Fill(cc,rr);
351  if(sum > trg->HADTHR0) mEH4x4Map[2]->Fill(cc,rr);
352  }
353  }
354  if(max>0) mE4x4->Fill(max);
355  if(emmax>0) mEM4x4->Fill(emmax);
356  if(elemax>0) mELE4x4->Fill(elemax);
357  if(summax>0) mEH4x4->Fill(summax);
358  if(hadmax>0) mHAD4x4->Fill(summax);
359  if(max>0) mERatio->Fill(trg->ratiomax[maxns][maxr][maxc]);
360  if(elemax>0) mELERatio->Fill(trg->ratiomax[maxns3][maxr3][maxc3]);
361  if(summax>0) mHRatio->Fill(trg->ratio[maxns4][maxr4][maxc4]);
362  if(hadmax>0) mHADRatio->Fill(trg->ratio[maxns5][maxr5][maxc5]);
363  }
364 
365  for(int det=0; det<kFcsNDet; det++){
366  StSPtrVecFcsHit& hits = fcs->hits(det);
367  int nh=fcs->numberOfHits(det);
368  for(int i=0; i<nh; i++) mAdc[det]->Fill(hits[i]->id(),(float)hits[i]->adcSum());
369  }
370 
371  return kStOK;
372 };
373 
375  mFile->Write();
376  mFile->Close();
377  printf("StFcsTrgQaMaker::Finish - Closing %s\n",mFilename);
378  return kStOK;
379 };
380 
381 ClassImp(StFcsTrgQaMaker);
382 
383 /*
384  * $Id: StFcsTrgQaMaker.cxx,v 1.6 2021/05/30 21:41:58 akio Exp $
385  * $Log: StFcsTrgQaMaker.cxx,v $
386  * Revision 1.6 2021/05/30 21:41:58 akio
387  * A lots of update for trigger comissionong Run21 OO200
388  *
389  * Revision 1.5 2021/03/30 13:36:51 akio
390  * change to StSpinPoll for include
391  *
392  * Revision 1.4 2021/03/30 13:31:27 akio
393  * StFcsDbMAker->StFcsDB
394  *
395  * Revision 1.3 2020/07/24 17:21:31 akio
396  * adding hist for DsmOut
397  *
398  * Revision 1.2 2020/06/01 19:34:41 akio
399  * adding normarization histo
400  *
401  * Revision 1.1 2020/05/29 18:59:32 akio
402  * Initial version of FCS Trigger QA maker
403  *
404  *
405  */
virtual Int_t Finish()
int getColumnNumber(int det, int id) const
get the row number for the channel
Definition: StFcsDb.cxx:490
int getRowNumber(int det, int id) const
maximum number of id
Definition: StFcsDb.cxx:485
virtual Int_t Make()
Definition: Stypes.h:40
int maxId(int det) const
number of column
Definition: StFcsDb.cxx:468
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56
Definition: Stypes.h:44
Definition: Stypes.h:41