StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBemcRaw.cxx
1 //
2 // $Id: StBemcRaw.cxx,v 1.40 2017/06/02 16:43:06 jlzhang Exp $
3 // $Log: StBemcRaw.cxx,v $
4 // Revision 1.40 2017/06/02 16:43:06 jlzhang
5 // peer review for picoDst production
6 //
7 // Revision 1.39 2010/12/22 22:58:57 stevens4
8 // Patch for BSMDE mapping problem in P10ih and P10ij productions (RT #2043)
9 //
10 // Revision 1.38 2009/11/17 15:55:48 mattheww
11 // fixed a bunch of warnings
12 //
13 // Revision 1.37 2009/03/23 21:08:32 mattheww
14 // Update default BPRS ZS handling and fix EEMC minor bug
15 //
16 // Revision 1.36 2009/02/26 12:00:40 mattheww
17 // added token check to BTOW header check
18 //
19 // Revision 1.35 2009/02/11 22:50:44 mattheww
20 // fixed a bug in getting CAP
21 //
22 // Revision 1.34 2009/02/11 22:38:56 mattheww
23 // fixed a bug in getting CAP
24 //
25 // Revision 1.33 2009/02/04 21:05:42 kocolosk
26 // Refactor StEEmcDb(Maker), new location for StEmcDecoder. Fixes RT #1388.
27 //
28 // Revision 1.32 2009/02/02 15:55:23 mattheww
29 // removed some debugging prints not taken out from last commit
30 //
31 // Revision 1.31 2009/01/28 15:42:44 mattheww
32 // Put back some obsolete methods to satisfy StBemcData
33 //
34 // Revision 1.30 2009/01/27 19:58:36 mattheww
35 // Updates to StEmcRawMaker to be compatible with 2009 DAQ Format
36 //
37 // Revision 1.29 2008/12/02 19:31:46 mattheww
38 // fixed bug in BPRS swap logic for run 8+
39 //
40 // Revision 1.28 2008/11/07 22:37:55 mattheww
41 // update date for bprs swap fix
42 //
43 // Revision 1.27 2008/10/24 18:19:06 mattheww
44 // Added option to throw out all hits in an event if any crates are corrupted
45 //
46 // Revision 1.26 2008/07/28 12:51:45 mattheww
47 // Minor bug fix in StBemcRaw::createDecoder
48 //
49 // Revision 1.25 2008/07/24 15:08:30 mattheww
50 // Minor bug fix and exception handling in setCheckStatus
51 //
52 // Revision 1.24 2008/07/23 23:53:24 mattheww
53 // Changed default status check mode to off
54 //
55 // Revision 1.23 2008/07/03 20:58:49 mattheww
56 // Added checking of every status table for each hit. Status table checks can be toggled using an option added to setCheckStatus. Also fixed a small bug.
57 //
58 // Revision 1.22 2008/06/12 13:25:32 mattheww
59 // Added a check on the pedestal status in makeHit
60 //
61 // Revision 1.21 2007/09/10 22:21:41 kocolosk
62 // Support for new BPRS swap fixes (off by default for 06/07 production, on for analysis).
63 // StBemcTables now matches map fixes in case end users want to use this copy.
64 //
65 // Revision 1.20 2007/01/22 19:13:37 kocolosk
66 // use STAR logger for all output
67 //
68 // Revision 1.19 2006/08/07 02:29:16 kocolosk
69 // one more change to allow saving CAP==127||128 via control table
70 //
71 // Revision 1.18 2006/08/07 01:58:06 kocolosk
72 // save hits from other CAPs using control table, can't comment out code b/c ADCtoEMaker needed it
73 //
74 // Revision 1.17 2006/08/04 12:54:10 kocolosk
75 // don't throw away CAP==127||128 PRS and SMD hits this year
76 //
77 // Revision 1.16 2006/08/01 17:07:07 kocolosk
78 // save all preshower hits for 2006 productions
79 //
80 // Revision 1.15 2006/01/16 11:12:00 suaide
81 // tower map bug fixed and astyle run
82 //
83 // Revision 1.14 2005/05/20 01:48:59 suaide
84 // small bug in the capacito assignement is fixed
85 //
86 // Revision 1.13 2005/02/02 11:09:59 suaide
87 // crate Id check is back!
88 //
89 // Revision 1.12 2005/01/14 12:20:31 suaide
90 // small bug fixed for the PSD
91 //
92 // Revision 1.11 2005/01/07 20:33:18 suaide
93 // created a new method to correct for the PSD map problem
94 //
95 // Revision 1.10 2004/12/21 12:53:48 suaide
96 // moved StBemcTables to StEmcUtil
97 // corrected for y2005 PSD data banks
98 //
99 // Revision 1.9 2004/12/14 11:32:11 suaide
100 // added histograms for status tables creation
101 //
102 // Revision 1.8 2004/11/22 12:46:22 suaide
103 // added new flags for hit reconstruction. Status are not checked
104 // dureing production anymore in order to avoid bad status loaded in
105 // DB
106 //
107 // Revision 1.7 2004/11/12 21:17:56 suaide
108 // non initialization of some variables were fixed
109 //
110 // Revision 1.6 2004/11/02 03:23:09 suaide
111 // small changes in order to fix a bug
112 //
113 // Revision 1.5 2004/10/21 00:01:42 suaide
114 // small changes in histogramming and messages for BEMC
115 // Complete version for EEMC done by Jan Balewski
116 //
117 // Revision 1.4 2004/10/20 15:45:19 suaide
118 // few bugs fixed
119 //
120 // Revision 1.3 2004/10/20 14:24:21 suaide
121 // small fix to crateUnknown status in old files
122 //
123 // Revision 1.2 2004/10/19 17:53:00 suaide
124 // code clean up
125 //
126 // Revision 1.1 2004/10/18 18:20:06 suaide
127 // New Maker. Will replace StEmcADCtoEMaker in production.
128 // It reads only DAQ structures. Output is StEvent.
129 //
130 #include "StBemcRaw.h"
131 #include "Stiostream.h"
132 #include "StEmcUtil/others/emcDetectorName.h"
133 #include "StEmcUtil/geometry/StEmcGeom.h"
134 #include "TString.h"
135 #include "StEventTypes.h"
136 #include "StEvent.h"
137 // DAQ Libraries
138 #include "StDaqLib/GENERIC/EventReader.hh"
139 #include "StDaqLib/EMC/EMC_Reader.hh"
140 #include "StDAQMaker/StDAQReader.h"
141 #include "DAQ_READER/daq_det.h"
142 #include "DAQ_BTOW/daq_btow.h"
143 #include "DAQ_BSMD/daq_bsmd.h"
144 #include "DAQ_ETOW/daq_etow.h"
145 #include "DAQ_ESMD/daq_esmd.h"
146 #include "DAQ_EMC/daq_emc.h"
147 #include "StEmcUtil/database/StEmcDecoder.h"
148 #include "StEmcRawMaker.h"
149 #include "StMessMgr.h"
150 #include "TGenericTable.h"
151 //#include "StChain/StRTSBaseMaker.h"
152 #include "StChain/StRtsTable.h"
153 
154 ClassImp(StBemcRaw)
155 
156 //_____________________________________________________________________________
157 /*
158  Default constructor. Set Initial values for some variables
159 */
161 {
162  mSaveAllStEvent = kFALSE;
163  mSaveAllBTOW = kFALSE;
164  mPsdMapBug = kFALSE;
165  mPsdMapBug2 = kFALSE;
166  mTowerMapBug = kFALSE;
167  mSmdMapBug = kFALSE;
168  mProdVer = "";
169  mDecoder = 0;
170  mDate = 0;
171  mTime = 0;
172  mTables = new StBemcTables();
173  mControlADCtoE = new controlADCtoE_st();
174  Int_t calib[] = {1, 1, 1, 1, 0, 0, 0, 0};
175  Int_t pedSub[] = {1, 0, 0, 0, 0, 0, 0, 0};//default no bsmd pedsub
176  Float_t cut[] = {-1, -1, 1.5, 1.5, -1, -1, -1, -1};
177  //cutType will now specify which daq data block to use
178  //cut will now do nothing
179  Int_t cutType[] = {0, 1, 1, 1, 0, 0, 0, 0};//default zs bsmd
180  Int_t onlyCal[] = {0, 0, 0, 0, 0, 0, 0, 0};
181  Int_t status[] = {0, 0, 0, 0, 0, 0, 0, 0};
182  Int_t crate[] = {1, 1, 1, 1, 0, 0, 0, 0};
183 
184  mCrateVeto = 0;
185  mAnyCorrupted = kFALSE;
186 
187  for(Int_t i=0; i<MAXDETBARREL; i++)
188  {
189  mControlADCtoE->Calibration[i]=calib[i];
190  mControlADCtoE->DeductPedestal[i]=pedSub[i];
191  mControlADCtoE->CutOff[i]=cut[i];
192  mControlADCtoE->CutOffType[i]=cutType[i];
193  mControlADCtoE->OnlyCalibrated[i]=onlyCal[i];
194  mControlADCtoE->CheckStatus[i]=status[i];
195  mControlADCtoE->CheckCrate[i]=crate[i];
196  mBarrelQAHisto[i] = 0;
197  for(int j = 0; j < 4; j++){
198  mCheckStatus[i][j]=0;
199  }
200  }
201  assert(mControlADCtoE->CutOffType[2]==mControlADCtoE->CutOffType[3]);
202 
203 }
204 //_____________________________________________________________________________
209 {
210  if(mTables)
211  delete mTables;
212  if(mDecoder)
213  delete mDecoder;
214  if(mControlADCtoE)
215  delete mControlADCtoE;
216 }
218 {
219  LOG_INFO <<"Configuration for BEMC hit reconstruction "<<endm;
220  for(Int_t i=0;i<MAXDETBARREL;i++)
221  {
222  LOG_INFO <<" Configuration for detector "<<detname[i].Data()<<endm;
223  LOG_INFO <<" switch for deducting pedestal = "<<mControlADCtoE->DeductPedestal[i]<<endm;
224  LOG_INFO <<" switch for calibration = "<<mControlADCtoE->Calibration[i]<<endm;
225  LOG_INFO <<" cutoff type = "<<mControlADCtoE->CutOffType[i]<<endm;
226  LOG_INFO <<" cutoff value = "<<mControlADCtoE->CutOff[i]<<endm;
227  LOG_INFO <<" save only calibrated hits = "<<mControlADCtoE->OnlyCalibrated[i]<<endm;
228  LOG_INFO <<" save only if status is ok = "<<mControlADCtoE->CheckStatus[i]<<endm;
229  LOG_INFO <<" save only if crate is ok = "<<mControlADCtoE->CheckCrate[i]<<endm;
230  LOG_INFO <<" SAVE ALL FLAG (overwrites above) = "<<(Int_t)mSaveAllStEvent<<endm;
231  }
232 }
233 void StBemcRaw::createDecoder(Int_t date, Int_t time)
234 {
235  if(mDecoder)
236  delete mDecoder;
237  mDecoder = new StEmcDecoder(date,time);
238  mDate = date;
239  mTime = time;
240 }
241 void StBemcRaw::initHisto()
242 {
243  mBarrelNHitHist = new TH2F("BarrelNHit","BarrelNHit",500,0.0,18000.0,4,0.5,4.5);
244  mBarrelEtotHist = new TH2F("BarrelEtot","BarrelEtot",500,0.0,10000.0,4,0.5,4.5);
245  mBarrelAdcSumHist = new TH2F("BarrelAdcSum","BarrelAdcSum",500,0.0,1000000.0,4,0.5,4.5);
246  mBarrelNCratesHist = new TH2F("BarrelNCrates","BarrelNCrates",31,0.0,31.0,4,0.5,4.5);
247  mBarrelCrateStatusHist = new TH2F("BarrelCrateStatus","BarrelCrateStatus",6,-0.5,5.5,30,0.5,30.5);
248 }
249 void StBemcRaw::initQAHisto()
250 {
251  for(Int_t det = 1;det<=MAXDETBARREL; det++)
252  {
253  Int_t N = BTOWCH;
254  if(det>2)
255  N= BSMDCH;
256  mBarrelQAHisto[det-1] = new TH2F(detname[det-1].Data(),detname[det-1].Data(),N,0.5,(Float_t)N+0.5,250,-0.5,249.5);
257  }
258 }
259 void StBemcRaw::fillHisto()
260 {
261  for(Int_t det = 1;det<=MAXDETBARREL; det++)
262  {
263  mBarrelNHitHist->Fill(getTotalSaved(det),det);
264  mBarrelEtotHist->Fill(getTotalE(det),det);
265  mBarrelAdcSumHist->Fill(getTotalADC(det),det);
266  mBarrelNCratesHist->Fill(getNCratesOK(det),det);
267  }
268  for(Int_t crate = 1;crate<=MAXCRATES; crate++)
269  {
270  mBarrelCrateStatusHist->Fill(getCrateStatus(BTOW,crate),crate);
271  }
272 }
273 Bool_t StBemcRaw::make(StEmcRawMaker * TheData, StEvent* event)
274 {
275  if(!TheData)
276  return kFALSE;
277  if(!event)
278  return kFALSE;
279  StEmcCollection* emc = event->emcCollection();
280  if(!emc)
281  return kFALSE;
282  StEmcRawData *bemcRaw = emc->bemcRawData();
283  if(!bemcRaw)
284  return kFALSE;
285  if(!convertFromDaq(TheData,bemcRaw))
286  return kFALSE;
287  return make(bemcRaw,event);
288 }
289 Bool_t StBemcRaw::convertFromDaq(StEmcRawMaker * DAQ, StEmcRawData* RAW)
290 {
291  if(!DAQ)
292  {
293  LOG_ERROR <<"Could not find DAQ DataSet "<<endm;
294  return kFALSE;
295  }
296  if(!RAW)
297  {
298  LOG_ERROR <<"Could not find StEmcRawData pointer for BEMC"<<endm;
299  return kFALSE;
300  }
301 
302  StRtsTable* btow = DAQ->GetDaqElement("btow/adc");
303  if(btow){
304  btow_t* btowdata = (btow_t*)*btow->begin();
305  if(RAW->header(BTOWBANK))
306  RAW->deleteBank(BTOWBANK);
307  RAW->createBank(0,BTOWHEADER,BTOWSIZE);
308 
309  for(int i = 0; i < BTOW_MAXFEE; i++){
310  for(int j = 0; j < BTOW_DATSIZE; j++){
311  int id = -1;
312  int daqid = -1;
313  mDecoder->GetTowerIdFromTDC(i,j,id);
314  mDecoder->GetDaqIdFromTowerId(id,daqid);
315  //printf("agrdl: BTOW ADC %d %d %d %d\n",i,j,id,btowdata->adc[i][j]);
316  RAW->setData(BTOWBANK,daqid,btowdata->adc[i][j]);
317  }
318  for(int j = 0; j < BTOW_PRESIZE; j++){
319  RAW->setHeader(BTOWBANK,i+j*30,btowdata->preamble[i][j]);
320  int crate;
321  mDecoder->GetTowerCrateFromTDC(i,crate);
322  //printf("agrdl: BTOW HEAD %d %d %d\n",crate,j,btowdata->preamble[i][j]);
323  }
324  }
325  }else{
326  LOG_ERROR<<"BTOW Structure not found"<<endm;
327  }
328 
329  while(DAQ->GetDaqElement("bsmd/adc")){
330  if(mDate < 20081101)continue;//Old daq files do not have this block
331  int rdo = DAQ->Rdo();
332  int use = 0;
333  if(rdo < 9 && mControlADCtoE->CutOffType[2])use=1;
334  if(rdo >=9 && mControlADCtoE->CutOffType[1])use=1;
335  bsmd_t* bsmddata = (bsmd_t*)*DAQ->Dta()->begin();
336  if(use){
337  if(RAW->header(rdo))
338  RAW->deleteBank(rdo);
339  RAW->createBank(rdo,1,BSMD_DATSIZE);
340  RAW->setHeader(rdo,0,(unsigned short)bsmddata->cap);
341  for(int j = 0; j < BSMD_DATSIZE; j++){
342  RAW->setData(rdo,j,bsmddata->adc[j]);
343  }
344  }
345  }
346 
347  while(DAQ->GetDaqElement("bsmd/adc_non_zs")){
348  int rdo = DAQ->Rdo();
349  int use = 0;
350  if((rdo < 9 && !mControlADCtoE->CutOffType[2]) || mDate < 20081101)use=1;
351  if((rdo >= 9 && !mControlADCtoE->CutOffType[1]) || mDate < 20081101)use=1;
352  if(use){
353  //printf("agrdl: entered smd rdo: %d\n",rdo);
354  bsmd_t* bsmddata = (bsmd_t*)*DAQ->Dta()->begin();
355  if(RAW->header(rdo))
356  RAW->deleteBank(rdo);
357  RAW->createBank(rdo,1,BSMD_DATSIZE);
358  RAW->setHeader(rdo,0,(unsigned short)bsmddata->cap);
359  //printf("agrdl: BSMD %d CAP %d\n",rdo,(unsigned short)bsmddata->cap);
360  for(int j = 0; j < BSMD_DATSIZE; j++){
361  RAW->setData(rdo,j,bsmddata->adc[j]);
362  //printf("agrdl: BSMD ADC %d %d %d\n",rdo,j,bsmddata->adc[j]);
363  }
364  }
365  }
366  return kTRUE;
367 }
368 //-------------------------------------------------------
369 Bool_t StBemcRaw::make(StEmcRawData* bemcRaw, StEvent* event)
370 {
371  if(!bemcRaw)
372  return kFALSE;
373  if(!event)
374  return kFALSE;
375  StEmcCollection* emc = event->emcCollection();
376  if(!emc)
377  return kFALSE;
378 
379  checkHeaders(bemcRaw, event);
380  emptyEmcCollection(emc);
381 
382  Int_t cap=0,crate=0;
383  Int_t ADC=0;
384  Float_t E=0;
385 
386  for(Int_t det = 1; det<=MAXDETBARREL; det++)
387  {
388  Int_t nch = BTOWCH;
389  if(det>2)
390  nch=BSMDCH;
391 
392  clearStats(det);
393  for(Int_t id = 1; id<=nch; id++)
394  {
395  ADC = getBemcADCRaw(det,id,bemcRaw,crate,cap);
396  Int_t S = makeHit(emc,det,id,ADC,crate,cap,E);
397  updateStats(det,S,ADC,E);
398  }
399  printStats(det);
400  StDetectorId did = static_cast<StDetectorId>(det+kBarrelEmcTowerId-1);
401  StEmcDetector* detector=emc->detector(did);
402  if(detector)
403  {
404  for(Int_t crate = 1;crate<=MAXCRATES;crate++)
405  detector->setCrateStatus(crate,(StEmcCrateStatus)mCrateStatus[det-1][crate-1]);
406  }
407  }
408 
409  return kTRUE;
410 }
411 //_____________________________________________________________________________
413 {
414  for(Int_t det=1;det<=MAXDETBARREL; det++)
415  {
416  for(Int_t crate = 1; crate<=MAXCRATES;crate++)
417  mCrateStatus[det-1][crate-1] = crateUnknown;
418  mIsCorrupted[det-1] = kFALSE;
419  }
420  checkBtowCrates(RAW,event);
421 
422  mNCRATESOK[BPRS-1]=mNCRATESOK[BSMDE-1]=mNCRATESOK[BSMDP-1]=0;
423  // smd data
424  for(Int_t i = 0; i<MAXSMDCRATES; i++)
425  {
426  UShort_t *header = RAW->header(i+BSMDOFFSET);
427  if(header)
428  {
429  mCrateStatus[BSMDE-1][i] = crateOK;
430  mCrateStatus[BSMDP-1][i] = crateOK;
431  mNCRATESOK[BSMDE-1]++;
432  mNCRATESOK[BSMDP-1]++;
433  }
434  }
435  // PSD data
436  for(Int_t i = 0; i<MAXBPRSCRATES; i++)
437  {
438  UShort_t *header = RAW->header(i+BPRSOFFSET);
439  if(header)
440  {
441  mCrateStatus[BPRS-1][i] = crateOK;
442  mNCRATESOK[BPRS-1]++;
443  }
444  }
445  for(Int_t i = 0; i < MAXDETBARREL; i++){
446  if(mIsCorrupted[i])mAnyCorrupted = kTRUE;
447  }
448 }
450 {
451  if(!emc)
452  return;
453  StSPtrVecEmcPoint& pvec = emc->barrelPoints();
454  if(pvec.size()>0)
455  pvec.clear();
456 
457  for(Int_t i=0; i<MAXDETBARREL; i++)
458  {
459  StDetectorId id = static_cast<StDetectorId>(i+kBarrelEmcTowerId);
460  StEmcDetector* detector=emc->detector(id);
461  if(detector)
462  {
463  if(detector->cluster())
464  {
465  StSPtrVecEmcCluster& cluster=detector->cluster()->clusters();
466  if(cluster.size()>0)
467  cluster.clear();
468  }
469  for(UInt_t j=1;j<=detector->numberOfModules() ;j++)
470  {
471  StEmcModule *module = detector->module(j);
472  if(module)
473  {
474  StSPtrVecEmcRawHit& hits=module->hits();
475  hits.clear();
476  }
477  }
478  }
479  }
480  return;
481 }
482 //_____________________________________________________________________________
487 {
488  if(!RAW)
489  return;
490  if(!mDecoder)
491  return;
492  UShort_t *header = RAW->header(BTOWBANK);
493  if(!header)
494  return;
495  mNCRATESOK[0] = 0;
496  int trgtoken = event->l0Trigger()->triggerToken();
497  for(Int_t crate = 1;crate<=MAXCRATES;crate++)
498  {
499  Int_t TDC;
500  mDecoder->GetTowerTDCFromCrate(crate,TDC);
501  Int_t sum = header[TDC];
502  Int_t token = header[TDC+BTOWTOKENOFFSET];
503  Int_t err = header[TDC+BTOWTDCERROFFSET];
504  Int_t crateFromHeader = header[TDC+BTOWCRATEOFFSET]& 0x0FF;
505  mCrateStatus[BTOW-1][crate-1] = crateUnknown;
506  if(sum==BTOWBYTESUM && err == BTOWERRFLAG && crate==crateFromHeader && token == trgtoken)
507  mCrateStatus[BTOW-1][crate-1] = crateOK;
508  else
509  mCrateStatus[BTOW-1][crate-1] = crateHeaderCorrupt;
510 
511  if(sum==BTOWNOTPRESENT && err == BTOWNOTPRESENT)
512  mCrateStatus[BTOW-1][crate-1] = crateNotPresent;
513 
514  if(mCrateStatus[BTOW-1][crate-1]==crateOK)
515  mNCRATESOK[BTOW-1]++;
516 
517  if(mCrateStatus[BTOW-1][crate-1]==crateHeaderCorrupt)
518  mIsCorrupted[BTOW-1] = kTRUE;
519  }
520  return;
521 }
522 void StBemcRaw::clearStats(Int_t det)
523 {
524  mNZ[det-1] = 0;
525  mNCRATE[det-1] = 0;
526  mNSTATUS[det-1] = 0;
527  mNRMS[det-1] = 0;
528  mNPED[det-1] = 0;
529  mNOK[det-1] = 0;
530  mNTOTAL[det-1] = 0;
531  mADCSUM[det-1] = 0;
532  mTOTALE[det-1] = 0;
533 }
534 void StBemcRaw::updateStats(Int_t det,Int_t S,Int_t ADC, Float_t E)
535 {
536  if(S==kZero)
537  mNZ[det-1]++;
538  else if(S==kCrate)
539  mNCRATE[det-1]++;
540  else if(S==kStatus)
541  mNSTATUS[det-1]++;
542  else if(S==kRms)
543  mNRMS[det-1]++;
544  else if(S==kPed)
545  mNPED[det-1]++;
546  else if(S==kOK)
547  mNOK[det-1]++;
548  mNTOTAL[det-1]++;
549  if(S==kOK)
550  {
551  mADCSUM[det-1]+=ADC;
552  mTOTALE[det-1]+=E;
553  }
554 }
555 void StBemcRaw::printStats(Int_t det)
556 {
557  LOG_DEBUG <<"Statistics for detector "<<detname[det-1].Data()<<endm;
558  LOG_DEBUG <<" Total number of crates with header ok = "<<mNCRATESOK[det-1]<<endm;
559  LOG_DEBUG <<" Total number of hits = "<<mNTOTAL[det-1]<<endm;
560  LOG_DEBUG <<" Total hits removed because of crates = "<<mNCRATE[det-1]<<endm;
561  LOG_DEBUG <<" Total hits removed because ADC = 0 = "<<mNZ[det-1]<<endm;
562  LOG_DEBUG <<" Total hits removed by Pedestal = "<<mNPED[det-1]+mNRMS[det-1]<<endm;
563  LOG_DEBUG <<" Total hits removed by Status = "<<mNSTATUS[det-1]<<endm;
564  LOG_DEBUG <<" Total number of hits saved = "<<mNOK[det-1]<<endm;
565  LOG_DEBUG <<" Total ADCSUM of valid hits = "<<mADCSUM[det-1]<<endm;
566  LOG_DEBUG <<" Total Energy of valid hits = "<<mTOTALE[det-1]<<endm;
567 }
568 //_____________________________________________________________________________
572 Int_t StBemcRaw::getBemcADCRaw(Int_t det, Int_t softId, StEmcRawData* RAW, Int_t& CRATE, Int_t& CAP)
573 {
574  CAP = 0;
575  CRATE = 0;
576  if(!RAW)
577  {
578  LOG_WARN <<"Could not find StEmcRawData pointer for BEMC det: " << det << " softId: " << softId <<endm;
579  return 0;
580  }
581  if(!mDecoder)
582  {
583  LOG_WARN <<"Could not find StEmcDecoder pointer for BEMC det: " << det << " softId: " << softId <<endm;
584  return 0;
585  }
586  if(det==BTOW) // tower
587  {
588  Int_t daq;
589  if(mDecoder->GetDaqIdFromTowerId(softId,daq)==1 && RAW->header(BTOWBANK))
590  {
591  Int_t CR,INDEX;
592  mDecoder->GetTowerCrateFromDaqId(daq,CR,INDEX);
593  CRATE = CR;
594  CAP = 0;
595  return RAW->data(BTOWBANK,daq);
596  }
597  return 0;
598  }
599  else if(det==BPRS) // PSD
600  {
601  Int_t RDO=0,index=0;
602  Int_t S = mDecoder->GetPsdRDO(softId,RDO,index);
603  CRATE = RDO+1;
604  //cout <<det<<" "<<RDO<<" "<<softId<<" "<<RAW->header(RDO+BPRSOFFSET)<<endl;
605  if(RDO<0 || RDO>=MAXBPRSCRATES)
606  return 0;
607  if(S==1 && RAW->header(RDO+BPRSOFFSET))
608  {
609  if(mDate < 20081101)CAP = RAW->header(RDO+BPRSOFFSET,SMDCAPACITOR);
610  else CAP = RAW->header(RDO+BPRSOFFSET,0);
611  while(CAP>127)
612  CAP-=128;
613  return RAW->data(RDO+BPRSOFFSET,index);
614  }
615  return 0;
616  }
617  else if(det==BSMDE) // SMDE
618  {
619  StEmcGeom *geo = StEmcGeom::instance("bsmde");
620  Int_t m=0,e=0,s=0;
621  if(geo->getBin(softId,m,e,s)==1)
622  return 0;
623  Int_t RDO=0,index=0;
624  Int_t S = mDecoder->GetSmdRDO(BSMDE,m,e,s,RDO,index);
625  CRATE = RDO+1;
626  if(S==1 && RAW->header(RDO+BSMDOFFSET) && RDO>=0 && RDO<MAXSMDCRATES)
627  {
628  if(mDate < 20081101)CAP = RAW->header(RDO+BSMDOFFSET,SMDCAPACITOR);
629  else CAP = RAW->header(RDO+BSMDOFFSET,0);
630  while(CAP>127)
631  CAP-=128;
632  return RAW->data(RDO+BSMDOFFSET,index);
633  }
634  return 0;
635  }
636  else if(det==BSMDP) // SMDP
637  {
638  StEmcGeom *geo = StEmcGeom::instance("bsmdp");
639  Int_t m=0,e=0,s=0;
640  if(geo->getBin(softId,m,e,s)==1)
641  return 0;
642  Int_t RDO=0,index=0;
643  Int_t S = mDecoder->GetSmdRDO(BSMDP,m,e,s,RDO,index);
644  CRATE = RDO+1;
645  if(S==1 && RAW->header(RDO+BSMDOFFSET) && RDO>=0 && RDO<MAXSMDCRATES)
646  {
647  if(mDate < 20081101)CAP = RAW->header(RDO+BSMDOFFSET,SMDCAPACITOR);
648  else CAP = RAW->header(RDO+BSMDOFFSET,0);
649  while(CAP>127)
650  CAP-=128;
651  return RAW->data(RDO+BSMDOFFSET,index);
652  }
653  return 0;
654  }
655  return 0;
656 }
657 //_____________________________________________________________________________
662 Int_t StBemcRaw::makeHit(StEmcCollection* emc, Int_t det, Int_t id, Int_t ADC, Int_t CRATE, Int_t CAP,Float_t& E)
663 {
664  E=0;
665 
666  if(det==BTOW && mTowerMapBug && mDate<20060101) // after this date the bug should be fixed
667  {
668  Int_t shift = 0;
669  mDecoder->GetTowerBugCorrectionShift(id,shift);
670  id+=shift;
671  }
672  if(det==BPRS && mPsdMapBug2 && mDate<20071101)
673  {
674  Int_t shift = 0;
675  mDecoder->GetPreshowerBugCorrectionShift(id,shift);
676  id+=shift;
677  }
678  if(det==BSMDE && mSmdMapBug && mDate>=20100101 && mDate<20110101 && (!mProdVer.compare("SL10h") || !mProdVer.compare("SL10i") || !mProdVer.compare("SL10j")))
679  {
680  Int_t shift = 0;
681  mDecoder->GetSmdBugCorrectionShift(id,shift);
682  if(id+shift < 0) return kZero; //mask lost channels
683  id+=shift;
684  }
685 
686  // dongx - save all BTOW hits
687  Bool_t skipSave = !mSaveAllStEvent && ( !mSaveAllBTOW || det!=BTOW );
688 
689  if(CRATE>0 && CRATE<=MAXCRATES && mControlADCtoE->CheckCrate[det-1]==1)
690  if((mCrateStatus[det-1][CRATE-1]!=crateOK &&
691  mCrateStatus[det-1][CRATE-1]!=crateUnknown) &&
692  skipSave)
693  return kCrate;
694 
695  if(skipSave && mCrateVeto && mAnyCorrupted)
696  return kCrate;
697 
698  if(ADC==0 && skipSave)
699  return kZero;
700 
701  if(mControlADCtoE->CheckStatus[det-1]==1)
702  {
703  if(mCheckStatus[det-1][0]==1 && skipSave){
704  Int_t STATUS;
705  mTables->getStatus(det,id,STATUS);
706  if(STATUS!=STATUS_OK && skipSave)
707  return kStatus;
708  }
709  if(mCheckStatus[det-1][1]==1 && skipSave){
710  Int_t pedSTATUS;
711  mTables->getStatus(det,id,pedSTATUS,"pedestal");
712  if(pedSTATUS!=STATUS_OK && skipSave)return kStatus;
713  }
714  if(mCheckStatus[det-1][2]==1 && skipSave){
715  Int_t calibSTATUS;
716  mTables->getStatus(det,id,calibSTATUS,"calib");
717  if(calibSTATUS!=STATUS_OK && skipSave)return kStatus;
718  }
719  if(mCheckStatus[det-1][3]==1 && skipSave){
720  Int_t gainSTATUS;
721  mTables->getStatus(det,id,gainSTATUS,"gain");
722  if(gainSTATUS!=STATUS_OK && skipSave)return kStatus;
723  }
724 
725  }
726 
727  Float_t PEDESTAL = 0,RMS = 0;
728  mTables->getPedestal(det,id,CAP,PEDESTAL,RMS);
729 
730  if(mControlADCtoE->DeductPedestal[det-1]>0)
731  {
732  // do not consider hits wih capacitor number CAP1 and CAP2 for
733  // PSD and SMD as valid hits
734  // for 2006 keep these hits by setting DeductPedestal == 2
735  if(mControlADCtoE->DeductPedestal[det-1]==1)
736  if(det>=BPRS && skipSave)
737  if(CAP==CAP1 || CAP==CAP2)
738  return kPed;
739  }
740 
741  if(mControlADCtoE->CutOffType[det-1]==1 && skipSave && mControlADCtoE->DeductPedestal[det-1] > 0) // pedestal cut
742  {
743  if(RMS<=0)
744  return kRms;
745  Float_t x = (ADC-PEDESTAL)/RMS;
746  if(x<=mControlADCtoE->CutOff[det-1])
747  return kPed;
748  }
749 
750  if(mControlADCtoE->Calibration[det-1]==1)
751  {
752  Float_t ADCP = 1;
753  Float_t C;
754  for(Int_t i=0;i<5;i++)
755  {
756  mTables->getCalib(det,id,i,C);
757  E+=ADCP*C;
758  ADCP*=(Float_t)(ADC-PEDESTAL);
759  }
760  mTables->getGain(det,id,C);
761  E*=C;
762 
763  if(mControlADCtoE->CutOffType[det-1]==2 && skipSave) // energy cut
764  {
765  if(E<mControlADCtoE->CutOff[det-1])
766  return kEn;
767  }
768  }
769 
770  if(mControlADCtoE->OnlyCalibrated[det-1]>0 && E==0 && skipSave)
771  return kCalib;
772 
773  StDetectorId did = static_cast<StDetectorId>(det+kBarrelEmcTowerId-1);
774  StEmcDetector* detector=emc->detector(did);
775  StEmcGeom *geo = StEmcGeom::instance(det);
776  if(!detector)
777  {
778  detector = new StEmcDetector(did,BEMCMODULES);
779  emc->setDetector(detector);
780  }
781  if(det==BPRS && mPsdMapBug && mDate<20060101) // after this date the map is fixed
782  {
783  Int_t PsdOffset_bug[40] = {20,21,22,23,0,1,2,3,24,25,26,27,4,5,6,7,28,29,30,31,
784  8,9,10,11,32,33,34,35,12,13,14,15,36,37,38,39,16,17,18,19};
785  Int_t PsdOffset_ok[40] = {36,37,38,39,16,17,18,19,32,33,34,35,12,13,14,15,28,29,30,31,
786  8,9,10,11,24,25,26,27,4,5,6,7,20,21,22,23,0,1,2,3};
787  Int_t RDO,index,PMT,wire,A_value;
788  mDecoder->GetPsdRDO(id,RDO,index);
789  mDecoder->GetPsdId(RDO,index,id,PMT,wire,A_value);
790  //int oldId = id;
791  id-=PsdOffset_bug[wire-1];
792  id+=PsdOffset_ok[wire-1];
793  //cout <<"PSD old id = "<<oldId<<" new id = "<<id<<" wire = "<<wire<<endl;
794  }
795  Int_t m,e,s;
796  geo->getBin(id,m,e,s);
797  StEmcRawHit* hit=new StEmcRawHit(did,m,e,s,(UInt_t)ADC);
798  if(mBarrelQAHisto[det-1] && !isCorrupted(det))
799  mBarrelQAHisto[det-1]->Fill((Float_t)id,(Float_t)ADC);
800  hit->setEnergy(E);
801  hit->setCalibrationType(CAP);
802  detector->addHit(hit);
803  return kOK;
804 }
805 
806 void StBemcRaw::setCheckStatus(Int_t det, Int_t flag, const char* option)
807 {
808  //change the status if a particular option is chosen
809  if(!strcmp(option,"status")){
810  mCheckStatus[det][0]=flag;
811  return;
812  }
813  if(!strcmp(option,"pedestal")){
814  mCheckStatus[det][1]=flag;
815  return;
816  }
817  if(!strcmp(option,"calib")){
818  mCheckStatus[det][2]=flag;
819  return;
820  }
821  if(!strcmp(option,"gain")){
822  mCheckStatus[det][3]=flag;
823  return;
824  }
825 
826  if(strcmp(option,"")){
827  LOG_WARN<<option<<" is not a valid option to setCheckStatus"<<endm;
828  return;
829  }
830 
831  //if no options chosen, change all status flags
832  for(int i = 0; i < 4; i++){
833  mCheckStatus[det][i]=flag;
834  }
835 
836  getControlTable()->CheckStatus[det] = flag;
837  return;
838 
839 }
840 void StBemcRaw::setCrateVeto(Int_t flag)
841 {
842  if(flag != 0 && flag != 1){
843  LOG_ERROR<<"Invalid flag passed to StBemcRaw::setCrateVeto, only 0 and 1 accepted"<<endm;
844  return;
845  }
846  mCrateVeto = flag;
847 }
848 Bool_t StBemcRaw::make(TDataSet* TheData, StEvent* event)
849 {
850  LOG_WARN<<"StBemcRaw::make(TDataSet*,StEvent*) is OBSOLETE for data in Run 9 or later"<<endm;
851  if(!TheData)
852  return kFALSE;
853  if(!event)
854  return kFALSE;
855  StEmcCollection* emc = event->emcCollection();
856  if(!emc)
857  return kFALSE;
858  StEmcRawData *bemcRaw = emc->bemcRawData();
859  if(!bemcRaw)
860  return kFALSE;
861  if(!convertFromDaq(TheData,bemcRaw))
862  return kFALSE;
863  return make(bemcRaw,event);
864 }
865 Bool_t StBemcRaw::convertFromDaq(TDataSet* DAQ, StEmcRawData* RAW)
866 {
867  LOG_WARN<<"StBemcRaw::convertFromDaq(TDataSet*,StEmcRawData*) is OBSOLETE for data in Run 9 or later"<<endm;
868  if(!DAQ)
869  {
870  LOG_ERROR <<"Could not find DAQ DataSet "<<endm;
871  return kFALSE;
872  }
873  if(!RAW)
874  {
875  LOG_ERROR <<"Could not find StEmcRawData pointer for BEMC"<<endm;
876  return kFALSE;
877  }
878 
879  StDAQReader* TheDataReader=(StDAQReader*)(DAQ->GetObject());
880  if(!TheDataReader || !TheDataReader->EMCPresent())
881  {
882  LOG_ERROR <<"Data Reader is not present "<<endm;
883  return kFALSE;
884  }
885 
886  StEMCReader* TheEmcReader=TheDataReader->getEMCReader();
887  if(!TheEmcReader)
888  {
889  LOG_ERROR <<"Could not find BEMC Reader "<<endm;
890  return kFALSE;
891  }
892 
893  EMC_Reader* reader = TheEmcReader->getBemcReader();
894  if(!reader)
895  {
896  LOG_ERROR <<"Could not find Barrel Reader "<<endm;
897  return kFALSE;
898  }
899 
900  if(reader->isTowerPresent())
901  {
902  Bank_BTOWERADCR& tower = reader->getBTOWERADCR();
903  if(RAW->header(BTOWBANK))
904  RAW->deleteBank(BTOWBANK);
905  RAW->createBank(0,BTOWHEADER,BTOWSIZE);
906  for(Int_t i = 0; i<BTOWSIZE ;i++){
907  int crate,sequence,tdc;
908  int id;
909  mDecoder->GetTowerIdFromDaqId(i,id);
910  mDecoder->GetCrateFromTowerId(id,crate,sequence);
911  mDecoder->GetTDCFromTowerId(id,tdc);
912  RAW->setData(BTOWBANK,i,tower.TowerADCArray[i]);
913  //printf("agrdl: BTOW ADC %d %d %d %d\n",tdc,sequence,id,tower.TowerADCArray[i]);
914  }
915  for(Int_t i = 0; i<BTOWHEADER ;i++){
916  RAW->setHeader(BTOWBANK,i,tower.TDCHeader[i]);
917  //printf("agrdl: BTOW HEAD %d %d\n",i,tower.TDCHeader[i]);
918  }
919  }
920  // smd data
921  if(reader->isSmdPresent())
922  {
923  Bank_BSMDADCR& smd = reader->getSMD_ADCR();
924  Int_t NSMD = MAXSMDCRATES;
925  // there is only 4 SMD Crates before that data and some
926  // of them are PSD crates. For Y2004 AuAu runs PSD do
927  // not have its own data format and it is being read as
928  // SMD
929  if(mDate<20040701)
930  NSMD = 4;
931 
932  for(Int_t i = 0; i<NSMD; i++)
933  {
934  if(smd.HasData[i]==1)
935  {
936  Int_t bank = i+BSMDOFFSET;
937  if(RAW->header(bank))
938  RAW->deleteBank(bank);
939  RAW->createBank(bank,BSMDHEADER,BSMDSIZE);
940  for(Int_t j=0; j<BSMDHEADER; j++)
941  RAW->setHeader(bank,j,smd.SmdHeader[i][j]);
942  //int CAP = RAW->header(bank,SMDCAPACITOR);
943  //printf("agrdl: BSMD %d CAP %d\n",bank,CAP);
944  for(Int_t j=0; j<BSMDSIZE; j++){
945  RAW->setData(bank,j,smd.SMDADCArray[i][j]);
946  //printf("agrdl: BSMD ADC %d %d %d\n",bank,j,smd.SMDADCArray[i][j]);
947  }
948  }
949  }
951  // read Pre Shower data for Y2004 AuAu data. This year, the PSD data
952  // is read as SMD data for fibers 4 and 5.
953  //
954  // For y2005 data, PSD data is on SMD banks 8 to 12
955  //
956  // This is a temporary solution while the PSD data format is not
957  // decided by Tonko. He needs to have a decision on some
958  // hardware issues before the data format is decided
959  //
960  // AAPSUAIDE 20040318
961  //
962  if(mDate>20040101)
963  {
964  for(Int_t RDO = 0; RDO<4; RDO++)
965  {
966  Int_t SMDRDO = RDO+NSMD;
967  if(smd.HasData[SMDRDO]==1)
968  {
969  Int_t bank = RDO+BPRSOFFSET;
970  if(RAW->header(bank))
971  RAW->deleteBank(bank);
972  RAW->createBank(bank,BPRSHEADER,BPRSSIZE);
973  for(Int_t i = 0; i<BPRSHEADER; i++)
974  RAW->setHeader(bank,i,smd.SmdHeader[SMDRDO][i]);
975  //int CAP = RAW->header(bank,SMDCAPACITOR);
976  //printf("agrdl: BSMD %d CAP %d\n",bank,CAP);
977  for(Int_t i = 0; i<BPRSSIZE; i++){
978  RAW->setData(bank,i,smd.SMDADCArray[SMDRDO][i]);
979  //printf("agrdl: BSMD ADC %d %d %d\n",bank,i,smd.SMDADCArray[SMDRDO][i]);
980  }
981  }
982  }
983  }
985  }
986  return kTRUE;
987 }
int GetSmdBugCorrectionShift(int id_original, int &shift) const
Returns the index shift for the SMD in original map.
Int_t getCrateStatus(Int_t det, Int_t c)
Return the status of the crate C.
Definition: StBemcRaw.h:220
void setCheckStatus(Int_t det, Int_t flag, const char *option="")
Definition: StBemcRaw.cxx:806
Float_t getTotalE(Int_t det)
Return the Total Energy Sum for the detector &#39;det&#39;.
Definition: StBemcRaw.h:236
Bank_BTOWERADCR & getBTOWERADCR()
EMC_Reader destructor.
Definition: EMC_Reader.cxx:246
void emptyEmcCollection(StEmcCollection *)
empty current emcCollection
Definition: StBemcRaw.cxx:449
void printStats(Int_t)
Print statistics for detector &#39;det&#39;.
Definition: StBemcRaw.cxx:555
int GetTowerCrateFromTDC(int TDC, int &crate) const
Get crate number from TDC channel for towers.
void getGain(Int_t det, Int_t softId, Float_t &gain) const
Return gain correction factor.
Int_t makeHit(StEmcCollection *, Int_t, Int_t, Int_t, Int_t, Int_t, Float_t &)
make StEmcRawHit
Definition: StBemcRaw.cxx:662
void checkHeaders(StEmcRawData *, StEvent *)
Check all BEMC detector headers.
Definition: StBemcRaw.cxx:412
Int_t getBemcADCRaw(Int_t, Int_t, StEmcRawData *, Int_t &, Int_t &)
get ADC from StEmcRawData structure
Definition: StBemcRaw.cxx:572
unsigned short TowerADCArray[4800]
Matrix of ADC&#39;s as obtained from daq.
Definition: EMC_Reader.hh:79
Int_t getNCratesOK(Int_t det)
Return the Total number of good crates for the detector &#39;det&#39; (only tower)
Definition: StBemcRaw.h:256
Int_t getTotalADC(Int_t det)
Return the Total ADC sum for the detector &#39;det&#39;.
Definition: StBemcRaw.h:232
controlADCtoE_st * getControlTable()
Return Control table (NULL)
Definition: StBemcRaw.h:215
void clearStats(Int_t)
Clear statistics for detector &#39;det&#39;.
Definition: StBemcRaw.cxx:522
unsigned short SmdHeader[12][128]
SMDHeader for each fiber.
Definition: EMC_Reader.hh:120
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
void updateStats(Int_t, Int_t, Int_t, Float_t)
Update statistics for detector &#39;det&#39;.
Definition: StBemcRaw.cxx:534
Int_t getTotalSaved(Int_t det)
Return the Total number of SAVED hits for the detector &#39;det&#39;.
Definition: StBemcRaw.h:228
int GetTowerCrateFromDaqId(int RDO, int &crate, int &sequence) const
Get crate number from Daq Id for towers.
void createDecoder(Int_t, Int_t)
Create new StEmcDecoder.
Definition: StBemcRaw.cxx:233
unsigned short TDCHeader[120]
This is the TDC event header.
Definition: EMC_Reader.hh:80
unsigned short HasData[12]
1 if there is data for that fiber
Definition: EMC_Reader.hh:121
int GetPreshowerBugCorrectionShift(int id_original, int &shift) const
Returns the index shift for the preshower in original map.
int GetTowerIdFromDaqId(int RDO, int &softId) const
Get Sofwtare Id from Daq Id for towers.
Definition: daq_btow.h:9
int GetPsdRDO(int softId, int &RDO, int &posInFiber) const
Get PSD fiber and position from id.
unsigned short SMDADCArray[12][4800]
Matrix of ADC&#39;s as obtained from daq.
Definition: EMC_Reader.hh:117
int GetCrateFromTowerId(int softId, int &crate, int &sequence) const
Get crate number and position in crate for Software Id.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
int GetTowerIdFromTDC(int TDC, int sequence, int &softId) const
Get Software Id from TDC channel number and position in TDC for towers.
void getCalib(Int_t det, Int_t softId, Int_t power, Float_t &calib) const
Return calibration constant.
virtual ~StBemcRaw()
StBemcRaw destructor.
Definition: StBemcRaw.cxx:208
Bool_t mPsdMapBug
switch for saving all BTOW hits (used in daq-&gt;picoDst production)
Definition: StBemcRaw.h:106
void printConf()
Print configuration.
Definition: StBemcRaw.cxx:217
int GetTowerBugCorrectionShift(int id_original, int &shift) const
Returns the index shift for the tower in original map.
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Definition: StEmcGeom.h:321
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
int GetPsdId(int RDO, int posInFiber, int &softId, bool print=false) const
Get PSD id.
int GetTowerTDCFromCrate(int crate, int &TDC) const
Get TDC channel from crate number for towers.
int GetSmdRDO(int detector, int m, int e, int s, int &RDO, int &posInFiber) const
Get SMD fiber and position from detector number (3==SMDE, 4==SMDP), m, e, s.
int GetDaqIdFromTowerId(int softId, int &RDO) const
Get Daq Id from Software Id for towers.
int GetTDCFromTowerId(int softId, int &TDC) const
Get TDC channel from Software Id.
void checkBtowCrates(StEmcRawData *, StEvent *)
check tower crates
Definition: StBemcRaw.cxx:486