StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFpsQaMaker.cxx
1 /*
2  *
3  * \class StFpsQaMaker
4  *
5  */
6 
7 #include "StFpsQaMaker.h"
8 
9 #include "StRoot/StEvent/StEvent.h"
10 #include "StRoot/St_base/StMessMgr.h"
11 #include "StRoot/StEvent/StTriggerData.h"
12 #include "StRoot/StEvent/StFmsCollection.h"
13 #include "StRoot/StEvent/StFmsHit.h"
14 #include "StRoot/StFmsDbMaker/StFmsDbMaker.h"
15 #include "StRoot/StSpinPool/StFpsRawDaqReader/StFpsRawDaqReader.h"
16 
17 #include "TH1F.h"
18 #include "TH2F.h"
19 #include "TString.h"
20 #include "TFile.h"
21 #include "TCanvas.h"
22 
23 #include <string.h>
24 #include <time.h>
25 
26 StFpsQaMaker::StFpsQaMaker(const Char_t* name) : StMaker(name),mFmsDbMkr(0),mFmsCollectionPtr(0), mRun(0) {};
27 
28 StFpsQaMaker::~StFpsQaMaker(){};
29 
30 Int_t StFpsQaMaker::Init(){
31  mFmsDbMkr = static_cast< StFmsDbMaker*>(GetMaker("fmsDb"));
32  if(!mFmsDbMkr){
33  LOG_FATAL << "Error finding StFmsDbMaker"<< endm;
34  return kStFatal;
35  }
36  int yday=mRun/1000;
37  sprintf(mFilename,"%d/%d.root",yday,mRun);
38  printf("StFpsQaMaker::Init - Opening %s\n",mFilename);
39  mFile=new TFile(mFilename,"RECREATE");
40  char name[100];
41  mDataSize[0] = new TH1F("TotalSize","TotalSize",100,-1.0,4.0);
42  mDataSize[1] = new TH1F("DataSize","DataSize",100,-1.0,3.0);
43  for(int i=0; i<mNPREPOST*2+1; i++){
44  int x=i-mNPREPOST;
45  sprintf(name,"Xing=%d",x);
46  mXing[i] = new TH1F(name,name,100,0.0,300.0);
47  }
48  if(mPed==0){
49  mAdc2[0] = new TH2F("Adc2", "Adc2", 252,0.0,252.0,64,0.0,4096.0);
50  mAdc2[1] = new TH2F("Adc2z","Adc2z",252,0.0,252.0,50,0.0,200.0);
51  for(int i=0; i<mNID; i++){
52  sprintf(name,"ADC%03d",i);
53  mAdc[i][0]=new TH1F(name,name,128,0.0,4096.0);
54  sprintf(name,"ADC%03dz",i);
55  mAdc[i][1]=new TH1F(name,name,150,0.0,300.0);
56  }
57  }else{
58  mAdc2[0] = new TH2F("Adc2", "Adc2", 252,0.0,252.0, 100,64.0,4096.0);
59  mAdc2[1] = new TH2F("Adc2z","Adc2z",252,0.0,252.0, 100,50.0,150.0);
60  for(int i=0; i<mNID; i++){
61  sprintf(name,"ADC%03d",i);
62  mAdc[i][0]=new TH1F(name,name,128,0.0,4096.0);
63  sprintf(name,"ADC%03dz",i);
64  mAdc[i][1]=new TH1F(name,name,100,50.0,150.0);
65  }
66  }
67  for(int q=0; q<mNQ; q++){
68  for(int l=0; l<mNL; l++){
69  sprintf(name,"NHIT_Q%1dL%1d",q+1,l+1);
70  mNHit[q][l]=new TH1F(name,name,22,0.0,22.0);
71  sprintf(name,"HIT_Q%1dL%1d",q+1,l+1);
72  mHit[q][l]=new TH1F(name,name,21,0.5,21.5);
73  }
74  }
75  for(int t=0; t<mNTRG+1; t++){
76  sprintf(name,"NHIT_TRG%02d",t);
77  mNHitTrg[t]=new TH1F(name,name,241,0.0,241.0);
78  }
79  sprintf(name,"NHIT_TRG");
80  mNHitTrg2=new TH2F(name,name,241,0.0,241.0,64,0.0,64.0);
81  return kStOK;
82 };
83 
85  StEvent* eventPtr=0;
86  mFmsCollectionPtr=0;
87 
88  //Getting StFpsRawDaqReader and TriggerData
89  StFpsRawDaqReader* fpsraw=(StFpsRawDaqReader*)GetMaker("daqReader");
90  if(!fpsraw){
91  LOG_ERROR << "Canot find fpsRawDaqReader" << endm;
92  return 0;
93  }
94  StTriggerData* trg = fpsraw->trgdata();
95  if(!trg){
96  LOG_ERROR << "Canot find Trigger Data" << endm;
97  return 0;
98  }
99  //check if FPS was readout for this event
100  unsigned int detmask=trg->getTrgDetMask();
101  //printf("TrgDetMask = %4x\n",detmask);
102  if(! ((detmask >> 10) & 0x1)){
103  //printf("No FPS/FPOST readout for this event\n");
104  return kStOK;
105  }
106 
107  eventPtr= (StEvent*)GetInputDS("StEvent");
108  if(!eventPtr) { LOG_INFO << "No StEvent found" << endm;}
109  else{ mFmsCollectionPtr=eventPtr->fmsCollection();}
110  if(!mFmsCollectionPtr){
111  LOG_INFO << "No StFmsCollection found" << endm;
112  return kStErr;
113  }
114  int nhit=mFmsCollectionPtr->numberOfHits();
115  StSPtrVecFmsHit hits = mFmsCollectionPtr->hits();
116  //printf("StFpsQaMaker found %d hits\n",nhit);
117  int nfpsdata=0;
118  int nfpsdatatot=0;
119  int nh[mNQ][mNL]; memset(nh,0,sizeof(nh));
120  int nhtot=0;
121  for (int i=0; i<nhit; i++){
122  int det = hits[i]->detectorId();
123  if(det==15){
124  nfpsdatatot++;
125  int xing=hits[i]->tdc(); if(xing>65536/2) xing-=65536;
126  int adc=hits[i]->adc();
127  int qt=hits[i]->qtSlot();
128  int ch=hits[i]->qtChannel();
129  int slatid = mFmsDbMkr->fpsSlatidFromQT(qt,ch);
130  int q,l,s;
131  mFmsDbMkr->fpsQLSfromSlatId(slatid,&q,&l,&s);
132  if(q>0 && l>0 && s>0 && abs(xing)<=mNPREPOST) {
133  mXing[xing+mNPREPOST]->Fill((float)adc);
134  if(xing==0){
135  nfpsdata++;
136  mAdc2[0]->Fill((float)slatid,(float)adc);
137  mAdc2[1]->Fill((float)slatid,(float)adc);
138  mAdc[slatid][0]->Fill((float)adc);
139  mAdc[slatid][1]->Fill((float)adc);
140  if( (l!=3 && adc>50) || (l==3 && adc>25) ){
141  nhtot++;
142  nh[q-1][l-1]++;
143  if(l==1 && (q==2 || q==4)){
144  mHit[q-1][l-1]->Fill(float(s+2));
145  }else{
146  mHit[q-1][l-1]->Fill(float(s));
147  }
148  }
149  }
150  }
151  //hits[i]->print();
152  }
153  }
154  mDataSize[0]->Fill(log10(nfpsdatatot));
155  mDataSize[1]->Fill(log10(nfpsdata));
156  for(int q=0; q<mNQ; q++){
157  for(int l=0; l<mNL; l++){
158  mNHit[q][l]->Fill(float(nh[q][l]));
159  }
160  }
161 
162  //total multiplicity by triggers
163  mNHitTrg[64]->Fill(float(nhtot));
164  unsigned long long one=1;
165  unsigned long long tmask = fpsraw->trgMask();
166  for(int t=0; t<mNTRG; t++){
167  if(tmask & (one<<t)) {
168  mNHitTrg[t]->Fill(float(nhtot));
169  mNHitTrg2->Fill(float(nhtot),float(t));
170  }
171  }
172  //printf("NFMSHIT=%4d NFPSHITTOT=%4d NFPSHIT(xing=0)=%d\n",nhit,nfpsdatatot,nfpsdata);
173 
174  unsigned int tcu=trg->tcuCounter();
175  unsigned int rfps=fpsraw->rccFps();
176  unsigned int dfps=rfps-tcu;
177  if(rfps==0){
178  dfps=0;
179  }else if(rfps< tcu){
180  const long long one=1;
181  const long long m=one<<32;
182  long long r=rfps;
183  long long t=tcu;
184  dfps=(unsigned int)(r+m-t);
185  }
186  unsigned int rfpo=fpsraw->rccFpost();
187  unsigned int dfpo=rfpo-tcu;
188  if(rfpo==0){
189  dfpo=0;
190  }else if(rfps < tcu){
191  const long long one=1;
192  const long long m=one<<32;
193  long long r=rfpo;
194  long long t=tcu;
195  dfpo=(unsigned int)(r+m-t);
196  }
197  printf("FPS RCC =%10d TCU=%10d DIFF=%10d ",rfps,tcu,dfps);
198  printf("FPOST RCC=%10d TCU=%10d DIFF=%10d\n",rfpo,tcu,dfpo);
199 
200  return kStOK;
201 };
202 
204  /*
205  mDataSize[0]->Write();
206  mDataSize[1]->Write();
207  for(int i=0; i<mNPREPOST*2+1; i++) mXing[i]->Write();
208  mAdc2->Write();
209  for(int i=0; i<mNID; i++) mAdc[i]->Write();
210  */
211  mFile->Write();
212  mFile->Close();
213  printf("StFpsQaMaker::Finish - Closing %s\n",mFilename);
214  return kStOK;
215 };
216 
217 ClassImp(StFpsQaMaker);
218 
219 /*
220  * $Id: StFpsQaMaker.cxx,v 1.6 2017/02/25 04:43:08 akio Exp $
221  * $Log: StFpsQaMaker.cxx,v $
222  * Revision 1.6 2017/02/25 04:43:08 akio
223  * added checking for trgDetMask for sparse readout (skipping event when FPS was NOT readout)
224  *
225  * Revision 1.5 2017/02/20 19:18:53 akio
226  * added check if we get StFpsRawDawReader
227  *
228  * Revision 1.4 2017/02/18 18:28:21 akio
229  * adding RCC-TCU check
230  *
231  * Revision 1.3 2015/05/30 16:08:00 akio
232  * *** empty log message ***
233  *
234  * Revision 1.2 2015/02/28 02:55:35 akio
235  * fix a bug
236  *
237  * Revision 1.1 2015/02/25 20:03:26 akio
238  * new fps qa maker
239  *
240  */
virtual Int_t Finish()
virtual Int_t Make()
Definition: Stypes.h:40
Definition: Stypes.h:44