diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx index 9292be399088bc4ab7805524157a2e52b4c3390a..888bd043d694b252660f9ab4e26df62faadbee8c 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx @@ -331,6 +331,8 @@ bool CbmTrdUnpackAlgoR::unpack(const fles::Timeslice* ts, std::uint16_t icomp, U { bool unpackOk = true; + if (fMonitor) fMonitor->SetCurrentTimesliceStartTime(fTsStartTime); + auto msdesc = ts->descriptor(icomp, imslice); // Get the µSlice starttime relative to the timeslice starttime. diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.cxx index b50245f9a11662b356d1cf82810c101275222e51..f203df472fc7c7d9d5931bf900fba368b272e366 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.cxx @@ -52,18 +52,62 @@ void CbmTrdUnpackMonitor::FillHistos(CbmTrdDigi* digi, CbmTrdRawMessageSpadic* r auto histo = modulepair->second; fillHisto(raw, pair.first, histo, digi); } + + /* Always save the time of the last processed raw message to use it as time + for BUF/BOM messages which have no time information themselves. + raw->GetTime() is relative to TS start only, so one needs to add fCurrentTimesliceStartTimeNs to it. + */ + fLastRawTime = fCurrentTimesliceStartTimeNs + raw->GetTime(); } } // ---- FillHistos ---- void CbmTrdUnpackMonitor::FillHisto(Spadic::MsInfoType type, std::uint32_t moduleid) { - auto pair = fOtherHistoMap.find(eOtherHistos::kSpadic_Info_Types); - if (pair == fOtherHistoMap.end()) return; + //kSpadic_Info_Types + { + auto pair = fOtherHistoMap.find(eOtherHistos::kSpadic_Info_Types); + if (pair != fOtherHistoMap.end()) { + auto histo = pair->second.find(moduleid)->second; + histo->Fill(static_cast<std::uint32_t>(type)); + } + } - auto histo = pair->second.find(moduleid)->second; + //kBomRate + if (type == Spadic::MsInfoType::kBOM) { + auto pair = fOtherHistoMap.find(eOtherHistos::kBomRate); + if (pair != fOtherHistoMap.end()) { + auto histo = pair->second.find(moduleid)->second; + histo->Fill((fLastRawTime - fCurrentTimeplotStartNs) * 1.0 / 1E9, 10); + } + } + + //kBufRate + if (type == Spadic::MsInfoType::kBUF) { + auto pair = fOtherHistoMap.find(eOtherHistos::kBufRate); + if (pair != fOtherHistoMap.end()) { + auto histo = pair->second.find(moduleid)->second; + histo->Fill((fLastRawTime - fCurrentTimeplotStartNs) * 1.0 / 1E9, 10); + } + } - histo->Fill(static_cast<std::uint32_t>(type)); + //kBomPerRawRate + if (type == Spadic::MsInfoType::kBOM) { + auto pairBomPerRawRate = fOtherHistoMap.find(eOtherHistos::kBomPerRawRate); + auto pairBomRate = fOtherHistoMap.find(eOtherHistos::kBomRate); + auto pairRawRate = fRawHistoMap.find(eRawHistos::kRawRate); + if (pairBomPerRawRate != fOtherHistoMap.end() && pairBomRate != fOtherHistoMap.end() + && pairRawRate != fRawHistoMap.end()) { + auto histoBomPerRawRate = pairBomPerRawRate->second.find(moduleid)->second; + auto histoBomRate = pairBomRate->second.find(moduleid)->second; + auto histoRawRate = pairRawRate->second.find(moduleid)->second; + + Int_t modifiedBin = histoBomRate->FindBin((fLastRawTime - fCurrentTimeplotStartNs) * 1.0 / 1E9); + if (histoRawRate->GetBinContent(modifiedBin) != 0) + histoBomPerRawRate->SetBinContent(modifiedBin, histoBomRate->GetBinContent(modifiedBin) + / histoRawRate->GetBinContent(modifiedBin)); + } + } } // ---- FillHistos ---- @@ -271,6 +315,12 @@ void CbmTrdUnpackMonitor::createHisto(eRawHistos kHisto) newhisto->SetXTitle("Spadic::eTriggerType"); newhisto->SetYTitle("Counts"); break; + case eRawHistos::kRawRate: + newhisto = std::make_shared<TH1D>(histoname.data(), histoname.data(), kTimeplotLenghtSeconds * 10 + 1, -0.05, + kTimeplotLenghtSeconds + 0.05); + newhisto->SetXTitle("Time t [s]"); + newhisto->SetYTitle("Rate [Hz]"); + break; default: return; break; } LOG(debug) << Class_Name() << "::CreateHisto() HistoRaw " << static_cast<size_t>(kHisto) << " Module " << moduleid @@ -318,6 +368,15 @@ void CbmTrdUnpackMonitor::createHisto(eOtherHistos kHisto) newhisto->GetXaxis()->SetBinLabel((static_cast<int>(fles::MicrosliceFlags::DataError) + 1), "DataError"); break; } + case eOtherHistos::kBomRate: + case eOtherHistos::kBufRate: + case eOtherHistos::kBomPerRawRate: { + newhisto = std::make_shared<TH1D>(histoname.data(), histoname.data(), kTimeplotLenghtSeconds * 10 + 1, -0.05, + kTimeplotLenghtSeconds + 0.05); + newhisto->SetXTitle("Time t [s]"); + newhisto->SetYTitle("Rate [Hz]"); + break; + } default: return; break; } LOG(debug) << Class_Name() << "::CreateHisto() HistoOther " << static_cast<size_t>(kHisto) << " Module " << moduleid @@ -435,6 +494,12 @@ void CbmTrdUnpackMonitor::fillHisto(CbmTrdRawMessageSpadic* raw, eRawHistos kHis break; } case eRawHistos::kHitType: histo->Fill(static_cast<int>(raw->GetHitType())); break; + case eRawHistos::kRawRate: + //raw->GetTime() is relative to TS start only, so one needs to add fCurrentTimesliceStartTimeNs to it + adjustTimeplots(fCurrentTimesliceStartTimeNs + raw->GetTime()); + histo->Fill((fCurrentTimesliceStartTimeNs + (std::uint64_t) raw->GetTime() - fCurrentTimeplotStartNs) * 1.0 / 1E9, + 10); + break; default: return; break; } } @@ -536,6 +601,7 @@ std::string CbmTrdUnpackMonitor::getHistoName(eRawHistos kHisto) case eRawHistos::kSampleDistStdDev: histoname += "SampleDistStdDev"; break; case eRawHistos::kSample0perChannel: histoname += "Sample0perChannel"; break; case eRawHistos::kHitType: histoname += "HitType"; break; + case eRawHistos::kRawRate: histoname += "RawRate"; break; } return histoname; } @@ -548,6 +614,9 @@ std::string CbmTrdUnpackMonitor::getHistoName(eOtherHistos kHisto) switch (kHisto) { case eOtherHistos::kSpadic_Info_Types: histoname += "Spadic_Info_Types"; break; case eOtherHistos::kMs_Flags: histoname += "Ms_Flags"; break; + case eOtherHistos::kBomRate: histoname += "BomRate"; break; + case eOtherHistos::kBufRate: histoname += "BufRate"; break; + case eOtherHistos::kBomPerRawRate: histoname += "BomPerRawRate"; break; } return histoname; } @@ -605,4 +674,44 @@ std::float_t CbmTrdUnpackMonitor::getSamplesStdDev(CbmTrdRawMessageSpadic* raw) return std::sqrt(1.0 / raw->GetNrSamples() * dev); } +// ---- resetTimeplots ---- +void CbmTrdUnpackMonitor::resetTimeplots() +{ + for (auto typemappair : fRawHistoMap) { + switch (typemappair.first) { + case eRawHistos::kRawRate: + for (auto histopair : typemappair.second) { + histopair.second->Reset("ICESM"); + } + break; + default: break; + } + } + for (auto typemappair : fOtherHistoMap) { + switch (typemappair.first) { + case eOtherHistos::kBomRate: + case eOtherHistos::kBufRate: + case eOtherHistos::kBomPerRawRate: + for (auto histopair : typemappair.second) { + histopair.second->Reset("ICESM"); + } + break; + default: break; + } + } +} + +// ---- adjustTimeplots ---- +void CbmTrdUnpackMonitor::adjustTimeplots(std::uint64_t newtime) +{ + if (fCurrentTimeplotStartNs == 0) fCurrentTimeplotStartNs = newtime; + + // shift timeplot start offset until the new time lies within the plot time boundaries + while (newtime > fCurrentTimeplotStartNs + kTimeplotLenghtSeconds * 1E9) { + fCurrentTimeplotStartNs += kTimeplotLenghtSeconds * 1E9; + std::cout << "adjusting timeplot start to " << fCurrentTimeplotStartNs << " ns" << std::endl; + resetTimeplots(); + } +} + ClassImp(CbmTrdUnpackMonitor) diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h b/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h index 318fde23a4a5496b436128a2e904a76c268c6fa8..0f67b9467e7cff7cdde817c7363fda62dafeeba8 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h +++ b/reco/detectors/trd/unpack/CbmTrdUnpackMonitor.h @@ -80,15 +80,22 @@ public: kSampleDistStdDev, kSample0perChannel, kHitType, + kRawRate, }; /** @brief Enum for the predefined other histograms. */ enum class eOtherHistos : size_t { kSpadic_Info_Types = 0, - kMs_Flags + kMs_Flags, + kBomRate, + kBufRate, + kBomPerRawRate }; + /** @brief Constant which defines the lenght of the time axis in seconds of plots which display a quantity over time. */ + static const std::uint32_t kTimeplotLenghtSeconds = 600; // 10 minuntes + /** @brief Create the Cbm Trd Unpack AlgoBase object */ CbmTrdUnpackMonitor(/* args */); @@ -147,6 +154,9 @@ public: /** @brief Set digi outpout vector (to make it usable for correlations) */ void SetDigiOutputVec(std::vector<CbmTrdDigi>* digiOutputVec) { fDigiOutputVec = digiOutputVec; } + /** @brief Set the start time of the current timeslice in ns */ + void SetCurrentTimesliceStartTime(std::uint64_t time) { fCurrentTimesliceStartTimeNs = time; }; + protected: template<class histotype> @@ -326,6 +336,12 @@ protected: /** @brief Fill the NeighborTrigger Checking Histogram */ void fillNtCorrHisto(std::shared_ptr<TH1> histo, CbmTrdDigi* digi); + /** @brief Reset the contents of all timeplots */ + void resetTimeplots(); + + /** @brief Adjust the boundaries of all timeplots to contain newtime */ + void adjustTimeplots(std::uint64_t newtime); + // Member variables /** @brief Digi histogram pointers stored in a map together with the module id */ std::map<eDigiHistos, std::map<std::uint32_t, std::shared_ptr<TH1>>> fDigiHistoMap = {}; @@ -376,6 +392,15 @@ protected: // All other parameters and containers std::shared_ptr<CbmTrdSpadic> fSpadic = nullptr; + /** @brief Variable which holds the start time in ns of the current time axis of plots which display a quantity over time */ + std::uint64_t fCurrentTimeplotStartNs = 0; + + /** @brief Variable which holds the start time in ns of the current timeslice */ + std::uint64_t fCurrentTimesliceStartTimeNs = 0; + + /** @brief Variable which holds the time in ns of the last processed raw message */ + std::uint64_t fLastRawTime = 0; + private: ClassDef(CbmTrdUnpackMonitor, 2) };