|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// |
| 13 | +/// \file RawDataCheck.cxx |
| 14 | +/// \author Ole Schmidt |
| 15 | + |
| 16 | +// C++ |
| 17 | +#include <string> |
| 18 | +#include <fmt/core.h> |
| 19 | +// Fair |
| 20 | +#include <fairlogger/Logger.h> |
| 21 | +// ROOT |
| 22 | +#include <TH1.h> |
| 23 | +#include <TH2.h> |
| 24 | +#include <TLatex.h> |
| 25 | +#include <TList.h> |
| 26 | +#include <TPaveText.h> |
| 27 | +#include <TBox.h> |
| 28 | +#include <TPad.h> |
| 29 | +#include <TCanvas.h> |
| 30 | +#include <TMath.h> |
| 31 | + |
| 32 | +// O2 |
| 33 | +#include <DataFormatsQualityControl/FlagReasons.h> |
| 34 | +#include <CommonConstants/LHCConstants.h> |
| 35 | +#include <DataFormatsParameters/GRPECSObject.h> |
| 36 | +#include <CCDB/BasicCCDBManager.h> |
| 37 | + |
| 38 | +// Quality Control |
| 39 | +#include "TRD/RawDataCheck.h" |
| 40 | +#include "QualityControl/MonitorObject.h" |
| 41 | +#include "QualityControl/Quality.h" |
| 42 | +#include "QualityControl/QcInfoLogger.h" |
| 43 | +#include "QualityControl/UserCodeInterface.h" |
| 44 | + |
| 45 | +using namespace std; |
| 46 | +using namespace o2::quality_control; |
| 47 | + |
| 48 | +namespace o2::quality_control_modules::trd |
| 49 | +{ |
| 50 | + |
| 51 | +void RawDataCheckStats::configure() {} |
| 52 | + |
| 53 | +Quality RawDataCheckStats::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) |
| 54 | +{ |
| 55 | + Quality result = Quality::Null; |
| 56 | + int runNumber = mActivity->mId; |
| 57 | + auto& ccdbmgr = o2::ccdb::BasicCCDBManager::instance(); |
| 58 | + auto runDuration = ccdbmgr.getRunDuration(runNumber, false); |
| 59 | + map<string, string> metaData; |
| 60 | + metaData.emplace(std::pair<std::string, std::string>("runNumber", to_string(runNumber))); |
| 61 | + auto calib = UserCodeInterface::retrieveConditionAny<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", metaData, runDuration.first); |
| 62 | + for (auto& [moName, mo] : *moMap) { |
| 63 | + (void)moName; |
| 64 | + if (mo->getName() == "stats") { |
| 65 | + auto* h = dynamic_cast<TH1F*>(mo->getObject()); |
| 66 | + result.set(Quality::Good); |
| 67 | + if (h->GetBinContent(1) < 1 || h->GetBinContent(2) < 1) { |
| 68 | + result.set(Quality::Bad); // no readout triggers or histogram is completely empty |
| 69 | + } else { |
| 70 | + mReadoutRate = h->GetBinContent(2) / h->GetBinContent(1); // number of triggers per TF |
| 71 | + mReadoutRate *= 1. / (calib->getNHBFPerTF() * o2::constants::lhc::LHCOrbitMUS * 1e-6); |
| 72 | + mCalTriggerRate = h->GetBinContent(3) / h->GetBinContent(2); |
| 73 | + } |
| 74 | + if (mReadoutRate > mMaxReadoutRate) { |
| 75 | + result.set(Quality::Bad); // too high rate (should be triggered only for COSMICS run) TOF noisy? |
| 76 | + } |
| 77 | + if (mCalTriggerRate < mMinCalTriggerRate) { |
| 78 | + result.set(Quality::Medium); // no calibration triggers configured? |
| 79 | + } |
| 80 | + result.addMetadata("readoutRate", to_string(mReadoutRate)); |
| 81 | + result.addMetadata("calTriggerRate", to_string(mCalTriggerRate)); |
| 82 | + } |
| 83 | + } |
| 84 | + return result; |
| 85 | +} |
| 86 | + |
| 87 | +void RawDataCheckStats::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult) |
| 88 | +{ |
| 89 | + |
| 90 | + if (mo->getName() == "stats") { |
| 91 | + auto* h = dynamic_cast<TH1F*>(mo->getObject()); |
| 92 | + if (h->GetMaximum() < 1) { |
| 93 | + return; |
| 94 | + } |
| 95 | + auto msg = new TPaveText(0.5, h->GetMaximum() / 1e2, 2.5, h->GetMaximum()); |
| 96 | + TText* txtPtr = nullptr; |
| 97 | + txtPtr = msg->AddText(Form("Readout rate: %.3f kHz", mReadoutRate / 1000.)); |
| 98 | + txtPtr->SetTextAlign(12); |
| 99 | + txtPtr = msg->AddText(Form("Calibration trigger rate: %.4f", mCalTriggerRate)); |
| 100 | + txtPtr->SetTextAlign(12); |
| 101 | + static_cast<TText*>(msg->GetListOfLines()->Last())->SetTextAlign(12); |
| 102 | + h->GetListOfFunctions()->Add(msg); |
| 103 | + if (checkResult == Quality::Good) { |
| 104 | + h->SetFillColor(kGreen); |
| 105 | + msg->SetFillColor(kGreen); |
| 106 | + } else if (checkResult == Quality::Bad) { |
| 107 | + ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM; |
| 108 | + h->SetFillColor(kRed); |
| 109 | + msg->SetFillColor(kRed); |
| 110 | + } else if (checkResult == Quality::Medium) { |
| 111 | + ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM; |
| 112 | + h->SetFillColor(kOrange); |
| 113 | + msg->SetFillColor(kOrange); |
| 114 | + } |
| 115 | + h->SetLineColor(kBlack); |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +std::string RawDataCheckStats::getAcceptedType() |
| 120 | +{ |
| 121 | + return "TH1"; |
| 122 | +} |
| 123 | + |
| 124 | +void RawDataCheckStats::reset() |
| 125 | +{ |
| 126 | + ILOG(Debug, Devel) << "RawDataCheckStats::reset" << ENDM; |
| 127 | +} |
| 128 | + |
| 129 | +void RawDataCheckStats::startOfActivity(const Activity& activity) |
| 130 | +{ |
| 131 | + ILOG(Debug, Devel) << "RawDataCheckStats::start : " << activity.mId << ENDM; |
| 132 | + mActivity = make_shared<Activity>(activity); |
| 133 | + // we cannot move the parameter initialization to configure(), as there the activity is not yet initialized |
| 134 | + mMaxReadoutRate = std::stof(mCustomParameters.atOptional("maxReadoutRate", *mActivity).value_or("1e6")); |
| 135 | + mMinCalTriggerRate = std::stof(mCustomParameters.atOptional("minCalTriggerRate", *mActivity).value_or("1e-5")); |
| 136 | +} |
| 137 | + |
| 138 | +void RawDataCheckStats::endOfActivity(const Activity& activity) |
| 139 | +{ |
| 140 | + ILOG(Debug, Devel) << "RawDataCheckStats::end : " << activity.mId << ENDM; |
| 141 | +} |
| 142 | + |
| 143 | +void RawDataCheckSizes::configure() {} |
| 144 | + |
| 145 | +Quality RawDataCheckSizes::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) |
| 146 | +{ |
| 147 | + Quality result = Quality::Null; |
| 148 | + |
| 149 | + for (auto& [moName, mo] : *moMap) { |
| 150 | + (void)moName; |
| 151 | + if (mo->getName() == "datavolumepersector") { |
| 152 | + auto* h = dynamic_cast<TH2F*>(mo->getObject()); |
| 153 | + result.set(Quality::Good); |
| 154 | + TObjArray fits; |
| 155 | + h->FitSlicesY(nullptr, 1, 18, 0, "QNR", &fits); |
| 156 | + auto hMean = (TH1F*)fits[1]; |
| 157 | + double sum = 0, sum2 = 0, n = 0; |
| 158 | + for (int iBin = 1; iBin <= 18; ++iBin) { |
| 159 | + sum += hMean->GetBinContent(iBin); |
| 160 | + sum2 += hMean->GetBinContent(iBin) * hMean->GetBinContent(iBin); |
| 161 | + ++n; |
| 162 | + mMeanDataSize = sum / n; |
| 163 | + mStdDevDataSize = sum2 / n - TMath::Power(sum / n, 2); |
| 164 | + } |
| 165 | + mStdDevDataSize = TMath::Sqrt(mStdDevDataSize); |
| 166 | + for (int iBin = 1; iBin <= 18; ++iBin) { |
| 167 | + if (TMath::Abs(hMean->GetBinContent(iBin) - mMeanDataSize) > mWarningThreshold * mStdDevDataSize) { |
| 168 | + ILOG(Debug, Support) << fmt::format("Found outlier in sector {} with mean value of {}", iBin - 1, hMean->GetBinContent(iBin)) << ENDM; |
| 169 | + result.set(Quality::Medium); |
| 170 | + } |
| 171 | + if (TMath::Abs(hMean->GetBinContent(iBin) - mMeanDataSize) > mErrorThreshold * mStdDevDataSize) { |
| 172 | + ILOG(Debug, Support) << fmt::format("Found strong outlier in sector {} with mean value of {}", iBin - 1, hMean->GetBinContent(iBin)) << ENDM; |
| 173 | + result.set(Quality::Bad); |
| 174 | + } |
| 175 | + } |
| 176 | + ILOG(Debug, Support) << fmt::format("Data size plot: Mean({}), StdDev({}).", mMeanDataSize, mStdDevDataSize) << ENDM; |
| 177 | + result.addMetadata("dataSizeMean", to_string(mMeanDataSize)); |
| 178 | + result.addMetadata("dataSizeStdDev", to_string(mStdDevDataSize)); |
| 179 | + } |
| 180 | + } |
| 181 | + return result; |
| 182 | +} |
| 183 | + |
| 184 | +void RawDataCheckSizes::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult) |
| 185 | +{ |
| 186 | + if (mo->getName() == "datavolumepersector") { |
| 187 | + ILOG(Debug, Support) << "Found the meta data \"foo\": " << checkResult.getMetadata("foo", "ramtam") << ENDM; |
| 188 | + auto* h = dynamic_cast<TH2F*>(mo->getObject()); |
| 189 | + auto msg = new TPaveText(4, 3000, 10, 3800); |
| 190 | + msg->AddText(Form("Average volume per sector: %.2f Bytes/TF", mMeanDataSize)); |
| 191 | + static_cast<TText*>(msg->GetListOfLines()->Last())->SetTextAlign(12); |
| 192 | + msg->AddText(Form("sigma: %.3f", mStdDevDataSize)); |
| 193 | + static_cast<TText*>(msg->GetListOfLines()->Last())->SetTextAlign(12); |
| 194 | + h->GetListOfFunctions()->Add(msg); |
| 195 | + if (checkResult == Quality::Good) { |
| 196 | + msg->SetFillColor(kGreen); |
| 197 | + } else if (checkResult == Quality::Bad) { |
| 198 | + ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM; |
| 199 | + msg->SetFillColor(kRed); |
| 200 | + } else if (checkResult == Quality::Medium) { |
| 201 | + ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM; |
| 202 | + msg->SetFillColor(kOrange); |
| 203 | + } |
| 204 | + } |
| 205 | +} |
| 206 | + |
| 207 | +std::string RawDataCheckSizes::getAcceptedType() |
| 208 | +{ |
| 209 | + return "TH2"; |
| 210 | +} |
| 211 | + |
| 212 | +void RawDataCheckSizes::reset() |
| 213 | +{ |
| 214 | + ILOG(Debug, Devel) << "RawDataCheckSizes::reset" << ENDM; |
| 215 | +} |
| 216 | + |
| 217 | +void RawDataCheckSizes::startOfActivity(const Activity& activity) |
| 218 | +{ |
| 219 | + ILOG(Debug, Devel) << "RawDataCheckSizes::start : " << activity.mId << ENDM; |
| 220 | + mActivity = make_shared<Activity>(activity); |
| 221 | + // we cannot move the parameter initialization to configure(), as there the activity is not yet initialized |
| 222 | + mWarningThreshold = std::stof(mCustomParameters.atOptional("warningThreshold", *mActivity).value_or("3")); |
| 223 | + mErrorThreshold = std::stof(mCustomParameters.atOptional("errorThreshold", *mActivity).value_or("5")); |
| 224 | +} |
| 225 | + |
| 226 | +void RawDataCheckSizes::endOfActivity(const Activity& activity) |
| 227 | +{ |
| 228 | + ILOG(Debug, Devel) << "RawDataCheckSizes::end : " << activity.mId << ENDM; |
| 229 | +} |
| 230 | + |
| 231 | +} // namespace o2::quality_control_modules::trd |
0 commit comments