|
| 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 NumPatchesPerFastORCheck.cxx |
| 14 | +/// \author Sierra Cantway |
| 15 | +/// |
| 16 | + |
| 17 | +#include "EMCAL/NumPatchesPerFastORCheck.h" |
| 18 | +#include "QualityControl/MonitorObject.h" |
| 19 | +#include "QualityControl/Quality.h" |
| 20 | +#include "QualityControl/QcInfoLogger.h" |
| 21 | +#include "EMCALBase/Geometry.h" |
| 22 | +#include <fairlogger/Logger.h> |
| 23 | +// ROOT |
| 24 | +#include <TH1.h> |
| 25 | +#include <TH2.h> |
| 26 | +#include <TPaveText.h> |
| 27 | +#include <TLatex.h> |
| 28 | +#include <TList.h> |
| 29 | +#include <TRobustEstimator.h> |
| 30 | +#include <TMath.h> |
| 31 | +#include <ROOT/TSeq.hxx> |
| 32 | +#include <TSpectrum.h> |
| 33 | +#include <iostream> |
| 34 | +#include <vector> |
| 35 | +#include <sstream> |
| 36 | + |
| 37 | +using namespace std; |
| 38 | + |
| 39 | +namespace o2::quality_control_modules::emcal |
| 40 | +{ |
| 41 | + |
| 42 | +void NumPatchesPerFastORCheck::configure() |
| 43 | +{ |
| 44 | + // configure threshold-based checkers for bad quality |
| 45 | + auto nBadThresholdNumPatchesPerFastOR = mCustomParameters.find("BadThresholdNumPatchesPerFastOR"); |
| 46 | + if (nBadThresholdNumPatchesPerFastOR != mCustomParameters.end()) { |
| 47 | + try { |
| 48 | + mBadThresholdNumPatchesPerFastOR = std::stof(nBadThresholdNumPatchesPerFastOR->second); |
| 49 | + } catch (std::exception& e) { |
| 50 | + ILOG(Error, Support) << fmt::format("Value {} not a float", nBadThresholdNumPatchesPerFastOR->second.data()) << ENDM; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + // configure TSpectrum parameters |
| 55 | + auto nSigmaTSpectrum = mCustomParameters.find("TSpecSigma"); |
| 56 | + if (nSigmaTSpectrum != mCustomParameters.end()) { |
| 57 | + try { |
| 58 | + mSigmaTSpectrum = std::stof(nSigmaTSpectrum->second); |
| 59 | + } catch (std::exception& e) { |
| 60 | + ILOG(Error, Support) << fmt::format("Value {} not a float", nSigmaTSpectrum->second.data()) << ENDM; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + auto nThreshTSpectrum = mCustomParameters.find("TSpecThresh"); |
| 65 | + if (nThreshTSpectrum != mCustomParameters.end()) { |
| 66 | + try { |
| 67 | + mThreshTSpectrum = std::stof(nThreshTSpectrum->second); |
| 68 | + } catch (std::exception& e) { |
| 69 | + ILOG(Error, Support) << fmt::format("Value {} not a float", nThreshTSpectrum->second.data()) << ENDM; |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +Quality NumPatchesPerFastORCheck::check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) |
| 75 | +{ |
| 76 | + auto mo = moMap->begin()->second; |
| 77 | + Quality result = Quality::Good; |
| 78 | + mErrorMessage.str(""); |
| 79 | + mNoisyTRUPositions.clear(); |
| 80 | + |
| 81 | + if (mo->getName() == "NumberOfPatchesWithFastOR") { |
| 82 | + auto* h = dynamic_cast<TH1*>(mo->getObject()); |
| 83 | + if (h->GetEntries() == 0) { |
| 84 | + result = Quality::Medium; |
| 85 | + } else { |
| 86 | + std::vector<double> smcounts; |
| 87 | + for (auto ib : ROOT::TSeqI(0, h->GetXaxis()->GetNbins())) { |
| 88 | + auto countSM = h->GetBinContent(ib + 1); |
| 89 | + if (countSM > 0) { |
| 90 | + smcounts.emplace_back(countSM); |
| 91 | + } |
| 92 | + } |
| 93 | + if (!smcounts.size()) { |
| 94 | + result = Quality::Medium; |
| 95 | + } else { |
| 96 | + TRobustEstimator meanfinder; |
| 97 | + double mean, sigma; |
| 98 | + meanfinder.EvaluateUni(smcounts.size(), smcounts.data(), mean, sigma); |
| 99 | + |
| 100 | + TSpectrum peakfinder; |
| 101 | + Int_t nfound = peakfinder.Search(h, mSigmaTSpectrum, "nobackground", mThreshTSpectrum); // Search for peaks //CHANGE - make config? |
| 102 | + Double_t* xpeaks = peakfinder.GetPositionX(); |
| 103 | + Double_t* ypeaks = peakfinder.GetPositionY(); |
| 104 | + std::sort(ypeaks, ypeaks + nfound, std::greater<double>()); // sort peaks in descending order to easy pick the y value of max peak |
| 105 | + double threshold = mBadThresholdNumPatchesPerFastOR * mean; |
| 106 | + |
| 107 | + for (Int_t n_peak = 0; n_peak < nfound; n_peak++) { |
| 108 | + Int_t bin = h->GetXaxis()->FindBin(xpeaks[n_peak]); |
| 109 | + Double_t peak_val = h->GetBinContent(bin); |
| 110 | + |
| 111 | + if (peak_val > threshold) { |
| 112 | + result = Quality::Bad; |
| 113 | + Double_t peak_pos = h->GetXaxis()->GetBinCenter(bin); |
| 114 | + auto [truID, fastorTRU] = mTriggerMapping->getTRUFromAbsFastORIndex(peak_pos); |
| 115 | + mErrorMessage << "TRU " << truID << " has a noisy FastOR at position " << fastorTRU << " in TRU." << std::endl; |
| 116 | + ILOG(Error, Support) << "TRU " << truID << " has a noisy FastOR at position " << fastorTRU << " in TRU." << ENDM; |
| 117 | + mNoisyTRUPositions.push_back(std::make_pair(truID, fastorTRU)); |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + return result; |
| 125 | +} |
| 126 | + |
| 127 | +std::string NumPatchesPerFastORCheck::getAcceptedType() { return "TH1"; } |
| 128 | + |
| 129 | +void NumPatchesPerFastORCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult) |
| 130 | +{ |
| 131 | + // To do - good message |
| 132 | + if (mo->getName() == "NumberOfPatchesWithFastOR") { |
| 133 | + auto* h = dynamic_cast<TH1*>(mo->getObject()); |
| 134 | + if (checkResult == Quality::Bad) { |
| 135 | + TLatex* msg; |
| 136 | + if (!mErrorMessage.str().empty()) { |
| 137 | + ILOG(Error, Support) << mErrorMessage.str() << ENDM; |
| 138 | + msg = new TLatex(0.15, 0.84, "#color[2]{Error: Noisy TRU(s)}"); |
| 139 | + msg->SetNDC(); |
| 140 | + msg->SetTextSize(16); |
| 141 | + msg->SetTextFont(43); |
| 142 | + msg->SetTextColor(kRed); |
| 143 | + h->GetListOfFunctions()->Add(msg); |
| 144 | + msg->Draw(); |
| 145 | + } |
| 146 | + for (int iErr = 0; iErr < mNoisyTRUPositions.size(); iErr++) { |
| 147 | + stringstream errorMessageIndiv; |
| 148 | + errorMessageIndiv << "Position " << mNoisyTRUPositions[iErr].second << " in TRU " << mNoisyTRUPositions[iErr].first << " is noisy." << std::endl; |
| 149 | + msg = new TLatex(0.15, 0.8 - iErr / 25., errorMessageIndiv.str().c_str()); |
| 150 | + msg->SetNDC(); |
| 151 | + msg->SetTextSize(16); |
| 152 | + msg->SetTextFont(43); |
| 153 | + msg->SetTextColor(kRed); |
| 154 | + h->GetListOfFunctions()->Add(msg); |
| 155 | + msg->Draw(); |
| 156 | + ILOG(Error, Support) << errorMessageIndiv.str() << ENDM; |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | +} |
| 161 | +} // namespace o2::quality_control_modules::emcal |
0 commit comments