1 #include "StFstRawHitMaker.h"
4 #include "St_base/StMessMgr.h"
5 #include "StRoot/RTS/src/DAQ_FGT/daq_fgt.h"
6 #include "StRoot/RTS/src/DAQ_READER/daq_dta.h"
7 #include "StChain/StRtsTable.h"
9 #include "StFstUtil/StFstCollection.h"
10 #include "StFstUtil/StFstRawHitCollection.h"
11 #include "StEvent/StFstRawHit.h"
12 #include "StEvent/StFstEvtCollection.h"
13 #include "StFstDbMaker/StFstDb.h"
14 #include "StEvent/StFstConsts.h"
16 #include "tables/St_fstPedNoise_Table.h"
17 #include "tables/St_fstGain_Table.h"
18 #include "tables/St_fstMapping_Table.h"
19 #include "tables/St_fstControl_Table.h"
20 #include "tables/St_fstChipConfig_Table.h"
23 StFstRawHitMaker::StFstRawHitMaker(
const char *name ):
StRTSBaseMaker(
"fst", name ),
24 mIsCaliMode(false), mDoEmbedding(false), mDoCmnCorrection(true),
25 mMinHitCut(2.5), mMedHitCut(3.5), mMaxHitCut(4.0),mCmnCut(3.),
26 mFstCollectionPtr(new
StFstCollection()), mFstCollectionSimuPtr(nullptr),
27 mCmnVec(kFstNumApvs, std::vector<std::vector<float>>(kFstNumRStripsPerSensor, std::vector<float>(kFstNumTimeBins, 0))),
28 mPedVec(kFstNumElecIds, std::vector<float>(kFstNumTimeBins, 0)),
29 mTotRmsVec(kFstNumElecIds, std::vector<float>(kFstNumTimeBins, 0)),
30 mRanRmsVec(kFstNumElecIds, std::vector<float>(kFstNumTimeBins, 0)),
31 mGainVec(kFstNumElecIds, 0),
32 mMappingVec(kFstNumElecIds, 0),
33 mConfigVec(kFstNumApvs, 1),
38 StFstRawHitMaker::~StFstRawHitMaker()
40 delete mFstCollectionPtr; mFstCollectionPtr = 0;
50 ToWhiteConst(
"fstRawHitAndCluster", mFstCollectionPtr);
72 LOG_ERROR <<
"InitRun : no fstDb" << endm;
77 const fstControl_st *fstControlTable = mFstDb->getControl() ;
79 if (!fstControlTable) {
80 LOG_ERROR <<
"Pointer to FST control table is null" << endm;
84 mMinHitCut = fstControlTable[0].kFstMinHitCutDefault;
85 mMedHitCut = fstControlTable[0].kFstMedHitCutDefault;
86 mMaxHitCut = fstControlTable[0].kFstMaxHitCutDefault;
87 mCmnCut = fstControlTable[0].kFstCMNCutDefault;
88 mChanMinRmsNoiseLevel = fstControlTable[0].kFstChanMinRmsNoiseLevel;
89 mChanMaxRmsNoiseLevel = fstControlTable[0].kFstChanMaxRmsNoiseLevel;
90 mApvMaxCmNoiseLevel = fstControlTable[0].kFstApvMaxCmNoiseLevel;
91 mALLdata = fstControlTable[0].kFstAlldata;
92 mADCdata = fstControlTable[0].kFstADCdata;
93 mZSdata = fstControlTable[0].kFstZSdata;
94 mDefaultTimeBin = fstControlTable[0].kFstDefaultTimeBin;
95 mCurrentTimeBinNum = fstControlTable[0].kFstCurrentTimeBinNum;
96 mMinNumOfRawHits = fstControlTable[0].kFstMinNumOfRawHits;
97 mMaxNumOfRawHits = fstControlTable[0].kFstMaxNumOfRawHits;
101 const fstPedNoise_st *gPN = mFstDb->getPedNoise();
104 LOG_ERROR <<
"Pointer to FST pedestal/noise table is null" << endm;
108 for (
int i = 0; i < kFstNumApvs; i++) {
109 for (
int j = 0; j < kFstNumRStripsPerSensor; j++) {
110 for (
int k = 0; k < mCurrentTimeBinNum; k++) {
111 LOG_DEBUG << Form(
" Print entry %d-%d-%d : CM noise=%f ", i, j, k, (
float)gPN[0].cmNoise[(i*kFstNumRStripsPerSensor+j)*mCurrentTimeBinNum+k] / 100.) << endm;
112 mCmnVec[i][j][k] = (float)gPN[0].cmNoise[(i*kFstNumRStripsPerSensor+j)*mCurrentTimeBinNum+k] / 100.0;
117 for (
int i = 0; i < kFstNumElecIds; i++) {
118 for (
int j = 0; j < mCurrentTimeBinNum; j++) {
119 LOG_DEBUG << Form(
" Print entry %d-%d : pedestal=%f ", i, j, (
float)gPN[0].pedestal[i*mCurrentTimeBinNum+j]) << endm;
120 mPedVec[i][j] = (float)gPN[0].pedestal[i*mCurrentTimeBinNum+j];
123 for (
int i = 0; i < kFstNumElecIds; i++) {
124 for (
int j = 0; j < mCurrentTimeBinNum; j++) {
125 LOG_DEBUG << Form(
" Print entry %d-%d : RMS noise=%f ", i, j, (
float)gPN[0].totNoise[i*mCurrentTimeBinNum+j] / 100.) << endm;
126 mTotRmsVec[i][j] = (float)gPN[0].totNoise[i*mCurrentTimeBinNum+j] / 100.;
129 for (
int i = 0; i < kFstNumElecIds; i++) {
130 for (
int j = 0; j < mCurrentTimeBinNum; j++) {
131 LOG_DEBUG << Form(
" Print entry %d-%d : RMS noise=%f ", i, j, (
float)gPN[0].ranNoise[i*mCurrentTimeBinNum+j] / 100.) << endm;
132 mRanRmsVec[i][j] = (float)gPN[0].ranNoise[i*mCurrentTimeBinNum+j] / 100.;
138 const fstGain_st *gG = mFstDb->getGain();
141 LOG_WARN <<
"Pointer to FST gain table is null" << endm;
145 for (
int i = 0; i < kFstNumElecIds; i++) {
146 LOG_DEBUG << Form(
" Print entry %d : gain=%f ", i, (
float)gG[0].gain[i]) << endm;
147 mGainVec[i] = (float)gG[0].gain[i];
152 const fstMapping_st *gM = mFstDb->getMapping();
155 LOG_ERROR <<
"Pointer to FST mapping table is null" << endm;
159 for (
int i = 0; i < kFstNumElecIds; i++) {
160 LOG_DEBUG << Form(
" Print entry %d : geoId=%d ", i, gM[0].mapping[i]) << endm;
161 mMappingVec[i] = gM[0].mapping[i];
166 const fstChipConfig_st *gCS = mFstDb->getChipStatus();
169 LOG_ERROR <<
"Pointer to FST chip configuration table is null" << endm;
173 for (
int i = 0; i < kFstNumApvs; i++) {
174 LOG_DEBUG << Form(
" Print entry %d : status=%d ", i, gCS[0].s[i]) << endm;
175 mConfigVec[i] = gCS[0].s[i];
196 if ( !fstSimuDataSet ) {
197 LOG_WARN <<
"StFstRawHitMaker::Make() - No raw ADC dataset found from simu data! " << endm;
202 if( !mFstCollectionSimuPtr ) {
203 LOG_WARN <<
"StFstRawHitMaker::Make() - No fstCollection found in simu dataset! "<<endm;
208 UChar_t dataFlag = mALLdata;
209 Int_t ntimebin = mCurrentTimeBinNum;
211 Int_t nRawAdcFromData = 0;
212 int nIdTruth_Fst = 0;
213 Bool_t printed = kFALSE;
215 if (dataFlag == mALLdata) {
216 if (mDataType == mALLdata) {
217 if(!printed) { LOG_INFO <<
" Trying to read ALLdata" << endm; printed = kTRUE; }
218 rts_tbl = GetNextDaqElement(
"fst/zs"); dataFlag = mZSdata;
221 LOG_WARN <<
"NO ZS-DATA BANK FOUND!!!" << endm;
222 rts_tbl = GetNextDaqElement(
"fst/adc"); dataFlag = mADCdata;
225 else if (mDataType == mADCdata) {
226 if(!printed) { LOG_INFO <<
" Trying to read ADCdata" << endm; printed = kTRUE; }
227 rts_tbl = GetNextDaqElement(
"fst/adc"); dataFlag = mADCdata;
229 else if (mDataType == mZSdata) {
230 if(!printed) { LOG_INFO <<
" Trying to read ZSdata" << endm; printed = kTRUE; }
231 rts_tbl = GetNextDaqElement(
"fst/zs"); dataFlag = mZSdata;
234 else if (dataFlag == mADCdata) {
235 if(!printed) { LOG_INFO <<
" Trying to read ADCdata" << endm; printed = kTRUE; }
236 rts_tbl = GetNextDaqElement(
"fst/adc");
238 else if (dataFlag == mZSdata) {
239 if(!printed) { LOG_INFO <<
" Trying to read ZSdata" << endm; printed = kTRUE; }
240 rts_tbl = GetNextDaqElement(
"fst/zs");
248 for (
int r = 1; r <= kFstNumRdos; r++) {
249 if (meta->arc[r].present == 0) continue ;
251 for (
int arm = 0; arm < kFstNumArmsPerRdo; arm++) {
252 if (meta->arc[r].arm[arm].present == 0) continue ;
254 for (
int apv = 0; apv < 24; apv++) {
255 if (meta->arc[r].arm[arm].apv[apv].present == 0) continue ;
257 int nt = meta->arc[r].arm[arm].apv[apv].ntim;
259 if (ntimebin != 0 && nt != 0 && ntimebin != nt)
260 LOG_WARN <<
"Different number of timebins in different APV!!! Taking larger one!!!" << endm;
269 mFstCollectionPtr->setNumTimeBins(ntimebin);
273 std::array< std::array<double, kFstNumTimeBins>, kFstNumApvChannels > signalUnCorrected{};
275 std::array< std::array<double, kFstNumTimeBins>, kFstNumApvChannels > signalCorrected{};
277 std::array< std::array<int, kFstNumTimeBins>, kFstNumApvChannels > seedFlag{};
279 std::array<int, kFstNumApvChannels> idTruth{};
282 double sumAdcPerRgroupPerEvent[kFstNumRStripsPerWedge][kFstNumTimeBins];
283 Int_t counterAdcPerRgroupPerEvent[kFstNumRStripsPerWedge][kFstNumTimeBins];
284 memset(sumAdcPerRgroupPerEvent, 0,
sizeof(sumAdcPerRgroupPerEvent));
285 memset(counterAdcPerRgroupPerEvent, 0,
sizeof(counterAdcPerRgroupPerEvent));
288 Int_t rdo = rts_tbl->Rdo();
289 Int_t arm = rts_tbl->Sector();
290 Int_t apvro = rts_tbl->Pad();
292 if(apvro>7) apv = apvro-4;
297 if (rdo < 1 || rdo > kFstNumRdos) flag = 1;
298 if (arm < 0 || arm >= kFstNumArmsPerRdo) flag = 1;
299 if (apv < 0 || apv >= kFstNumApvsPerArm) flag = 1;
302 LOG_INFO <<
"Corrupt data rdo: " << rdo <<
" arm: " << arm <<
" apv: " << apv << endm;
307 int apvElecId = (rdo - 1) * kFstNumArmsPerRdo * kFstNumApvsPerArm * kFstNumApvChannels + arm * kFstNumApvsPerArm * kFstNumApvChannels + apv * kFstNumApvChannels;
313 Int_t channel = f->ch;
315 Short_t timebin = f->tb;
316 Int_t sFlag = f->flags;
317 LOG_DEBUG <<
"channel: " << channel <<
" adc: " << adc <<
" time bin: " << timebin << endm;
321 if ((dataFlag == mADCdata) && (adc < 0 || adc >= kFstMaxAdc)) flag = 1;
322 if (channel < 0 || channel >= kFstNumApvChannels) flag = 1;
323 if (timebin < 0 || timebin >= ntimebin) flag = 1;
326 LOG_INFO <<
"Corrupt data channel: " << channel <<
" tbin: " << timebin <<
" adc: " << adc << endm;
330 signalUnCorrected[channel][timebin] = adc;
331 seedFlag[channel][timebin] = sFlag;
332 if(adc>0) nRawAdcFromData++;
334 if ( !mIsCaliMode ) {
335 Int_t elecId = apvElecId + channel;
337 if (elecId < 0 || elecId >= kFstNumElecIds) {
338 LOG_INFO <<
"Wrong elecId: " << elecId << endm;
344 if (mFstCollectionSimuPtr)
346 Int_t geoId = mMappingVec[elecId];
347 Int_t wedge = 1 + geoId / (kFstNumInnerSensorsPerWedge * kFstNumStripsPerInnerSensor + kFstNumOuterSensorsPerWedge * kFstNumStripsPerOuterSensor);
349 StFstRawHitCollection *rawHitCollectionSimuPtr = mFstCollectionSimuPtr->getRawHitCollection(wedge-1);
350 if(rawHitCollectionSimuPtr)
352 StFstRawHit * rawHitSimu = rawHitCollectionSimuPtr->getRawHit(elecId);
353 idTruth[channel] = 0;
354 if(rawHitSimu->getCharge(timebin) > 0) {
355 signalUnCorrected[channel][timebin] += rawHitSimu->getCharge(timebin);
361 if ( dataFlag == mADCdata ) {
362 signalCorrected[channel][timebin] = signalUnCorrected[channel][timebin] - mPedVec[elecId][timebin];
365 if ( (signalCorrected[channel][timebin] > (-mCmnCut)*mTotRmsVec[elecId][timebin]) &&
366 (signalCorrected[channel][timebin] < mCmnCut *mTotRmsVec[elecId][timebin]) )
368 Int_t geoId = mMappingVec[elecId];
369 int rstrip = (geoId % (kFstNumInnerSensorsPerWedge * kFstNumStripsPerInnerSensor + kFstNumOuterSensorsPerWedge * kFstNumStripsPerOuterSensor))/kFstNumPhiSegPerWedge;
370 sumAdcPerRgroupPerEvent[rstrip][timebin] += signalCorrected[channel][timebin];
371 counterAdcPerRgroupPerEvent[rstrip][timebin]++;
374 LOG_DEBUG <<
" Corrected = " << signalCorrected[channel][timebin] << endm;
377 signalCorrected[channel][timebin] = signalUnCorrected[channel][timebin];
382 nIdTruth_Fst += FillRawHitCollectionFromAPVData(dataFlag, ntimebin, counterAdcPerRgroupPerEvent, sumAdcPerRgroupPerEvent, apvElecId, signalUnCorrected, signalCorrected, seedFlag, idTruth);
385 LOG_INFO <<
" Total number of FST Raw Hits - Step I = " << mFstCollectionPtr->getNumRawHits() <<
" w/ idTruth = " << nIdTruth_Fst << endm;
390 if(!mDoEmbedding && !nRawAdcFromData) nIdTruth_Fst += FillRawHitCollectionFromSimData();
392 LOG_INFO <<
" Total number of FST Raw Hits - Step II = " << mFstCollectionPtr->getNumRawHits() <<
" w/ idTruth = " << nIdTruth_Fst << endm;
395 if(IAttr(
"fstEvtRawHit")) {
396 LOG_INFO <<
" Filling FST Raw Hits into StEvent" << endm;
399 mEvent = (
StEvent *) GetInputDS(
"StEvent");
402 LOG_DEBUG<<
"Found StEvent"<<endm;
406 LOG_DEBUG <<
"Added StEvent"<<endm;
410 mFstEvtCollection = mEvent->fstEvtCollection();
413 if (!mFstEvtCollection) {
415 mEvent->setFstEvtCollection(mFstEvtCollection);
416 LOG_DEBUG <<
"Make() - Added new StFstEvtCollection to this StEvent" << endm;
419 if(mFstCollectionPtr->getNumRawHits() > 0) {
420 for(
int wedgeIdx=0; wedgeIdx<kFstNumWedges; ++wedgeIdx ){
422 if( rawHitCollectionPtr ){
423 std::vector<StFstRawHit*>& rawHitVec = rawHitCollectionPtr->getRawHitVec();
424 std::vector< StFstRawHit* >::iterator rawHitIter;
426 for( rawHitIter = rawHitVec.begin(); rawHitIter != rawHitVec.end(); ++rawHitIter ){
429 mFstEvtCollection->addRawHit(newRawHit);
444 int StFstRawHitMaker::FillRawHitCollectionFromAPVData(
unsigned char dataFlag,
int ntimebin,
445 int counterAdcPerRgroupPerEvent[][kFstNumTimeBins],
double sumAdcPerRgroupPerEvent[][kFstNumTimeBins],
int apvElecId,
446 std::array< std::array<double, kFstNumTimeBins>, kFstNumApvChannels > &signalUnCorrected,
447 std::array< std::array<double, kFstNumTimeBins>, kFstNumApvChannels > &signalCorrected,
448 std::array< std::array<int, kFstNumTimeBins>, kFstNumApvChannels > &seedFlag,
449 std::array<int, kFstNumApvChannels> &idTruth)
453 double commonModeNoise[kFstNumRStripsPerWedge][kFstNumTimeBins];
455 for (
int tbIdx = 0; tbIdx < kFstNumTimeBins; tbIdx++){
456 for (
int rindex = 0; rindex < kFstNumRStripsPerWedge; rindex++)
457 commonModeNoise[rindex][tbIdx] = 0.;
460 if ( !mIsCaliMode && dataFlag == mADCdata ) {
461 for (
short iTb = 0; iTb < ntimebin; iTb++) {
462 for (
int rindex = 0; rindex < kFstNumRStripsPerWedge; rindex++){
463 if (counterAdcPerRgroupPerEvent[rindex][iTb] > 0)
464 commonModeNoise[rindex][iTb] = sumAdcPerRgroupPerEvent[rindex][iTb] / counterAdcPerRgroupPerEvent[rindex][iTb];
470 std::vector<bool> isPassRawHitCut(kFstNumApvChannels,
false);
471 Int_t nChanPassedCut = 0;
473 for (
int iChan = 0; iChan < kFstNumApvChannels; iChan++)
475 Int_t elecId = apvElecId + iChan;
476 Int_t geoId = mMappingVec[elecId];
478 for (
int iTBin = 0; iTBin < ntimebin; iTBin++)
480 if (!mIsCaliMode && mDoCmnCorrection && dataFlag == mADCdata ){
481 int rstrip = (geoId % (kFstNumInnerSensorsPerWedge * kFstNumStripsPerInnerSensor + kFstNumOuterSensorsPerWedge * kFstNumStripsPerOuterSensor))/kFstNumPhiSegPerWedge;
482 signalCorrected[iChan][iTBin] -= commonModeNoise[rstrip][iTBin];
486 for (
int iTB = 0; iTB < ntimebin; iTB++)
489 if ( (dataFlag == mADCdata) && (signalUnCorrected[iChan][iTB] > 0) &&
490 (signalUnCorrected[iChan][iTB] < kFstMaxAdc) &&
491 ((signalCorrected[iChan][iTB] > mMedHitCut * mRanRmsVec[elecId][iTB])||
492 (iTB >0 && (signalCorrected[iChan][iTB-1] > mMinHitCut * mRanRmsVec[elecId][iTB]) &&
493 (signalCorrected[iChan][iTB] > mMinHitCut * mRanRmsVec[elecId][iTB]))))
495 isPassRawHitCut[iChan] = kTRUE;
500 if( (dataFlag == mZSdata) && (seedFlag[iChan][iTB] > 0) )
502 isPassRawHitCut[iChan] = kTRUE;
510 if ( !mIsCaliMode && (nChanPassedCut > mMaxNumOfRawHits || nChanPassedCut < mMinNumOfRawHits) ) {
511 LOG_DEBUG <<
"Skip: The APV chip could be hot with " << nChanPassedCut <<
" channels fired!!" << endm;
516 for (
int iChan = 0; iChan < kFstNumApvChannels; iChan++)
518 Int_t seedhitflag = 0;
520 Int_t elecId = apvElecId + iChan;
521 Int_t geoId = mMappingVec[elecId];
522 Int_t wedge = 1 + geoId / (kFstApvsPerWedge * kFstNumApvChannels);
523 Int_t apvId = elecId / kFstNumApvChannels;
528 if ( !rawHitCollectionPtr ) {
529 LOG_WARN <<
"StFstRawHitMaker::Make() -- Could not access rawHitCollection for wedge " << wedge << endm;
534 if (dataFlag == mADCdata) {
536 StFstRawHit *rawHitPtr = rawHitCollectionPtr->getRawHit( elecId );
537 rawHitPtr->
setCharges(signalUnCorrected[iChan]);
538 rawHitPtr->setChannelId( elecId );
539 rawHitPtr->setGeoId( geoId );
545 if (mConfigVec[apvId] < 1 || mConfigVec[apvId] > 9) {
546 LOG_DEBUG <<
"Skip: Channel belongs to dead/bad/mis-configured APV chip electronic index: " << apvId <<
" on wedge " << wedge << endm;
551 if (mRanRmsVec[elecId][mDefaultTimeBin] < mChanMinRmsNoiseLevel ||
552 mRanRmsVec[elecId][mDefaultTimeBin] > mChanMaxRmsNoiseLevel ||
553 mRanRmsVec[elecId][mDefaultTimeBin] > 99.0)
555 LOG_DEBUG <<
"Skip: Noisy/hot/dead channel electronics index: " << elecId << endm;
559 if ( !isPassRawHitCut[iChan] )
562 UChar_t tempMaxTB = -1;
563 double tempMaxCharge = -999.0;
565 StFstRawHit *rawHitPtr = rawHitCollectionPtr->getRawHit( elecId );
568 for (
int iTBin = 0; iTBin < ntimebin; iTBin++)
570 if (signalCorrected[iChan][iTBin] < 0)
571 signalCorrected[iChan][iTBin] = 0.1;
573 rawHitPtr->setChargeErr(mRanRmsVec[elecId][iTBin] * mGainVec[elecId], (
unsigned char)iTBin);
575 if (signalCorrected[iChan][iTBin] > tempMaxCharge) {
576 tempMaxCharge = signalCorrected[iChan][iTBin];
577 tempMaxTB = (
unsigned char)iTBin;
580 signalCorrected[iChan][iTBin] *= mGainVec[elecId];
581 if( (dataFlag == mADCdata) && (iTBin >0) &&
582 (signalCorrected[iChan][iTBin-1] > mMaxHitCut * mRanRmsVec[elecId][iTBin-1]) &&
583 (signalCorrected[iChan][iTBin] > mMaxHitCut * mRanRmsVec[elecId][iTBin]))
587 if( (dataFlag == mZSdata) && (seedFlag[iChan][iTBin] == 7) )
593 rawHitPtr->
setCharges(signalCorrected[iChan]);
594 rawHitPtr->setChannelId( elecId );
595 rawHitPtr->setGeoId( geoId );
596 rawHitPtr->setSeedhitflag( seedhitflag );
597 rawHitPtr->setMaxTimeBin( tempMaxTB );
598 rawHitPtr->setDefaultTimeBin( mDefaultTimeBin );
599 rawHitPtr->setIdTruth( idTruth[iChan] );
600 if(idTruth[iChan]>0) nIdTruth++;
616 int StFstRawHitMaker::FillRawHitCollectionFromSimData()
619 if(!mFstCollectionSimuPtr)
return 0;
621 for( UChar_t wedgeIdx=0; wedgeIdx < kFstNumWedges; ++wedgeIdx )
624 std::vector<StFstRawHit *> rawAdcSimuVec = mFstCollectionSimuPtr->getRawHitCollection(wedgeIdx)->getRawHitVec();
626 for (
const auto rawAdcSimuPtr : rawAdcSimuVec)
628 if (!rawAdcSimuPtr)
continue;
631 if(rawAdcSimuPtr->getIdTruth()>0) nIdTruth++;
639 if (mFstCollectionPtr ) {
640 for (
unsigned char i = 0; i < kFstNumWedges; ++i ) {
641 mFstCollectionPtr->getRawHitCollection(i)->Clear(
"" );
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
void addRawHit(StFstRawHit *fstRawHit)
Int_t InitRun(Int_t runNumber)
unsigned short getIdTruth() const
for embedding, 0 as background
void setCharges(const Container &charges)
void Clear(Option_t *opts="")
User defined functions.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)