StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEqaSorterA.cxx
1 // $Id: EEqaSorterA.cxx,v 1.10 2010/04/09 04:48:33 ogrebeny Exp $
2 #include <string.h>
3 #include <stdlib.h>
4 
5 #include <TObjArray.h>
6 #include <TClonesArray.h>
7 
8 #include <TH2.h>
9 #include <TFile.h>
10 
11 #include <StMessMgr.h>
12 
13 #include "EEqaSorterA.h"
14 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
15 
16 ClassImp(EEqaSorterA)
17 
18 //-------------------------------------------
20  : TObject()
21  , hCrate(0)
22  , hCrateHot(0)
23  , hotTwThres(40)// used to count hot towers
24 {
25  memset(feePed,0,sizeof(feePed)); // clear ped values
26 }
27 
28 //-------------------------------------------
29 EEqaSorterA::~EEqaSorterA() {
30  for(int icr = 0;icr < MaxAnyCrate;icr++) {
31  if (hCrate && hCrate[icr]) delete hCrate[icr];
32  }
33  if (hCrate) delete hCrate;
34  for(int icr = 0;icr < MaxTwCrateID;icr++) {
35  if (hCrateHot && hCrateHot[icr]) delete hCrateHot[icr];
36  }
37  if (hCrateHot) delete hCrateHot;
38 }
39 
40 //-------------------------------------------
41 void EEqaSorterA::sort(const EztEmcRawData *t, const EztEmcRawData *s, int ver) {
42  sortDaqTower1(t);
43  sortDaqMapmt0(s, ver);
44  sortDaqTowerHot(t);
45 }
46 
47 //-------------------------------------------
48 void EEqaSorterA::Finish(){
49 }
50 
51 //-------------------------------------------
52 void EEqaSorterA::sortDaqTower1(const EztEmcRawData *t){
53  /* Goals of this method:
54  make histos of adc vs channel for each tower crate
55  and count ADC values = n*256 in all data blocks
56  */
57  if(!t) return;
58  for(int icr=0;icr<t->getNBlocks() && icr<MaxTwCrateID;icr++) {
59  if(t->isCrateVoid(icr)) continue;
60  int crateID=icr+1;
61  const UShort_t* data=t->data(icr);
62  for(int i=0;i<t->sizeData(icr) && i<MaxTwCrateCh;i++) {
63  int chan=i;
64  float adc=data[i];
65  if (hCrate && hCrate[crateID - 1]) hCrate[crateID - 1]->Fill(adc, chan);
66  }
67  }// end of loop over crates
68 }
69 
70 //-------------------------------------------
71 void EEqaSorterA::sortDaqTowerHot(const EztEmcRawData *t){
72  /* Goals of this method:
73  increment (hot) towers above some threshold
74  */
75 
76  if(!t) return;
77  for(int icr=0;icr<t->getNBlocks() && icr<MaxTwCrateID;icr++) {
78  if(t->isCrateVoid(icr)) continue;
79  int crateID=icr+1;
80  const UShort_t* data=t->data(icr);
81  int *pedA= &feePed[(crateID-1)*MaxTwCrateCh];
82  if (data) for(int i=0;i<t->sizeData(icr) && i<MaxTwCrateCh;i++) {
83  int chan=i;
84  float adc=data[i]-24+ pedA[i];
85  if(adc<hotTwThres) continue;
86  if (hCrateHot && hCrateHot[crateID-1]) hCrateHot[crateID-1]->Fill(chan);
87  }
88  }// end of loop over crates
89 }
90 
91 //-------------------------------------------
92 void EEqaSorterA::sortDaqMapmt0(const EztEmcRawData *s, int ver){
93  /* Goal of this method:
94  make histos of adc vs channel for each MAPMT crate
95  */
96  if(!s) return;
97  for(int icr=0;icr<s->getNBlocks();icr++) {
98  if(s->isCrateVoid(icr)) continue;
99  int crateID=icr+64;
100  // in 2004 there was only 16 MAPMT crates for sectors 5-8
101  if(ver<0x22) {
102  if(icr>=16) break;
103  crateID=icr+84;
104  }
105  const UShort_t* data=s->data(icr);
106  for(int i=0;i<s->sizeData(icr) && i<MaxMapmtCrateCh;i++) {
107  int chan=i;
108  float adc=data[i];
109  if (hCrate && hCrate[crateID-1]) hCrate[crateID-1]->Fill(adc,chan);
110  }
111  }// end of loop over crates
112 
113 }
114 
115 //--------------------------------------------------
116 void EEqaSorterA::initCrateHisto(TObjArray *HList, int nBin, int mxADC) {
117  const char *sectL[]={"11TD-1TC", "1TD-3TC", "3TD-5TC", "5TD-7TC", "7TD-9TC", "9TD-11TC"};
118  LOG_DEBUG << Form(" EEqaSorterA::initCrateHisto(nb=%d, max=%d)\n", nBin,mxADC) << endm;
119  // init histo
120  int nOK=0;
121  hCrate = new TH2F *[MaxAnyCrate];
122  for(int icr=0;icr<MaxAnyCrate;icr++) {
123  //if(icr!=63) continue;
124  int crateID=icr+1;
125  hCrate[icr]=0;
126  int mxChan=0;
127  TString physDet;
128  if(crateID>=MinTwCrateID && crateID<=MaxTwCrateID) {
129  // Towers
130  mxChan=MaxTwCrateCh;
131  physDet=sectL[crateID-1];
132  } else if (crateID>=MinMapmtCrateID && crateID<=MaxMapmtCrateID ){
133  //MAPMT
134  mxChan=MaxMapmtCrateCh;
135  int sec=1+(7+crateID/4)%MaxSectors;
136  int box=1+crateID%4;
137  physDet = (box==4) ? Form("%dP1",sec) : Form("%dS%d",sec,box);
138  }
139 
140  if(mxChan==0) continue; // skip nonexisting crates
141  nOK++;
142  hCrate[icr] = new TH2F(Form("cr%d",crateID),Form(" %s",physDet.Data()),nBin,-0.5, mxADC-0.5, mxChan, -0.5, mxChan-0.5);
143  if (HList) HList->Add(hCrate[icr]);
144  // printf("Histo Init: icr=%d crID=%d %s \n",icr,crateID,h->GetTitle());
145  }
146  hCrateHot = new TH1F *[MaxTwCrateID];
147  for(int icr=0;icr<MaxTwCrateID;icr++) {
148  int crateID=icr+1;
149  hCrateHot[icr]=0;
150  int mxChan=MaxTwCrateCh;
151  hCrateHot[icr] = new TH1F(Form("cr%dHot",crateID),Form("%s thr=feePed+%d",sectL[crateID-1],hotTwThres), mxChan, -0.5, mxChan-0.5);
152  hCrateHot[icr]->SetFillColor(kBlue);
153  if (HList) HList->Add(hCrateHot[icr]);
154  }
155  LOG_DEBUG << "Initialized " << nOK << " 2D carte-histos" << endm;
156 }
157 
158 void EEqaSorterA::saveHisto(TFile *f) const {
159  if (f) f->cd();
160  for(int icr = 0;icr < MaxAnyCrate;icr++) {
161  if (hCrate && hCrate[icr]) hCrate[icr]->Write();
162  }
163  for(int icr = 0;icr < MaxTwCrateID;icr++) {
164  if (hCrateHot && hCrateHot[icr]) hCrateHot[icr]->Write();
165  }
166 }
167 
168 void EEqaSorterA::resetHisto() {
169  for(int icr = 0;icr < MaxAnyCrate;icr++) {
170  if (hCrate && hCrate[icr]) hCrate[icr]->Reset();
171  }
172  for(int icr = 0;icr < MaxTwCrateID;icr++) {
173  if (hCrateHot && hCrateHot[icr]) hCrateHot[icr]->Reset();
174  }
175 }
176 
177 //--------------------------------------------------
178 int EEqaSorterA::usePed4(const Char_t *filename) {
179  int ok = 0;
180  //......................... load ped for L-0
181  LOG_DEBUG << " EEqaSorterA::usePed4(\"" << filename << "\") ..." << endm;
182  FILE *fd=fopen(filename,"r");
183  if (fd) {
184  ok = 1;
185  for(int cr=MinTwCrateID;cr<=MaxTwCrateID;cr++) {
186  for(int ch=0;ch<MaxTwCrateCh; ch++) {
187  int xcr = -1, xch = -1, ped4 = 0;
188  float xped = 0;
189  int ret=fscanf(fd,"%d %d %f %d",&xcr,&xch,&xped,&ped4);
190  if ((ret == 4) && (xcr >= MinTwCrateID) && (xcr <= MaxTwCrateID) && (xch >= 0) && (xch < MaxTwCrateCh)) {
191  feePed[(xcr - 1)*MaxTwCrateCh + xch]=4*ped4;
192  } else {
193  LOG_ERROR << "Bad format in " << filename << ": read xcr=" << xcr << ", xch=" << xch << ", xped=" << xped << ", ped4=" << ped4 << ", ret=" << ret << "; expected xcr=" << cr << ", xch=" << ch << endm;
194  ok = 0;
195  }
196  }
197  }
198  fclose(fd);
199  fd = 0;
200  LOG_DEBUG << " EEqaSorterA::usePed4(...) Loaded" << endm;
201  } else {
202  LOG_ERROR << "Cannot read file " << filename << endm;
203  }
204  return ok;
205 }
206 
207 
208 // $Log: EEqaSorterA.cxx,v $
209 // Revision 1.10 2010/04/09 04:48:33 ogrebeny
210 // Added more protection against out-of-boundary errors. See bug report 1903.
211 //
212 // Revision 1.9 2010/03/05 23:46:42 ogrebeny
213 // Make it a little less strict on the ped file format
214 //
215 // Revision 1.8 2010/03/05 23:16:44 ogrebeny
216 // A little more debug output
217 //
218 // Revision 1.7 2009/04/30 21:20:31 ogrebeny
219 // Improved constness after fixing bug 1457
220 //
221 // Revision 1.6 2009/02/27 18:34:13 ogrebeny
222 // Small bug fixed
223 //
224 // Revision 1.5 2009/02/24 18:19:47 ogrebeny
225 // Small workaround until ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1457 is resolved
226 //
227 // Revision 1.4 2009/02/24 04:07:45 ogrebeny
228 // Fixed part of the trigger histograms
229 //
230 // Revision 1.3 2009/01/25 01:36:54 ogrebeny
231 // *** empty log message ***
232 //
233 // Revision 1.2 2009/01/23 00:14:50 ogrebeny
234 // Inherited EEmcDb from StEEmcDbMaker to fix run-time bug http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1378
235 //
236 // Revision 1.1 2005/04/28 20:54:46 balewski
237 // start
238 //
239 // Revision 1.8 2004/03/13 22:03:13 balewski
240 // new plots from Hal added
241 //
242 // Revision 1.6 2004/02/26 04:22:24 balewski
243 // more Hal's plots
244 //
245 // Revision 1.5 2004/02/17 03:09:18 balewski
246 // *** empty log message ***
247 //
248 // Revision 1.4 2004/01/29 17:23:14 balewski
249 // fix for BTOW
250 //
251 // Revision 1.3 2004/01/27 16:29:39 balewski
252 // reset added
253 //