StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEqaSorterC.cxx
1 // $Id: EEqaSorterC.cxx,v 1.10 2010/04/09 04:48:33 ogrebeny Exp $
2 #include <stdio.h>
3 #include <assert.h>
4 #include <string.h>
5 #include <stdlib.h>
6 
7 #include <TObjArray.h>
8 #include <TClonesArray.h>
9 
10 #include <TH2.h>
11 #include <TFile.h>
12 #include <TLine.h>
13 #include <TText.h>
14 
15 #include "EEqaSorterC.h"
16 
17 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
18 
19 #include "StEEmcUtil/database/StEEmcDb.h"
20 #include "StEEmcUtil/database/EEmcDbItem.h"
21 
22 //tmp until I find better solution
23 #include "EEqaPresenter.h"
24 // tmp end
25 
26 
27 ClassImp(EEqaSorterC)
28 
29 //-------------------------------------------
31  : TObject()
32  , hMAPMT(0)
33  , adcThrTw(40)
34  , adcThrPrs(200)
35  , adcThrPost(50)
36  , adcThrSmd(100)
37  , eeDb(dbx)
38 {
39  memset(h2D,0,sizeof(h2D));
40  memset(hMult,0,sizeof(hMult));
41  memset(hSmd,0,sizeof(hSmd));
42  memset(hnHSmd,0,sizeof(hnHSmd));
43 }
44 
45 //-------------------------------------------
46 EEqaSorterC::~EEqaSorterC() {
47  for(int i = 0;i < mxh;i++) {
48  if (hMult[i]) delete hMult[i];
49  if (h2D[i]) delete h2D[i];
50  }
51  memset(h2D,0,sizeof(h2D));
52  memset(hMult,0,sizeof(hMult));
53  if (hMAPMT) delete hMAPMT;
54  hMAPMT = 0;
55  for(int iSec = 0;iSec < MaxSectors;iSec++) {
56  for(int pl = 0;pl < MaxSmdPlains;pl++) {
57  if (hSmd[iSec][pl]) delete hSmd[iSec][pl];
58  if (hnHSmd[iSec][pl]) delete hnHSmd[iSec][pl];
59  }
60  }
61  memset(hSmd,0,sizeof(hSmd));
62  memset(hnHSmd,0,sizeof(hnHSmd));
63 }
64 
65 //-------------------------------------------
66 void EEqaSorterC::sort(const EztEmcRawData *t, const EztEmcRawData *s, int ver ) {
67  sortTower(t);
68  sortMapmt(s, ver);
69 }
70 
71 //-------------------------------------------
72 void EEqaSorterC::sortTower(const EztEmcRawData *t){
73  if(!t) return;
74  int nTw=0;
75  for(int icr=0;icr<t->getNBlocks();icr++) {
76  if(t->isCrateVoid(icr)) continue;
77  int crateID=icr+1;
78  const UShort_t* data=t->data(icr);
79  for(int i=0;i<t->sizeData(icr) && i<MaxTwCrateCh;i++) {
80  int chan=i;
81  const EEmcDbItem *x = eeDb ? eeDb->getByCrate(crateID,chan) : 0;
82  if(!x) continue; // noDB info
83  if(x->fail ) continue; // drop broken channels
84  float adc=data[i]-x->ped; // ped subtracted ADC
85  if(adc<adcThrTw) continue;
86  nTw++;
87  int iphi=(x->sec-1)*MaxSubSec+(x->sub-'A');
88  h2D[0]->Fill(iphi,x->eta);
89  } // end of loop over hist
90  }// end of loop over crates
91  hMult[0] ->Fill(nTw);
92 }
93 
94 //-------------------------------------------
95 void EEqaSorterC::sortMapmt(const EztEmcRawData *s, int ver){
96  if(s==0) return;
97  int nHit[mxh], nSmdH[MaxSectors][MaxSmdPlains];
98  memset(nHit,0,sizeof(nHit));
99  memset(nSmdH,0,sizeof(nSmdH));
100 
101  for(int icr=0;icr<s->getNBlocks();icr++) {
102  if(s->isCrateVoid(icr)) continue;
103  int crateID=icr+64;
104  // in 2004 there was only 16 MAPMT crates for sectors 5-8
105  if(ver<0x22) {
106  if(icr>=16) break;
107  crateID=icr+84;
108  }
109  //printf("ddd %d %d\n",icr,crateID);
110  const UShort_t* data=s->data(icr);
111  for(int i=0;i<s->sizeData(icr) && i<MaxMapmtCrateCh;i++) {
112  int chan=i;
113  const EEmcDbItem *x = eeDb ? eeDb->getByCrate(crateID,chan) : 0;
114  if(!x) continue; // noDB info
115  if(x->fail) continue; // drop broken channels
116 
117  float thr=0;
118  char cD=x->name[2];
119  switch(cD) {
120  case 'P':
121  case 'Q': thr=adcThrPrs; break;
122  case 'R': thr=adcThrPost; break;
123  case 'U':
124  case 'V': thr=adcThrSmd; break;
125  default :;
126  }
127  if(thr<=0) continue; // should never happend
128  float adc=data[i]-x->ped; // ped subtracted ADC
129  if(adc<thr) continue;
130  // printf("%d %f =%c= p=%p i=%d ",data[i],adc,cPQR,h,1-cPQR-'P'); x->print();
131 
132  if(x->isSMD()) {
133  int strip=x->strip;
134  int iplane =x->plane-'U';
135  int isec=x->sec-1;
136  hSmd[isec][iplane]->Fill(strip);
137  nSmdH[isec][iplane]++;
138  } else {
139  int ik=1+cD-'P';
140  nHit[ik]++;
141  int iphi=(x->sec-1)*MaxSubSec+(x->sub-'A');
142  h2D[ik]->Fill(iphi,x->eta);
143  }
144  hMAPMT->Fill(crateID,x->mapmtId());
145  }
146  }// end of loop over crates
147 
148  for(int j=1;j<=3;j++) hMult[j]->Fill(nHit[j]);
149 
150  for (int j=0; j<MaxSectors; j++) {
151  for (int pl=0; pl<MaxSmdPlains; pl++) {
152  hnHSmd[j][pl]->Fill(nSmdH[j][pl]);
153  }
154  }
155 }
156 
157 //--------------------------------------------------
158 void EEqaSorterC::initHisto(TObjArray *HList){
159  int i;
160  char tit[500];
161  sprintf (tit, "EEMC Tower hits>ped+%d; phibin : 1TA=0 3TA=10 5TA=20 7TA=30 9TA=40 11TA=50 ; #eta bin ",adcThrTw);
162  h2D[0] = new TH2F("TowHits",tit, 60, -0.5, 59.5, 12, 0.5, 12.5);
163 
164  addJPphiLimits( h2D[0]);
165  //TList *Lx= h2D[0]->GetListOfFunctions();
166 
167  sprintf (tit, "EEMC pres-1 hits>ped+%d; phi bin : 1TA=0 3TA=10 5TA=20 7TA=30 9TA=40 11TA=50 ; #eta bin ",adcThrPrs);
168  h2D[1] = new TH2F("Pre1Hits",tit , 60, -0.5, 59.5, 12, 0.5, 12.5);
169  sprintf (tit, "EEMC pres-2 hits>ped+%d; phi bin: 1TA=0 3TA=10 5TA=20 7TA=30 9TA=40 11TA=50 ; #eta bin ",adcThrPrs);
170  h2D[2] =new TH2F("Pre2Hits",tit , 60, -0.5, 59.5, 12, 0.5, 12.5);
171 
172  sprintf (tit, "EEMC post hits>ped+%d; phi bin : 1TA=0 3TA=10 5TA=20 7TA=30 9TA=40 11TA=50 ; #eta bin ",adcThrPost);
173  h2D[3] = new TH2F("PostHits",tit , 60, -0.5, 59.5, 12, 0.5, 12.5);
174 
175 
176  sprintf (tit, "EEMC # Tower w/ adc>ped+%d; # Towers",adcThrTw);
177  hMult[0] = new TH1F("HTow", tit, 100, -0.5, 99.5);
178 
179  sprintf (tit, "EEMC # Pre-1 w/ adc>ped+%d; # Tiles",adcThrPrs);
180  hMult[1] = new TH1F("HPre1", tit, 100, -0.5, 199.5);
181  sprintf (tit, "EEMC # Pre-2 w/ adc>ped+%d; # Tiles",adcThrPrs);
182  hMult[2] = new TH1F("HPre2", tit, 100, -0.5, 199.5);
183  sprintf (tit, "EEMC # Post w/ adc>ped+%d; # Tiles",adcThrPrs);
184  hMult[3] = new TH1F("HPost", tit, 100, -0.5, 199.5);
185 
186 
187  for(i=0;i<mxh;i++) {
188  if(HList && hMult[i]) HList->Add(hMult[i]);
189  if(HList && h2D[i]) HList->Add(h2D[i]);
190  }
191 
192  hMAPMT= new TH2F("MAPMHits","MAPMT Hits adc>ped+thr; crateID ; tube no.", 48, 63.5, 111.5, 12, 0.5, 12.5);
193  if (HList && hMAPMT) HList->Add(hMAPMT);
194 
195  int iSec;
196  for(iSec=0; iSec<MaxSectors; iSec++) {
197  char cid[50], ctitl[50];
198  int pl;
199  for(pl=0;pl<MaxSmdPlains;pl++) {
200  char uv='U'+pl;
201  sprintf (cid, "SmdA%d%c",iSec+1,uv);
202  sprintf (ctitl, "ESMD %02d%c adc>ped+%02d;"
203  "Strip no.", iSec+1,uv, adcThrSmd);
204  hSmd[iSec][pl] = new TH1F(cid, ctitl, 290, -0.5, 289.5);
205  if (HList && hSmd[iSec][pl]) HList->Add(hSmd[iSec][pl]);
206 
207  sprintf (cid, "HSmd%d%c",iSec+1,uv);
208  sprintf (ctitl, "ESMD %02d%c Hits/eve adc>ped+%d; No. Hits", iSec+1, uv,adcThrSmd);
209  hnHSmd[iSec][pl] = new TH1F(cid, ctitl, 100, -0.5, 99.5);
210  if (HList && hnHSmd[iSec][pl]) HList->Add(hnHSmd[iSec][pl]);
211  }
212  }
213 
214 }
215 
216 //-------------------------------------------
217 void EEqaSorterC::saveHisto(TFile *f) const {
218  if (f) f->cd();
219  for(int i = 0;i < mxh;i++) {
220  if (hMult[i]) hMult[i]->Write();
221  if (h2D[i]) h2D[i]->Write();
222  }
223  if (hMAPMT) hMAPMT->Write();
224  for(int iSec = 0;iSec < MaxSectors;iSec++) {
225  for(int pl = 0;pl < MaxSmdPlains;pl++) {
226  if (hSmd[iSec][pl]) hSmd[iSec][pl]->Write();
227  if (hnHSmd[iSec][pl]) hnHSmd[iSec][pl]->Write();
228  }
229  }
230 }
231 
232 //-------------------------------------------
233 void EEqaSorterC::resetHisto() {
234  for(int i = 0;i < mxh;i++) {
235  if (hMult[i]) hMult[i]->Reset();
236  if (h2D[i]) h2D[i]->Reset();
237  }
238  if (hMAPMT) hMAPMT->Reset();
239  for(int iSec = 0;iSec < MaxSectors;iSec++) {
240  for(int pl = 0;pl < MaxSmdPlains;pl++) {
241  if (hSmd[iSec][pl]) hSmd[iSec][pl]->Reset();
242  if (hnHSmd[iSec][pl]) hnHSmd[iSec][pl]->Reset();
243  }
244  }
245 }
246 
247 //-------------------------------------------
248 void EEqaSorterC::initRun() {
249 }
250 
251 
252 
253 // $Log: EEqaSorterC.cxx,v $
254 // Revision 1.10 2010/04/09 04:48:33 ogrebeny
255 // Added more protection against out-of-boundary errors. See bug report 1903.
256 //
257 // Revision 1.9 2009/04/30 21:20:31 ogrebeny
258 // Improved constness after fixing bug 1457
259 //
260 // Revision 1.8 2009/02/24 18:19:47 ogrebeny
261 // Small workaround until ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1457 is resolved
262 //
263 // Revision 1.7 2009/02/24 04:07:46 ogrebeny
264 // Fixed part of the trigger histograms
265 //
266 // Revision 1.6 2009/02/14 03:16:52 ogrebeny
267 // Updated some histo titles. Removed unnecessary histo Clone() and Delete().
268 //
269 // Revision 1.5 2009/02/04 20:33:26 ogrebeny
270 // Moved the EEMC database functionality from StEEmcDbMaker to StEEmcUtil/database. See ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1388
271 //
272 // Revision 1.4 2009/01/25 01:36:54 ogrebeny
273 // *** empty log message ***
274 //
275 // Revision 1.3 2009/01/23 00:14:50 ogrebeny
276 // Inherited EEmcDb from StEEmcDbMaker to fix run-time bug http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1378
277 //
278 // Revision 1.2 2007/06/01 17:47:05 jml
279 // attempt to fix panitkin plot compile
280 //
281 // Revision 1.1 2005/04/28 20:54:46 balewski
282 // start
283 //
284 // Revision 1.8 2004/03/13 22:03:13 balewski
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
Definition: EEmcDbItem.h:20