10 #include "TObjString.h"
22 , fbMonitorMode(kFALSE)
23 , fbDebugMonitorMode(kFALSE)
24 , fbWriteOutput(kTRUE)
25 , fbDebugWriteOutput(kFALSE)
26 , fbBaselineAvg(kFALSE)
27 , fTrdDigiVector(nullptr)
28 , fTrdRawMessageVector(nullptr)
29 , fSpadicInfoMsgVector(nullptr)
38 , fTsStopTimeCore(0.0)
44 , fNbSpadicErrorMsg(0)
46 , fNbSpadicEpochMsg(0)
47 , fParContList(nullptr)
48 , fRefGeoTag(
"trd_v20a_mcbm")
55 , fIsFirstChannelsElinkEven(false) {}
69 LOG(debug) <<
"Initializing CbmMcbm2018UnpackerAlgoTrdR";
84 LOG(info) <<
"Finish of CbmMcbm2018UnpackerAlgoTrdR. Unpacked \n "
95 LOG(debug) <<
"Initializing Containers of CbmMcbm2018UnpackerAlgoTrdR";
104 LOG(debug) <<
"(Re-)Initializing Containers of CbmMcbm2018UnpackerAlgoTrdR";
106 Bool_t initOk = kTRUE;
110 LOG(warning) <<
"CbmTrdParSetAsic not found";
115 LOG(warning) <<
"CbmTrdParSetDigi not found";
120 LOG(warning) <<
"CbmTrdParSetGas not found";
125 LOG(warning) <<
"CbmTrdParSetGain not found";
158 Bool_t initOk = kTRUE;
169 LOG(debug) <<
"CbmMcbm2018UnpackerAlgoTrdR - Successfully initialized "
170 "Spadic hardware address map";
176 fTsStartTime =
static_cast<Double_t
>(ts.descriptor(0, 0).idx);
184 LOG(info) <<
"CbmMcbm2018UnpackerAlgoTrdR::ProcessTs :";
193 LOG(info) <<
"In each TS " <<
fuNbMsLoop <<
" MS will be looped over";
197 for (UInt_t MsIndex = 0; MsIndex <
fuNbMsLoop; MsIndex++) {
203 if (kFALSE ==
ProcessMs(ts, uMsComp, MsIndex)) {
209 return a.GetTime() < b.GetTime();
216 return a.GetTime() < b.GetTime();
220 LOG(error) <<
"Failed to process ts " <<
fCurrTsIdx <<
" MS " << MsIndex
221 <<
" for component " << uMsComp;
231 return a.GetTime() < b.GetTime();
241 fles::MicrosliceDescriptor msDesc = ts.descriptor(uMsCompIdx, uMsIdx);
251 const uint8_t* msPointer =
252 reinterpret_cast<const uint8_t*
>(ts.content(uMsCompIdx, uMsIdx));
253 const uint64_t* msContent =
reinterpret_cast<const uint64_t*
>(
257 for (uint32_t iWord = 0; iWord < msNbWords; iWord++) {
258 uint64_t curWord =
static_cast<uint64_t
>(msContent[iWord]);
268 uint8_t curSample = 3;
270 for (uint8_t iRda = 0; iRda < nRda; iRda++) {
272 curWord =
static_cast<uint64_t
>(msContent[(iWord)]);
275 <<
"[CbmMcbm2018UnpackerAlgoTrdR::ProcessMs] Incomplete Spadic "
276 "Message! RDA Word missing, Microslice corrupted.";
280 for (uint8_t j = 0; curSample < nSamples && curSample < 32 && j < 7;
289 std::shared_ptr<CbmTrdDigi> digi =
MakeDigi(raw);
302 <<
"Failed to fill CbmTrdDigi histograms";
306 <<
"Failed to fill CbmTrdRawMessageSpadic histograms";
311 LOG(error) <<
"[CbmMcbm2018UnpackerAlgoTrdR::ProcessMs] Unexpected RDA "
312 "Word. Microslice corrupted.";
334 if (iWord != (msNbWords - 1))
336 LOG(error) <<
"[CbmMcbm2018UnpackerAlgoTrdR::ProcessMs] Null Word but "
337 "not at end of Microslice.";
341 LOG(error) <<
"[CbmMcbm2018UnpackerAlgoTrdR::ProcessMs] Unknown Word. "
342 "Microslice corrupted.";
348 uint64_t mask = 0x3FFFFFFF;
350 uint64_t uTS_MSB = (uint64_t)((curWord & mask) >> 32);
353 LOG(debug4) <<
"[CbmMcbm2018UnpackerAlgoTrdR::ProcessMs] dt_epoch = "
367 UShort_t usDetectorId) {
375 LOG(info) <<
"CbmMcbm2018UnpackerAlgoTrdR::AddMsComponentToList => Component "
376 << component <<
" with detector ID 0x" << std::hex << usDetectorId
377 << std::dec <<
" added to list";
381 size_t uOverlapMsNb) {
393 Bool_t createHistosOk = kTRUE;
394 Int_t iHisto(ECbmTrdUnpackerHistograms::kBeginDefinedHistos);
402 return createHistosOk;
408 Bool_t createHistoOk = kFALSE;
409 TString histName =
"";
410 TH1* newHisto =
nullptr;
411 std::map<Int_t, CbmTrdParMod*> parDigiModuleMap =
414 for (
auto mapIt : parDigiModuleMap) {
417 histName.Form(
"Module%d-", moduleId);
420 histName +=
"RawMessage_Signalshape_all";
422 histName.Data(), histName.Data(), 32, -0.5, 31.5, 512, -256.5, 255.5);
423 newHisto->SetXTitle(
"time [cc]");
424 newHisto->SetYTitle(
"Pulse height [ADC channels]");
427 histName +=
"RawMessage_Signalshape_St";
429 histName.Data(), histName.Data(), 32, -0.5, 31.5, 512, -256.5, 255.5);
430 newHisto->SetXTitle(
"time [cc]");
431 newHisto->SetYTitle(
"Pulse height [ADC channels]");
434 histName +=
"RawMessage_Signalshape_Nt";
436 histName.Data(), histName.Data(), 32, -0.5, 31.5, 512, -256.5, 255.5);
437 newHisto->SetXTitle(
"time [cc]");
438 newHisto->SetYTitle(
"Pulse height [ADC channels]");
441 histName +=
"RawMessage_Signalshape_filtered";
443 histName.Data(), histName.Data(), 32, -0.5, 31.5, 512, -256.5, 255.5);
446 histName +=
"RawDistributionMapModule5";
448 histName.Data(), histName.Data(), 42, -0.5, 41.5, 16, -0.5, 15.5);
451 histName +=
"RawHitTypes";
452 newHisto =
new TH1I(histName.Data(),
459 histName +=
"RawPulserDeltaT";
461 new TH1I(histName.Data(), histName.Data(), 40000, 0, 4000000);
462 newHisto->SetXTitle(
"#Delta t [cc]");
463 newHisto->SetYTitle(
"Counts");
466 histName +=
"Spadic_Info_Types";
468 histName.Data(), histName.Data(), 500000, 0, 5e9, 5, -0.5, 4.5);
469 ((TH2I*) newHisto)->SetXTitle(
"t /Clockcycles");
470 ((TH2I*) newHisto)->SetYTitle(
"messagetype");
471 ((TH2I*) newHisto)->GetYaxis()->SetBinLabel(1,
"BOM");
472 ((TH2I*) newHisto)->GetYaxis()->SetBinLabel(2,
"MSB");
473 ((TH2I*) newHisto)->GetYaxis()->SetBinLabel(3,
"BUF");
474 ((TH2I*) newHisto)->GetYaxis()->SetBinLabel(4,
"UNU");
475 ((TH2I*) newHisto)->GetYaxis()->SetBinLabel(5,
"MIS");
478 histName +=
"DigiPulserDeltaT";
479 newHisto =
new TH1I(histName.Data(), histName.Data(), 60000, 0, 6e8);
480 newHisto->SetXTitle(
"#Delta t [ns]");
481 newHisto->SetYTitle(
"Counts");
484 histName +=
"DigiDeltaT";
486 new TH1I(histName.Data(), histName.Data(), 6000, -10, ((6e7) - 10));
492 newHisto->SetXTitle(
"#Delta t [ns]");
493 newHisto->SetYTitle(
"Counts");
496 histName +=
"DigiMeanHitFrequency";
497 newHisto =
new TProfile(
508 newHisto->SetXTitle(
"Pad-Channel");
509 newHisto->SetYTitle(
"Hit frequency [kHz]");
512 histName +=
"DigiDistributionMap";
513 newHisto =
new TH2I(histName.Data(),
522 newHisto->SetXTitle(
"Pad column");
523 newHisto->SetYTitle(
"Pad row");
526 histName +=
"DigiDistributionMapSt";
527 newHisto =
new TH2I(histName.Data(),
536 newHisto->SetXTitle(
"Pad column");
537 newHisto->SetYTitle(
"Pad row");
540 histName +=
"DigiDistributionMapNt";
541 newHisto =
new TH2I(histName.Data(),
550 newHisto->SetXTitle(
"Pad column");
551 newHisto->SetYTitle(
"Pad row");
554 histName +=
"DigiChargeSpectrum";
555 newHisto =
new TH1I(histName.Data(), histName.Data(), 512, 0, 512);
556 newHisto->SetYTitle(
"Counts");
557 newHisto->SetXTitle(
"MaxAdc [ADC channels]");
560 histName +=
"DigiChargeSpectrumSt";
561 newHisto =
new TH1I(histName.Data(), histName.Data(), 512, 0, 512);
562 newHisto->SetYTitle(
"Counts");
563 newHisto->SetXTitle(
"MaxAdc [ADC channels]");
566 histName +=
"DigiChargeSpectrumNt";
567 newHisto =
new TH1I(histName.Data(), histName.Data(), 512, 0, 512);
568 newHisto->SetYTitle(
"Counts");
569 newHisto->SetXTitle(
"MaxAdc [ADC channels]");
572 histName +=
"DigiRelativeTimeMicroslice";
577 histName +=
"DigiTriggerType";
578 newHisto =
new TH1I(histName.Data(),
585 histName +=
"DigiHitFrequency";
587 new TProfile(histName.Data(), histName.Data(), 100000, 0, 100000);
588 newHisto->SetXTitle(
"Timeslice");
589 newHisto->SetYTitle(
"#langle hit frequency #rangle");
591 default:
return createHistoOk;
break;
594 "UnpackerTrdAlgo - Histo[%d]-%s - initialize", iHisto, histName.Data());
596 TString moduleName(Form(
"%d", moduleId));
601 Int_t histoPosition = moduleId << bitShift;
602 histoPosition += iHisto;
604 fHistoArray.AddAtAndExpand(newHisto, histoPosition);
607 if (newHisto->IsA() == TProfile::Class())
610 if (newHisto->IsA() == TH2I::Class())
613 if (newHisto->IsA() == TH1I::Class())
616 if (newHisto->IsA() == TH1D::Class())
619 createHistoOk = kTRUE;
622 return createHistoOk;
629 Bool_t isOkFill = kTRUE;
640 Int_t rotatedAddress =
642 ? (channelAddress * (-1)
645 Int_t row = parModDigi->
GetPadRow(rotatedAddress);
646 Int_t column = parModDigi->
GetPadColumn(rotatedAddress);
668 std::uint64_t digiTime = digi.
GetTime();
669 std::uint64_t deltaT =
711 Double_t hitFreq = (Double_t) dt;
713 hitFreq = 1.0 / hitFreq;
716 ->
Fill(channelAddress, hitFreq);
721 Int_t pulserChannelAddress(663);
722 Int_t pulserModule(5);
723 if (channelAddress == pulserChannelAddress
736 Double_t hitFreq = (Double_t) dt;
738 hitFreq = 1.0 / hitFreq;
741 ->
Fill(tsCounter, hitFreq);
756 Bool_t isOkFill = kTRUE;
802 std::uint8_t pulserChannelId = 0;
803 std::uint8_t pulserElinkId = 29;
824 ((TH1*) *it)->Reset();
830 std::vector<CbmTrdDigi>*
const pVector) {
840 std::vector<CbmTrdRawMessageSpadic>*
const pVector,
841 std::vector<std::pair<std::uint64_t, std::uint64_t>>*
const qVector) {
859 std::shared_ptr<CbmTrdDigi>
861 Int_t digiAddress = -1;
868 if (digiTriggerType == 1)
870 if (digiTriggerType == 2)
872 if (digiTriggerType == 3) digiTriggerType = 0;
874 Int_t digiErrClass = 0;
876 std::uint64_t spadicHwAddress(0);
880 Int_t asicAddress(0);
881 auto mapIt =
fSpadicMap.find(spadicHwAddress);
883 LOG(debug4) << Form(
"CbmMcbm2018UnpackerAlgoTrdR::MakeDigi - No asic "
884 "address found for Spadic hardware address %lu",
888 asicAddress = mapIt->second;
889 Int_t uniqueModuleId = asicAddress / 1000;
898 digiAddress = (
fAsicChannelMap.find(asicAddress))->second.at(asicChannelId);
900 std::shared_ptr<CbmTrdDigi> digi =
901 std::make_shared<CbmTrdDigi>(
CbmTrdDigi(digiAddress,
913 if ((msg >> 61) == 1)
916 }
else if ((msg >> 63) == 1)
919 }
else if ((msg >> 62) == 1)
922 }
else if ((msg >> 60) == 1)
936 uint64_t mask = 0x000FFFFF;
938 if (((msg & mask) >> 18) == 3)
942 if (((msg & mask) >> 17) == 2)
946 if (((msg & mask) >> 17) == 3)
950 if (((msg & mask) >> 17) == 4)
954 if (((msg & mask) >> 17) == 5)
958 LOG(error) <<
"[CbmMcbm2018UnpackerAlgoTrdR::GetInfoType] unknown type!";
965 fles::MicrosliceDescriptor msDesc) {
968 <<
"[CbmMcbm2018UnpackerAlgoTrdR::CreateRawMessage] Not a SOM word!";
972 uint8_t elinkId = 0, chId = 0, crobId = 0;
973 uint16_t criId = msDesc.eq_id;
975 uint8_t hitType = 0, nSamples = 0;
976 bool multihit =
false;
977 uint16_t timestamp = 0;
978 uint64_t mask = 0x3F;
980 elinkId = (char) ((word & mask) >> 55);
984 chId = (char) ((word & mask) >> 51);
988 timestamp = (uint16_t)((word & mask) >> 35);
992 hitType = (uint8_t)((word & mask) >> 33);
996 multihit = (bool) ((word & mask) >> 32);
1000 nSamples = (uint8_t)((word & mask) >> 27);
1011 std::vector<int16_t> samples;
1012 for (
int i = 0;
i < nSamples &&
i < 3;
i++) {
1032 else if (nsamples < 11)
1034 else if (nsamples < 18)
1036 else if (nsamples < 25)
1038 else if (nsamples < 32)
1047 const std::array<uint16_t, 32> indices {{4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0,
1048 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4,
1049 5, 6, 0, 1, 2, 3, 4, 5, 6, 0}};
1050 uint64_t mask = 0x1FF;
1054 <<
"[CbmMcbm2018UnpackerAlgoTrdR::ExtractSample] Wrong Message Type!";
1060 <<
"[CbmMcbm2018UnpackerAlgoTrdR::ExtractSample] Wrong sample index!";
1064 && (sample < 3 || sample > 31)) {
1066 <<
"[CbmMcbm2018UnpackerAlgoTrdR::ExtractSample] Wrong sample index!";
1069 uint16_t index = indices[sample];
1071 mask = mask << (9 * (6 - index));
1072 uint64_t temp = word & mask;
1073 temp = temp >> (6 - index) * 9;
1083 temp ^= (-0 ^ temp) & (1 << 7);
1084 temp ^= (-1 ^ temp) & (1 << 8);
1089 int16_t result = s.x = temp;