diff --git a/core/detectors/trd/CbmTrdParFasp.h b/core/detectors/trd/CbmTrdParFasp.h index bdb2ed5197712bb7e8502aa61df003a1e62ee3f6..8648992d7b81e294a1fb705d4ebf0bb8a49691ed 100644 --- a/core/detectors/trd/CbmTrdParFasp.h +++ b/core/detectors/trd/CbmTrdParFasp.h @@ -5,7 +5,7 @@ #ifndef CBMTRDPARFASP_H #define CBMTRDPARFASP_H -#define NFASPMOD 30 +#define NFASPMOD 180 #define NFASPCH 16 #include "CbmTrdParAsic.h" // for CbmTrdParAsic diff --git a/macro/run/run_unpack_online.C b/macro/run/run_unpack_online.C index 1f4bc17ba3aeebdec87ab185a9b830dead8c92bf..fbda6452d269e69ebaea409d11d680224c341845 100644 --- a/macro/run/run_unpack_online.C +++ b/macro/run/run_unpack_online.C @@ -375,12 +375,12 @@ std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename, boo monitor->SetActiveHistos(rawhistovec); monitor->SetActiveHistos(otherhistovec); monitor->SetWriteToFile(outfilename.data()); - } + } else { // FASP monitoring settings auto monitor = std::make_shared<CbmTrdUnpackFaspMonitor>(); monitor->SetActiveHistos(digihistovec); - //monitor->SetActiveHistos(rawhistovec); - //monitor->SetActiveHistos(otherhistovec); + filetypepos = outfilename.find(".trd.root"); + outfilename.replace(filetypepos, 10, ".fasp.root"); monitor->SetWriteToFile(outfilename.data()); } return monitor; diff --git a/macro/run/run_unpack_tsa.C b/macro/run/run_unpack_tsa.C index fd3314440503f9bbfb4562a43d15466323923c9c..e11c2e9493e72dfcceb8fcc31dfe32a81468a2c9 100644 --- a/macro/run/run_unpack_tsa.C +++ b/macro/run/run_unpack_tsa.C @@ -235,7 +235,7 @@ void run_unpack_tsa(std::vector<std::string> infile = {"test.tsa"}, UInt_t runid std::string parfilesbasepathTrdfasp2d = Form("%s/parameters/trd", srcDir.Data()); trdfasp2dconfig->SetParFilesBasePath(parfilesbasepathTrdfasp2d); trdfasp2dconfig->SetSystemTimeOffset(-1800); // [ns] value to be updated - trdfasp2dconfig->SetMonitor(dynamic_pointer_cast<CbmTrdUnpackFaspMonitor>(GetTrdMonitor(outfilename, 1))); + // trdfasp2dconfig->SetMonitor(dynamic_pointer_cast<CbmTrdUnpackFaspMonitor>(GetTrdMonitor(outfilename, 1))); } // ------------- @@ -379,12 +379,12 @@ std::shared_ptr<CbmTrdUnpackMonitor> GetTrdMonitor(std::string treefilename, boo monitor->SetActiveHistos(rawhistovec); monitor->SetActiveHistos(otherhistovec); monitor->SetWriteToFile(outfilename.data()); - } + } else { // FASP monitoring settings monitor = std::make_shared<CbmTrdUnpackFaspMonitor>(); monitor->SetActiveHistos(digihistovec); - //monitor->SetActiveHistos(rawhistovec); - //monitor->SetActiveHistos(otherhistovec); + filetypepos = outfilename.find(".trd.root"); + outfilename.replace(filetypepos, 10, ".fasp.root"); monitor->SetWriteToFile(outfilename.data()); } diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx index b5c97dc7d9578828e1bec9fd3487c249001353b5..a09c8070a82c4e718247614d1bf7b803a4e4e3fa 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.cxx @@ -48,6 +48,7 @@ Bool_t CbmTrdUnpackFaspAlgo::initParSet(FairParGenericSet* parset) const CbmTrdParSetAsic* setDet = static_cast<const CbmTrdParSetAsic*>(setPar->GetModuleSet(did)); if (!setDet) continue; if (setDet->GetAsicType() != Int_t(CbmTrdDigi::eCbmTrdAsicType::kFASP)) continue; + if (fMonitor) fMonitor->addParam(did, setDet); nModules++; std::vector<Int_t> a; setDet->GetAsicAddresses(&a); @@ -65,15 +66,12 @@ Bool_t CbmTrdUnpackFaspAlgo::initParSet(FairParGenericSet* parset) else if (strcmp(parset->ClassName(), "CbmTrdParSetDigi") == 0) { fDigiSet = static_cast<CbmTrdParSetDigi*>(parset); map<Int_t, CbmTrdParMod*> digiPar = fDigiSet->GetModuleMap(); - for (auto digi : digiPar) + for (auto digi : digiPar) { fModuleId.emplace_back(digi.first); + if (fMonitor) fMonitor->addParam(digi.first, (CbmTrdParModDigi*) digi.second); + } // setPar->printParams(); LOG(info) << GetName() << "::initParSet - for container " << parset->ClassName() << " modules " << fModuleId.size(); - - if (fMonitor) { - LOG(info) << fName << "::initParSet(CbmTrdParSetDigi) - Forwarding ParSetDigi to the monitor"; - fMonitor->Init(fDigiSet); - } } else if (strcmp(parset->ClassName(), "CbmTrdParSetGas") == 0) { CbmTrdParSetGas* setPar = static_cast<CbmTrdParSetGas*>(parset); @@ -138,10 +136,11 @@ void CbmTrdUnpackFaspAlgo::PrintAsicMapping() } LOG(info) << GetName() << "Fasp Asic mapping on modules:"; for (auto imod : (*fFaspMap)) { - printf("Mod [%6d] : ", imod.first); + printf("Mod [%6d] :", imod.first); for (int ifasp(0); ifasp < NFASPMOD; ifasp++) { + if (ifasp % 30 == 0) printf("\n"); int jfasp = imod.second[ifasp]; - printf("%2d ", (jfasp == 0xff ? -1 : jfasp)); + printf("%3d ", (jfasp == 0xff ? -1 : jfasp)); } printf("\n"); } @@ -269,7 +268,6 @@ bool CbmTrdUnpackFaspAlgo::pushDigis(std::vector<CbmTrdUnpackFaspAlgo::CbmTrdFas CbmTrdDigi* digi = new CbmTrdDigi(pad, lchT, lchR, imess->tlab); digi->SetAddressModule(imess->cri); digis.push_back(digi); - if (fMonitor) fMonitor->FillHistos(digi); } delete imess; } @@ -278,6 +276,7 @@ bool CbmTrdUnpackFaspAlgo::pushDigis(std::vector<CbmTrdUnpackFaspAlgo::CbmTrdFas for (vector<CbmTrdDigi*>::iterator id = digis.begin(); id != digis.end(); id++) { (*id)->SetTimeDAQ(fTime[0] + (*id)->GetTimeDAQ()); fOutputVec.emplace_back(*std::move(*id)); + if (fMonitor) fMonitor->FillHistos((*id)); if (VERBOSE) cout << (*id)->ToString(); } diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h index 4a10e8582a8d215c4e6883e86f044275c165122e..3eedd67f9a94873d269a52d2a93f6a56fa626212 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspAlgo.h @@ -130,7 +130,8 @@ protected: ULong64_t fTime[NCRI]; /** @brief Finish function for this algorithm base clase */ - void finish() { + void finish() + { if (fMonitor) fMonitor->Finish(); } diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx index 682bbe89572d74dc39aba107fa6cbb73331f3cf1..34909da4e54e79a95aa5f9457936c06454019754 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspConfig.cxx @@ -33,15 +33,21 @@ std::shared_ptr<CbmTrdUnpackFaspAlgo> CbmTrdUnpackFaspConfig::chooseAlgo() //_____________________________________________________________________ void CbmTrdUnpackFaspConfig::InitAlgo() { - if (fDoLog) LOG(info) << fName << "::InitAlgo - SetFaspMapping"; + if (fDoLog) LOG(info) << fName << "::InitAlgo - Setup Fasp mapping"; fAlgo->SetAsicMapping(fFaspMap); /*if (fDoLog) */ fAlgo->PrintAsicMapping(); // If we have a monitor in the config add it to the algo if (fMonitor) fAlgo->SetMonitor(fMonitor); - + // Now we have all information required to initialise the algorithm fAlgo->Init(); + + // Finish initialization of the monitoring task after all information for the run are gathered + if (fMonitor) { + /*if (fDoLog)*/ LOG(info) << fName << "::InitAlgo - Setup monitoring task"; + fMonitor->Init(); + } } //_____________________________________________________________________ diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.cxx index 07cbb6b776a4407361b91bf48df3aa189538ee3f..f809ea2623913d335b627e3ebfd76c8c30ee0f6b 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.cxx @@ -1,12 +1,11 @@ -/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt +/* Copyright (C) 2022 Horia Hulubei National Institute of Physics and Nuclear Engineering, Bucharest SPDX-License-Identifier: GPL-3.0-only - Authors: Pascal Raisig [committer] */ + Authors: Alexandru Bercuci [committer] */ #include "CbmTrdUnpackFaspMonitor.h" #include "CbmTrdDigi.h" -#include "CbmTrdParModDigi.h" -#include "CbmTrdRawMessageSpadic.h" +#include "CbmTrdParFasp.h" #include <MicrosliceDescriptor.hpp> @@ -32,11 +31,13 @@ #include <cmath> +//_________________________________________________________________________ CbmTrdUnpackFaspMonitor::CbmTrdUnpackFaspMonitor(/* args */) {} +//_________________________________________________________________________ CbmTrdUnpackFaspMonitor::~CbmTrdUnpackFaspMonitor() {} -// ---- FillHistos ---- +//_________________________________________________________________________ void CbmTrdUnpackFaspMonitor::FillHistos(CbmTrdDigi* digi) { auto moduleid = digi->GetAddressModule(); @@ -47,6 +48,7 @@ void CbmTrdUnpackFaspMonitor::FillHistos(CbmTrdDigi* digi) } } +//_________________________________________________________________________ void CbmTrdUnpackFaspMonitor::Finish() { LOG(info) << Class_Name() << "::Finish() - "; @@ -75,21 +77,11 @@ void CbmTrdUnpackFaspMonitor::Finish() } } -// ---- Init ---- -Bool_t CbmTrdUnpackFaspMonitor::Init(CbmTrdParSetDigi* digiParSet) +//_________________________________________________________________________ +Bool_t CbmTrdUnpackFaspMonitor::Init() { - auto modulemap = digiParSet->GetModuleMap(); - for (auto modulepair : modulemap) { - auto parmoddigi = static_cast<CbmTrdParModDigi*>(modulepair.second); - fModuleIdsVec.emplace_back(modulepair.first); - - fModuleOrientation.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetOrientation())); - fModuleNrRows.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetNofRows())); - fModuleNrColumns.emplace(std::pair<std::uint32_t, std::uint8_t>(modulepair.first, parmoddigi->GetNofColumns())); - } - - if (fModuleOrientation.empty() || fModuleNrRows.empty() || fModuleNrColumns.empty()) return kFALSE; + if (!fModuleDef.size()) return kFALSE; // Check if there is a HttpServer and if so we later on register the created histograms in it. if (FairRun::Instance()->IsA() == FairRunOnline::Class()) { @@ -98,415 +90,181 @@ Bool_t CbmTrdUnpackFaspMonitor::Init(CbmTrdParSetDigi* digiParSet) fHistoServer = run->GetHttpServer(); } + // Purge the module list. Remove non-FASP modules + for (auto moduleDef : fModuleDef) { + if (!(std::get<0>(moduleDef.second).size())) fModuleDef.erase(moduleDef.first); + } createHistos(); return kTRUE; } -// ---- createHisto ---- +//_________________________________________________________________________ +void CbmTrdUnpackFaspMonitor::addParam(uint32_t madd, const CbmTrdParSetAsic* asics) +{ + auto moduleDef = fModuleDef.find(madd); + if (moduleDef == fModuleDef.end()) { + LOG(warning) << Class_Name() << "::addParam(CbmTrdParSetAsic*) Module " << madd << " not in the list ! Skip."; + return; + } + + std::vector<int32_t> faspMapping(NFASPMOD * NFASPCH, -1); + std::vector<Int_t> add; + asics->GetAsicAddresses(&add); + for (auto afasp : add) { + CbmTrdParFasp* fasp = (CbmTrdParFasp*) asics->GetModulePar(afasp); + + int faspid(afasp % 1000), ich(faspid * 100); + for (auto ach : fasp->GetChannelAddresses()) { + faspMapping[ach] = ich; + ich++; + } + } + std::get<0>((*moduleDef).second) = faspMapping; +} + +//_________________________________________________________________________ +void CbmTrdUnpackFaspMonitor::addParam(uint32_t madd, CbmTrdParModDigi* pp) +{ + auto moduleDef = fModuleDef.find(madd); + if (moduleDef == fModuleDef.end()) + fModuleDef.emplace(madd, std::make_tuple(std::vector<int32_t>(), pp->GetNofColumns(), pp->GetNofRows())); + else { + LOG(warning) << Class_Name() << "::addParam(CbmTrdParModDigi*) Module " << madd + << " already loaded ! Replacing pad-plane definition."; + std::get<1>((*moduleDef).second) = pp->GetNofColumns(); + std::get<2>((*moduleDef).second) = pp->GetNofRows(); + } +} + +//_________________________________________________________________________ void CbmTrdUnpackFaspMonitor::createHisto(eDigiHistos kHisto) { std::string histoname = ""; std::shared_ptr<TH1> newhisto = nullptr; - for (auto moduleid : fModuleIdsVec) { - auto ncols = fModuleNrColumns.find(moduleid)->second; - auto nrows = fModuleNrRows.find(moduleid)->second; - auto nchannels = nrows * ncols; + for (auto moduleDef : fModuleDef) { + auto modId = moduleDef.first; + auto ncols = std::get<1>(moduleDef.second); + auto nrows = std::get<2>(moduleDef.second); + auto nchs = nrows * ncols; - histoname = "ModuleId_" + std::to_string(moduleid) + "-"; + histoname = "ModuleId_" + std::to_string(modId) + "-"; histoname += getTypeName(kHisto) + "_"; histoname += getHistoName(kHisto); - - printf("AB :: createHisto(%s)\n", histoname.c_str()); switch (kHisto) { case eDigiHistos::kMap: - newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), ncols, -0.5, (ncols - 0.5), nrows, -0.5, - (nrows - 0.5)); - newhisto->SetXTitle("Pad column"); - newhisto->SetYTitle("Pad row"); + newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 2 * ncols, -0.5, (ncols - 0.5), nrows, + -0.5, (nrows - 0.5)); + newhisto->SetXTitle("COL (pad)"); + newhisto->SetYTitle("ROW (pad)"); + newhisto->SetZTitle("Yield"); break; case eDigiHistos::kCharge: - newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), 4095, 0.5, - 4095.5); - newhisto->SetXTitle("Sgn [ADU]"); - newhisto->SetYTitle("Counts"); + newhisto = + std::make_shared<TH2I>(histoname.data(), histoname.data(), 2 * nchs, -0.5, (nchs - 0.5), 4095, 0.5, 4095.5); + newhisto->SetXTitle("Pad-Id"); + newhisto->SetYTitle("Sgn [ADU]"); + newhisto->SetZTitle("Yield"); break; case eDigiHistos::kChannel: - newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5)); - newhisto->SetXTitle("ChannelId"); - newhisto->SetYTitle("Counts"); + newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), NFASPMOD, -0.5, (NFASPMOD - 0.5), NFASPCH, + -0.5, NFASPCH - 0.5); + newhisto->SetXTitle("FASP-Id"); + newhisto->SetYTitle("FASP-Ch"); + newhisto->SetZTitle("Yield"); break; case eDigiHistos::kDigiDeltaT: - newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 3500, - -2e6, 5e6); - newhisto->SetXTitle("ChannelId"); - newhisto->SetYTitle("#DeltaT(Digi(n)-Digi(n-1)) [ns]"); + newhisto = + std::make_shared<TH2I>(histoname.data(), histoname.data(), 2 * nchs, -0.5, (nchs - 0.5), 1000, 0, 1e2); + newhisto->SetXTitle("Pad-Id"); + newhisto->SetYTitle("Rate_{SGN} [kHz]"); + newhisto->SetZTitle("Yield"); break; default: return; } - LOG(debug) << Class_Name() << "::CreateHisto() HistoDigi " << static_cast<size_t>(kHisto) << " Module " << moduleid + // printf("AB :: createHisto(%s) row[%d] col[%d]\n", histoname.c_str(), nrows, ncols); + LOG(debug) << Class_Name() << "::CreateHisto() HistoDigi " << static_cast<size_t>(kHisto) << " Module " << modId << " initialized as " << histoname.data(); - if (newhisto) { addHistoToMap<eDigiHistos>(newhisto, &fDigiHistoMap, moduleid, kHisto); } + if (newhisto) { addHistoToMap<eDigiHistos>(newhisto, &fDigiHistoMap, modId, kHisto); } + } +} + +//_________________________________________________________________________ +void CbmTrdUnpackFaspMonitor::fillHisto(CbmTrdDigi* d, eDigiHistos kHisto, std::uint32_t moduleid, + std::shared_ptr<TH1> histo) +{ + auto modDef = fModuleDef[moduleid]; + int pad = d->GetAddressChannel(), ncol = std::get<1>(modDef), row = pad / ncol, col = pad % ncol, dtime, + cht = 2 * pad, chr = cht + 1; + double t, r = d->GetCharge(t, dtime); + switch (kHisto) { + case eDigiHistos::kMap: + if (t > 0) histo->Fill(col - 0.25, row); + if (r > 0) histo->Fill(col + 0.25, row); + break; + + case eDigiHistos::kCharge: + if (t > 0) histo->Fill(pad - 0.25, t); + if (r > 0) histo->Fill(pad + 0.25, r); + break; + + case eDigiHistos::kChannel: { + int fasp, faspid = -1, faspch = -1; + if (t > 0) { + if ((fasp = std::get<0>(modDef).at(cht)) < 0) { + LOG(debug) << Class_Name() << "::fillHisto() Missing FASP params for pad-T " << pad; + } + else { + faspid = fasp / 100; + faspch = fasp % 100; + histo->Fill(faspid, faspch); + } + } + + if (r > 0) { + if ((fasp = std::get<0>(modDef).at(chr)) < 0) { + LOG(debug) << Class_Name() << "::fillHisto() Missing FASP params for pad-R " << pad; + } + else { + faspid = fasp / 100; + faspch = fasp % 100; + histo->Fill(faspid, faspch); + } + } + break; + } + case eDigiHistos::kDigiDeltaT: + if (t > 0) histo->Fill(pad - 0.25, fFaspInvClk / getDeltaT(moduleid, cht, d->GetTimeDAQ())); + if (r > 0) histo->Fill(pad + 0.25, fFaspInvClk / getDeltaT(moduleid, chr, d->GetTimeDAQ() + dtime)); + break; + + default: return; + } +} + +//_________________________________________________________________________ +std::uint64_t CbmTrdUnpackFaspMonitor::getDeltaT(uint32_t modid, int32_t ch, uint64_t daqt) +{ + auto modulevecpair = fLastDigiTimeMap.find(modid); + if (modulevecpair == fLastDigiTimeMap.end()) { + auto modDef = fModuleDef[modid]; + int ncol = std::get<1>(modDef), nrow = std::get<2>(modDef), nchs = 2 * ncol * nrow; + std::vector<size_t> channelsvec(nchs, 0); + + if (ch > nchs) return 0; + channelsvec.at(ch) = daqt; + auto pair = std::make_pair(modid, channelsvec); + fLastDigiTimeMap.emplace(pair); + return daqt; + } + else { + auto prevtime = modulevecpair->second.at(ch); + modulevecpair->second.at(ch) = daqt; + auto dt = daqt - prevtime; + return dt; } } -// -// // ---- createHisto ---- -// void CbmTrdUnpackFaspMonitor::createHisto(eRawHistos kHisto) -// { -// std::string histoname = ""; -// std::shared_ptr<TH1> newhisto = nullptr; -// -// for (auto moduleid : fModuleIdsVec) { -// auto ncols = fModuleNrColumns.find(moduleid)->second; -// auto nrows = fModuleNrRows.find(moduleid)->second; -// auto nchannels = nrows * ncols; -// -// histoname = "ModuleId_" + std::to_string(moduleid) + "-"; -// histoname += getTypeName(kHisto) + "_"; -// histoname += getHistoName(kHisto); -// switch (kHisto) { -// case eRawHistos::kSignalshape: -// case eRawHistos::kSignalshape_St: -// case eRawHistos::kSignalshape_Nt: -// newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 32, -0.5, 31.5, 520, -260, 260); -// newhisto->SetXTitle("ADC Sample [CC]"); -// newhisto->SetYTitle("ADC Value [a.u.]"); -// break; -// case eRawHistos::kMap: -// case eRawHistos::kMap_St: -// case eRawHistos::kMap_Nt: -// newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), 42, -0.5, 41.5, 16, -0.5, 15.5); -// newhisto->SetXTitle("ElinkId"); -// newhisto->SetYTitle("eLink-ChannelId"); -// break; -// case eRawHistos::kElinkId: -// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), 42, -0.5, 41.5); -// newhisto->SetXTitle("ElinkId"); -// newhisto->SetYTitle("Counts"); -// break; -// case eRawHistos::kSampleDistStdDev: -// newhisto = std::make_shared<TH1F>(histoname.data(), histoname.data(), 200, 0.0, 100.0); -// newhisto->SetXTitle("ADC signal std. deviation [#sigma]"); -// newhisto->SetYTitle("Counts"); -// break; -// case eRawHistos::kSample0perChannel: -// newhisto = std::make_shared<TH2I>(histoname.data(), histoname.data(), nchannels, -0.5, (nchannels - 0.5), 601, -// -300, 300); -// newhisto->SetXTitle("ChannelId"); -// newhisto->SetYTitle("ADC Value(Sample-0) [a.u.]"); -// break; -// case eRawHistos::kHitType: -// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), -// static_cast<Int_t>(Spadic::eTriggerType::kGlobal) + 1, -0.5, -// (static_cast<Int_t>(Spadic::eTriggerType::kSandN) + 0.5)); -// newhisto->SetXTitle("Spadic::eTriggerType"); -// newhisto->SetYTitle("Counts"); -// break; -// default: return; break; -// } -// LOG(debug) << Class_Name() << "::CreateHisto() HistoRaw " << static_cast<size_t>(kHisto) << " Module " << moduleid -// << "initialized as " << histoname.data(); -// /** @todo the part below is in principle copy paste for all histo types, so we should be able to move this to a single function */ -// if (newhisto) { addHistoToMap<eRawHistos>(newhisto, &fRawHistoMap, moduleid, kHisto); } -// } -// } -// -// // ---- createHisto ---- -// void CbmTrdUnpackFaspMonitor::createHisto(eOtherHistos kHisto) -// { -// std::string histoname = ""; -// std::shared_ptr<TH1> newhisto = nullptr; -// -// for (auto moduleid : fModuleIdsVec) { -// histoname = "ModuleId_" + std::to_string(moduleid) + "-"; -// histoname += getTypeName(kHisto) + "_"; -// histoname += getHistoName(kHisto); -// switch (kHisto) { -// case eOtherHistos::kSpadic_Info_Types: { -// auto nbins = static_cast<std::uint32_t>(Spadic::MsInfoType::kNInfMsgs); -// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5); -// newhisto->SetXTitle("Info message type"); -// newhisto->SetYTitle("Counts"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kBOM) + 1), "BOM"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kMSB) + 1), "MSB"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kBUF) + 1), "BUF"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kUNU) + 1), "UNU"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kMIS) + 1), "MIS"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kChannelBuf) + 1), "ChBuf"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kOrdFifoBuf) + 1), "OrdFifoBuf"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(Spadic::MsInfoType::kChannelBufM) + 1), "ChBufMH"); -// ; -// break; -// } -// case eOtherHistos::kMs_Flags: { -// auto nbins = static_cast<std::uint32_t>(fles::MicrosliceFlags::DataError) + 1; -// newhisto = std::make_shared<TH1I>(histoname.data(), histoname.data(), nbins, -0.5, nbins - 0.5); -// newhisto->SetXTitle("#muSlice info/error flags"); -// newhisto->SetYTitle("Counts"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::CrcValid) + 1), "CrcValid"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::OverflowFlim) + 1), "OverflowFlim"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::OverflowUser) + 1), "OverflowUser"); -// newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::DataError) + 1), "DataError"); -// break; -// } -// default: return; break; -// } -// LOG(debug) << Class_Name() << "::CreateHisto() HistoOther " << static_cast<size_t>(kHisto) << " Module " << moduleid -// << "initialized as " << histoname.data(); -// -// if (newhisto) { addHistoToMap<eOtherHistos>(newhisto, &fOtherHistoMap, moduleid, kHisto); } -// } -// } -// -// // ---- createHistos ---- -// void CbmTrdUnpackFaspMonitor::createHistos() -// { -// for (auto kHisto : fActiveDigiHistos) { -// createHisto(kHisto); -// } -// for (auto kHisto : fActiveRawHistos) { -// createHisto(kHisto); -// } -// for (auto kHisto : fActiveOtherHistos) { -// createHisto(kHisto); -// } -// } -// -// // ---- fillHisto ---- -// void CbmTrdUnpackFaspMonitor::fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, std::uint32_t moduleid, -// std::shared_ptr<TH1> histo) -// { -// auto triggerpair = digi->GetTriggerPair(digi->GetTriggerType()); -// auto triggertype = triggerpair.first; -// auto isMultihit = triggerpair.second; -// switch (kHisto) { -// case eDigiHistos::kMap_St: { -// if (triggertype != CbmTrdDigi::eTriggerType::kSelf) { return; } -// else { -// auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel()); -// histo->Fill(addresspair.second, addresspair.first); -// break; -// } -// } -// case eDigiHistos::kMap_Nt: { -// if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) { return; } -// else { -// auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel()); -// histo->Fill(addresspair.second, addresspair.first); -// break; -// } -// } -// case eDigiHistos::kMap: { -// auto addresspair = getRowAndCol(moduleid, digi->GetAddressChannel()); -// histo->Fill(addresspair.second, addresspair.first); -// break; -// } -// -// case eDigiHistos::kCharge: histo->Fill(digi->GetCharge()); break; -// case eDigiHistos::kCharge_St: -// if (triggertype != CbmTrdDigi::eTriggerType::kSelf) { return; } -// histo->Fill(digi->GetCharge()); -// break; -// case eDigiHistos::kCharge_Nt: -// if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) { return; } -// histo->Fill(digi->GetCharge()); -// break; -// -// case eDigiHistos::kChannel: histo->Fill(digi->GetAddressChannel()); break; -// case eDigiHistos::kChannel_St: -// if (triggertype != CbmTrdDigi::eTriggerType::kSelf) { return; } -// histo->Fill(digi->GetAddressChannel()); -// break; -// case eDigiHistos::kChannel_Nt: -// if (triggertype != CbmTrdDigi::eTriggerType::kNeighbor) { return; } -// histo->Fill(digi->GetAddressChannel()); -// break; -// -// case eDigiHistos::kTriggerType: { -// if (isMultihit) histo->Fill(static_cast<int>(CbmTrdDigi::eTriggerType::kMulti)); -// histo->Fill(static_cast<int>(triggertype)); -// break; -// } -// case eDigiHistos::kDigiDeltaT: histo->Fill(digi->GetAddressChannel(), getDeltaT(digi)); break; -// -// default: return; break; -// } -// } -// -// // ---- fillHisto ---- -// void CbmTrdUnpackFaspMonitor::fillHisto(CbmTrdRawMessageSpadic* raw, eRawHistos kHisto, std::shared_ptr<TH1> histo, -// CbmTrdDigi* digi) -// { -// auto triggertype = static_cast<Spadic::eTriggerType>(raw->GetHitType()); -// switch (kHisto) { -// case eRawHistos::kSignalshape: fillSamplesHisto(histo, raw); break; -// case eRawHistos::kSignalshape_St: -// if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return; -// fillSamplesHisto(histo, raw); -// break; -// case eRawHistos::kSignalshape_Nt: -// if (triggertype != Spadic::eTriggerType::kNeigh) return; -// fillSamplesHisto(histo, raw); -// break; -// case eRawHistos::kMap: histo->Fill(raw->GetElinkId(), raw->GetChannelId()); break; -// case eRawHistos::kMap_St: -// if (triggertype != Spadic::eTriggerType::kSelf && triggertype != Spadic::eTriggerType::kSandN) return; -// histo->Fill(raw->GetElinkId(), raw->GetChannelId()); -// break; -// case eRawHistos::kMap_Nt: -// if (triggertype != Spadic::eTriggerType::kNeigh) return; -// histo->Fill(raw->GetElinkId(), raw->GetChannelId()); -// break; -// case eRawHistos::kElinkId: histo->Fill(raw->GetElinkId()); break; -// case eRawHistos::kSampleDistStdDev: histo->Fill(getSamplesStdDev(raw)); break; -// case eRawHistos::kSample0perChannel: { -// if (!digi) return; -// histo->Fill(digi->GetAddressChannel(), raw->GetSamples()->at(0)); -// break; -// } -// case eRawHistos::kHitType: histo->Fill(static_cast<int>(raw->GetHitType())); break; -// default: return; break; -// } -// } -// -// // ---- fillSamplesHisto ---- -// void CbmTrdUnpackFaspMonitor::fillSamplesHisto(std::shared_ptr<TH1> histo, CbmTrdRawMessageSpadic* raw) -// { -// for (size_t isample = 0; isample < raw->GetSamples()->size(); isample++) { -// histo->Fill(isample, raw->GetSamples()->at(isample)); -// } -// } -// -// // ---- getDeltaT ---- -// std::double_t CbmTrdUnpackFaspMonitor::getDeltaT(CbmTrdDigi* digi) -// { -// auto moduleid = digi->GetAddressModule(); -// auto channelid = digi->GetAddressChannel(); -// auto modulevecpair = fLastDigiTimeMap.find(moduleid); -// if (modulevecpair == fLastDigiTimeMap.end()) { -// auto nchannels = fModuleNrColumns.find(moduleid)->second * fModuleNrRows.find(moduleid)->second; -// std::vector<size_t> channelsvec(nchannels, 0); -// if (channelid > nchannels) return 0; -// channelsvec.at(channelid) = digi->GetTime(); -// auto pair = std::make_pair(moduleid, channelsvec); -// fLastDigiTimeMap.emplace(pair); -// return digi->GetTime(); -// ; -// } -// else { -// auto prevtime = modulevecpair->second.at(channelid); -// modulevecpair->second.at(channelid) = digi->GetTime(); -// auto dt = digi->GetTime() - prevtime; -// return dt; -// } -// } -// -// // ---- getHistoName ---- -// std::string CbmTrdUnpackFaspMonitor::getHistoName(eDigiHistos kHisto) -// { -// std::string histoname = ""; -// -// switch (kHisto) { -// case eDigiHistos::kMap: histoname += "Map"; break; -// case eDigiHistos::kMap_St: histoname += "Map_St"; break; -// case eDigiHistos::kMap_Nt: histoname += "Map_Nt"; break; -// case eDigiHistos::kCharge: histoname += "Charge"; break; -// case eDigiHistos::kCharge_St: histoname += "Charge_St"; break; -// case eDigiHistos::kCharge_Nt: histoname += "Charge_Nt"; break; -// case eDigiHistos::kChannel: histoname += "Channel"; break; -// case eDigiHistos::kChannel_St: histoname += "Channel_St"; break; -// case eDigiHistos::kChannel_Nt: histoname += "Channel_Nt"; break; -// case eDigiHistos::kTriggerType: histoname += "TriggerType"; break; -// case eDigiHistos::kDigiDeltaT: histoname += "DigiDeltaT"; break; -// } -// return histoname; -// } -// -// // ---- getHistoName ---- -// std::string CbmTrdUnpackFaspMonitor::getHistoName(eRawHistos kHisto) -// { -// std::string histoname = ""; -// -// switch (kHisto) { -// case eRawHistos::kSignalshape: histoname += "Signalshape"; break; -// case eRawHistos::kSignalshape_St: histoname += "Signalshape_St"; break; -// case eRawHistos::kSignalshape_Nt: histoname += "Signalshape_Nt"; break; -// case eRawHistos::kMap: histoname += "Map"; break; -// case eRawHistos::kMap_St: histoname += "Map_St"; break; -// case eRawHistos::kMap_Nt: histoname += "Map_Nt"; break; -// case eRawHistos::kElinkId: histoname += "ElinkId"; break; -// case eRawHistos::kSampleDistStdDev: histoname += "SampleDistStdDev"; break; -// case eRawHistos::kSample0perChannel: histoname += "Sample0perChannel"; break; -// case eRawHistos::kHitType: histoname += "HitType"; break; -// } -// return histoname; -// } -// -// // ---- getHistoName ---- -// std::string CbmTrdUnpackFaspMonitor::getHistoName(eOtherHistos kHisto) -// { -// std::string histoname = ""; -// -// switch (kHisto) { -// case eOtherHistos::kSpadic_Info_Types: histoname += "Spadic_Info_Types"; break; -// case eOtherHistos::kMs_Flags: histoname += "Ms_Flags"; break; -// } -// return histoname; -// } -// -// // ---- getHistoType ---- -// std::string CbmTrdUnpackFaspMonitor::getHistoType(std::shared_ptr<TH1> histo) -// { -// std::string histoname = histo->GetName(); -// // The type follows on the module id separated by the first occurance of "-" -// auto startpos = histoname.find_first_of("-"); -// // Now we are positioned at "-" so we move one further to get the correct place -// startpos++; -// // Extract the type from the rest of the string -// auto length = histoname.find_first_of("_", startpos) - startpos; -// auto histotype = histoname.substr(startpos, length); -// -// return histotype; -// } -// -// // ---- getRowAndCol ---- -// std::pair<std::uint32_t, std::uint32_t> CbmTrdUnpackFaspMonitor::getRowAndCol(std::uint32_t moduleid, -// std::uint32_t channelid) -// { -// // Check if we have to rotate the address, is true in case of 180(2) or 270(3) degree rotation -// bool doRotate = fModuleOrientation.find(moduleid)->second / 2; -// bool isYsensitive = fModuleOrientation.find(moduleid)->second % 2; -// auto nrows = static_cast<std::uint32_t>(fModuleNrRows.find(moduleid)->second); -// auto ncols = static_cast<std::uint32_t>(fModuleNrColumns.find(moduleid)->second); -// -// // Potentially rotate the address -// std::uint32_t rotatedid = doRotate ? (channelid * (-1) + (nrows * ncols) - 1) : channelid; -// -// auto row = rotatedid / ncols; -// auto col = rotatedid % ncols; -// -// // In case we have a chamber with the columns along x we return row,col -// if (!isYsensitive) return std::make_pair(row, col); -// else -// // In case we have a chamber with the columns along y we return col,row -// return std::make_pair(col, row); -// } -// -// // ---- getSamplesStdDev ---- -// std::float_t CbmTrdUnpackFaspMonitor::getSamplesStdDev(CbmTrdRawMessageSpadic* raw) -// { -// std::float_t sum = std::accumulate(raw->GetSamples()->begin(), raw->GetSamples()->end(), 0); -// -// std::float_t mean = sum / raw->GetNrSamples(); -// -// std::float_t dev = 0; -// -// for (auto sample : *raw->GetSamples()) { -// dev += (sample - mean) * (sample - mean); -// } -// return std::sqrt(1.0 / raw->GetNrSamples() * dev); -// } ClassImp(CbmTrdUnpackFaspMonitor) diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.h b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.h index 35d327482d5f1e14ac95de77cfb499ffd198eebd..3dce9adbdc251e4447d1eaac79ff9d0bd02ce287 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackFaspMonitor.h @@ -11,18 +11,16 @@ * * @copyright Copyright (c) 2022 * - * This class can be attached to an unpacker algorithm class. It will - * CbmTrdDigi and CbmTrdRawMessageSpadic - * - * -*/ + * This class is companion to the CbmTrdUnpackFaspAlgo and it provides online + * visualization of unpacked digi (CbmTrdDigi) properties and FASP ASICs response + */ #ifndef CbmTrdUnpackFaspMonitor_H #define CbmTrdUnpackFaspMonitor_H #include "CbmTrdDigi.h" -#include "CbmTrdParSetDigi.h" -#include "CbmTrdSpadic.h" +#include "CbmTrdParModDigi.h" +#include "CbmTrdParSetAsic.h" #include "CbmTrdUnpackMonitor.h" #include <MicrosliceDescriptor.hpp> @@ -47,45 +45,9 @@ #include <cmath> class CbmTrdUnpackFaspMonitor : public CbmTrdUnpackMonitor { -public: -// /** @brief Enum for the predefined digi histograms. */ -// enum class eDigiHistos : size_t -// { -// kMap = 0, -// kMap_St, -// kMap_Nt, -// kChannel, -// kChannel_St, -// kChannel_Nt, -// kCharge, -// kCharge_St, -// kCharge_Nt, -// kTriggerType, -// kDigiDeltaT -// }; -// -// /** @brief Enum for the predefined raw histograms. */ -// enum class eRawHistos : size_t -// { -// kSignalshape = 0, -// kSignalshape_St, -// kSignalshape_Nt, -// kMap, -// kMap_St, -// kMap_Nt, -// kElinkId, -// kSampleDistStdDev, -// kSample0perChannel, -// kHitType, -// }; -// -// /** @brief Enum for the predefined other histograms. */ -// enum class eOtherHistos : size_t -// { -// kSpadic_Info_Types = 0, -// kMs_Flags -// }; + friend class CbmTrdUnpackFaspAlgo; +public: /** @brief Create the Cbm Trd Unpack AlgoBase object */ CbmTrdUnpackFaspMonitor(/* args */); @@ -106,7 +68,7 @@ public: // Runtime functions /** @brief Init all required parameter informations */ - Bool_t Init(CbmTrdParSetDigi* digiParSet); + Bool_t Init(); /** @brief transfer the enums for the histos to be activated to the member vector */ void SetActiveHistos(std::vector<eDigiHistos> vec) { fActiveDigiHistos.swap(vec); } @@ -115,10 +77,45 @@ public: void SetActiveHistos(std::vector<eRawHistos> vec) { fActiveRawHistos.swap(vec); } protected: + /** @brief Init module and link asics properties + * @param madd module address to be added + * @param asics asic properties for the current module + */ + void addParam(uint32_t madd, const CbmTrdParSetAsic* asics); + /** @brief Init module pad-plane parameters + * @param madd module address to be checked + * @param digis pad-plane properties for the current module + */ + void addParam(uint32_t madd, CbmTrdParModDigi* pp); /** @brief Create the actual TH1 shared_ptrs of the Digi histos */ void createHisto(eDigiHistos kHisto); + /** @brief Fill the given histo with the information from the digi. Reimplement from CbmTrdUnpackMonitor + * @param[in] digi CbmTrdDigi + * @param[in] kHisto Histo definition + * @param[in] moduleid Unique module Id from which the digi came + * @param[out] histo pointer to the histo + */ + virtual void fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, std::uint32_t moduleid, std::shared_ptr<TH1> histo); + /** @brief Paralell implementation of the omonime function from CbmTrdUnpackMonitor + * for the case of FASP digis. The default values of the input parameters mark missing + * information. + * @param[in] modid module address + * @param[in] ch module-wise channel address of the signal + * @param[in] daqt DAQ time [clk] for the "ch" paired signal + * @return + */ + virtual std::uint64_t getDeltaT(uint32_t modid, int32_t ch = -1, uint64_t daqt = 0); private: + /** @brief save 1/clk for the FASP FEE in kHz*/ + const double fFaspInvClk = 1.e6 / CbmTrdDigi::Clk(CbmTrdDigi::eCbmTrdAsicType::kFASP); + /** @brief Map of definitions for each module under monitoring : + * std::get<0> : pad to FASP channel mapping + * std::get<1> : no of pad columns in the module + * std::get<2> : no of pad rows in the module + */ + std::map<uint32_t, std::tuple<std::vector<int32_t>, uint8_t, uint8_t>> fModuleDef = {}; + ClassDef(CbmTrdUnpackFaspMonitor, 1) };