2 #include "StIstRawHitMaker.h"
5 #include "St_base/StMessMgr.h"
6 #include "RTS/src/DAQ_FGT/daq_fgt.h"
7 #include "RTS/src/DAQ_READER/daq_dta.h"
8 #include "StChain/StRtsTable.h"
10 #include "StIstUtil/StIstCollection.h"
11 #include "StIstUtil/StIstRawHitCollection.h"
12 #include "StIstUtil/StIstRawHit.h"
13 #include "StIstDbMaker/StIstDb.h"
14 #include "StIstUtil/StIstConsts.h"
16 #include "tables/St_istPedNoise_Table.h"
17 #include "tables/St_istGain_Table.h"
18 #include "tables/St_istMapping_Table.h"
19 #include "tables/St_istControl_Table.h"
20 #include "tables/St_istChipConfig_Table.h"
23 StIstRawHitMaker::StIstRawHitMaker(
const char *name ):
StRTSBaseMaker(
"ist", name ),
24 mIsCaliMode(false), mDoEmbedding(false), mDoCmnCorrection(false),
25 mHitCut(5.), mCmnCut(3.),
26 mIstCollectionPtr(new
StIstCollection()), mIstCollectionSimuPtr(nullptr),
27 mCmnVec(kIstNumApvs, 0),
28 mPedVec(kIstNumElecIds, 0),
29 mRmsVec(kIstNumElecIds, 0),
30 mGainVec(kIstNumElecIds, 0),
31 mMappingVec(kIstNumElecIds, 0),
32 mConfigVec(kIstNumApvs, 1),
37 StIstRawHitMaker::~StIstRawHitMaker()
71 LOG_ERROR <<
"InitRun : no istDb" << endm;
76 const istControl_st *istControlTable = mIstDb->getControl() ;
78 if (!istControlTable) {
79 LOG_ERROR <<
"Pointer to IST control table is null" << endm;
83 mHitCut = istControlTable[0].kIstHitCutDefault;
84 mCmnCut = istControlTable[0].kIstCMNCutDefault;
85 mChanMinRmsNoiseLevel = istControlTable[0].kIstChanMinRmsNoiseLevel;
86 mChanMaxRmsNoiseLevel = istControlTable[0].kIstChanMaxRmsNoiseLevel;
87 mApvMaxCmNoiseLevel = istControlTable[0].kIstApvMaxCmNoiseLevel;
88 mALLdata = istControlTable[0].kIstAlldata;
89 mADCdata = istControlTable[0].kIstADCdata;
90 mZSdata = istControlTable[0].kIstZSdata;
91 mDefaultTimeBin = istControlTable[0].kIstDefaultTimeBin;
92 mCurrentTimeBinNum = istControlTable[0].kIstCurrentTimeBinNum;
93 mMinNumOfRawHits = istControlTable[0].kIstMinNumOfRawHits;
94 mMaxNumOfRawHits = istControlTable[0].kIstMaxNumOfRawHits;
98 const istPedNoise_st *gPN = mIstDb->getPedNoise();
101 LOG_ERROR <<
"Pointer to IST pedestal/noise table is null" << endm;
105 for (
int i = 0; i < kIstNumApvs; i++) {
106 LOG_DEBUG << Form(
" Print entry %d : CM noise=%f ", i, (
float)gPN[0].cmNoise[i] / 100.) << endm;
107 mCmnVec[i] = (float)gPN[0].cmNoise[i] / 100.0;
110 for (
int i = 0; i < kIstNumElecIds; i++) {
111 LOG_DEBUG << Form(
" Print entry %d : pedestal=%f ", i, (
float)gPN[0].pedestal[i]) << endm;
112 mPedVec[i] = (float)gPN[0].pedestal[i];
115 for (
int i = 0; i < kIstNumElecIds; i++) {
116 LOG_DEBUG << Form(
" Print entry %d : RMS noise=%f ", i, (
float)gPN[0].rmsNoise[i] / 100.) << endm;
117 mRmsVec[i] = (float)gPN[0].rmsNoise[i] / 100.;
122 const istGain_st *gG = mIstDb->getGain();
125 LOG_WARN <<
"Pointer to IST gain table is null" << endm;
129 for (
int i = 0; i < kIstNumElecIds; i++) {
130 LOG_DEBUG << Form(
" Print entry %d : gain=%f ", i, (
float)gG[0].gain[i]) << endm;
136 const istMapping_st *gM = mIstDb->getMapping();
139 LOG_ERROR <<
"Pointer to IST mapping table is null" << endm;
143 for (
int i = 0; i < kIstNumElecIds; i++) {
144 LOG_DEBUG << Form(
" Print entry %d : geoId=%d ", i, gM[0].mapping[i]) << endm;
150 const istChipConfig_st *gCS = mIstDb->getChipStatus();
153 LOG_ERROR <<
"Pointer to IST chip configuration table is null" << endm;
157 if (runnumber == gCS[0].run) {
158 for (
int i = 0; i < kIstNumApvs; i++) {
159 LOG_DEBUG << Form(
" Print entry %d : status=%d ", i, gCS[0].s[i]) << endm;
182 if ( !istSimuDataSet ) {
183 LOG_WARN <<
"StIstRawHitMaker::Make() - No raw ADC dataset found from simu data! " << endm;
189 LOG_WARN <<
"StIstRawHitMaker::Make() - No istCollection found in simu dataset! "<<endm;
194 UChar_t dataFlag = mALLdata;
195 Int_t ntimebin = mCurrentTimeBinNum;
197 Int_t nRawAdcFromData = 0;
198 int nIdTruth_Ist = 0;
199 Bool_t printed = kFALSE;
201 if (dataFlag == mALLdata) {
202 if (mDataType == mALLdata) {
203 if(!printed) { LOG_INFO <<
" Trying to read ALLdata" << endm; printed = kTRUE; }
207 LOG_WARN <<
"NO ZS-DATA BANK FOUND!!!" << endm;
211 else if (mDataType == mADCdata) {
212 if(!printed) { LOG_INFO <<
" Trying to read ADCdata" << endm; printed = kTRUE; }
215 else if (mDataType == mZSdata) {
216 if(!printed) { LOG_INFO <<
" Trying to read ZSdata" << endm; printed = kTRUE; }
220 else if (dataFlag == mADCdata) {
221 if(!printed) { LOG_INFO <<
" Trying to read ADCdata" << endm; printed = kTRUE; }
224 else if (dataFlag == mZSdata) {
225 if(!printed) { LOG_INFO <<
" Trying to read ZSdata" << endm; printed = kTRUE; }
234 for (
int r = 1; r <= kIstNumRdos; r++) {
235 if (meta->arc[r].present == 0) continue ;
237 for (
int arm = 0; arm < kIstNumArmsPerRdo; arm++) {
238 if (meta->arc[r].arm[arm].present == 0) continue ;
240 for (
int apv = 0; apv < kIstNumApvsPerArm; apv++) {
241 if (meta->arc[r].arm[arm].apv[apv].present == 0) continue ;
243 int nt = meta->arc[r].arm[arm].apv[apv].ntim;
245 if (ntimebin != 0 && nt != 0 && ntimebin != nt)
246 LOG_WARN <<
"Different number of timebins in different APV!!! Taking larger one!!!" << endm;
259 std::array< std::array<double, kIstNumTimeBins>, kIstNumApvChannels > signalUnCorrected{};
261 std::array< std::array<double, kIstNumTimeBins>, kIstNumApvChannels > signalCorrected{};
263 std::array<int, kIstNumApvChannels> idTruth{};
266 double sumAdcPerEvent[kIstNumTimeBins];
267 Int_t counterAdcPerEvent[kIstNumTimeBins];
268 memset(sumAdcPerEvent, 0,
sizeof(sumAdcPerEvent));
269 memset(counterAdcPerEvent, 0,
sizeof(counterAdcPerEvent));
272 Int_t rdo = rts_tbl->Rdo();
273 Int_t arm = rts_tbl->Sector();
274 Int_t apv = rts_tbl->Pad();
278 if (rdo < 1 || rdo > kIstNumRdos) flag = 1;
279 if (arm < 0 || arm >= kIstNumArmsPerRdo) flag = 1;
280 if (apv < 0 || apv >= kIstNumApvsPerArm) flag = 1;
283 LOG_INFO <<
"Corrupt data rdo: " << rdo <<
" arm: " << arm <<
" apv: " << apv << endm;
288 int apvElecId = (rdo - 1) * kIstNumArmsPerRdo * kIstNumApvsPerArm * kIstNumApvChannels + arm * kIstNumApvsPerArm * kIstNumApvChannels + apv * kIstNumApvChannels;
294 Int_t channel = f->ch;
296 Short_t timebin = f->tb;
297 LOG_DEBUG <<
"channel: " << channel <<
" adc: " << adc <<
" time bin: " << timebin << endm;
301 if ((dataFlag == mADCdata) && (adc < 0 || adc >= kIstMaxAdc)) flag = 1;
302 if (channel < 0 || channel >= kIstNumApvChannels) flag = 1;
303 if (timebin < 0 || timebin >= ntimebin) flag = 1;
306 LOG_INFO <<
"Corrupt data channel: " << channel <<
" tbin: " << timebin <<
" adc: " << adc << endm;
310 signalUnCorrected[channel][timebin] = adc;
311 if(adc>0) nRawAdcFromData++;
313 if ( !mIsCaliMode ) {
314 Int_t elecId = apvElecId + channel;
316 if (elecId < 0 || elecId >= kIstNumElecIds) {
317 LOG_INFO <<
"Wrong elecId: " << elecId << endm;
329 if(rawHitCollectionSimuPtr)
331 StIstRawHit * rawHitSimu = rawHitCollectionSimuPtr->getRawHit(elecId);
332 idTruth[channel] = 0;
333 if(rawHitSimu->getCharge(timebin) > 0) {
334 signalUnCorrected[channel][timebin] += rawHitSimu->getCharge(timebin);
340 if ( dataFlag == mADCdata ) {
341 signalCorrected[channel][timebin] = signalUnCorrected[channel][timebin] -
mPedVec[elecId];
344 if ( (signalCorrected[channel][timebin] > (-mCmnCut)*
mRmsVec[elecId]) &&
345 (signalCorrected[channel][timebin] < mCmnCut *
mRmsVec[elecId]) )
347 sumAdcPerEvent[timebin] += signalCorrected[channel][timebin];
348 counterAdcPerEvent[timebin]++;
351 LOG_DEBUG <<
" Corrected = " << signalCorrected[channel][timebin] <<
"\t sumAdcPerEvent = " << sumAdcPerEvent[timebin] << endm;
354 signalCorrected[channel][timebin] = signalUnCorrected[channel][timebin];
359 nIdTruth_Ist += FillRawHitCollectionFromAPVData(dataFlag, ntimebin, counterAdcPerEvent, sumAdcPerEvent, apvElecId, signalUnCorrected, signalCorrected, idTruth);
362 LOG_INFO <<
" Total number of IST Raw Hits - Step I = " <<
mIstCollectionPtr->getNumRawHits() <<
" w/ idTruth = " << nIdTruth_Ist << endm;
367 if(!mDoEmbedding && !nRawAdcFromData) nIdTruth_Ist += FillRawHitCollectionFromSimData();
369 LOG_INFO <<
" Total number of IST Raw Hits - Step II = " <<
mIstCollectionPtr->getNumRawHits() <<
" w/ idTruth = " << nIdTruth_Ist << endm;
379 int StIstRawHitMaker::FillRawHitCollectionFromAPVData(
unsigned char dataFlag,
int ntimebin,
380 int counterAdcPerEvent[],
double sumAdcPerEvent[],
int apvElecId,
381 std::array< std::array<double, kIstNumTimeBins>, kIstNumApvChannels > &signalUnCorrected,
382 std::array< std::array<double, kIstNumTimeBins>, kIstNumApvChannels > &signalCorrected,
383 std::array<int, kIstNumApvChannels> &idTruth)
387 double commonModeNoise[kIstNumTimeBins];
389 for (
int tbIdx = 0; tbIdx < kIstNumTimeBins; tbIdx++)
390 commonModeNoise[tbIdx] = 0.;
392 if ( !mIsCaliMode && dataFlag == mADCdata ) {
393 for (
short iTb = 0; iTb < ntimebin; iTb++) {
394 if (counterAdcPerEvent[iTb] > 0)
395 commonModeNoise[iTb] = sumAdcPerEvent[iTb] / counterAdcPerEvent[iTb];
400 std::vector<bool> isPassRawHitCut(kIstNumApvChannels,
false);
401 Int_t nChanPassedCut = 0;
404 for (
int iChan = 0; iChan < kIstNumApvChannels; iChan++)
406 Int_t elecId = apvElecId + iChan;
408 for (
int iTB = 1; iTB < ntimebin - 1; iTB++)
411 if ( (signalUnCorrected[iChan][iTB] > 0) &&
412 (signalUnCorrected[iChan][iTB] < kIstMaxAdc) &&
413 (signalCorrected[iChan][iTB - 1] > mHitCut *
mRmsVec[elecId]) &&
414 (signalCorrected[iChan][iTB] > mHitCut *
mRmsVec[elecId]) &&
415 (signalCorrected[iChan][iTB + 1] > mHitCut *
mRmsVec[elecId]) )
417 isPassRawHitCut[iChan] = kTRUE;
425 if ( !mIsCaliMode && (nChanPassedCut > mMaxNumOfRawHits || nChanPassedCut < mMinNumOfRawHits) ) {
426 LOG_DEBUG <<
"Skip: The APV chip could be hot with " << nChanPassedCut <<
" channels fired!!" << endm;
431 for (
int iChan = 0; iChan < kIstNumApvChannels; iChan++)
434 Int_t elecId = apvElecId + iChan;
436 Int_t ladder = 1 + (geoId - 1) / (kIstApvsPerLadder * kIstNumApvChannels);
437 Int_t apvId = 1 + (geoId - 1) / kIstNumApvChannels;
442 if ( !rawHitCollectionPtr ) {
443 LOG_WARN <<
"StIstRawHitMaker::Make() -- Could not access rawHitCollection for ladder " << ladder << endm;
448 if (dataFlag == mADCdata) {
456 LOG_DEBUG <<
"Skip: Channel belongs to dead/bad/mis-configured APV chip geometry index: " << apvId <<
" on ladder " << ladder << endm;
461 if (
mRmsVec[elecId] < mChanMinRmsNoiseLevel ||
462 mRmsVec[elecId] > mChanMaxRmsNoiseLevel ||
465 LOG_DEBUG <<
"Skip: Noisy/hot/dead channel electronics index: " << elecId << endm;
469 if ( !isPassRawHitCut[iChan] )
472 UChar_t tempMaxTB = -1;
473 double tempMaxCharge = -999.0;
475 StIstRawHit *rawHitPtr = rawHitCollectionPtr->getRawHit( elecId );
478 for (
int iTBin = 0; iTBin < ntimebin; iTBin++)
480 if ( mDoCmnCorrection && dataFlag == mADCdata )
481 signalCorrected[iChan][iTBin] -= commonModeNoise[iTBin];
483 if (signalCorrected[iChan][iTBin] < 0)
484 signalCorrected[iChan][iTBin] = 0.1;
486 rawHitPtr->setChargeErr(
mRmsVec[elecId] *
mGainVec[elecId], (
unsigned char)iTBin);
488 if (signalCorrected[iChan][iTBin] > tempMaxCharge) {
489 tempMaxCharge = signalCorrected[iChan][iTBin];
490 tempMaxTB = (
unsigned char)iTBin;
493 signalCorrected[iChan][iTBin] *=
mGainVec[elecId];
496 rawHitPtr->
setCharges(signalCorrected[iChan]);
497 rawHitPtr->setChannelId( elecId );
498 rawHitPtr->setGeoId( geoId );
499 rawHitPtr->setMaxTimeBin( tempMaxTB );
500 rawHitPtr->setDefaultTimeBin( mDefaultTimeBin );
501 rawHitPtr->setIdTruth( idTruth[iChan] );
502 if(idTruth[iChan]>0) nIdTruth++;
518 int StIstRawHitMaker::FillRawHitCollectionFromSimData()
523 for( UChar_t ladderIdx=0; ladderIdx <
kIstNumLadders; ++ladderIdx )
526 std::vector<StIstRawHit *> rawAdcSimuVec =
mIstCollectionSimuPtr->getRawHitCollection(ladderIdx)->getRawHitVec();
528 for (
const auto rawAdcSimuPtr : rawAdcSimuVec)
530 if (!rawAdcSimuPtr)
continue;
533 if(rawAdcSimuPtr->getIdTruth()>0) nIdTruth++;
const int kIstNumPadsPerSensor
768 pads in each sensor
StRtsTable * GetNextDaqElement(const char *elementPath)
Query the STAR production chain for the DAQ data.
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
std::vector< float > mRmsVec
Channel elec. index, RMS noise.
std::vector< float > mPedVec
Channel elec. index, pedestal.
StIstCollection * mIstCollectionPtr
const int kIstNumLadders
24 IST Ladders
std::vector< unsigned char > mConfigVec
APV chip configuration status indexed by geom. id.
std::vector< float > mCmnVec
APV chip geom. index, common mode (CM) noise.
std::vector< float > mGainVec
Channel elec. index, gain.
Int_t InitRun(Int_t runNumber)
std::vector< int > mMappingVec
Channel elec. index to geometry ID mapping.
StIstCollection * mIstCollectionSimuPtr
void addRawHit(StIstRawHit *istRawHit)
unsigned short getIdTruth() const
for embedding, 0 as background
void setCharges(const Container &charges)
void Clear(Option_t *opts="")
User defined functions.
const int kIstNumSensorsPerLadder
6 sensor per one IST Ladder
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)