104 #include "StSstDaqMaker.h"
105 #include "St_base/StMessMgr.h"
106 #include "RTS/src/DAQ_SST/daq_sst.h"
107 #include "RTS/src/DAQ_READER/daq_dta.h"
108 #include "RTS/src/DAQ_READER/daqReader.h"
109 #include "StEventTypes.h"
110 #include "StMessMgr.h"
111 #include "StRtsTable.h"
112 #include "StSsdDbMaker/StSsdDbMaker.h"
113 #include "StSsdDbMaker/StSstDbMaker.h"
114 #include "tables/St_spa_strip_Table.h"
115 #include "tables/St_sstConfiguration_Table.h"
116 #include "tables/St_sstStripCalib_Table.h"
117 #include "StSstUtil/StSstConfig.hh"
118 #include "StIOMaker/StIOMaker.h"
119 #include "tables/St_sstChipCorrect_Table.h"
120 #include "tables/St_sstNoise_Table.h"
121 #include "tables/St_sstBadStrips_Table.h"
129 const Int_t
StSstDaqMaker::RDO2LADDER[5][8] = { {1, 2, 3, 4, 5, 6, 7, 8},
130 {9, 10, 11, 12, 13, 14, 15, 16},
131 {17, 18, 19, 20, 1, 2, 3, 4},
132 {5, 6, 7, 8, 9, 10, 11, 12},
133 {13, 14, 15, 16, 17, 18, 19, 20}
137 const Int_t StSstDaqMaker::ReadOutMap[128] = {
138 97, 96, 98, 95, 99, 94, 100, 93,
139 101, 92, 102, 91, 103, 90, 104, 89,
140 105, 88, 106, 87, 107, 86, 108, 85,
141 109, 84, 110, 83, 111, 82, 112, 81,
142 113, 80, 114, 79, 115, 78, 116, 77,
143 117, 76, 118, 75, 119, 74, 120, 73,
144 121, 72, 122, 71, 123, 70, 124, 69,
145 125, 68, 126, 67, 127, 66, 128, 65,
146 1, 64, 2, 63, 3, 62, 4, 61,
147 5, 60, 6, 59, 7, 58, 8, 57,
148 9, 56, 10, 55, 11, 54, 12, 53,
149 13, 52, 14, 51, 15, 50, 16, 49,
150 17, 48, 18, 47, 19, 46, 20, 45,
151 21, 44, 22, 43, 23, 42, 24, 41,
152 25, 40, 26, 39, 27, 38, 28, 37,
153 29, 36, 30, 35, 31, 34, 32, 33
157 const Int_t StSstDaqMaker::Rev_ReadOutMap[128] = {
158 65, 67, 69, 71, 73, 75, 77, 79,
159 81, 83, 85, 87, 89, 91, 93, 95,
160 97, 99, 101, 103, 105, 107, 109, 111,
161 113, 115, 117, 119, 121, 123, 125, 127,
162 128, 126, 124, 122, 120, 118, 116, 114,
163 112, 110, 108, 106, 104, 102, 100, 98,
164 96, 94, 92, 90, 88, 86, 84, 82,
165 80, 78, 76, 74, 72, 70, 68, 66,
166 64, 62, 60, 58, 56, 54, 52, 50,
167 48, 46, 44, 42, 40, 38, 36, 34,
168 32, 30, 28, 26, 24, 22, 20, 18,
169 16, 14, 12, 10, 8, 6, 4, 2,
170 1, 3, 5, 7, 9, 11, 13, 15,
171 17, 19, 21, 23, 25, 27, 29, 31,
172 33, 35, 37, 39, 41, 43, 45, 47,
173 49, 51, 53, 55, 57, 59, 61, 63
176 StSstDaqMaker::StSstDaqMaker(
const Char_t *name)
187 mTrailerDataLength=0;
201 for(
int i=0;i<8;i++){
212 StSstDaqMaker::~StSstDaqMaker()
216 Int_t StSstDaqMaker::InitRun(Int_t runumber)
218 mEventrunumber = runumber;
220 LOG_INFO <<
"InitRun(Int_t runumber) - Read now Databases" << endm;
221 mRunNum = (runumber / 1000000) - 1;
222 stripCal =
new St_sstStripCalib(
"sstStripCalib",1);
225 St_sstStripCalib *mStripCalib = (St_sstStripCalib*)GetDataBase(
"Calibrations/sst/sstStripCalib");
227 LOG_INFO <<
"sst readout pedestal table found ... initialize" << endm;
228 FillReadOutPedTable(mStripCalib->GetTable());}
230 LOG_WARN <<
"InitRun : No access to sstStripCalib table - we will use the default pedestal values( ped = 0)." << endm;
231 FillDefaultReadOutPedTable();
234 St_sstNoise *mNoise = (St_sstNoise*)GetDataBase(
"Calibrations/sst/sstNoise");
236 LOG_INFO <<
"sst noise table found ... initialize" << endm;
237 FillNoiseTable(mNoise->GetTable());}
239 LOG_WARN <<
"InitRun : No access to ssdNoise - will use the default noise(rms in all channel will be 0 adc )" << endm;
240 FillDefaultNoiseTable();
244 LOG_WARN <<
"InitRun : Unsupported data - we will not save any information )" << endm;
245 FillDefaultReadOutPedTable();
246 FillDefaultNoiseTable();
249 if (mRunNum >= 14 && mRunNum <= 15) {
250 St_sstChipCorrect *mChipCorrect = (St_sstChipCorrect*)GetDataBase(
"Calibrations/sst/sstChipCorrect");
252 LOG_INFO <<
"sst mask chips table found ... initialize" << endm;
253 FillChipNoiseTable(mChipCorrect->GetTable());}
255 LOG_WARN <<
" no sst masking chips table " << endm;
256 FillDefaultChipNoiseTable();
261 LOG_WARN <<
"InitRun : We will not use ChipCorrection Table any more )" << endm;
262 FillDefaultChipNoiseTable();
266 LOG_DEBUG <<
" searching for a bad Strip table" << endm;
267 St_sstBadStrips *mBadStrip = (St_sstBadStrips*)GetDataBase(
"Calibrations/sst/sstBadStrips");
269 LOG_DEBUG <<
"sst bad strips table found ... initialize" << endm;
270 FillBadStripsTable(mBadStrip->GetTable());
274 St_sstConfiguration *configTable = (St_sstConfiguration *) GetInputDB(
"Geometry/sst/sstConfiguration");
277 LOG_ERROR <<
"InitRun: No relevant entry found in 'Geometry/sst/sstConfiguration' table" << endm;
281 mConfigTable = (sstConfiguration_st *) configTable->GetTable() ;
284 Int_t totLadderPresent = 0;
286 for (Int_t ladder = 1; ladder <= mConfigTable->nMaxLadders; ladder++) {
287 if (mConfigTable->ladderIsPresent[ladder - 1] != 0)
290 mConfig->setLadderIsActive(ladder, mConfigTable->ladderIsPresent[ladder - 1]);
293 PrintConfiguration(mRunNum, mConfigTable);
294 mConfig->setNumberOfLadders(totLadderPresent);
295 mConfig->setNumberOfWafers(mConfigTable->nMaxWafers / mConfigTable->nMaxLadders);
296 mConfig->setNumberOfHybrids(2);
297 mConfig->setTotalNumberOfHybrids(nSstSide * nSstWaferPerLadder * totLadderPresent);
298 mConfig->setTotalNumberOfLadders(mConfigTable->nMaxLadders);
299 mConfig->setNumberOfStrips(nSstStripsPerWafer);
300 mConfig->setConfiguration();
303 LOG_INFO <<
"_____________________________" << endm;
304 LOG_INFO <<
" Via Datababase......." << endm;
305 LOG_INFO <<
".......numberOfSectors = " << mConfigTable->nMaxSectors << endm;
306 LOG_INFO <<
".......numberOfLadders = " << totLadderPresent << endm;
307 LOG_INFO <<
" .numberOfWafersPerLadder = " << mConfigTable->nMaxWafers / mConfigTable->nMaxLadders << endm;
308 LOG_INFO <<
"_____________________________" << endm;
309 LOG_INFO <<
" InitRun() - Done " << endm;
310 LOG_INFO <<
"StSstDaqMaker initialization." << endm;
318 LOG_INFO <<
"StSstDaqMaker Start Make..." << endm;
327 mRdoData = (UInt_t *)rts_table->
At(0);
328 mRdoDataLength = rts_table->
GetNRows();
329 LOG_INFO <<
"Found sst Physics Run data at " << hex << mRdoData << dec <<
" , length in byte: "
330 << mRdoDataLength <<
" in UInt_t: " << mRdoDataLength /
sizeof(UInt_t) << endm;
336 sstStripCalib_st *noise_strip =
new sstStripCalib_st();
337 memset(noise_strip,0,491520*(
sizeof(Short_t) +
sizeof(Char_t)));
340 mRdoData = (UInt_t *)rts_table->
At(0);
341 mRdoDataLength = rts_table->
GetNRows();
342 LOG_INFO <<
"Found sst Pedestal Run data at " << hex << mRdoData
343 << dec <<
" , length in byte: " << mRdoDataLength << endm;
345 Int_t id_side, ladder;
346 Int_t ladderCountN[20] = {0};
347 Int_t ladderCountP[20] = {0};
349 Int_t channelindex = 0;
350 mSec = rts_table->Sector();
351 mRDO = rts_table->Rdo();
352 mFiber = rts_table->Pad();
354 if (mSec != 1) mRDO = mRDO + 3;
356 if (mRDO < 1 || mRDO > 5) flag = 1;
358 if (mSec < 1 || mSec > 3) flag = 1;
360 if (mFiber < 0 || mFiber > 7) flag = 1;
363 LOG_WARN <<
"BAD pedestal data. Sector: " << mSec <<
" RDO: "
364 << mRDO <<
" fiber: " << mFiber << endm;
368 FindLadderSide(mRDO, mFiber, ladder, id_side);
372 for (Int_t c = 0; c < nSstStripsPerWafer; c++) {
374 c_correct = (Int_t)c;
376 if (!Shift(mEventrunumber, c_correct)) {
377 LOG_INFO <<
"First readout channel in old LC FPGA is not usable." << endm;
381 for (Int_t h = 0; h < nSstWaferPerLadder; h++) {
385 mPed = (short)(f->ped[h][c_correct] - 375);
386 mRms = (short)(f->rms[h][c_correct]);
387 channelindex = id_side*nSstLadder*nSstWaferPerLadder*nSstStripsPerWafer
388 + ladder*nSstWaferPerLadder*nSstStripsPerWafer
389 + h*nSstStripsPerWafer
391 noise_strip->rms[channelindex] = mRms;
392 noise_strip->pedestals[channelindex] = mPed;
394 if (id_side == 0) ladderCountP[ladder]++;
395 else ladderCountN[ladder]++;
400 if (StMaker::GetDebug()) {
401 LOG_DEBUG <<
"Make()/Counts (p-side): ";
403 for (Int_t i = 0; i < nSstLadder; i++) {
405 LOG_DEBUG << ladderCountP[i] <<
" ";
409 LOG_DEBUG <<
"Make()/Counts (n-side): ";
411 for (Int_t i = 0; i < nSstLadder; i++) {
413 LOG_DEBUG << ladderCountN[i] <<
" ";
421 if (stripCal && stripCal->GetNRows() != 0) {
422 LOG_DEBUG <<
"Make()/ Read Pedestal & Noise" << endm;
423 LOG_DEBUG <<
"Make()/stripCal->NRows= " << stripCal->GetNRows() << endm;
429 sprintf(name,
"sstStripCalib.%d.%06d.root", GetDate(), GetTime());
431 TFile f1(name,
"RECREATE",
"SSD ped and noise file",9);
432 stripCal->AddAt(noise_strip);
442 void StSstDaqMaker::DecodeRdoData()
449 mTrailerDataLength = 0;
454 for (Int_t f = 0; f < 8; f++) mFiberFlag[f] = 1;
456 if (mRdoDataLength == 0 || !mRdoData) {
457 LOG_WARN <<
"NO RDO OUTPUT DATA!" << endm;
462 if (mRdoData[0] != HEADER_TOKEN) {
463 LOG_WARN <<
"SST DAQ DATA HEADER_TOKEN is not correct!!" << endm;
468 LOG_DEBUG <<
"SST DAQ DATA HEADER_TOKEN correct: 0x" << hex << mRdoData[0] << dec << endm;
471 mEventTime = mRdoData[2];
472 mPEventTime = mRdoData[4];
474 mHeaderData = mRdoData + index;
476 if (StMaker::GetDebug()) {
477 for (UInt_t h = 0; h < HEADER_LENGTH; h++) {
478 if (h == 0) LOG_DEBUG <<
"Start Print Event HEADER info... " << endm;
480 LOG_DEBUG <<
"0x" << hex << mHeaderData[h] << dec << endm;
484 mTrigger = Mid(TRIG_START, TRIG_END, mRdoData[1]);
485 LOG_DEBUG <<
"Current Event Trigger words is " << mTrigger << endm;
486 mRDO = Mid(RDO_START, RDO_END, mRdoData[3]);
488 if (mRDO == 6) mRDO = 1;
490 LOG_DEBUG <<
"Current RDO number is :" << mRDO << endm;
492 if (mRDO < 1 || mRDO > nSstRdo) {
493 LOG_WARN <<
"RDO number is BAD number(<1 || >5), reject this RDO" << endm;
498 index += HEADER_LENGTH;
500 for (Int_t i = 0; i < 8; i++) {
502 mAdcHeader[i] = (mRdoData + index);
503 mAdc[i] = mAdcHeader[i] + FIBER_HEADER_LENGTH;
506 mAdc[i] = mAdc[i - 1] + mAdcLength[i - 1];
507 mAdcHeader[i] = (mAdcHeader[i - 1] + mAdcLength[i - 1]);
510 mAdcLength[i] = Mid(ADC_START, ADC_END, mAdcHeader[i][1]);
511 mDataMode[i] = Mid(DATAMODE_START, DATAMODE_END, mAdcHeader[i][1]);
512 mChannel[i] = Mid(FIBER_START, FIBER_END, mAdcHeader[i][2]);
513 mFlag[i] = Mid(FLAG_START, FLAG_END, mAdcHeader[i][1]);
515 if (mAdcHeader[i][0] == FIBER_LINK_TOKEN) {
516 LOG_DEBUG <<
"Fiber [" << mChannel[i] <<
"]: link Token correct : 0x"
517 << hex << mAdcHeader[i][0] << dec << endm;
520 LOG_WARN <<
"Fiber [" << mChannel[i] <<
"]: Link Token wrong :0x"
521 << hex << mAdcHeader[i][0] << dec << endm;
526 if (mDataMode[i] == RAWMODE) {
527 LOG_DEBUG <<
"Fiber [" << mChannel[i] <<
"]:Data mode is RAW data. ADC Length "
528 << mAdcLength[i] << endm;
530 else if (mDataMode[i] == COMPRESSEDMODE) {
531 LOG_DEBUG <<
"Fiber [" << mChannel[i] <<
"]:Data mode is COMPRESSED data. ADC Length "
532 << mAdcLength[i] << endm;
534 else if (mDataMode[i] == CMNSMODE) {
535 LOG_DEBUG <<
"Fiber [" << mChannel[i] <<
"]:Data mode is CMN suppressed data. ADC Length "
536 << mAdcLength[i] << endm;
539 LOG_WARN <<
"Fiber [" << mChannel[i] <<
"]: DO not have this data mode; error data mode = "
540 << mDataMode[i] << endm;
545 if (mFlag[i] == NODATA) {
546 LOG_DEBUG <<
"Fiber [" << mChannel[i] <<
"] Flag:NO DATA FLAG,reject this fiber data" << endm;
548 if (mAdcLength[i] == FIBER_HEADER_LENGTH)
549 LOG_DEBUG <<
"Fiber [" << mChannel[i] <<
"] Flag and adc length is consistent! let's look at next fiber.." << endm;
551 if (mAdcLength[i] != FIBER_HEADER_LENGTH) {
552 LOG_WARN <<
"Fiber [" << mChannel[i] <<
"] Flag and adc length is not consistent,Stop !" << endm;
558 if (mFlag[i] == OVERFLOWFLAG) {
559 LOG_WARN <<
"Fiber [" << mChannel[i] <<
"] Flag:Over Flow" << endm;
564 if (mFlag[i] == EARLY_ABORT) {
565 LOG_WARN <<
"Fiber [" << mChannel[i] <<
"] Flag:Abort Early!" << endm;
570 if (mFlag[i] == WRONG_PIPE_MODE) {
571 LOG_WARN <<
"FIBER [" << mChannel[i] <<
"] Flag:Wrong pipe mode!" << endm;
576 LOG_DEBUG <<
"Fiber [" << mChannel[i] <<
"]: ADC Length = " << mAdcLength[i] << endm;
580 if (mRdoData[mRdoDataLength /
sizeof(UInt_t) - 1] == END_TOKEN) {
581 LOG_DEBUG <<
"End Token Correct: 0x" << hex << mRdoData[mRdoDataLength /
sizeof(UInt_t) - 1] << dec << endm;
584 LOG_WARN <<
"End Token Wrong : 0x" << hex << mRdoData[mRdoDataLength /
sizeof(UInt_t) - 1] << dec << endm;
590 if (mRdoData[mRdoDataLength /
sizeof(UInt_t) - 3] == TCD_END_TOKEN) {
591 LOG_DEBUG <<
"TCD End Token Correct: 0x" << hex << mRdoData[mRdoDataLength /
sizeof(UInt_t) - 3] << dec << endm;
594 LOG_WARN <<
"TCD End Token Wrong : 0x" << hex << mRdoData[mRdoDataLength /
sizeof(UInt_t) - 3] << dec << endm;
600 mTrailerData = mAdcHeader[7] + mAdcLength[7];
602 if (mTrailerData[0] == TCD_TOKEN) {
603 LOG_DEBUG <<
"TCD Token Correct: 0x" << hex << mTrailerData[0] << dec << endm;
606 LOG_WARN <<
"TCD Token Wrong : 0x" << hex << mTrailerData[0] << dec << endm;
611 if (StMaker::GetDebug()) {
612 for (Int_t t = 0; t < 10; t++) {
613 if (t == 0) LOG_DEBUG <<
"Start Print Trailer info... " << endm;
615 LOG_DEBUG <<
"0x" << hex << mTrailerData[t] << dec << endm;
617 if (mTrailerData[t] == END_TOKEN)
break;
622 Int_t StSstDaqMaker::GetHitsDataLength(Int_t FiberNumber)
624 return mAdcLength[FiberNumber];
627 void StSstDaqMaker::DecodeHitsData()
629 if (mRdoFlag != 1)
return;
631 LOG_DEBUG <<
"START Decoding RDO [" << mRDO <<
"] data, rdo flag is " << mRdoFlag << endm;
633 for (Int_t j = 0; j < 8; j++) {
634 if (mFiberFlag[j] != 1)
continue;
636 if (mChannel[j] < 0 || mChannel[j] > (nSstFiberPerRdo - 1)) {
637 LOG_WARN <<
"Fiber number is BAD (<0 || >7), reject this Fiber" << endm;
641 Int_t temp = mAdcLength[j] - FIBER_HEADER_LENGTH;
643 if (temp == 0 || !mAdc[j]) {
644 LOG_WARN <<
"Fiber [" << mChannel[j] <<
"]: do not have any data..." << endm;
648 if (mFlag[j] != NORMAL) {
649 LOG_WARN <<
"Fiber[" << mChannel[j] <<
"]: data flag is not normal, reject this fiber" << endm;
653 if (mDataMode[j] == RAWMODE) {
655 DecodeRawWords_r15(mAdc[j], temp, mChannel[j]);
658 if ((mDataMode[j] == COMPRESSEDMODE) || (mDataMode[j] == CMNSMODE))
659 DecodeCompressedWords(mAdc[j], temp, mChannel[j]);
663 void StSstDaqMaker::DecodeRawWords(UInt_t *val, Int_t vallength, Int_t channel)
665 Int_t strip_number[3] = {0};
666 Int_t id_wafer[3] = {0};
667 Int_t ladderCountN[20] = {0};
668 Int_t ladderCountP[20] = {0};
670 Int_t wafer[3] = {0};
671 Int_t hybrid[3] = {0};
672 Int_t strip[3] = {0};
673 Int_t readout[3] = {0};
674 Int_t readout_correct[3] = {0};
680 spa_strip =
dynamic_cast<St_spa_strip *
>( m_DataSet->
Find(
"spa_strip"));
683 spa_strip =
new St_spa_strip(
"spa_strip", vallength);
684 m_DataSet->Add(spa_strip);
687 spa_strip_st out_strip;
688 LOG_DEBUG <<
"DECODING RAW MODE data....." << endm;
690 FindLadderSide(mRDO, channel, ladder, id_side);
705 for (Int_t i = 0; i < vallength; i++) {
706 if (i == 0) hybrid[0] = 0;
707 else hybrid[0] = hybrid[2] + 1;
709 if (hybrid[0] >= 16) hybrid[0] = hybrid[0] % 16;
711 hybrid[1] = hybrid[0] + 1;
713 if (hybrid[1] >= 16) hybrid[1] = hybrid[1] % 16;
715 hybrid[2] = hybrid[0] + 2;
717 if (hybrid[2] >= 16) hybrid[2] = hybrid[2] % 16;
719 LOG_DEBUG <<
"Three hybrid number in current word is :"
720 << hybrid[0] <<
"," << hybrid[1] <<
"," << hybrid[2] << endm;
723 if (hybrid[0] == 0) readout[0] = readout[0] + 1;
725 if (readout[2] > readout[0]) readout[0] = readout[2];
727 if (hybrid[1] == 0) readout[1] = readout[1] + 1;
729 if (readout[0] > readout[1]) readout[1] = readout[0];
731 if (hybrid[2] == 0) readout[2] = readout[2] + 1;
733 if (readout[1] > readout[2]) readout[2] = readout[1];
736 LOG_DEBUG <<
"[adc_pointer,readout_0,hybrid_0] = [" << i <<
","
737 << readout[0] <<
"," << hybrid[0] <<
"]" << endm;
738 LOG_DEBUG <<
"[adc_pointer,readout_1,hybrid_1] = [" << i <<
","
739 << readout[1] <<
"," << hybrid[1] <<
"]" << endm;
740 LOG_DEBUG <<
"[adc_pointer,readout_2,hybrid_2] = [" << i <<
","
741 << readout[2] <<
"," << hybrid[2] <<
"]" << endm;
743 data[0] = Mid(HYBRID_ONE_START, HYBRID_ONE_END, val[i]);
744 data[1] = Mid(HYBRID_TWO_START, HYBRID_TWO_END, val[i]);
745 data[2] = Mid(HYBRID_THREE_START, HYBRID_THREE_END, val[i]);
747 for (Int_t n = 0; n < 3; n++) {
748 readout_correct[n] = readout[n];
750 if (!Shift(mEventrunumber, readout_correct[n])) {
751 LOG_DEBUG <<
"First readout channel in old LC FPGA is not usable." << endm;
755 strip[n] = readout[n];
756 wafer[n] = hybrid[n];
757 FindStripNumber(strip[n]);
760 id_wafer[n] = 7000 + 100 * (nSstWaferPerLadder - wafer[n]) + ladder + 1;
761 strip_number[n] = strip[n] + 1;
764 id_wafer[n] = 7000 + 100 * ((wafer[n]) + 1) + ladder + 1;
765 strip_number[n] = nSstStripsPerWafer - strip[n];
768 if( mRunNum >= 14 && mRunNum <=15) {
769 if (gStSstDbMaker->maskChip(id_side, ladder, wafer[n], strip[n] / 128))
continue;
772 out_strip.id = count;
773 out_strip.adc_count = data[n];
774 out_strip.id_strip = 10000 * (10 * strip_number[n] + id_side) + id_wafer[n];
775 out_strip.id_mchit[0] = 0 ;
776 out_strip.id_mchit[1] = 0 ;
777 out_strip.id_mchit[2] = 0 ;
778 out_strip.id_mchit[3] = 0 ;
779 out_strip.id_mchit[4] = 0 ;
781 spa_strip->AddAt(&out_strip);
784 ladderCountP[ladder]++;
787 ladderCountN[ladder]++;
794 LOG_DEBUG <<
"Last readout number: [readout[0] , readout[1] , readout[2]] = [" << readout[0] <<
","
795 << readout[1] <<
"," << readout[2] <<
"]" << endm;
797 if (readout[0] > nSstStripsPerWafer || readout[1] > nSstStripsPerWafer || readout[2] > nSstStripsPerWafer) {
798 LOG_WARN <<
"Strip number is larger than 768." << endm;
802 if (StMaker::GetDebug()) {
803 LOG_DEBUG <<
"Make()/Counts (p-side): ";
805 for (Int_t i = 0; i < nSstLadder; i++) {
807 LOG_DEBUG << ladderCountP[i] <<
" ";
811 LOG_DEBUG <<
"Make()/Counts (n-side): ";
813 for (Int_t i = 0; i < nSstLadder; i++) {
815 LOG_DEBUG << ladderCountN[i] <<
" ";
820 if (spa_strip->GetNRows() != 0) {
821 LOG_DEBUG <<
"Make()/ Read Signal from Physics Run" << endm;
822 LOG_DEBUG <<
"Make()/ spa_strip->NRows= " << spa_strip->GetNRows() << endm;
827 void StSstDaqMaker::DecodeRawWords_r15(UInt_t *val, Int_t vallength, Int_t channel)
829 vector<vector<int> > vadc(16, vector<int>(768));
830 vector<vector<float> > vcmnoise(16, vector<float>(6));
831 vector<int> vtemp(128);
833 for (
int i = 0; i < 16; i++) {
835 vcmnoise[i].resize(6);
839 Int_t wafer[3] = {0};
840 Int_t hybrid[3] = {0};
841 Int_t strip[3] = {0};
842 Int_t readout[3] = {0};
843 Int_t readout_correct[3] = {0};
846 Int_t readoutindex = 0;
848 LOG_DEBUG <<
"DECODING RAW MODE data....." << endm;
850 FindLadderSide(mRDO, channel, ladder, id_side);
852 for (Int_t i = 0; i < vallength; i++) {
853 if (i == 0) hybrid[0] = 0;
854 else hybrid[0] = hybrid[2] + 1;
856 if (hybrid[0] >= 16) hybrid[0] = hybrid[0] % 16;
858 hybrid[1] = hybrid[0] + 1;
860 if (hybrid[1] >= 16) hybrid[1] = hybrid[1] % 16;
862 hybrid[2] = hybrid[0] + 2;
864 if (hybrid[2] >= 16) hybrid[2] = hybrid[2] % 16;
866 LOG_DEBUG <<
"Three hybrid number in current word is :"
867 << hybrid[0] <<
"," << hybrid[1] <<
"," << hybrid[2] << endm;
870 if (hybrid[0] == 0) readout[0] = readout[0] + 1;
872 if (readout[2] > readout[0]) readout[0] = readout[2];
874 if (hybrid[1] == 0) readout[1] = readout[1] + 1;
876 if (readout[0] > readout[1]) readout[1] = readout[0];
878 if (hybrid[2] == 0) readout[2] = readout[2] + 1;
880 if (readout[1] > readout[2]) readout[2] = readout[1];
883 LOG_DEBUG <<
"[adc_pointer,readout_0,hybrid_0] = [" << i <<
","
884 << readout[0] <<
"," << hybrid[0] <<
"]" << endm;
885 LOG_DEBUG <<
"[adc_pointer,readout_1,hybrid_1] = [" << i <<
","
886 << readout[1] <<
"," << hybrid[1] <<
"]" << endm;
887 LOG_DEBUG <<
"[adc_pointer,readout_2,hybrid_2] = [" << i <<
","
888 << readout[2] <<
"," << hybrid[2] <<
"]" << endm;
890 data[0] = Mid(HYBRID_ONE_START, HYBRID_ONE_END, val[i]);
891 data[1] = Mid(HYBRID_TWO_START, HYBRID_TWO_END, val[i]);
892 data[2] = Mid(HYBRID_THREE_START, HYBRID_THREE_END, val[i]);
894 for (Int_t n = 0; n < 3; n++) {
895 readout_correct[n] = readout[n];
897 if (!Shift(mEventrunumber, readout_correct[n])) {
898 LOG_DEBUG <<
"First readout channel in old LC FPGA is not usable." << endm;
902 strip[n] = readout_correct[n];
903 wafer[n] = hybrid[n];
904 readoutindex = id_side * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer
905 + ladder * nSstWaferPerLadder * nSstStripsPerWafer
906 + wafer[n] * nSstStripsPerWafer
910 data[n] = data[n] + 375;
911 if(data[n]>1024) data[n] = data[n] - 1024;
914 data[n] = data[n] - 375 - mReadOutPed[readoutindex];
915 vadc[wafer[n]][strip[n]] = data[n];
919 for (
int i = 0; i < 16; i++) {
920 for (
int j = 0; j < 768; j++) {
921 vtemp[j % 128] = vadc[i][j];
923 if ((j + 1) % 128 == 0) {
924 vcmnoise[i][j / 128] = CalculateCommonModeNoiseSimple(vtemp);
929 FillData(vadc, vcmnoise, id_side, ladder, vallength);
931 LOG_DEBUG <<
"Last readout number: [readout[0] , readout[1] , readout[2]] = [" << strip[0] <<
","
932 << strip[1] <<
"," << strip[2] <<
"]" << endm;
934 if (strip[0] > nSstStripsPerWafer || strip[1] > nSstStripsPerWafer || strip[2] > nSstStripsPerWafer) {
935 LOG_WARN <<
"Strip number is larger than 768." << endm;
944 void StSstDaqMaker::DecodeCompressedWords(UInt_t *val, Int_t vallength, Int_t channel)
946 Int_t ladderCountN[20] = {0};
947 Int_t ladderCountP[20] = {0};
948 Int_t strip_number = 0;
961 UInt_t errorcode = 0;
962 int wafDecodeBadStrip = 0;
963 int stripDecodeBadStrip = 0;
964 int indexDecodeBadStrip = 0;
966 LOG_DEBUG <<
"Current Event data length : " << vallength << endm;
967 spa_strip =
dynamic_cast<St_spa_strip *
>( m_DataSet->
Find(
"spa_strip"));
970 spa_strip =
new St_spa_strip(
"spa_strip", vallength);
971 m_DataSet->Add(spa_strip);
974 spa_strip_st out_strip;
976 FindLadderSide(mRDO, channel, ladder, id_side);
978 for (Int_t i = 0; i < vallength; i++) {
979 wafer = Mid(HYBRID_START, HYBRID_END, val[i]);
980 strip = Mid(STRIP_START, STRIP_END, val[i]);
981 data = Mid(COM_ADC_START, COM_ADC_END, val[i]);
982 errorcode = Mid(ERROR_START,ERROR_END,val[i]);
983 chip = strip/nSstStripsPerChip;
984 chipIndex = ladder*nSstWaferPerLadder*nSstChipPerWafer + wafer*nSstChipPerWafer + chip;
987 if(oldchip!=chipIndex) chipflag = 0;
988 if(strip%nSstStripsPerChip==0 && errorcode==CMNERRORCODE) chipflag = 1;
989 if(chipflag)
continue;
991 if (!Shift(mEventrunumber, strip)) {
992 LOG_INFO <<
"First readout channel in old LC FPGA is not usable." << endm;
997 if(data<mNoiseCut[chipIndex][id_side]) data = 0;
998 else data = data - mCorrectFactor[chipIndex][id_side];
1002 FindStripNumber(strip);
1005 id_wafer = 7000 + 100 * (nSstWaferPerLadder - wafer) + ladder + 1;
1006 strip_number = strip + 1;
1009 id_wafer = 7000 + 100 * ((wafer) + 1) + ladder + 1;
1010 strip_number = nSstStripsPerWafer - strip;
1013 if( mRunNum >= 14 && mRunNum <=15) {
1014 if (gStSstDbMaker->maskChip(id_side, ladder, wafer, chip))
continue;
1019 wafDecodeBadStrip = nSstWaferPerLadder - wafer - 1;
1020 stripDecodeBadStrip = strip + 1;
1023 wafDecodeBadStrip = wafer + 1 - 1;
1024 stripDecodeBadStrip = nSstStripsPerWafer - strip;
1027 indexDecodeBadStrip = id_side * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer
1028 + ladder * nSstWaferPerLadder * nSstStripsPerWafer
1029 + wafDecodeBadStrip * nSstStripsPerWafer
1030 + stripDecodeBadStrip -1;
1031 if(mBadStrip[indexDecodeBadStrip]!=0)
continue;
1036 out_strip.id = count;
1037 out_strip.adc_count = data;
1038 out_strip.id_strip = 10000 * (10 * strip_number + id_side) + id_wafer;
1039 out_strip.id_mchit[0] = 0 ;
1040 out_strip.id_mchit[1] = 0 ;
1041 out_strip.id_mchit[2] = 0 ;
1042 out_strip.id_mchit[3] = 0 ;
1043 out_strip.id_mchit[4] = 0 ;
1044 spa_strip->AddAt(&out_strip);
1047 ladderCountP[ladder]++;
1050 ladderCountN[ladder]++;
1055 oldchip = chipIndex;
1058 if (readout > nSstStripsPerWafer) {
1059 LOG_WARN <<
"Strip number is larger than 768, ERROR" << endm;
1063 if (StMaker::GetDebug()) {
1064 LOG_DEBUG <<
"Make()/Counts (p-side): ";
1066 for (Int_t i = 0; i < nSstLadder; i++) {
1068 LOG_DEBUG << ladderCountP[i] <<
" ";
1072 LOG_DEBUG <<
"Make()/Counts (n-side): ";
1074 for (Int_t i = 0; i < nSstLadder; i++) {
1076 LOG_DEBUG << ladderCountN[i] <<
" ";
1081 if (spa_strip->GetNRows() != 0) {
1082 LOG_DEBUG <<
"Make()/ Read Signal from Physics Run" << endm;
1083 LOG_DEBUG <<
"Make()/ spa_strip->NRows= " << spa_strip->GetNRows() << endm;
1089 Int_t StSstDaqMaker::Shift(Int_t runnumber, Int_t &channel)
1091 if (runnumber < 15150058) {
1092 if (channel == 0)
return 0;
1094 channel = channel - 1;
1103 UInt_t StSstDaqMaker::Mid(Int_t start, Int_t end, UInt_t input)
1106 buf = input << (32 - end);
1107 buf = buf >> (32 - end);
1108 return buf >> start;
1112 void StSstDaqMaker::FindLadderSide(Int_t RDO, Int_t channel, Int_t &ladder, Int_t &side)
1114 ladder = RDO2LADDER[RDO - 1][channel] - 1;
1116 if (ladder > 20) LOG_WARN <<
"Ladder >20. RDO Number is" << RDO <<
", channel number :" << channel << endm;
1118 if (RDO < 3) side = 1;
1119 else if (RDO > 3) side = 0;
1120 else if (channel < 4) side = 1;
1124 void StSstDaqMaker::FindStripNumber(Int_t &strip)
1126 Int_t temp = (strip / 128) * 128 + ReadOutMap[strip % 128];
1130 void StSstDaqMaker::FindChannelNumber(Int_t &channel)
1132 Int_t temp = (channel / 128) * 128 + Rev_ReadOutMap[channel % 128];
1137 void StSstDaqMaker::PrintConfiguration(Int_t runumber, sstConfiguration_st *config)
1141 LOG_INFO <<
"Configuration of ladders for run IV" << endm;
1146 LOG_INFO <<
"Configuration of ladders for run V" << endm;
1151 LOG_INFO <<
"Configuration of ladders for run VI" << endm;
1156 LOG_INFO <<
"Configuration of ladders for run VII" << endm;
1162 Int_t totladderPresent = 0;
1163 LOG_INFO <<
"PrintLadderSummary:ladder id :";
1165 for (i = 1; i <= config->nMaxLadders; i++) {
1171 LOG_INFO <<
"PrintLadderSummary:Active Ladders on sectors: ";
1173 for (i = 1; i <= config->nMaxLadders; i++) {
1175 LOG_INFO << mConfig->getLadderIsActive(i);
1177 if (mConfig->getLadderIsActive(i) > 0)totladderPresent++;
1182 LOG_INFO <<
"totLadderActive = " << totladderPresent << endm;
1185 void StSstDaqMaker::Clear(
const Option_t *)
1200 void StSstDaqMaker::FillReadOutPedTable(sstStripCalib_st *noise)
1202 LOG_INFO <<
"InirTun : New Table(sstStripCalib) is used ! " << endm;
1205 int totStripSst = nSstSide*nSstLadder*nSstWaferPerLadder*nSstStripsPerWafer;
1206 for (Int_t i = 0 ; i < totStripSst ; i++)
1207 mReadOutPed[i] = (Int_t)noise[0].pedestals[i];
1210 void StSstDaqMaker::FillDefaultReadOutPedTable()
1212 Int_t size = nSstSide * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer;
1214 for (Int_t i = 0; i < size; i++) {
1219 void StSstDaqMaker::FillNoiseTable(sstNoise_st *noise)
1222 LOG_INFO <<
"InitRun for real data : new Table(ssdNoise) is used" << endm;
1223 Int_t size = nSstSide * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer;
1225 for (Int_t i = 0 ; i < size ; i++)
1226 mIntrinsicRms[i] = (Int_t)noise[0].rms[i]/10.0;
1229 void StSstDaqMaker::FillDefaultNoiseTable()
1231 Int_t size = nSstSide * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer;
1233 for (Int_t i = 0; i < size; i++) {
1234 mIntrinsicRms[i] = nRmsCut;
1238 void StSstDaqMaker::FillChipNoiseTable(sstChipCorrect_st *chipCorrectTable){
1239 int side=0,ladder=0,wafer=0,chip=0;
1240 LOG_DEBUG<<
"New ChipNoiseTable was used! "<<endm;
1241 int totChipSst = nSstSide*nSstLadder*nSstWaferPerLadder*nSstChipPerWafer;
1242 int totChipSstSide = nSstLadder*nSstWaferPerLadder*nSstChipPerWafer;
1243 int totChipSstLadder = nSstWaferPerLadder*nSstChipPerWafer;
1245 for(Int_t i=0; i<totChipSst;i++){
1246 side = i/totChipSstSide;
1247 ladder = (i - side*totChipSstSide)/totChipSstLadder;
1248 wafer = (i - side*totChipSstSide - ladder*totChipSstLadder)/nSstChipPerWafer;
1249 chip = (i - side*totChipSstSide - ladder*totChipSstLadder - wafer*nSstChipPerWafer);
1251 LOG_DEBUG <<
" i/side/ladder/wafer/chip/correct/CutPos : "
1257 <<chipCorrectTable[0].nCorrect[i] <<
" "
1258 <<chipCorrectTable[0].nCutPos[i] <<
" " <<endm;
1260 mCorrectFactor[ladder*totChipSstLadder+wafer*nSstChipPerWafer+chip][side] = chipCorrectTable[0].nCorrect[i];
1261 mNoiseCut[ladder*totChipSstLadder+wafer*nSstChipPerWafer+chip][side] = chipCorrectTable[0].nCutPos[i];
1265 void StSstDaqMaker::FillDefaultChipNoiseTable(){
1266 LOG_DEBUG <<
" Default is no any correction ." << endm;
1267 Int_t size = nSstLadder*nSstWaferPerLadder*nSstChipPerWafer;
1268 for(Int_t s=0;s<nSstSide;s++) {
1269 for(Int_t i=0;i<size;i++) {
1270 mCorrectFactor[i][s] = 0;
1271 mNoiseCut[i][s] = 0;
1276 void StSstDaqMaker::FillBadStripsTable(sstBadStrips_st* badStripTable){
1277 int totChipSst = nSstSide*nSstLadder*nSstWaferPerLadder*nSstStripsPerWafer;
1278 for(Int_t i=0; i<totChipSst;i++){
1279 mBadStrip[i] = badStripTable[0].status[i];
1283 Float_t StSstDaqMaker::CalculateCommonModeNoiseSimple(vector<int> vadc)
1286 Float_t preMean = 0;
1288 Float_t devcut = 20;
1291 TH1I *hadc =
new TH1I(
"hadc",
"adc in each chip", 768, -512, 1024);
1292 Float_t chipRms = 0;
1294 for (
int i = 1; i < 128; i++) {
1295 hadc->Fill(vadc[i]);
1298 chipRms = hadc->GetRMS();
1308 for (
int i = 1; i < 128; i++) {
1312 preMean = preSum / 127.;
1314 Float_t thresholdhig = preMean + devcut;
1315 Float_t thresholdlow = preMean - devcut;
1317 for (
int i = 1; i < 128; i++) {
1318 if (vadc[i] < thresholdlow || vadc[i] > thresholdhig)
continue;
1321 counter = counter + 1;
1324 return (counter>0)?(sum/counter):0;
1327 void StSstDaqMaker::FillData(vector<vector<int> > vadc, vector<vector<float> > vcmnoise, Int_t id_side, Int_t ladder, Int_t vallength)
1330 Int_t strip_number = 0;
1332 Int_t ladderCountN[20] = {0};
1333 Int_t ladderCountP[20] = {0};
1335 Float_t cmnoise = 0;
1336 Float_t intrinsicnoise = 0;
1337 Int_t stripindex = 0;
1339 const Float_t Epsinon = 0.00001;
1340 spa_strip = (St_spa_strip *) m_DataSet->
Find(
"spa_strip");
1343 spa_strip =
new St_spa_strip(
"spa_strip", vallength);
1344 m_DataSet->Add(spa_strip);
1347 spa_strip_st out_strip;
1349 for (
int i = 0; i < 16; i++) {
1350 for (
int j = 0; j < 768; j++) {
1352 adc = (Float_t)vadc[i][j];
1353 cmnoise = vcmnoise[i][j / 128];
1358 if ((cmnoise >= -Epsinon) && (cmnoise <= Epsinon)) adc = 0;
1360 adc = adc - cmnoise;
1363 if (j % 128 == 0) adc = 0;
1365 if (id_side == 1) adc = -1 * adc;
1371 if( mRunNum >= 14 && mRunNum <=15) {
1372 if (gStSstDbMaker->maskChip(id_side, ladder, i, j / 128))
continue;
1376 id_wafer = 7000 + 100 * (nSstWaferPerLadder - i) + ladder + 1;
1377 strip_number = s + 1;
1380 id_wafer = 7000 + 100 * (i + 1) + ladder + 1;
1381 strip_number = nSstStripsPerWafer - s;
1386 stripindex = id_side * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer
1387 + ladder * nSstWaferPerLadder * nSstStripsPerWafer
1388 + i * nSstStripsPerWafer
1391 intrinsicnoise = mIntrinsicRms[stripindex];
1392 if(intrinsicnoise<std::numeric_limits<float>::epsilon()) intrinsicnoise = std::numeric_limits<unsigned short>::max();
1394 if (adc < nSigmaCut * intrinsicnoise)
continue;
1395 if (adc <=0)
continue;
1396 if (mReadOutPed[stripindex] == 0)
continue;
1398 if(intrinsicnoise>=nRmsCut)
continue;
1400 out_strip.id = count;
1401 out_strip.adc_count = adc;
1402 out_strip.id_strip = 10000 * (10 * strip_number + id_side) + id_wafer;
1403 out_strip.id_mchit[0] = 0 ;
1404 out_strip.id_mchit[1] = 0 ;
1405 out_strip.id_mchit[2] = 0 ;
1406 out_strip.id_mchit[3] = 0 ;
1407 out_strip.id_mchit[4] = 0 ;
1409 spa_strip->AddAt(&out_strip);
1412 ladderCountP[ladder]++;
1415 ladderCountN[ladder]++;
1420 if (StMaker::GetDebug()) {
1421 LOG_DEBUG <<
"Make()/Counts (p-side): ";
1423 for (Int_t i = 0; i < nSstLadder; i++) {
1425 LOG_DEBUG << ladderCountP[i] <<
" ";
1429 LOG_DEBUG <<
"Make()/Counts (n-side): ";
1431 for (Int_t i = 0; i < nSstLadder; i++) {
1433 LOG_DEBUG << ladderCountN[i] <<
" ";
1438 if (spa_strip->GetNRows() != 0) {
1439 LOG_DEBUG <<
"Make()/ Read Signal from Physics Run" << endm;
1440 LOG_DEBUG <<
"Make()/ spa_strip->NRows= " << spa_strip->GetNRows() << endm;
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...
virtual void Clear(Option_t *option="")
User defined functions.
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
const void * At(Int_t i) const
Returns a pointer to the i-th row of the table.
virtual TDataSet * Find(const char *path) const