StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFstRawHitMaker.cxx
1 #include "StFstRawHitMaker.h"
2 
3 #include "StEvent.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"
8 
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"
15 
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"
21 
22 
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),
34  mDataType(0)
35 {
36 }
37 
38 StFstRawHitMaker::~StFstRawHitMaker()
39 {
40  delete mFstCollectionPtr; mFstCollectionPtr = 0;
41 }
42 
43 
49 {
50  ToWhiteConst("fstRawHitAndCluster", mFstCollectionPtr);
51 
52  return kStOk;
53 }
54 
55 
60 Int_t StFstRawHitMaker::InitRun(Int_t runnumber)
61 {
62  Int_t ierr = kStOk;
63 
64  TObjectSet *fstDbDataSet = (TObjectSet *)GetDataSet("fst_db");
65  StFstDb *mFstDb = NULL;
66 
67  if (fstDbDataSet) {
68  mFstDb = (StFstDb *)fstDbDataSet->GetObject();
69  assert(mFstDb);
70  }
71  else {
72  LOG_ERROR << "InitRun : no fstDb" << endm;
73  return kStErr;
74  }
75 
76  // FST control parameters
77  const fstControl_st *fstControlTable = mFstDb->getControl() ;
78 
79  if (!fstControlTable) {
80  LOG_ERROR << "Pointer to FST control table is null" << endm;
81  ierr = kStErr;
82  }
83  else {
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;
98  }
99 
100  // FST pedestal/rms table
101  const fstPedNoise_st *gPN = mFstDb->getPedNoise();
102 
103  if ( !gPN ) {
104  LOG_ERROR << "Pointer to FST pedestal/noise table is null" << endm;
105  ierr = kStErr;
106  }
107  else {
108  for (int i = 0; i < kFstNumApvs; i++) {
109  for ( int j = 0; j < kFstNumRStripsPerSensor; j++) {
110  for ( int k = 0; k < kFstNumTimeBins; k++) {
111  LOG_DEBUG << Form(" Print entry %d-%d-%d : CM noise=%f ", i, j, k, (float)gPN[0].cmNoise[(i*kFstNumRStripsPerSensor+j)*kFstNumTimeBins+k] / 100.) << endm;
112  mCmnVec[i][j][k] = (float)gPN[0].cmNoise[(i*kFstNumRStripsPerSensor+j)*kFstNumTimeBins+k] / 100.0;
113  }
114  }
115  }
116 
117  for (int i = 0; i < kFstNumElecIds; i++) {
118  for ( int j = 0; j < kFstNumTimeBins; j++) {
119  LOG_DEBUG << Form(" Print entry %d-%d : pedestal=%f ", i, j, (float)gPN[0].pedestal[i*kFstNumTimeBins+j]) << endm;
120  mPedVec[i][j] = (float)gPN[0].pedestal[i*kFstNumTimeBins+j];
121  }
122  }
123  for (int i = 0; i < kFstNumElecIds; i++) {
124  for ( int j = 0; j < kFstNumTimeBins; j++) {
125  LOG_DEBUG << Form(" Print entry %d-%d : RMS noise=%f ", i, j, (float)gPN[0].totNoise[i*kFstNumTimeBins+j] / 100.) << endm;
126  mTotRmsVec[i][j] = (float)gPN[0].totNoise[i*kFstNumTimeBins+j] / 100.;
127  }
128  }
129  for (int i = 0; i < kFstNumElecIds; i++) {
130  for ( int j = 0; j < kFstNumTimeBins; j++) {
131  LOG_DEBUG << Form(" Print entry %d-%d : RMS noise=%f ", i, j, (float)gPN[0].ranNoise[i*kFstNumTimeBins+j] / 100.) << endm;
132  mRanRmsVec[i][j] = (float)gPN[0].ranNoise[i*kFstNumTimeBins+j] / 100.;
133  }
134  }
135  }
136 
137  // FST gain table
138  const fstGain_st *gG = mFstDb->getGain();
139 
140  if ( !gG ) {
141  LOG_WARN << "Pointer to FST gain table is null" << endm;
142  ierr = kStWarn;
143  }
144  else {
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];
148  }
149  }
150 
151  // FST mapping table
152  const fstMapping_st *gM = mFstDb->getMapping();
153 
154  if ( !gM ) {
155  LOG_ERROR << "Pointer to FST mapping table is null" << endm;
156  ierr = kStErr;
157  }
158  else {
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];
162  }
163  }
164 
165  // FST chip configuration status table
166  const fstChipConfig_st *gCS = mFstDb->getChipStatus();
167 
168  if ( !gCS ) {
169  LOG_ERROR << "Pointer to FST chip configuration table is null" << endm;
170  ierr = kStErr;
171  }
172  else {
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]; /* 0 dead; 1 good; 2-9 reserved good status; 10 mis-configured */
176  }
177  }
178 
179  return ierr;
180 }
181 
182 
191 {
192  Int_t ierr = kStOk;
193 
194  //access raw ADC containers from simu data
195  TObjectSet* fstSimuDataSet = (TObjectSet*)GetDataSet("fstRawAdcSimu");
196  if ( !fstSimuDataSet ) {
197  LOG_WARN << "StFstRawHitMaker::Make() - No raw ADC dataset found from simu data! " << endm;
198  }
199  if(fstSimuDataSet) {
200  mFstCollectionSimuPtr = (StFstCollection*)fstSimuDataSet->GetObject();
201  }
202  if( !mFstCollectionSimuPtr ) {
203  LOG_WARN << "StFstRawHitMaker::Make() - No fstCollection found in simu dataset! "<<endm;
204  }
205 
206 
207  StRtsTable *rts_tbl = 0;
208  UChar_t dataFlag = mALLdata;
209  Int_t ntimebin = mCurrentTimeBinNum;
210 
211  Int_t nRawAdcFromData = 0;
212  int nIdTruth_Fst = 0;
213  Bool_t printed = kFALSE;
214  while (1) { //loops over input raw data
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;
219 
220  if (!rts_tbl) {
221  LOG_WARN << "NO ZS-DATA BANK FOUND!!!" << endm;
222  rts_tbl = GetNextDaqElement("fst/adc"); dataFlag = mADCdata;
223  }
224  }
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;
228  }
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;
232  }
233  }
234  else if (dataFlag == mADCdata) {
235  if(!printed) { LOG_INFO << " Trying to read ADCdata" << endm; printed = kTRUE; }
236  rts_tbl = GetNextDaqElement("fst/adc");
237  }
238  else if (dataFlag == mZSdata) {
239  if(!printed) { LOG_INFO << " Trying to read ZSdata" << endm; printed = kTRUE; }
240  rts_tbl = GetNextDaqElement("fst/zs");
241  }
242 
243  if (!rts_tbl) break;
244 
245  apv_meta_t *meta = (apv_meta_t *)rts_tbl->Meta();
246 
247  if (meta) {
248  for (int r = 1; r <= kFstNumRdos; r++) { //6 rdos needed for whole FST detector
249  if (meta->arc[r].present == 0) continue ;
250 
251  for (int arm = 0; arm < kFstNumArmsPerRdo; arm++) { //3 arms per arc
252  if (meta->arc[r].arm[arm].present == 0) continue ;
253 
254  for (int apv = 0; apv < 24; apv++) { //16 apvs per arm
255  if (meta->arc[r].arm[arm].apv[apv].present == 0) continue ;
256 
257  int nt = meta->arc[r].arm[arm].apv[apv].ntim;
258 
259  if (ntimebin != 0 && nt != 0 && ntimebin != nt)
260  LOG_WARN << "Different number of timebins in different APV!!! Taking larger one!!!" << endm;
261 
262  if (ntimebin < nt)
263  ntimebin = nt;
264  }
265  }
266  }
267  }
268 
269  mFstCollectionPtr->setNumTimeBins(ntimebin);
270 
271  // Arrays to store ADC information per APV chip (128 channels over all time bins)
272  // Signal w/o pedestal subtracted
273  std::array< std::array<double, kFstNumTimeBins>, kFstNumApvChannels > signalUnCorrected{};
274  // Signal w/ pedestal subtracted
275  std::array< std::array<double, kFstNumTimeBins>, kFstNumApvChannels > signalCorrected{};
276  // seed hit flag: non-zs: 0 | zs: >0 & 7 for seed hit
277  std::array< std::array<int, kFstNumTimeBins>, kFstNumApvChannels > seedFlag{};
278  // id of mc track
279  std::array<int, kFstNumApvChannels> idTruth{};
280 
281  // arrays to calculate dynamical common mode noise contribution to the APV chip in current event
282  double sumAdcPerRgroupPerEvent[kFstNumRStripsPerWedge][kFstNumTimeBins];
283  Int_t counterAdcPerRgroupPerEvent[kFstNumRStripsPerWedge][kFstNumTimeBins];
284  memset(sumAdcPerRgroupPerEvent, 0, sizeof(sumAdcPerRgroupPerEvent));
285  memset(counterAdcPerRgroupPerEvent, 0, sizeof(counterAdcPerRgroupPerEvent));
286 
287  // electronics coordinate info.: RDO, ARM, APV
288  Int_t rdo = rts_tbl->Rdo(); // 1, 2, ..., 6
289  Int_t arm = rts_tbl->Sector(); // 0, 1, 2
290  Int_t apvro = rts_tbl->Pad(); // 0-7&12-19
291  Int_t apv = -1;
292  if(apvro>7) apv = apvro-4;
293  else apv = apvro; //APV:0-15
294 
295  Int_t flag = 0;
296 
297  if (rdo < 1 || rdo > kFstNumRdos) flag = 1;
298  if (arm < 0 || arm >= kFstNumArmsPerRdo) flag = 1;
299  if (apv < 0 || apv >= kFstNumApvsPerArm) flag = 1;
300 
301  if (flag == 1) {
302  LOG_INFO << "Corrupt data rdo: " << rdo << " arm: " << arm << " apv: " << apv << endm;
303  continue;
304  }
305 
306  // Define apv Id to form full channel id later
307  int apvElecId = (rdo - 1) * kFstNumArmsPerRdo * kFstNumApvsPerArm * kFstNumApvChannels + arm * kFstNumApvsPerArm * kFstNumApvChannels + apv * kFstNumApvChannels;
308 
309  // Loop over the data in this APV to get raw hit info. (channel, timebin, adc)
310  for (StRtsTable::iterator it = rts_tbl->begin(); it != rts_tbl->end(); it++) {
311  // channel info.
312  fgt_adc_t *f = (fgt_adc_t *)*it;
313  Int_t channel = f->ch; //channel index 0, 1, ..., 127
314  Int_t adc = f->adc; //adc
315  Short_t timebin = f->tb; //time bin
316  Int_t sFlag = f->flags; // seed hit flag
317  LOG_DEBUG << "channel: " << channel << " adc: " << adc << " time bin: " << timebin << endm;
318 
319  flag = 0;
320 
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;
324 
325  if (flag == 1) {
326  LOG_INFO << "Corrupt data channel: " << channel << " tbin: " << timebin << " adc: " << adc << endm;
327  continue;
328  }
329 
330  signalUnCorrected[channel][timebin] = adc;
331  seedFlag[channel][timebin] = sFlag;
332  if(adc>0) nRawAdcFromData++;
333 
334  if ( !mIsCaliMode ) {
335  Int_t elecId = apvElecId + channel;
336 
337  if (elecId < 0 || elecId >= kFstNumElecIds) {
338  LOG_INFO << "Wrong elecId: " << elecId << endm;
339  continue;
340  }
341 
342  // This is where we get the simulated hits from the simu container if it is available
343  // and merge with real data ADC values
344  if (mFstCollectionSimuPtr)
345  {
346  Int_t geoId = mMappingVec[elecId];
347  Int_t wedge = 1 + geoId / (kFstNumInnerSensorsPerWedge * kFstNumStripsPerInnerSensor + kFstNumOuterSensorsPerWedge * kFstNumStripsPerOuterSensor);
348 
349  StFstRawHitCollection *rawHitCollectionSimuPtr = mFstCollectionSimuPtr->getRawHitCollection(wedge-1);
350  if(rawHitCollectionSimuPtr)
351  {
352  StFstRawHit * rawHitSimu = rawHitCollectionSimuPtr->getRawHit(elecId);
353  idTruth[channel] = 0;
354  if(rawHitSimu->getCharge(timebin) > 0) { // a valid MC hit
355  signalUnCorrected[channel][timebin] += rawHitSimu->getCharge(timebin);
356  idTruth[channel] = rawHitSimu->getIdTruth();
357  }
358  }
359  }
360 
361  if ( dataFlag == mADCdata ) { // non-ZS data
362  signalCorrected[channel][timebin] = signalUnCorrected[channel][timebin] - mPedVec[elecId][timebin];
363 
364  // exclude signal-related channels for common mode noise calculation
365  if ( (signalCorrected[channel][timebin] > (-mCmnCut)*mTotRmsVec[elecId][timebin]) &&
366  (signalCorrected[channel][timebin] < mCmnCut *mTotRmsVec[elecId][timebin]) )
367  {
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]++;
372  }
373 
374  LOG_DEBUG << " Corrected = " << signalCorrected[channel][timebin] << endm;
375  }
376  else { // ZS data
377  signalCorrected[channel][timebin] = signalUnCorrected[channel][timebin];
378  }
379  }
380  } // end current APV loops
381 
382  nIdTruth_Fst += FillRawHitCollectionFromAPVData(dataFlag, ntimebin, counterAdcPerRgroupPerEvent, sumAdcPerRgroupPerEvent, apvElecId, signalUnCorrected, signalCorrected, seedFlag, idTruth);
383 
384  }//end while
385  LOG_INFO << " Total number of FST Raw Hits - Step I = " << mFstCollectionPtr->getNumRawHits() << " w/ idTruth = " << nIdTruth_Fst << endm;
386 
387  // In case of pure simulation mode when neither real data hits from DAQ
388  // records is available nor embedding is requested fill the output container
389  // with simulated hits
390  if(!mDoEmbedding && !nRawAdcFromData) nIdTruth_Fst += FillRawHitCollectionFromSimData();
391 
392  LOG_INFO << " Total number of FST Raw Hits - Step II = " << mFstCollectionPtr->getNumRawHits() << " w/ idTruth = " << nIdTruth_Fst << endm;
393 
394  // Fill Fst raw hits we got so far into StEvent if the chain option is called
395  if(IAttr("fstEvtRawHit")) {//True for storing FST Raw hits
396  LOG_INFO << " Filling FST Raw Hits into StEvent" << endm;
397 
398  //prepare for StEvent
399  mEvent = (StEvent *) GetInputDS("StEvent");
400 
401  if(mEvent) {
402  LOG_DEBUG<<"Found StEvent"<<endm;
403  } else {
404  mEvent = new StEvent();
405  AddData(mEvent);
406  LOG_DEBUG <<"Added StEvent"<<endm;
407  }
408 
409  // Get pointer to an existing StFstEvtCollection if any
410  mFstEvtCollection = mEvent->fstEvtCollection();
411 
412  // If no fst raw hit collection, create one
413  if (!mFstEvtCollection) {
414  mFstEvtCollection = new StFstEvtCollection();
415  mEvent->setFstEvtCollection(mFstEvtCollection);
416  LOG_DEBUG << "Make() - Added new StFstEvtCollection to this StEvent" << endm;
417  }
418 
419  if(mFstCollectionPtr->getNumRawHits() > 0) {
420  for(int wedgeIdx=0; wedgeIdx<kFstNumWedges; ++wedgeIdx ){
421  StFstRawHitCollection *rawHitCollectionPtr = mFstCollectionPtr->getRawHitCollection( wedgeIdx );
422  if( rawHitCollectionPtr ){
423  std::vector<StFstRawHit*>& rawHitVec = rawHitCollectionPtr->getRawHitVec();
424  std::vector< StFstRawHit* >::iterator rawHitIter;
425 
426  for( rawHitIter = rawHitVec.begin(); rawHitIter != rawHitVec.end(); ++rawHitIter ){
427  StFstRawHit* rawHit = *rawHitIter;
428  StFstRawHit* newRawHit = new StFstRawHit( *rawHit );
429  mFstEvtCollection->addRawHit(newRawHit);
430  }
431  }
432  }
433  }
434  }
435 
436  return ierr;
437 }
438 
439 
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)
450 {
451  int nIdTruth = 0;
452  // calculate the dynamical common mode noise for the current chip in this event
453  double commonModeNoise[kFstNumRStripsPerWedge][kFstNumTimeBins];
454 
455  for (int tbIdx = 0; tbIdx < kFstNumTimeBins; tbIdx++){
456  for (int rindex = 0; rindex < kFstNumRStripsPerWedge; rindex++)
457  commonModeNoise[rindex][tbIdx] = 0.;
458  }
459 
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];
465  }
466  }
467  }
468 
469  // CMN correction, raw hit decision and channel counter passed the hit decision
470  std::vector<bool> isPassRawHitCut(kFstNumApvChannels, false);
471  Int_t nChanPassedCut = 0;
472 
473  for (int iChan = 0; iChan < kFstNumApvChannels; iChan++)
474  {
475  Int_t elecId = apvElecId + iChan;
476  Int_t geoId = mMappingVec[elecId];
477  // Modify signalCorrected values in some ways
478  for (int iTBin = 0; iTBin < ntimebin; iTBin++)
479  {
480  if (!mIsCaliMode && mDoCmnCorrection && dataFlag == mADCdata ){
481  int rstrip = (geoId % (kFstNumInnerSensorsPerWedge * kFstNumStripsPerInnerSensor + kFstNumOuterSensorsPerWedge * kFstNumStripsPerOuterSensor))/kFstNumPhiSegPerWedge;
482  signalCorrected[iChan][iTBin] -= commonModeNoise[rstrip][iTBin];
483  }
484  }
485 
486  for (int iTB = 0; iTB < ntimebin; iTB++)
487  {
488  // raw hit decision for non-zs
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]))))
494  {
495  isPassRawHitCut[iChan] = kTRUE;
496  nChanPassedCut++;
497  iTB = 999;
498  }
499  // zs data are all raw hits candidates
500  if( (dataFlag == mZSdata) && (seedFlag[iChan][iTB] > 0) )
501  {
502  isPassRawHitCut[iChan] = kTRUE;
503  nChanPassedCut++;
504  iTB = 999;
505  }
506  }
507  }
508 
509  // skip the chip filling if the signal-channel number too large (20% chip occupancy was set) to exclude hot chip
510  if ( !mIsCaliMode && (nChanPassedCut > mMaxNumOfRawHits || nChanPassedCut < mMinNumOfRawHits) ) {
511  LOG_DEBUG << "Skip: The APV chip could be hot with " << nChanPassedCut << " channels fired!!" << endm;
512  return 0;
513  }
514 
515  // fill FST raw hits for current APV chip
516  for (int iChan = 0; iChan < kFstNumApvChannels; iChan++)
517  {
518  Int_t seedhitflag = 0;
519  //mapping info.
520  Int_t elecId = apvElecId + iChan;
521  Int_t geoId = mMappingVec[elecId]; // channel geometry ID which is numbering from 0 to 36863
522  Int_t wedge = 1 + geoId / (kFstApvsPerWedge * kFstNumApvChannels); // wedge geometry ID: 1, 2, ..., 36
523  Int_t apvId = elecId / kFstNumApvChannels; // APV geometry ID: 0, ..., 287 (numbering from wedge 1 to wedge 36)
524 
525  //store raw hits information
526  StFstRawHitCollection *rawHitCollectionPtr = mFstCollectionPtr->getRawHitCollection( wedge - 1 );
527 
528  if ( !rawHitCollectionPtr ) {
529  LOG_WARN << "StFstRawHitMaker::Make() -- Could not access rawHitCollection for wedge " << wedge << endm;
530  continue;
531  }
532 
533  if ( mIsCaliMode ) { //calibration mode (non-ZS data): only write raw ADC value
534  if (dataFlag == mADCdata) {
535  // rawHitCollectionPtr->addRawHit( new StFstRawHit(elecId, geoId, signalUnCorrected[iChan]) );
536  StFstRawHit *rawHitPtr = rawHitCollectionPtr->getRawHit( elecId );
537  rawHitPtr->setCharges(signalUnCorrected[iChan]);
538  rawHitPtr->setChannelId( elecId );
539  rawHitPtr->setGeoId( geoId );
540  }
541  else return 0;
542  }
543  else { //physics mode: pedestal subtracted + dynamical common mode correction
544  //skip dead chips and bad mis-configured chips
545  if (mConfigVec[apvId] < 1 || mConfigVec[apvId] > 9) { //1-9 good status code
546  LOG_DEBUG << "Skip: Channel belongs to dead/bad/mis-configured APV chip electronic index: " << apvId << " on wedge " << wedge << endm;
547  continue;
548  }
549 
550  //skip current channel marked as suspicious status
551  if (mRanRmsVec[elecId][mDefaultTimeBin] < mChanMinRmsNoiseLevel ||
552  mRanRmsVec[elecId][mDefaultTimeBin] > mChanMaxRmsNoiseLevel ||
553  mRanRmsVec[elecId][mDefaultTimeBin] > 99.0)
554  {
555  LOG_DEBUG << "Skip: Noisy/hot/dead channel electronics index: " << elecId << endm;
556  continue;
557  }
558 
559  if ( !isPassRawHitCut[iChan] )
560  continue;
561 
562  UChar_t tempMaxTB = -1;
563  double tempMaxCharge = -999.0;
564 
565  StFstRawHit *rawHitPtr = rawHitCollectionPtr->getRawHit( elecId );
566 
567  // Modify signalCorrected values in some ways
568  for (int iTBin = 0; iTBin < ntimebin; iTBin++)
569  {
570  if (signalCorrected[iChan][iTBin] < 0)
571  signalCorrected[iChan][iTBin] = 0.1;
572 
573  rawHitPtr->setChargeErr(mRanRmsVec[elecId][iTBin] * mGainVec[elecId], (unsigned char)iTBin);
574 
575  if (signalCorrected[iChan][iTBin] > tempMaxCharge) {
576  tempMaxCharge = signalCorrected[iChan][iTBin];
577  tempMaxTB = (unsigned char)iTBin;
578  }
579 
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]))
584  {
585  seedhitflag = 1;
586  }
587  if( (dataFlag == mZSdata) && (seedFlag[iChan][iTBin] == 7) )
588  {
589  seedhitflag = 1;
590  }
591  }
592 
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++;
601 
602  }//end filling hit info
603  } //end single APV chip hits filling
604  return nIdTruth;
605 }
606 
607 
616 int StFstRawHitMaker::FillRawHitCollectionFromSimData()
617 {
618  int nIdTruth = 0;
619  if(!mFstCollectionSimuPtr) return 0;
620 
621  for( UChar_t wedgeIdx=0; wedgeIdx < kFstNumWedges; ++wedgeIdx )
622  {
623  StFstRawHitCollection *rawHitCollectionDataPtr = mFstCollectionPtr->getRawHitCollection( wedgeIdx );
624  std::vector<StFstRawHit *> rawAdcSimuVec = mFstCollectionSimuPtr->getRawHitCollection(wedgeIdx)->getRawHitVec();
625 
626  for (const auto rawAdcSimuPtr : rawAdcSimuVec)
627  {
628  if (!rawAdcSimuPtr) continue;
629 
630  rawHitCollectionDataPtr->addRawHit(new StFstRawHit(*rawAdcSimuPtr));
631  if(rawAdcSimuPtr->getIdTruth()>0) nIdTruth++;
632  }
633  }
634  return nIdTruth;
635 }
636 
637 void StFstRawHitMaker::Clear( Option_t *opts )
638 {
639  if (mFstCollectionPtr ) {
640  for ( unsigned char i = 0; i < kFstNumWedges; ++i ) {
641  mFstCollectionPtr->getRawHitCollection(i)->Clear( "" );
642  }
643  }
644 }
645 
646 ClassImp(StFstRawHitMaker)
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.
Definition: StMaker.cxx:332
void addRawHit(StFstRawHit *fstRawHit)
Int_t InitRun(Int_t runNumber)
unsigned short getIdTruth() const
for embedding, 0 as background
Definition: StFstRawHit.cxx:55
Definition: Stypes.h:42
void setCharges(const Container &charges)
Definition: StFstRawHit.h:55
void Clear(Option_t *opts="")
User defined functions.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56
Definition: Stypes.h:44
Definition: Stypes.h:41