From e287afc69545874d9d095c1baa2d2a4cc2214fa8 Mon Sep 17 00:00:00 2001 From: Markus Fasel Date: Thu, 2 May 2024 11:25:28 +0200 Subject: [PATCH] [EMCAL-529] Adjust verbosity in infologger (#2272) - Configurable log levels for messages in InfoLogger - Add flag to Quality object - Add position of the FastOR inside the TRU - Introduce medium-level threshold and handle in beautify --- .../include/EMCAL/NumPatchesPerFastORCheck.h | 35 +++++- .../EMCAL/src/NumPatchesPerFastORCheck.cxx | 113 +++++++++++++++--- 2 files changed, 126 insertions(+), 22 deletions(-) diff --git a/Modules/EMCAL/include/EMCAL/NumPatchesPerFastORCheck.h b/Modules/EMCAL/include/EMCAL/NumPatchesPerFastORCheck.h index 3bcc847b29..8952a83e59 100644 --- a/Modules/EMCAL/include/EMCAL/NumPatchesPerFastORCheck.h +++ b/Modules/EMCAL/include/EMCAL/NumPatchesPerFastORCheck.h @@ -20,6 +20,7 @@ #include "QualityControl/CheckInterface.h" #include "EMCALBase/TriggerMappingV2.h" #include "EMCALBase/Geometry.h" +#include namespace o2::quality_control_modules::emcal { @@ -41,19 +42,43 @@ class NumPatchesPerFastORCheck : public o2::quality_control::checker::CheckInter void beautify(std::shared_ptr mo, Quality checkResult = Quality::Null) override; std::string getAcceptedType() override; + struct FastORNoiseInfo { + int mTRUIndex; + int mFastORIndex; + int mPosPhi; + int mPosEta; + + bool operator==(const FastORNoiseInfo& other) const + { + return mTRUIndex == other.mTRUIndex && mFastORIndex == other.mFastORIndex; + } + bool operator<(const FastORNoiseInfo& other) const + { + if (mTRUIndex < other.mTRUIndex) { + return true; + } + if (mTRUIndex == other.mTRUIndex) { + return mFastORIndex < other.mFastORIndex; + } + return false; + } + }; + private: /************************************************ * threshold cuts * ************************************************/ - float mBadThresholdNumPatchesPerFastOR = 4.; ///< Bad Threshold used in the Number of Patches Per FastOR check - float mSigmaTSpectrum = 0.1; ///< TSpectrum parameter sigma - float mThreshTSpectrum = 0.01; ///< TSpectrum parameter threshold + float mBadThresholdNumPatchesPerFastOR = 4.; ///< Bad Threshold used in the Number of Patches Per FastOR check + float mMediumThresholdNumPatchesPerFastOR = 2.; ///< Bad Threshold used in the Number of Patches Per FastOR check + float mSigmaTSpectrum = 0.1; ///< TSpectrum parameter sigma + float mThreshTSpectrum = 0.01; ///< TSpectrum parameter threshold + int mLogLevelIL = 0; ///< Log level on InfoLogger o2::emcal::Geometry* mGeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(300000); ///< Geometry for mapping position between SM and full EMCAL std::unique_ptr mTriggerMapping = std::make_unique(mGeometry); ///!> mNoisyTRUPositions; ///< Positions of all found noisy TRUs + std::set mNoisyTRUPositions; ///< Positions of all found noisy TRUs (bad quality) + std::set mHighCountTRUPositions; ///< Positions of all FastORs with high count rate (medium Quality) ClassDefOverride(NumPatchesPerFastORCheck, 1); }; diff --git a/Modules/EMCAL/src/NumPatchesPerFastORCheck.cxx b/Modules/EMCAL/src/NumPatchesPerFastORCheck.cxx index cd393e7c99..cb004e0638 100644 --- a/Modules/EMCAL/src/NumPatchesPerFastORCheck.cxx +++ b/Modules/EMCAL/src/NumPatchesPerFastORCheck.cxx @@ -18,6 +18,8 @@ #include "QualityControl/MonitorObject.h" #include "QualityControl/Quality.h" #include "QualityControl/QcInfoLogger.h" +#include +#include #include "EMCALBase/Geometry.h" #include // ROOT @@ -47,7 +49,16 @@ void NumPatchesPerFastORCheck::configure() try { mBadThresholdNumPatchesPerFastOR = std::stof(nBadThresholdNumPatchesPerFastOR->second); } catch (std::exception& e) { - ILOG(Error, Support) << fmt::format("Value {} not a float", nBadThresholdNumPatchesPerFastOR->second.data()) << ENDM; + ILOG(Error, Support) << "Value " << nBadThresholdNumPatchesPerFastOR->second.data() << " not a float" << ENDM; + } + } + + auto nMediumThresholdNumPatchesPerFastOR = mCustomParameters.find("MediumThresholdNumPatchesPerFastOR"); + if (nMediumThresholdNumPatchesPerFastOR != mCustomParameters.end()) { + try { + mMediumThresholdNumPatchesPerFastOR = std::stof(nMediumThresholdNumPatchesPerFastOR->second); + } catch (std::exception& e) { + ILOG(Error, Support) << "Value " << nMediumThresholdNumPatchesPerFastOR->second.data() << " not a float" << ENDM; } } @@ -57,7 +68,7 @@ void NumPatchesPerFastORCheck::configure() try { mSigmaTSpectrum = std::stof(nSigmaTSpectrum->second); } catch (std::exception& e) { - ILOG(Error, Support) << fmt::format("Value {} not a float", nSigmaTSpectrum->second.data()) << ENDM; + ILOG(Error, Support) << "Value " << nSigmaTSpectrum->second.data() << " not a float" << ENDM; } } @@ -66,7 +77,16 @@ void NumPatchesPerFastORCheck::configure() try { mThreshTSpectrum = std::stof(nThreshTSpectrum->second); } catch (std::exception& e) { - ILOG(Error, Support) << fmt::format("Value {} not a float", nThreshTSpectrum->second.data()) << ENDM; + ILOG(Error, Support) << "Value " << nThreshTSpectrum->second.data() << " not a float" << ENDM; + } + } + + auto logLevelIL = mCustomParameters.find("LogLevelIL"); + if (logLevelIL != mCustomParameters.end()) { + try { + mLogLevelIL = std::stoi(logLevelIL->second); + } catch (std::exception& e) { + ILOG(Error, Support) << "Value " << logLevelIL->second << " not an integer" << ENDM; } } } @@ -75,8 +95,8 @@ Quality NumPatchesPerFastORCheck::check(std::mapbegin()->second; Quality result = Quality::Good; - mErrorMessage.str(""); mNoisyTRUPositions.clear(); + std::stringstream messagebuilder; if (mo->getName() == "NumberOfPatchesWithFastOR") { auto* h = dynamic_cast(mo->getObject()); @@ -102,24 +122,43 @@ Quality NumPatchesPerFastORCheck::check(std::map()); // sort peaks in descending order to easy pick the y value of max peak - double threshold = mBadThresholdNumPatchesPerFastOR * mean; + double thresholdBad = mBadThresholdNumPatchesPerFastOR * mean, + thresholdMedium = mMediumThresholdNumPatchesPerFastOR * mean; for (Int_t n_peak = 0; n_peak < nfound; n_peak++) { Int_t bin = h->GetXaxis()->FindBin(xpeaks[n_peak]); Double_t peak_val = h->GetBinContent(bin); - if (peak_val > threshold) { - result = Quality::Bad; + if (peak_val > thresholdBad || peak_val > thresholdMedium) { Double_t peak_pos = h->GetXaxis()->GetBinCenter(bin); auto [truID, fastorTRU] = mTriggerMapping->getTRUFromAbsFastORIndex(peak_pos); - mErrorMessage << "TRU " << truID << " has a noisy FastOR at position " << fastorTRU << " in TRU." << std::endl; - ILOG(Error, Support) << "TRU " << truID << " has a noisy FastOR at position " << fastorTRU << " in TRU." << ENDM; - mNoisyTRUPositions.push_back(std::make_pair(truID, fastorTRU)); + auto [truID1, posEta, posPhi] = mTriggerMapping->getPositionInTRUFromAbsFastORIndex(peak_pos); + FastORNoiseInfo obj{ static_cast(truID), static_cast(fastorTRU), static_cast(posPhi), static_cast(posEta) }; + if (peak_val > thresholdBad) { + result = Quality::Bad; + std::string errorMessage = "TRU " + std::to_string(truID) + " has a noisy FastOR at position " + std::to_string(fastorTRU) + " (eta " + std::to_string(posEta) + ", phi " + std::to_string(posPhi) + ") in TRU."; + messagebuilder << errorMessage << std::endl; + if (mLogLevelIL > 1) { + ILOG(Error, Support) << errorMessage << ENDM; + } + mNoisyTRUPositions.insert(obj); + } else if (peak_val > thresholdMedium) { + if (result != Quality::Bad) { + result = Quality::Medium; + std::string errorMessage = "TRU " + std::to_string(truID) + " has a high rate in FastOR at position " + std::to_string(fastorTRU) + " (eta " + std::to_string(posEta) + ", phi " + std::to_string(posPhi) + ") in TRU."; + messagebuilder << errorMessage << std::endl; + if (mLogLevelIL > 2) { + ILOG(Warning, Support) << errorMessage << ENDM; + } + mHighCountTRUPositions.insert(obj); + } + } } } } } } + result.addFlag(o2::quality_control::FlagTypeFactory::BadEMCalorimetry(), messagebuilder.str()); return result; } @@ -133,27 +172,67 @@ void NumPatchesPerFastORCheck::beautify(std::shared_ptr mo, Quali auto* h = dynamic_cast(mo->getObject()); if (checkResult == Quality::Bad) { TLatex* msg; - if (!mErrorMessage.str().empty()) { - ILOG(Error, Support) << mErrorMessage.str() << ENDM; - msg = new TLatex(0.15, 0.84, "#color[2]{Error: Noisy TRU(s)}"); + msg = new TLatex(0.15, 0.84, "#color[2]{Error: Noisy TRU(s)}"); + msg->SetNDC(); + msg->SetTextSize(16); + msg->SetTextFont(43); + msg->SetTextColor(kRed); + h->GetListOfFunctions()->Add(msg); + msg->Draw(); + int iErr = 0; + for (const auto& noiseinfo : mNoisyTRUPositions) { + stringstream errorMessageIndiv; + errorMessageIndiv << "Position " << noiseinfo.mFastORIndex << " (eta " << noiseinfo.mPosEta << ", phi " << noiseinfo.mPosPhi << ") in TRU " << noiseinfo.mTRUIndex << " is noisy." << std::endl; + msg = new TLatex(0.15, 0.8 - iErr / 25., errorMessageIndiv.str().c_str()); msg->SetNDC(); msg->SetTextSize(16); msg->SetTextFont(43); msg->SetTextColor(kRed); h->GetListOfFunctions()->Add(msg); msg->Draw(); + if (mLogLevelIL > 0) { + ILOG(Error, Support) << errorMessageIndiv.str() << ENDM; + } + iErr++; } - for (int iErr = 0; iErr < mNoisyTRUPositions.size(); iErr++) { + for (const auto& noiseinfo : mHighCountTRUPositions) { stringstream errorMessageIndiv; - errorMessageIndiv << "Position " << mNoisyTRUPositions[iErr].second << " in TRU " << mNoisyTRUPositions[iErr].first << " is noisy." << std::endl; + errorMessageIndiv << "Position " << noiseinfo.mFastORIndex << " (eta " << noiseinfo.mPosEta << ", phi " << noiseinfo.mPosPhi << ") in TRU " << noiseinfo.mTRUIndex << " has high counts" << std::endl; msg = new TLatex(0.15, 0.8 - iErr / 25., errorMessageIndiv.str().c_str()); msg->SetNDC(); msg->SetTextSize(16); msg->SetTextFont(43); - msg->SetTextColor(kRed); + msg->SetTextColor(kOrange); + h->GetListOfFunctions()->Add(msg); + msg->Draw(); + if (mLogLevelIL > 0) { + ILOG(Warning, Support) << errorMessageIndiv.str() << ENDM; + } + iErr++; + } + } else if (checkResult == Quality::Medium) { + TLatex* msg; + msg = new TLatex(0.15, 0.84, "#color[2]{Error: High rate TRU(s)}"); + msg->SetNDC(); + msg->SetTextSize(16); + msg->SetTextFont(43); + msg->SetTextColor(kRed); + h->GetListOfFunctions()->Add(msg); + int iErr = 0; + for (const auto& noiseinfo : mHighCountTRUPositions) { + stringstream errorMessageIndiv; + errorMessageIndiv << "Position " << noiseinfo.mFastORIndex << " (eta " << noiseinfo.mPosEta << ", phi " << noiseinfo.mPosPhi << ") in TRU " << noiseinfo.mTRUIndex << " has high counts" << std::endl; + msg = new TLatex(0.15, 0.8 - iErr / 25., errorMessageIndiv.str().c_str()); + msg->SetNDC(); + msg->SetTextSize(16); + msg->SetTextFont(43); + msg->SetTextColor(kOrange); h->GetListOfFunctions()->Add(msg); msg->Draw(); - ILOG(Error, Support) << errorMessageIndiv.str() << ENDM; + if (mLogLevelIL > 0) { + ILOG(Warning, Support) << errorMessageIndiv.str() << ENDM; + } + iErr++; } } }