6 #include "StEvent/StTriggerData.h"
7 #include "StMtdCollection.h"
8 #include "StMtdHeader.h"
9 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
10 #include "StMuDSTMaker/COMMON/StMuDst.h"
11 #include "StMuDSTMaker/COMMON/StMuEvent.h"
12 #include "StMuDSTMaker/COMMON/StMuMtdHeader.h"
13 #include "StPicoDstMaker/StPicoDstMaker.h"
14 #include "StPicoEvent/StPicoDst.h"
15 #include "StPicoEvent/StPicoEvent.h"
16 #include "StPicoEvent/StPicoMtdTrigger.h"
17 #include "tables/St_mtdModuleToQTmap_Table.h"
18 #include "tables/St_mtdQTSlewingCorr_Table.h"
19 #include "tables/St_mtdQTSlewingCorrPart2_Table.h"
21 #include "StMtdTrigUtil.h"
32 mPosCorrToQTtac = kTRUE;
37 void StMtdTrigUtil::reset()
42 memset(mTHUBtime,0,
sizeof(mTHUBtime));
43 memset(mQtTacSum,0,
sizeof(mQtTacSum));
44 memset(mMT101Tac,0,
sizeof(mMT101Tac));
45 memset(mMT101Id,0,
sizeof(mMT101Id));
46 memset(mQtPosTrig,-1,
sizeof(mQtPosTrig));
47 memset(mQtPosHighestTwo,-1,
sizeof(mQtPosHighestTwo));
48 memset(mQtTacSumHighestTwo,0,
sizeof(mQtTacSumHighestTwo));
52 StMtdTrigUtil::~StMtdTrigUtil()
57 Int_t StMtdTrigUtil::Init()
71 if(GetInputDS(
"StEvent"))
73 LOG_DEBUG <<
"Running on StEvent ..." << endm;
74 mStEvent = (
StEvent*) GetInputDS(
"StEvent");
77 else if(GetMaker(
"MuDst"))
79 LOG_DEBUG <<
"Running on MuDst ..." << endm;
81 mMuDst = muDstMaker->
muDst();
82 extractTrigInfo(const_cast<StTriggerData*>(mMuDst->
event()->triggerData()));
84 else if(GetMaker(
"picoDst"))
86 LOG_DEBUG <<
"Running on PicoDst ..." << endm;
88 mPicoDst = picoDstMaker->
picoDst();
89 extractTrigInfo(mPicoDst);
93 LOG_ERROR <<
"Input file format unrecongnized ..." << endm;
106 LOG_ERROR <<
"No trigger data available ..." << endm;
111 if(mStEvent) runnumber = mStEvent->runId();
112 else if(mMuDst) runnumber = mMuDst->
event()->runNumber();
115 LOG_ERROR <<
"Invalid input data format ..." << endm;
118 int year = runnumber / 1e6 + 1999;
119 if ((runnumber % 1000000) / 1000 >= 273) year += 1;
127 StMtdHeader *mtdHeader = mtdCollection->mtdHeader();
130 mTHUBtime[0] = 25 * (mtdHeader->triggerTime(0)&0xfff);
131 mTHUBtime[1] = 25 * (mtdHeader->triggerTime(1)&0xfff);
140 mTHUBtime[0] = 25 * ( muMtdHeader->triggerTime(1) & 0xfff );
141 mTHUBtime[1] = 25 * ( muMtdHeader->triggerTime(2) & 0xfff );
146 mVpdTacSum = trigData->vpdEarliestTDCHighThr(east,0) + trigData->vpdEarliestTDCHighThr(west,0);
149 Int_t mtd_qt_tac_max = 4095;
150 Int_t mtd_qt_tac_min = 100;
151 if (runnumber >= 16045067) mtd_qt_tac_min = 80;
152 if (runnumber >= 18070005) mtd_qt_tac_min = 200;
153 Int_t mtd_qt_tac_diff_range_abs = 600;
154 if (year == 2015) mtd_qt_tac_diff_range_abs = 1023;
156 Int_t mtdQTtac[kNQTboard][16];
157 Int_t mtdQTadc[kNQTboard][16];
158 for(Int_t i=0; i<32; i++)
160 Int_t type = (i/4)%2;
165 mtdQTtac[0][i-i/4*2-2] = trigData->mtdAtAddress(i,0);
166 mtdQTtac[1][i-i/4*2-2] = trigData->mtdgemAtAddress(i,0);
167 mtdQTtac[2][i-i/4*2-2] = trigData->mtd3AtAddress(i,0);
168 mtdQTtac[3][i-i/4*2-2] = trigData->mtd4AtAddress(i,0);
172 mtdQTadc[0][i-i/4*2] = trigData->mtdAtAddress(i,0);
173 mtdQTadc[1][i-i/4*2] = trigData->mtdgemAtAddress(i,0);
174 mtdQTadc[2][i-i/4*2] = trigData->mtd3AtAddress(i,0);
175 mtdQTadc[3][i-i/4*2] = trigData->mtd4AtAddress(i,0);
180 for(
int im=0; im<kNQTboard; im++)
182 if(type==0) mtdQTadc[im][i-i/4*2] = trigData->mtdQtAtCh(im+1,i,0);
183 else mtdQTtac[im][i-i/4*2-2] = trigData->mtdQtAtCh(im+1,i,0);
190 for(Int_t im=0; im<kNQTboard; im++)
192 if(year<=2015 && im>3)
continue;
193 for(
int i=0; i<8; i++)
195 if(year==2016 && i%2 == 0)
197 mQtTacSum[im][i] = 0;
203 for (Int_t k=0; k<2; k++)
205 j[k] = mtdQTtac[im][i*2+k];
206 a[k] = mtdQTadc[im][i*2+k];
209 if (a[k]>0 && a[k]<=mQTSlewBinEdge[im][i*2+k][0])
215 for (Int_t l=1; l<8; l++)
217 if (a[k] > mQTSlewBinEdge[im][i*2+k][l-1] && a[k]<=mQTSlewBinEdge[im][i*2+k][l])
226 j[k] += mQTSlewCorr[im][i * 2 + k][slew_bin];
231 if (j[0] <= mtd_qt_tac_min || j[0] >= mtd_qt_tac_max ||
232 j[1] <= mtd_qt_tac_min || j[1] >= mtd_qt_tac_max ||
233 fabs(j[0] - j[1]) >= mtd_qt_tac_diff_range_abs)
235 mQtTacSum[im][i] = 0;
240 Int_t sumTac = j[0] + j[1];
243 Int_t module = mQTtoModule[im][i];
244 if(module<0) sumTac = 0;
245 else sumTac = Int_t( j[0] + j[1] + abs(module-3)*1./8 * (j[0]-j[1]) );
247 mQtTacSum[im][i] = sumTac;
252 for(Int_t i = 0; i < kNQTboard; i++)
256 if(year==2016) idx = i / 2 * 3 + i % 2 * 16;
258 mMT101Tac[i][0] = (trigData->mtdDsmAtCh(idx, 0)) + ((trigData->mtdDsmAtCh(idx + 1, 0) & 0x3) << 8);
259 mMT101Id[i][0] = (trigData->mtdDsmAtCh(idx + 1, 0) & 0xc) >> 2;
260 mMT101Tac[i][1] = (trigData->mtdDsmAtCh(idx + 1, 0) >> 4) + ((trigData->mtdDsmAtCh(idx + 2, 0) & 0x3f) << 4);
261 mMT101Id[i][1] = (trigData->mtdDsmAtCh(idx + 2, 0) & 0xc0) >> 6;
265 Int_t dsmBit1 = trigData->dsmTF201Ch(0);
267 if (year == 2016) dsmBit2 = trigData->dsmTF201Ch(6);
268 for (Int_t i = 0; i < 4; i++)
270 for (Int_t j = 0; j < 2; j++)
275 mTF201TriggerBit |= ((dsmBit1 >> (i * 2 + j + 4)) & 0x1) << (qt * 2 + j);
277 mTF201TriggerBit |= ((dsmBit2 >> (i * 2 + j + 4)) & 0x1) << (qt * 2 + j);
282 mTF201TriggerBit |= ((dsmBit1 >> (i * 2 + j + 4)) & 0x1) << (qt * 2 + j);
289 void StMtdTrigUtil::extractTrigInfo(
StPicoDst *picoDst)
293 LOG_ERROR <<
"No picoDst files available ... " << endm;
300 LOG_ERROR <<
"No StPicoMtdTrigger available ... " << endm;
308 for(Int_t im=0; im<kNQTboard; im++)
310 for(Int_t i=0; i<8; i++)
317 for(Int_t i = 0; i < kNQTboard; i++)
319 for(Int_t j=0; j<2; j++)
333 void StMtdTrigUtil::findFireQT()
336 Int_t mxq_tacsum[kNQTboard][2];
337 Int_t mxq_tacsum_pos[kNQTboard][2];
338 for(Int_t i=0; i<kNQTboard; i++)
340 for(Int_t j=0; j<2; j++)
342 mxq_tacsum[i][j] = 0;
343 mxq_tacsum_pos[i][j] = -1;
347 for(Int_t im=0; im<kNQTboard; im++)
349 for(Int_t i=0; i<8; i++)
351 Int_t sumTac = mQtTacSum[im][i];
353 if(mxq_tacsum[im][0] < sumTac)
355 mxq_tacsum[im][1] = mxq_tacsum[im][0];
356 mxq_tacsum[im][0] = sumTac;
358 mxq_tacsum_pos[im][1] = mxq_tacsum_pos[im][0];
359 mxq_tacsum_pos[im][0] = i+1;
361 else if (mxq_tacsum[im][1] < sumTac)
363 mxq_tacsum[im][1] = sumTac;
364 mxq_tacsum_pos[im][1] = i+1;
367 mQtPosHighestTwo[im][0] = mxq_tacsum_pos[im][0];
368 mQtPosHighestTwo[im][1] = mxq_tacsum_pos[im][1];
369 mQtTacSumHighestTwo[im][0] = mxq_tacsum[im][0];
370 mQtTacSumHighestTwo[im][1] = mxq_tacsum[im][1];
373 for(Int_t im = 0; im < kNQTboard; im++)
375 for(Int_t j=0; j<2; j++)
377 if((mTF201TriggerBit>>(im*2+j))&0x1)
379 mQtPosTrig[im][j] = mQtPosHighestTwo[im][j];
383 mQtPosTrig[im][j] = -1;
390 Bool_t StMtdTrigUtil::isQtFireTrigger(
const Int_t qt,
const Int_t pos)
392 if(qt<1)
return kFALSE;
393 return (pos==mQtPosTrig[qt-1][0] || pos==mQtPosTrig[qt-1][1]);
397 Bool_t StMtdTrigUtil::isQtHighestTwo(
const int qt,
const int pos)
399 if(qt<1)
return kFALSE;
400 return (pos==mQtPosHighestTwo[qt-1][0] || pos==mQtPosHighestTwo[qt-1][1]);
404 Int_t StMtdTrigUtil::getHitTimeInQT(
const int backleg,
const int module)
406 if(backleg<1 || backleg>30 || module<1 || module>5)
return kFALSE;
407 return mQtTacSum[mModuleToQT[backleg-1][module-1]-1][mModuleToQTPos[backleg-1][module-1]-1];
411 Int_t StMtdTrigUtil::getHitTimeDiffToVPDInQT(
const int backleg,
const int module)
413 return getHitTimeInQT(backleg,module)/8 - mVpdTacSum/8 + 1024;
417 Int_t StMtdTrigUtil::getHitTimeDiffToVPDInMT101(
const int backleg,
const int module)
419 Int_t qt = mModuleToQT[backleg-1][module-1];
420 Int_t pos = mModuleToQTPos[backleg-1][module-1];
422 if(pos==mQtPosHighestTwo[qt-1][0]) index = 0;
423 if(pos==mQtPosHighestTwo[qt-1][1]) index = 1;
424 if(index==-1)
return 0;
425 else return (getMT101Tac(qt, index) - mVpdTacSum/8 + 1024);
429 Bool_t StMtdTrigUtil::isHitFireTrigger(
const Int_t backleg,
const Int_t module)
431 if(backleg<1 || backleg>30 || module<1 || module>5)
return kFALSE;
432 return isQtFireTrigger( mModuleToQT[backleg-1][module-1], mModuleToQTPos[backleg-1][module-1] );
436 Bool_t StMtdTrigUtil::isHitHighestTwo(
const Int_t backleg,
const Int_t module)
438 if(backleg<1 || backleg>30 || module<1 || module>5)
return kFALSE;
439 return isQtHighestTwo( mModuleToQT[backleg-1][module-1], mModuleToQTPos[backleg-1][module-1]);
443 Int_t StMtdTrigUtil::InitRun(
const Int_t runNumber)
446 memset(mModuleToQT,-1,
sizeof(mModuleToQT));
447 memset(mModuleToQTPos,-1,
sizeof(mModuleToQTPos));
448 memset(mQTtoModule,-1,
sizeof(mQTtoModule));
451 LOG_INFO <<
"Retrieving mtdModuleToQTmap table from database ..." << endm;
452 TDataSet *dataset = GetDataBase(
"Geometry/mtd/mtdModuleToQTmap");
453 St_mtdModuleToQTmap *mtdModuleToQTmap =
static_cast<St_mtdModuleToQTmap*
>(dataset->
Find(
"mtdModuleToQTmap"));
454 if(!mtdModuleToQTmap)
456 LOG_ERROR <<
"No mtdModuleToQTmap table found in database" << endm;
459 mtdModuleToQTmap_st *mtdModuleToQTtable =
static_cast<mtdModuleToQTmap_st*
>(mtdModuleToQTmap->GetTable());
461 for(Int_t i=0; i<gMtdNBacklegs; i++)
463 for(Int_t j=0; j<gMtdNModules; j++)
465 Int_t index = i*5 + j;
466 Int_t qt = mtdModuleToQTtable->qtBoardId[index];
467 Int_t channel = mtdModuleToQTtable->qtChannelId[index];
468 mModuleToQT[i][j] = qt;
471 mModuleToQTPos[i][j] = channel;
475 if(channel%8==1) mModuleToQTPos[i][j] = 1 + channel/8 * 2;
476 else mModuleToQTPos[i][j] = 2 + channel/8 * 2;
478 if(mModuleToQT[i][j]>0 && mModuleToQTPos[i][j]>0)
479 mQTtoModule[mModuleToQT[i][j]-1][mModuleToQTPos[i][j]-1] = j + 1;
484 memset(mQTSlewBinEdge,-1,
sizeof(mQTSlewBinEdge));
485 memset(mQTSlewCorr,-1,
sizeof(mQTSlewCorr));
486 LOG_INFO <<
"Retrieving mtdQTSlewingCorr table from database ..." << endm;
488 dataset = GetDataBase(
"Calibrations/mtd/mtdQTSlewingCorr");
491 LOG_ERROR <<
"No dataset for mtdQTSlewingCorr found in database" << endm;
494 St_mtdQTSlewingCorr *mtdQTSlewingCorr =
static_cast<St_mtdQTSlewingCorr*
>(dataset->
Find(
"mtdQTSlewingCorr"));
495 if(!mtdQTSlewingCorr)
497 LOG_ERROR <<
"No mtdQTSlewingCorr table found in database" << endm;
500 mtdQTSlewingCorr_st *mtdQTSlewingCorrtable =
static_cast<mtdQTSlewingCorr_st*
>(mtdQTSlewingCorr->GetTable());
501 for(
int j=0; j<4; j++)
503 for(
int i=0; i<16; i++)
505 for(Int_t k=0; k<8; k++)
507 Int_t index = j*16*8 + i*8 + k;
508 mQTSlewBinEdge[j][i][k] = (int) mtdQTSlewingCorrtable->slewingBinEdge[index];
509 mQTSlewCorr[j][i][k] = (
int) mtdQTSlewingCorrtable->slewingCorr[index];
514 LOG_INFO <<
"Retrieving mtdQTSlewingCorrPart2 table from database ..." << endm;
515 dataset = GetDataBase(
"Calibrations/mtd/mtdQTSlewingCorrPart2");
518 St_mtdQTSlewingCorrPart2 *mtdQTSlewingCorr2 =
static_cast<St_mtdQTSlewingCorrPart2*
>(dataset->
Find(
"mtdQTSlewingCorrPart2"));
519 mtdQTSlewingCorrPart2_st *mtdQTSlewingCorrtable2 =
static_cast<mtdQTSlewingCorrPart2_st*
>(mtdQTSlewingCorr2->GetTable());
520 for(
int j=0; j<4; j++)
522 for(
int i=0; i<16; i++)
524 for(Int_t k=0; k<8; k++)
526 Int_t index = j*16*8 + i*8 + k;
527 mQTSlewBinEdge[j+4][i][k] = (int) mtdQTSlewingCorrtable2->slewingBinEdge[index];
528 mQTSlewCorr[j+4][i][k] = (
int) mtdQTSlewingCorrtable2->slewingCorr[index];
534 LOG_INFO <<
"===== End retrieving mtdQTSlewingCorr =====" << endm;
Class that converts MuDst into PicoDst.
Class storing MTD trigger information including VPD, QT, MT101, TF201.
UShort_t getMT101Tac(const Int_t qt, const Int_t index) const
UInt_t getTF201TriggerBit() const
Main class that keeps TClonesArrays with main classes.
StPicoDst * picoDst()
Returns null pointer if no StPicoDst.
UShort_t getMT101Id(const Int_t qt, const Int_t index) const
static StPicoMtdTrigger * mtdTrigger(Int_t i)
Return pointer to i-th MTD trigger data.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
UShort_t getQTtacSum(const Int_t qt, const Int_t pos) const
UShort_t getVpdTacSum() const
VPD tag sum.
virtual TDataSet * Find(const char *path) const