28 #include "TObjectSet.h"
29 #include "StMessMgr.h"
31 #include "StSvtBadAnodesMaker.h"
32 #include "StarClassLibrary/StSequence.hh"
33 #include "StSvtClassLibrary/StSvtHybridBadAnodes.hh"
34 #include "StSvtClassLibrary/StSvtHybridData.hh"
35 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
36 #include "StSvtClassLibrary/StSvtData.hh"
37 #include "StSvtClassLibrary/StSvtHybridPed.hh"
40 #define MAX_NUMBER_OF_ANODES 240
50 mHybridBadAnodes = NULL;
62 BAD_MEAN_PED_MAX = 255;
64 BAD_MEAN_RMS_MAX = 255;
66 NULL_ADC_THRESHOLD = 129;
67 OVERLOADED_ADC_THRESHOLD = 129;
68 OCCUP_THRESHOLD = 129;
71 FREQ_OVERLOADED_ADC = 1.1;
75 mFileName =
new TString(
"badAnodes.root");
79 StSvtBadAnodesMaker::~StSvtBadAnodesMaker()
82 void StSvtBadAnodesMaker::setOutputFile(
const char* name)
87 mFileName =
new TString(name);
91 Int_t StSvtBadAnodesMaker::Init()
93 if (Debug()) gMessMgr->Debug() <<
"StSvtBadAnodesMaker::Init" << endm;
109 if (Debug()) bookHistograms();
111 gMessMgr->Info() <<
"NULL_ADC = " << NULL_ADC << endm;
112 gMessMgr->Info() <<
"OVERLOADED_ADC = " << OVERLOADED_ADC << endm;
114 gMessMgr->Info() <<
"THRESHOLD NULL_ADC (fraction of time bins) = " << NULL_ADC_THRESHOLD << endm;
115 gMessMgr->Info() <<
"THRESHOLD OVERLOADED_ADC (fraction of time bins) = " << OVERLOADED_ADC_THRESHOLD << endm;
116 gMessMgr->Info() <<
"THRESHOLD OCCUP (fraction of time bins) = " << OCCUP_THRESHOLD << endm;
118 gMessMgr->Info() <<
"FREQUENCY OVERLOADED_ADC (fraction of events) = " << FREQ_OVERLOADED_ADC << endm;
119 gMessMgr->Info() <<
"FREQUENCY NULL_ADC (fraction of events) = " << FREQ_NULL_ADC << endm;
120 gMessMgr->Info() <<
"FREQUENCY OCCUP (fraction of events) = " << FREQ_OCCUP << endm;
122 gMessMgr->Info() <<
"BAD MEAN PED_MIN = " << BAD_MEAN_PED_MIN << endm;
123 gMessMgr->Info() <<
"BAD MEAN PED_MAX = " << BAD_MEAN_PED_MAX << endm;
124 gMessMgr->Info() <<
"BAD MEAN RMS_MIN = " << BAD_MEAN_RMS_MIN << endm;
125 gMessMgr->Info() <<
"BAD MEAN RMS_MAX = " << BAD_MEAN_RMS_MAX << endm;
127 return StMaker::Init();
131 void StSvtBadAnodesMaker::setSvtData()
135 dataSet = GetDataSet(
"StSvtRawData");
142 void StSvtBadAnodesMaker::setPedestal()
144 if (Debug()) gMessMgr->Debug() <<
"StSvtQAMaker::setPedestal" << endm;
148 dataSet = GetDataSet(
"StSvtPedestal");
157 void StSvtBadAnodesMaker::setRMSPedestal()
159 if (Debug()) gMessMgr->Debug() <<
"StSvtQAMaker::setRMSPedestal" << endm;
163 dataSet = GetDataSet(
"StSvtRMSPedestal");
172 void StSvtBadAnodesMaker::setSvtBadAnodes()
179 if (!mSvtBadAnodes) {
181 dataset->
SetObject((TObject*)mSvtBadAnodes);
182 assert(mSvtBadAnodes);
187 void StSvtBadAnodesMaker::bookHistograms()
194 mFile =
new TFile(mFileName->Data(),
"RECREATE");
196 mBadAnodesHist =
new TH2F*[mSvtData->getTotalNumberOfHybrids()];
198 mBadAnodesBarrel =
new TH1F*[3];
199 mBadAnodesBarrel[0] =
new TH1F(
"barrel1",
"Fraction of Bad Anodes",8,0.5,8.5);
200 mBadAnodesBarrel[1] =
new TH1F(
"barrel2",
"Fraction of Bad Anodes",12,0.5,12.5);
201 mBadAnodesBarrel[2] =
new TH1F(
"barrel3",
"Fraction of Bad Anodes",16,0.5,16.5);
203 mBadAnodesLadder =
new TH1F*[36];
205 for (
int barrel = 1;barrel <= mSvtData->getNumberOfBarrels();barrel++) {
206 for (
int ladder = 1;ladder <= mSvtData->getNumberOfLadders(barrel);ladder++) {
207 for (
int wafer = 1;wafer <= mSvtData->getNumberOfWafers(barrel);wafer++) {
208 for (
int hybrid = 1;hybrid <= mSvtData->getNumberOfHybrids();hybrid++) {
210 index = mSvtData->getHybridIndex(barrel,ladder,wafer,hybrid);
211 if(index < 0)
continue;
213 sprintf(preTitle,
"BadAnodes");
214 sprintf(posTitle,
"b%dl%dw%dh%d",barrel, ladder, wafer, hybrid);
215 title = strcat(preTitle,posTitle);
217 mBadAnodesHist[index] =
new TH2F(title,
"Bad Anodes ADC",240,0.5,240.5,128,-0.5,127.5);
221 sprintf(preTitle,
"ladder");
222 sprintf(posTitle,
"b%dl%d",barrel, ladder);
223 title = strcat(preTitle,posTitle);
228 mBadAnodesLadder[index2] =
new TH1F(title,
"Fraction of Bad Anodes",8,0.5,8.5);
231 index2 = mSvtData->getNumberOfLadders(barrel) + (ladder-1);
232 mBadAnodesLadder[index2] =
new TH1F(title,
"Fraction of Bad Anodes",12,0.5,12.5);
235 index2 = mSvtData->getNumberOfLadders(barrel) + (ladder-1);
236 mBadAnodesLadder[index2] =
new TH1F(title,
"Fraction of Bad Anodes",14,0.5,14.5);
247 int adc, anode, nAnodes, nSeq, iseq, time, timeSeq, status, index;
250 int nullAdc, overloadedAdc, occup, badRMS;
251 float ped,rms,meanPed, meanRms;
259 for (
int barrel = 1;barrel <= mSvtData->getNumberOfBarrels();barrel++) {
260 for (
int ladder = 1;ladder <= mSvtData->getNumberOfLadders(barrel);ladder++) {
261 for (
int wafer = 1;wafer <= mSvtData->getNumberOfWafers(barrel);wafer++) {
262 for (
int hybrid = 1;hybrid <= mSvtData->getNumberOfHybrids();hybrid++) {
264 index = mSvtData->getHybridIndex(barrel, ladder, wafer, hybrid);
265 if (index < 0)
continue;
269 if (!mHybridData)
continue;
272 if (!mHybridBadAnodes)
276 nAnodes = mHybridData->getAnodeList(anodeList);
278 for (
int ianode=0;ianode<nAnodes;ianode++) {
286 anode = anodeList[ianode];
290 status = mHybridData->getSequences(anode,nSeq,Seq);
292 for (iseq=0;iseq<nSeq;iseq++) {
293 for (timeSeq=0; timeSeq<Seq[iseq].length; timeSeq++) {
295 time = Seq[iseq].startTimeBin + timeSeq;
296 adc =(int)Seq[iseq].firstAdc[timeSeq];
303 if (adc == OVERLOADED_ADC)
307 if ((adc > 0) && (adc < 255))
312 if (nullAdc >= NULL_ADC_THRESHOLD)
313 mHybridBadAnodes->addNullAdc(anode,kTRUE,mEvents);
315 mHybridBadAnodes->addNullAdc(anode,kFALSE,mEvents);
316 if (overloadedAdc >= OVERLOADED_ADC_THRESHOLD)
317 mHybridBadAnodes->addOverloadedAdc(anode,kTRUE,mEvents);
319 mHybridBadAnodes->addOverloadedAdc(anode,kFALSE,mEvents);
320 if (occup >= OCCUP_THRESHOLD)
321 mHybridBadAnodes->addHighOccup(anode,kTRUE,mEvents);
323 mHybridBadAnodes->addHighOccup(anode,kFALSE,mEvents);
326 mSvtBadAnodes->put_at((TObject*)mHybridBadAnodes,index);
335 for (
int barrel = 1;barrel <= mSvtPed->getNumberOfBarrels();barrel++) {
336 for (
int ladder = 1;ladder <= mSvtPed->getNumberOfLadders(barrel);ladder++) {
337 for (
int wafer = 1;wafer <= mSvtPed->getNumberOfWafers(barrel);wafer++) {
338 for (
int hybrid = 1;hybrid <= mSvtPed->getNumberOfHybrids();hybrid++) {
340 index = mSvtPed->getHybridIndex(barrel, ladder, wafer, hybrid);
341 if (index < 0)
continue;
345 if (!mHybridPed)
continue;
348 if (!mHybridBadAnodes)
351 for (
int anode=1;anode<=240;anode++) {
353 for (time=4; time<127; time++) {
356 ped = mHybridPed->At(mHybridPed->getPixelIndex(anode, time));
362 if ((meanPed < BAD_MEAN_PED_MIN) || (meanPed > BAD_MEAN_PED_MAX))
363 mHybridBadAnodes->setBadAnode(anode);
366 mSvtBadAnodes->put_at((TObject*)mHybridBadAnodes,index);
375 for (
int barrel = 1;barrel <= mSvtRMSPed->getNumberOfBarrels();barrel++) {
376 for (
int ladder = 1;ladder <= mSvtRMSPed->getNumberOfLadders(barrel);ladder++) {
377 for (
int wafer = 1;wafer <= mSvtRMSPed->getNumberOfWafers(barrel);wafer++) {
378 for (
int hybrid = 1;hybrid <= mSvtRMSPed->getNumberOfHybrids();hybrid++) {
380 index = mSvtRMSPed->getHybridIndex(barrel, ladder, wafer, hybrid);
381 if (index < 0)
continue;
385 if (!mHybridRMSPed)
continue;
388 if (!mHybridBadAnodes)
391 for (
int anode=1;anode<=240;anode++) {
393 for (time=4; time<127; time++) {
396 rms = (mHybridRMSPed->At(mHybridRMSPed->getPixelIndex(anode, time)))/mRmsScaleFactor;
406 if ((meanRms < BAD_MEAN_RMS_MIN) || (meanRms > BAD_MEAN_RMS_MAX))
407 mHybridBadAnodes->setBadAnode(anode);
410 mSvtBadAnodes->put_at((TObject*)mHybridBadAnodes,index);
421 void StSvtBadAnodesMaker::writeToFile(
const char* fileName)
423 mFileNameTxt =
new TString(mFileName->Data());
424 mFileNameTxt->ReplaceAll(
"root",
"txt");
425 ofstream file2(mFileNameTxt->Data());
426 mFileNameTxt->ReplaceAll(
"txt",
"Daq.txt");
427 ofstream file(mFileNameTxt->Data());
429 int anode, index, nTotalBadAnodes = 0;
430 int recBoard, mezz, mz_hyb;
433 for (
int barrel = 1;barrel <= mSvtBadAnodes->getNumberOfBarrels();barrel++) {
434 for (
int ladder = 1;ladder <= mSvtBadAnodes->getNumberOfLadders(barrel);ladder++) {
435 for (
int wafer = 1;wafer <= mSvtBadAnodes->getNumberOfWafers(barrel);wafer++) {
436 for (
int hybrid = 1;hybrid <= mSvtBadAnodes->getNumberOfHybrids();hybrid++) {
438 blwh2rma(barrel, ladder, wafer, hybrid, recBoard, mezz, mz_hyb);
440 index = mSvtBadAnodes->getHybridIndex(barrel, ladder, wafer, hybrid);
441 if (index < 0)
continue;
445 if (!mHybridBadAnodes)
continue;
447 for (
int ianode=0;ianode<MAX_NUMBER_OF_ANODES;ianode++) {
449 if (mHybridBadAnodes->isBadAnode(anode)) {
450 file << recBoard <<
" " << mezz <<
" " << mz_hyb <<
" "
451 << anode <<
" " <<
"0.0" << endl;
452 file2 << barrel <<
" " << ladder <<
" " << wafer <<
" " << hybrid <<
" " << anode << endl;
461 file2 << (float)nTotalBadAnodes/((
float)MAX_NUMBER_OF_ANODES*432.) << endl;
467 if (Debug()) gMessMgr->Debug() <<
"StSvtBadAnodesMaker::Finish" << endm;
469 cout << FREQ_NULL_ADC <<
" " << FREQ_OVERLOADED_ADC <<
" " << FREQ_OCCUP << endl;
471 int adc, anode, nSeq, iseq, time, timeSeq, status, index, index2, ihybrid;
472 int nBadAnodesHyb=0, nBadAnodesLadder=0;
477 for (
int barrel = 1;barrel <= mSvtBadAnodes->getNumberOfBarrels();barrel++) {
478 for (
int ladder = 1;ladder <= mSvtBadAnodes->getNumberOfLadders(barrel);ladder++) {
479 for (
int wafer = 1;wafer <= mSvtBadAnodes->getNumberOfWafers(barrel);wafer++) {
480 for (
int hybrid = 1;hybrid <= mSvtBadAnodes->getNumberOfHybrids();hybrid++) {
482 index = mSvtBadAnodes->getHybridIndex(barrel, ladder, wafer, hybrid);
483 if (index < 0)
continue;
487 if (!mHybridBadAnodes)
continue;
491 if (!mHybridData)
continue;
493 for (
int ianode=0;ianode<MAX_NUMBER_OF_ANODES;ianode++) {
496 if ((mHybridBadAnodes->getNullAdc(anode) >= FREQ_NULL_ADC) ||
497 (mHybridBadAnodes->getOverloadedAdc(anode) >= FREQ_OVERLOADED_ADC) ||
498 (mHybridBadAnodes->getHighOccup(anode) >= FREQ_OCCUP))
499 mHybridBadAnodes->setBadAnode(anode);
504 if (mHybridBadAnodes->isBadAnode(anode)) {
512 status = mHybridData->getSequences(anode,nSeq,Seq);
514 for (iseq=0;iseq<nSeq;iseq++) {
515 for (timeSeq=0; timeSeq<Seq[iseq].length; timeSeq++) {
517 time = Seq[iseq].startTimeBin + timeSeq;
518 adc =(int)Seq[iseq].firstAdc[timeSeq];
520 mBadAnodesHist[index]->Fill(anode,time,adc);
528 ihybrid = (wafer-1)*2+hybrid;
529 fraction = (float)nBadAnodesHyb/240.;
534 mBadAnodesLadder[index2]->Fill(ihybrid,fraction);
537 index2 = mSvtData->getNumberOfLadders(barrel) + (ladder-1);
538 mBadAnodesLadder[index2]->Fill(ihybrid,fraction);
541 index2 = mSvtData->getNumberOfLadders(barrel) + (ladder-1);
542 mBadAnodesLadder[index2]->Fill(ihybrid,fraction);
552 fraction = (float)nBadAnodesLadder/(240.*(
float)mSvtBadAnodes->getNumberOfLadders(barrel));
553 mBadAnodesBarrel[barrel-1]->Fill(ladder,fraction);
554 nBadAnodesLadder = 0;
570 void StSvtBadAnodesMaker::Reset()
572 if (Debug()) gMessMgr->Debug() <<
"StSvtBadAnodesMaker::Clear" << endm;
575 for (
int barrel = 1;barrel <= mSvtBadAnodes->getNumberOfBarrels();barrel++) {
576 for (
int ladder = 1;ladder <= mSvtBadAnodes->getNumberOfLadders(barrel);ladder++) {
577 for (
int wafer = 1;wafer <= mSvtBadAnodes->getNumberOfWafers(barrel);wafer++) {
578 for (
int hybrid = 1;hybrid <= mSvtBadAnodes->getNumberOfHybrids();hybrid++) {
580 index = mSvtBadAnodes->getHybridIndex(barrel, ladder, wafer, hybrid);
581 if (index < 0)
continue;
585 if (mHybridBadAnodes)
delete mHybridBadAnodes;
586 mSvtBadAnodes->put_at(NULL,index);
594 void StSvtBadAnodesMaker::blwh2rma(
int barrel,
int ladder,
int wafer,
int hybrid,
595 int& recBoard,
int& mezz,
int& mz_hyb)
599 recBoard = key_barrel1[ladder-1][wafer-1][hybrid-1][0];
600 mezz = key_barrel1[ladder-1][wafer-1][hybrid-1][1];
601 mz_hyb = key_barrel1[ladder-1][wafer-1][hybrid-1][2];
604 recBoard = key_barrel2[ladder-1][wafer-1][hybrid-1][0];
605 mezz = key_barrel2[ladder-1][wafer-1][hybrid-1][1];
606 mz_hyb = key_barrel2[ladder-1][wafer-1][hybrid-1][2];
609 recBoard = key_barrel3[ladder-1][wafer-1][hybrid-1][0];
610 mezz = key_barrel3[ladder-1][wafer-1][hybrid-1][1];
611 mz_hyb = key_barrel3[ladder-1][wafer-1][hybrid-1][2];
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)