|
| 1 | +#include "EMCAL/CellAmpCheck.h" |
| 2 | +#include "QualityControl/MonitorObject.h" |
| 3 | +#include "QualityControl/QcInfoLogger.h" |
| 4 | +#include "QualityControl/Quality.h" |
| 5 | + |
| 6 | +// ROOT |
| 7 | +#include <ROOT/TSeq.hxx> |
| 8 | +#include <TCanvas.h> |
| 9 | +#include <TH1.h> |
| 10 | +#include <TH2.h> |
| 11 | +#include <TLatex.h> |
| 12 | +#include <TList.h> |
| 13 | +#include <TPaveText.h> |
| 14 | +#include <TRobustEstimator.h> |
| 15 | +#include <iostream> |
| 16 | +#include <string> |
| 17 | +#include <vector> |
| 18 | + |
| 19 | +using namespace std; |
| 20 | + |
| 21 | +namespace o2::quality_control_modules::emcal |
| 22 | +{ |
| 23 | +void CellAmpCheck::configure() |
| 24 | +{ |
| 25 | + // configure threshold-based checkers |
| 26 | + auto nChiSqMedThresh = mCustomParameters.find("ChiSqMedThresh"); |
| 27 | + if (nChiSqMedThresh != mCustomParameters.end()) { |
| 28 | + try { |
| 29 | + mChiSqMedThresh = std::stod(nChiSqMedThresh->second); |
| 30 | + } catch (std::exception& e) { |
| 31 | + ILOG(Error, Support) << "Value " << nChiSqMedThresh->second.data() |
| 32 | + << " not a double" << ENDM; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + auto nBadChiSqThresh = mCustomParameters.find("BadChiSqThresh"); |
| 37 | + if (nBadChiSqThresh != mCustomParameters.end()) { |
| 38 | + try { |
| 39 | + mChiSqBadThresh = std::stod(nBadChiSqThresh->second); |
| 40 | + } catch (std::exception& e) { |
| 41 | + ILOG(Error, Support) << "Value " << nBadChiSqThresh->second.data() |
| 42 | + << " not a double" << ENDM; |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +Quality CellAmpCheck::check( |
| 48 | + std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) |
| 49 | +{ |
| 50 | + if (!mCellAmpReference) { |
| 51 | + // Load reference histogram from the CCDB |
| 52 | + mCellAmpReference = |
| 53 | + this->retrieveConditionAny<TH1>("EMC/QCREF/CellAmpCalibCheck"); |
| 54 | + } |
| 55 | + if (!mCellAmpReference) { |
| 56 | + // If histogram not found print out error message |
| 57 | + ILOG(Error, Support) << "Could not find the reference histogram!" << ENDM; |
| 58 | + } |
| 59 | + |
| 60 | + Quality result = Quality::Good; |
| 61 | + for (auto& [moName, mo] : *moMap) { |
| 62 | + if (mo->getName() == "cellAmplitudeCalib_PHYS") { |
| 63 | + |
| 64 | + auto* h = dynamic_cast<TH1*>(mo->getObject()); |
| 65 | + h->Scale(1. / h->Integral()); |
| 66 | + mCellAmpReference->Scale(1. / mCellAmpReference->Integral()); |
| 67 | + |
| 68 | + Double_t chisq_val = h->Chi2Test(mCellAmpReference, "UU NORM CHI2/NDF"); |
| 69 | + if (chisq_val > mChiSqMedThresh) { |
| 70 | + result = Quality::Medium; |
| 71 | + } |
| 72 | + if (mChiSqBadThresh < chisq_val) { |
| 73 | + result = Quality::Bad; |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + return result; |
| 78 | +} |
| 79 | + |
| 80 | +std::string CellAmpCheck::getAcceptedType() { return "TH1"; } |
| 81 | + |
| 82 | +void CellAmpCheck::beautify(std::shared_ptr<MonitorObject> mo, |
| 83 | + Quality checkResult) |
| 84 | +{ |
| 85 | + if (mo->getName() == "cellAmplitudeCalib_PHYS") { |
| 86 | + auto* h = dynamic_cast<TH1*>(mo->getObject()); |
| 87 | + TPaveText* msg = new TPaveText(0.5, 0.5, 0.9, 0.75, "NDC"); |
| 88 | + h->GetListOfFunctions()->Add(msg); |
| 89 | + msg->SetName(Form("%s_msg", mo->GetName())); |
| 90 | + if (checkResult == Quality::Good) { |
| 91 | + // |
| 92 | + msg->Clear(); |
| 93 | + msg->AddText("Cell amplitude within expectations."); |
| 94 | + msg->SetFillColor(kGreen); |
| 95 | + msg->Draw(); |
| 96 | + // |
| 97 | + h->SetFillColor(kGreen); |
| 98 | + } else if (checkResult == Quality::Bad) { |
| 99 | + ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM; |
| 100 | + msg->Clear(); |
| 101 | + msg->AddText("Suspicious cell amplitude detected."); |
| 102 | + msg->AddText("If NOT a technical run,"); |
| 103 | + msg->AddText("call EMCAL on-call."); |
| 104 | + msg->Draw(); |
| 105 | + h->SetFillColor(kRed); |
| 106 | + } else if (checkResult == Quality::Medium) { |
| 107 | + ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM; |
| 108 | + msg->Clear(); |
| 109 | + msg->AddText("WARNING: Deviation from expectations. Keep monitoring"); |
| 110 | + msg->Draw(); |
| 111 | + h->SetFillColor(kOrange); |
| 112 | + } |
| 113 | + h->SetLineColor(kBlack); |
| 114 | + } |
| 115 | +} |
| 116 | +} // namespace o2::quality_control_modules::emcal |
0 commit comments