1 #include "StFmsCalibMaker.h"
2 #include "StFmsCalibMakerQa.h"
7 #include "StLorentzVectorF.hh"
10 #include "StEventTypes.h"
11 #include "StEvent/StEvent.h"
12 #include "StEvent/StFmsCollection.h"
13 #include "StEvent/StFmsHit.h"
14 #include "StEvent/StFmsPoint.h"
15 #include "StEvent/StFmsPointPair.h"
16 #include "StEvent/StTriggerData.h"
17 #include "StEvent/StTriggerId.h"
18 #include "StFmsDbMaker/StFmsDbMaker.h"
19 #include "StMessMgr.h"
20 #include "StMuDSTMaker/COMMON/StMuEvent.h"
21 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
38 void StFmsCalibMaker::ReadCellStat(
const char* list)
41 cout <<Form(
"Reading cell status from %s...", list) <<endl;
43 int detId, ch, stat, nBad = 0, nDead = 0;
48 LOG_ERROR <<
"StFmsCalibMaker::ReadCellStat - cannot find the list!\n" <<endm;
53 in >> detId >> ch >> stat;
54 if (!in.good())
break;
56 mCellStat[detId-8].insert(std::pair<int, int>(ch, stat));
57 if (stat==BAD) { cout <<Form(
"%2i %3i, %i", detId, ch, stat) <<endl; nBad++; }
58 if (stat==DEAD) { cout <<Form(
"%2i %3i, %i", detId, ch, stat) <<endl; nDead++; }
62 cout <<Form(
"Total # of bad/dead channels: %i/%i \n", nBad, nDead) <<endl;
68 Int_t StFmsCalibMaker::CheckFmsTrigger(
const StTriggerId& trigId,
const int mFmsTrigIdBase)
73 for (
int a=0; a<4; a++)
74 for (
int b=0; b<3; b++)
75 for (
int c=0; c<13; c++)
77 int tempId = mFmsTrigIdBase + 10000*a + 20*b + 1+c;
78 if (trigId.isTrigger(tempId)) trigFired |= (1 << c);
85 Int_t StFmsCalibMaker::ReadBbcSlewing(
const char* filename_bbc)
94 FILE *pFile = fopen( filename_bbc,
"read" );
95 fgets( s, 100, pFile );
96 for(
int ew=0; ew<2; ew++ )
97 for(
int p=0; p<16; p++ )
99 fscanf( pFile,
" %d %d %f %f %f \n", &iew, &ipmt, &ca, &cb, &cc);
100 if ( ew==iew && p+1==ipmt )
102 mBbcSlew[ew][p][0] = ca;
103 mBbcSlew[ew][p][1] = cb;
104 mBbcSlew[ew][p][2] = cc;
110 cout <<
"BBC slewing: z(A+B/[C+adc])" << endl;
111 for(
int ew=0; ew<2; ew++ )
113 if( ew==0 ) cout <<
" East" << endl;
114 if( ew==1 ) cout <<
" West" << endl;
115 for(
int p=0; p<16; p++ )
117 cout << Form(
"PMT%2d - %7.2f %7.2f %7.2f ",
118 p+1, mBbcSlew[ew][p][0], mBbcSlew[ew][p][1], mBbcSlew[ew][p][2]) << endl;
127 Float_t StFmsCalibMaker::GetBbcZCorr(
const StTriggerData* triggerData)
130 Float_t bbcZ = -999.;
131 Float_t bbcTdiff = -999.;
132 UShort_t tdc1east, tdc1west;
133 UShort_t pmt1east, pmt1west;
134 UShort_t adc1east, adc1west;
135 unsigned int tdcMatchEast = 0;
136 unsigned int tdcMatchWest = 0;
137 bbcTdiff = (float)triggerData->bbcTimeDifference();
138 tdc1east = triggerData->bbcEarliestTDC(east);
139 tdc1west = triggerData->bbcEarliestTDC(west);
142 for (
int i=1; i<=16; i++ )
144 if ( tdc1east==triggerData->bbcTDC(east, i) )
146 adc1east = triggerData->bbcADC(east, i);
150 if ( tdc1west==triggerData->bbcTDC(west, i) )
152 adc1west = triggerData->bbcADC(west, i);
159 if ( tdcMatchEast==1 && tdcMatchWest==1 )
161 Float_t zEast = -0.3 * ( bbcTdiff
162 - mBbcSlew[0][pmt1east][0]
163 - mBbcSlew[0][pmt1east][1]/(mBbcSlew[0][pmt1east][2] + adc1east) );
164 Float_t zWest = -0.3 * ( bbcTdiff
165 - mBbcSlew[1][pmt1west][0]
166 - mBbcSlew[1][pmt1west][1]/(mBbcSlew[1][pmt1west][2] + adc1west) );
167 bbcZ = (zEast + zWest)/2.0;
174 Float_t StFmsCalibMaker::GetBbcZCorrMass(
StFmsPointPair* pair, Float_t bbcZ,
bool returnOpenA)
176 const Float_t e0 = pair->point(0)->energy();
177 const Float_t e1 = pair->point(1)->energy();
178 const Float_t x0 = pair->point(0)->XYZ().x();
179 const Float_t x1 = pair->point(1)->XYZ().x();
180 const Float_t y0 = pair->point(0)->XYZ().y();
181 const Float_t y1 = pair->point(1)->XYZ().y();
182 const Float_t z0 = pair->point(0)->XYZ().z() - bbcZ;
183 const Float_t z1 = pair->point(1)->XYZ().z() - bbcZ;
185 const Float_t dist = sqrt(pow(x0 - x1, 2) + pow(y0 - y1, 2) + pow(z0 - z1, 2));
186 const Float_t zAvg = (z0 + z1)/2;
188 const Float_t corrOpenA = 2 * atan(dist / (2*zAvg));
189 const Float_t corrMass = sqrt(2 * e0 * e1 * (1 - cos(corrOpenA)));
191 if (returnOpenA)
return corrOpenA;
196 Int_t StFmsCalibMaker::Init()
198 mFmsDbMk =
static_cast<StFmsDbMaker*
>(GetMaker(
"fmsDb"));
201 LOG_ERROR <<
"StFmsCalibMaker::InitRun - !StFmsDbMaker" <<endl;
209 Int_t StFmsCalibMaker::InitRun(
int runNo)
211 Info(
"InitRun",
"Start run %i...", runNo);
214 mFile =
new TFile(mOutName,
"RECREATE");
215 mFile->SetCompressionLevel(9);
219 for (
int a=0; a<4; a++)
221 const int detId = a+8;
222 const int maxCh = mFmsDbMk->maxChannel(detId);
225 for (
int b=0; b<maxCh; b++)
228 const float gain = mFmsDbMk->getGain(detId, ch);
229 const float gainCorr = mFmsDbMk->getGainCorrection(detId, ch);
230 if (gain==0)
continue;
232 const char* stat =
"";
233 if (mCellStat[a][ch]==BAD) stat =
"BAD";
234 else if (mCellStat[a][ch]==DEAD) stat =
"DEAD";
235 cout <<Form(
"%2i %3i %4.3f %s", detId, ch, gainCorr, stat) <<endl;
238 if (mReadCellStat==
true && mCellStat[a][ch]==BAD && gainCorr!=0.000)
240 cout <<Form(
"\nWARNING!!! Bad marked cell's gainCorr is alive: d%i ch%i\n", detId, ch) <<endl;
246 mH2_mass[a] =
new TH2F(Form(
"mass_d%i", detId),
";ch;mass", maxCh,0.5,maxCh+0.5, 50,0.,0.5);
247 mH2_mass[a]->Sumw2();
248 mH2_massFine[a] =
new TH2F(Form(
"mass_d%i_fine", detId),
";ch;mass", maxCh,0.5,maxCh+0.5, 250,0.,0.5);
249 mH2_massFine[a]->Sumw2();
256 out1.open(
"FmsMapBase.txt");
257 out2.open(
"FmsMapBitShift.txt");
258 for (
int a=0; a<4; a++)
260 const int detId = a+8;
261 const int maxCh = mFmsDbMk->maxChannel(detId);
262 for (
int b=0; b<maxCh; b++)
265 const float gain = mFmsDbMk->getGain(detId, ch);
266 if (gain==0)
continue;
268 const int bs = mFmsDbMk->getBitShiftGain(detId, ch);
269 const int col = mFmsDbMk->getColumnNumber(detId, ch);
270 const int row = mFmsDbMk->getRowNumber(detId, ch);
271 const float chX = mFmsDbMk->getStarXYZ(detId, ch).x();
272 const float chY = mFmsDbMk->getStarXYZ(detId, ch).y();
274 out1 <<Form(
"%2i %3i %4.3f %2i %2i %6.2f %6.2f", detId, ch, gain, col, row, chX, chY) <<endl;
275 out2 <<Form(
"%2i %3i %2i", detId, ch, bs) <<endl;
288 if (mApplyBbcZvtx) mQa->CreateQaHistZVtx();
289 for (
int a=0; a<4; a++)
291 const int detId = a+8;
292 const int maxCh = mFmsDbMk->maxChannel(detId);
293 if (mGetQaHist) mQa->CreateQaHist(detId, maxCh);
296 mQa->CreateQaHistAdc(detId, maxCh, mTrigMB);
297 if (a==0) cout <<Form(
"\nWARNING! GetQaHistAdc() is used with trigger %i\n", mTrigMB) <<endl;
300 if (mGetQaTree) mQa->CreateQaTree();
317 if (mEvent%1000 == 0) cout <<Form(
"%5i processed...", mEvent) <<endl;
318 if (mGetQaHist) mQa->mH1_nEvents->Fill(mRunNo);
323 LOG_ERROR <<
"StFmsCalibMaker::Make - !MuDst" <<endl;
329 mXing = muDST->
event()->triggerData()->bunchId7Bit();
330 if ((mXing>=30 && mXing<40) || (mXing>=110 && mXing<120))
return kStSkip;
335 const StTriggerId& trigId = muDST->
event()->triggerIdCollection().nominal();
336 if (trigId.isTrigger(mTrigMB)) mQa->mH1_trig->Fill(mTrigMB);
342 mTrig = CheckFmsTrigger(muDST->
event()->triggerIdCollection().nominal());
345 cout <<
"No FMS trigger fired! Skip event " <<mEvent <<endl;
348 for (
int i=0; i<13; i++)
350 bool mTrigFire =
false;
351 if (mTrig & (1<<i)) mTrigFire =
true;
352 if (i==11 && mTrigFire==
true)
return kStSkip;
353 if (i==12 && mTrigFire==
true)
return kStSkip;
361 if (!triggerData) { LOG_ERROR <<
"StFmsCalibMaker::Make - !triggerData" <<endl;
return kStErr; }
362 UShort_t vpdWestTdc = triggerData->vpdEarliestTDC(west);
363 if (vpdWestTdc > mVpdCut)
return kStSkip;
370 LOG_ERROR <<
"StFmsCalibMaker::Make - !StEvent" <<endl;
383 mBbcZ = GetBbcZCorr(triggerData);
384 if (mBbcZ == -999.)
return kStSkip;
385 else mQa->mH1_bbcZ->Fill(mBbcZ);
391 StSPtrVecFmsHit& HITS = mFmsColl->hits();
392 const int nHITS = mFmsColl->numberOfHits();
393 for (
int a=0; a<nHITS; a++)
395 const int detId = HITS[a]->detectorId();
396 const int ch = HITS[a]->channel();
397 if (detId<8 || detId>11)
continue;
399 const unsigned short adcRaw = HITS[a]->adc();
400 const unsigned short adcCor = mFmsDbMk->getCorrectedAdc(detId, ch, adcRaw);
402 if (adcCor>3 && adcCor<250) mQa->mH2_adc[detId-8]->Fill(ch, adcCor);
403 mQa->mH2_adcWide[detId-8]->Fill(ch, adcCor);
412 vector<StFmsPointPair*>& PAIRS = mFmsColl->pointPairs();
413 const int nPAIRS = mFmsColl->numberOfPointPairs();
414 for (
int a=0; a<nPAIRS; a++)
418 if (pair->energy() < 20.)
continue;
419 if (pair->energy() > 40.)
continue;
420 if (pair->zgg() > 0.7)
continue;
423 const float mass = (mApplyBbcZvtx)?GetBbcZCorrMass(pair, mBbcZ):pair->mass();
424 if (mass > 0.5)
continue;
427 if (pair->point(0)->nParentClusterPhotons() != 1 ||
428 pair->point(1)->nParentClusterPhotons() != 1)
continue;
431 bool massFilled =
false;
432 for (
int b=0; b<2; b++)
437 const float nTowers = cluster->nTowers();
438 const float sigMax = cluster->sigmaMax();
439 const float sigMin = cluster->sigmaMin();
440 if (nTowers < 2 || sigMax < 0.1 || sigMin < 0.01) cutClu =
false;
442 StPtrVecFmsHit* hits = &(cluster->hits());
443 const int nHits = hits->size();
444 for (
int c=0; c<nHits; c++)
446 const int tempDet = hits->at(c)->detectorId();
447 const int tempCh = hits->at(c)->channel();
448 const float tempE = hits->at(c)->energy();
449 if (tempDet<8 || tempDet>11)
continue;
450 if (tempDet>9 && cutClu==
false)
continue;
452 if (tempE/pair->energy() > 0.3)
454 mH2_mass [tempDet-8]->Fill(tempCh, mass);
455 mH2_massFine[tempDet-8]->Fill(tempCh, mass);
462 if (massFilled && mApplyBbcZvtx)
466 const float pointE0 = pair->point(0)->energy();
467 const float pointE1 = pair->point(1)->energy();
468 const float orig_openA = acos((v0.px()*v1.px() + v0.py()*v1.py() + v0.pz()*v1.pz()) / (pointE0*pointE1));
469 const float orig_mass = pair->mass();
470 const float corr_openA = GetBbcZCorrMass(pair, mBbcZ,
true);
471 const float corr_mass = GetBbcZCorrMass(pair, mBbcZ);
472 mQa->mH1_diffOpenA->Fill(orig_openA - corr_openA);
473 mQa->mH1_diffMass ->Fill(orig_mass - corr_mass);
480 if (mGetQaHist==
false && mGetQaTree==
false)
return kStOk;
482 for (
int a=0; a<nPAIRS; a++)
486 if (pair->energy() < 20.)
continue;
487 if (pair->zgg() > 0.7)
continue;
490 const float openA = (mApplyBbcZvtx)?GetBbcZCorrMass(pair, mBbcZ,
true):GetBbcZCorrMass(pair, 0,
true);
491 const float mass = (mApplyBbcZvtx)?GetBbcZCorrMass(pair, mBbcZ):pair->mass();
492 if (mass > 1.0)
continue;
495 if (pair->point(0)->nParentClusterPhotons() != 1 ||
496 pair->point(1)->nParentClusterPhotons() != 1)
continue;
499 const float pairE = pair->energy();
500 bool fillQaTree =
false;
501 for (
int b=0; b<2; b++)
503 const float pointX = pair->point(b)->XYZ().x();
504 const float pointY = pair->point(b)->XYZ().y();
509 const float nTowers = cluster->nTowers();
510 const float sigMax = cluster->sigmaMax();
511 const float sigMin = cluster->sigmaMin();
512 if (nTowers < 2 || sigMax < 0.1 || sigMin < 0.01) cutClu =
false;
514 StPtrVecFmsHit* hits = &(cluster->hits());
515 const int nHits = hits->size();
516 for (
int c=0; c<nHits; c++)
518 const int tempDet = hits->at(c)->detectorId();
519 const int tempCh = hits->at(c)->channel();
520 const float tempE = hits->at(c)->energy();
521 if (tempDet<8 || tempDet>11)
continue;
527 if (tempE/pairE > 0.3) fillQaTree =
true;
529 const int nHit = mQa->mNhit;
530 if (nHit > mQa->mNhitMax) LOG_ERROR <<
"WARNING! nhit exceeds allowed limit!" <<endl;
531 mQa->mDetId [nHit] = tempDet;
532 mQa->mCh [nHit] = tempCh;
533 mQa->mPointB[nHit] = b;
534 mQa->mHitE [nHit] = tempE;
542 if (tempDet>9 && cutClu==
false)
continue;
545 for (
int i=0; i<7; i++) {
if (pair->zgg() > 0.1*i && pair->zgg() < 0.1*(i+1)) iZgg = i; }
548 for (
int i=0; i<7; i++)
550 if (pairE > 20+10*i && pairE < 20+10*(i+1)) iPairE = i;
551 if (pairE > 80) iPairE = 6;
555 if (pairE<40 && mass<0.5 && tempE/pairE>0.3)
557 mQa->mH2_pointsEP[tempDet-8]->Fill(vecF.pseudoRapidity(), vecF.phi());
558 mQa->mH2_pointsXY[b][0]->Fill(pointX, pointY);
559 if (tempDet<=9) mQa->mH2_pointsXY[b][1]->Fill(pointX, pointY);
560 else mQa->mH2_pointsXY[b][2]->Fill(pointX, pointY);
564 if (pairE<40 && tempE/pairE>0.3)
566 mQa->mH2_massWide[tempDet-8]->Fill(tempCh, mass);
567 mQa->mH2_massOpenA[tempDet-8][iZgg]->Fill(openA, mass);
573 mQa->mH2_massPairE[tempDet-8][iZgg]->Fill(pairE, mass);
574 mQa->mH2_massZgg[tempDet-8][iPairE]->Fill(pair->zgg(), mass);
581 mQa->mCluTowers[b] = cluster->nTowers();
582 mQa->mCluMax[b] = cluster->sigmaMax();
583 mQa->mCluMin[b] = cluster->sigmaMin();
584 mQa->mCluX[b] = cluster->x();
585 mQa->mCluY[b] = cluster->y();
587 mQa->mPointE[b] = pair->point(b)->energy();
588 mQa->mPointX[b] = pair->point(b)->XYZ().x();
589 mQa->mPointY[b] = pair->point(b)->XYZ().y();
594 if (mGetQaTree && fillQaTree && mQa->mNhit>0)
597 mQa->mOpenA = (mApplyBbcZvtx)?GetBbcZCorrMass(pair, mBbcZ,
true):GetBbcZCorrMass(pair, 0,
true);
598 mQa->mZgg = pair->zgg();
599 mQa->mTrigBit = mTrig;
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)