From eee85cc92d77b4b80914353cd8315eee083bedf8 Mon Sep 17 00:00:00 2001 From: Deependra Sharma Date: Mon, 16 Oct 2023 16:09:20 +0530 Subject: [PATCH] adding combined check on tracklet count per trigger and per timeframe --- Modules/TRD/CMakeLists.txt | 3 +- Modules/TRD/include/TRD/LinkDef.h | 1 + Modules/TRD/include/TRD/TrackletCountCheck.h | 51 +++++ Modules/TRD/src/TrackletCountCheck.cxx | 190 +++++++++++++++++++ 4 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 Modules/TRD/include/TRD/TrackletCountCheck.h create mode 100644 Modules/TRD/src/TrackletCountCheck.cxx diff --git a/Modules/TRD/CMakeLists.txt b/Modules/TRD/CMakeLists.txt index 0d81cf1722..17e954d160 100644 --- a/Modules/TRD/CMakeLists.txt +++ b/Modules/TRD/CMakeLists.txt @@ -2,7 +2,7 @@ add_library(O2QcTRD) -target_sources(O2QcTRD PRIVATE src/TrackletsPerTimeFrameCheck.cxx src/TrackletPerTriggerCheck.cxx src/TRDReductor.cxx src/PulsePositionCheck.cxx src/TrackingTask.cxx src/PulseHeightTrackMatch.cxx src/TrackletsCheck.cxx src/TrackletsTask.cxx src/PulseHeightCheck.cxx src/PulseHeight.cxx src/RawData.cxx src/DigitsTask.cxx +target_sources(O2QcTRD PRIVATE src/TrackletCountCheck.cxx src/TrackletsPerTimeFrameCheck.cxx src/TrackletPerTriggerCheck.cxx src/TRDReductor.cxx src/PulsePositionCheck.cxx src/TrackingTask.cxx src/PulseHeightTrackMatch.cxx src/TrackletsCheck.cxx src/TrackletsTask.cxx src/PulseHeightCheck.cxx src/PulseHeight.cxx src/RawData.cxx src/DigitsTask.cxx src/DigitsCheck.cxx src/TRDTrending.cxx src/TrendingTaskConfigTRD.cxx src/PulseHeightPostProcessing.cxx) target_include_directories( @@ -20,6 +20,7 @@ install(TARGETS O2QcTRD add_root_dictionary(O2QcTRD HEADERS + include/TRD/TrackletCountCheck.h include/TRD/TrackletsPerTimeFrameCheck.h include/TRD/TrackletPerTriggerCheck.h include/TRD/TRDReductor.h diff --git a/Modules/TRD/include/TRD/LinkDef.h b/Modules/TRD/include/TRD/LinkDef.h index 67bb2edb77..d0a0a3c569 100644 --- a/Modules/TRD/include/TRD/LinkDef.h +++ b/Modules/TRD/include/TRD/LinkDef.h @@ -19,4 +19,5 @@ #pragma link C++ class o2::quality_control_modules::trd::TRDReductor + ; #pragma link C++ class o2::quality_control_modules::trd::TrackletPerTriggerCheck + ; #pragma link C++ class o2::quality_control_modules::trd::TrackletsPerTimeFrameCheck + ; +#pragma link C++ class o2::quality_control_modules::trd::TrackletCountCheck+; #endif diff --git a/Modules/TRD/include/TRD/TrackletCountCheck.h b/Modules/TRD/include/TRD/TrackletCountCheck.h new file mode 100644 index 0000000000..d66ca6e955 --- /dev/null +++ b/Modules/TRD/include/TRD/TrackletCountCheck.h @@ -0,0 +1,51 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file TrackletCountCheck.h +/// \author My Name +/// + +#ifndef QC_MODULE_TRD_TRDTRACKLETCOUNTCHECK_H +#define QC_MODULE_TRD_TRDTRACKLETCOUNTCHECK_H + +#include "QualityControl/CheckInterface.h" + +namespace o2::quality_control_modules::trd +{ + +/// \brief Example QC Check +/// \author My Name +class TrackletCountCheck : public o2::quality_control::checker::CheckInterface +{ + public: + /// Default constructor + TrackletCountCheck() = default; + /// Destructor + ~TrackletCountCheck() override = default; + + // Override interface + void configure() override; + Quality check(std::map>* moMap) override; + void beautify(std::shared_ptr mo, Quality checkResult = Quality::Null) override; + std::string getAcceptedType() override; + float mThresholdMeanLowPerTrigger,mThresholdMeanHighPerTrigger, mThresholdMeanLowPerTimeFrame,mThresholdMeanHighPerTimeFrame; + int mStatThresholdPerTrigger; + Quality mResultPertrigger; + Quality mResultPerTimeFrame; + Quality mFinalResult; + + ClassDefOverride(TrackletCountCheck, 2); +}; + +} // namespace o2::quality_control_modules::trd + +#endif // QC_MODULE_TRD_TRDTRACKLETCOUNTCHECK_H diff --git a/Modules/TRD/src/TrackletCountCheck.cxx b/Modules/TRD/src/TrackletCountCheck.cxx new file mode 100644 index 0000000000..56005388bf --- /dev/null +++ b/Modules/TRD/src/TrackletCountCheck.cxx @@ -0,0 +1,190 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// +/// \file TrackletCountCheck.cxx +/// \author My Name +/// + +#include "TRD/TrackletCountCheck.h" +#include "QualityControl/MonitorObject.h" +#include "QualityControl/Quality.h" +#include "QualityControl/QcInfoLogger.h" +#include "Common/Utils.h" +// ROOT +#include +#include + +#include + +using namespace std; +using namespace o2::quality_control; +using namespace o2::quality_control_modules::common; + +namespace o2::quality_control_modules::trd +{ + +void TrackletCountCheck::configure() +{ + ILOG(Debug, Devel) << "initializing TrackletCountCheck" << ENDM; + + mThresholdMeanHighPerTimeFrame = getFromConfig(mCustomParameters, "UpperthresholdPerTimeFrame", 520.f); + ILOG(Debug, Support) << "using Upperthreshold Per Timeframe= " << mThresholdMeanHighPerTimeFrame << ENDM; + + mThresholdMeanLowPerTimeFrame = getFromConfig(mCustomParameters, "LowerthresholdPerTimeFrame", 600.f); + ILOG(Debug, Support) << "using Lowerthreshold Per Timeframe= " << mThresholdMeanLowPerTimeFrame << ENDM; + + mThresholdMeanHighPerTrigger = getFromConfig(mCustomParameters, "UpperthresholdPerTrigger", 520.f); + ILOG(Debug, Support) << "using Upperthreshold Per Trigger= " << mThresholdMeanHighPerTrigger << ENDM; + + mThresholdMeanLowPerTrigger = getFromConfig(mCustomParameters, "LowerthresholdPerTrigger", 500.f); + ILOG(Debug, Support) << "using Lowerthreshold Per Trigger= " << mThresholdMeanLowPerTrigger << ENDM; + + mStatThresholdPerTrigger = getFromConfig(mCustomParameters, "StatThresholdPerTrigger", 1000); + ILOG(Debug, Support) << "using StatThreshold Per Trigger= " << mStatThresholdPerTrigger << ENDM; +} + +Quality TrackletCountCheck::check(std::map>* moMap) +{ + mResultPertrigger = Quality::Null; + mResultPerTimeFrame = Quality::Null; + + for (auto& [moName, mo] : *moMap) { + + (void)moName; + if (mo->getName() == "trackletsperevent") { + auto* h = dynamic_cast(mo->getObject()); + if (h == nullptr) { + // ILOG(Debug, Support) << "Requested Histogram type does not match with the Histogram in source" << ENDM; + continue; + } + // warning about statistics available + TPaveText* msg1 = new TPaveText(0.3, 0.7, 0.7, 0.9, "NDC"); // check option "br","NDC" + h->GetListOfFunctions()->Add(msg1); + msg1->SetTextSize(10); + int Entries = h->GetEntries(); + if (Entries > mStatThresholdPerTrigger) { + msg1->AddText(TString::Format("Hist Can't be ignored. Stat is enough. Entries: %d > Threshold: %d", Entries, mStatThresholdPerTrigger)); + // msg1->SetTextColor(kGreen); + } else if (Entries > 0) { + msg1->AddText(TString::Format("Hist Can be ignored. Stat is low. Entries: %d < Threshold: %d", Entries, mStatThresholdPerTrigger)); + // msg1->SetTextColor(kYellow); + } else if (Entries == 0) { + msg1->AddText(TString::Format("Hist is empty. Entries: %d < Threshold: %d", Entries, mStatThresholdPerTrigger)); + msg1->SetTextColor(kRed); + } + + // Warning about triggers without any tracklets + int UnderFlowTrackletsPerTrigger = h->GetBinContent(0); + if (UnderFlowTrackletsPerTrigger > 0.) { + msg1->AddText(TString::Format("Triggers without Tracklets: %d", UnderFlowTrackletsPerTrigger)); + } + + // applying check + float MeanTrackletPertrigger = h->GetMean(); + if (MeanTrackletPertrigger > mThresholdMeanLowPerTrigger && MeanTrackletPertrigger < mThresholdMeanHighPerTrigger) { + TText* Checkmsg = msg1->AddText("Mean Per Trigger is found in bound region: ok"); + Checkmsg->SetTextColor(kGreen); + mResultPertrigger = Quality::Good; + } else { + mResultPertrigger = Quality::Bad; + TText* Checkmsg = msg1->AddText("Mean PerTrigger is not found in bound region: not ok"); + Checkmsg->SetTextColor(kRed); + mResultPertrigger.addReason(FlagReasonFactory::Unknown(), "MeanTrackletPertrigger is not in bound region"); + } + } + if (mo->getName() == "trackletspertimeframe") { + auto* h2 = dynamic_cast(mo->getObject()); + if (h2 == nullptr) { + // ILOG(Debug, Support) << "Requested Histogram type does not match with the Histogram in source" << ENDM; + continue; + } + + TPaveText* msg2 = new TPaveText(0.3, 0.7, 0.7, 0.9, "NDC"); // check option "br","NDC" + h2->GetListOfFunctions()->Add(msg2); + msg2->SetTextSize(10); + + // Warning about TimeFrame without any tracklets + int UnderFlowTrackletsPertrigger = h2->GetBinContent(0); + if (UnderFlowTrackletsPertrigger > 0.) { + msg2->AddText(TString::Format("TimeFrame without Tracklets: %d", UnderFlowTrackletsPertrigger)); + } + + // applying check + float MeanTrackletPerTimeFrame = h2->GetMean(); + if (MeanTrackletPerTimeFrame > mThresholdMeanLowPerTimeFrame && MeanTrackletPerTimeFrame < mThresholdMeanHighPerTimeFrame) { + TText* Checkmsg2 = msg2->AddText("Mean Per Timeframe is found in bound region: ok"); + Checkmsg2->SetTextColor(kGreen); + mResultPerTimeFrame = Quality::Good; + } else { + mResultPerTimeFrame = Quality::Bad; + TText* Checkmsg2 = msg2->AddText("Mean per Timeframe is not found in bound region: not ok"); + Checkmsg2->SetTextColor(kRed); + mResultPerTimeFrame.addReason(FlagReasonFactory::Unknown(), "MeanTrackletPerTimeFrame is not in bound region"); + } + } + } + if(mResultPertrigger == Quality::Null && mResultPerTimeFrame == Quality::Null){ + mFinalResult = Quality::Null; + mFinalResult.addReason(FlagReasonFactory::Unknown(),"Quality of both trackletspertimeframe and trackletsperevent is unknown"); + } else if((mResultPertrigger == Quality::Null && mResultPerTimeFrame == Quality::Good)||(mResultPertrigger == Quality::Good && mResultPerTimeFrame == Quality::Null)){ + mFinalResult = Quality::Medium; + mFinalResult.addReason(FlagReasonFactory::Unknown(),"Quality of any of trackletspertimeframe and trackletsperevent is unknown"); + } else if(mResultPertrigger == Quality::Bad || mResultPerTimeFrame ==Quality::Bad){ + mFinalResult = Quality::Bad; + mFinalResult.addReason(FlagReasonFactory::Unknown(),"Quality of both or any of trackletspertimeframe and trackletsperevent is bad"); + } else { + mFinalResult = Quality::Good; + } + return mFinalResult; +} + +std::string TrackletCountCheck::getAcceptedType() { return "TH1"; } + +void TrackletCountCheck::beautify(std::shared_ptr mo, Quality checkResult) +{ + if (mo->getName() == "trackletsperevent") { + auto* h1 = dynamic_cast(mo->getObject()); + if (h1 == nullptr) { + // ILOG(Debug, Support) << "Requested Histogram type does not match with the Histogram in source" << ENDM; + return; + } + if (mResultPertrigger == Quality::Good) { + h1->SetFillColor(kGreen); + } else if (mResultPertrigger == Quality::Bad) { + ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM; + h1->SetFillColor(kRed); + } else if (mResultPertrigger == Quality::Medium) { + ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM; + h1->SetFillColor(kOrange); + } + h1->SetLineColor(kBlack); + } + if(mo->getName() == "trackletspertimeframe"){ + auto* h2 = dynamic_cast(mo->getObject()); + if (h2 == nullptr) { + // ILOG(Debug, Support) << "Requested Histogram type does not match with the Histogram in source" << ENDM; + return; + } + if (mResultPerTimeFrame == Quality::Good) { + h2->SetFillColor(kGreen); + } else if (mResultPerTimeFrame == Quality::Bad) { + ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM; + h2->SetFillColor(kRed); + } else if (mResultPerTimeFrame == Quality::Medium) { + ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM; + h2->SetFillColor(kOrange); + } + h2->SetLineColor(kBlack); + } +} + +} // namespace o2::quality_control_modules::trd