Skip to content

Commit

Permalink
CTP: update of the check class (#2372)
Browse files Browse the repository at this point in the history
* Checking the change in nSigma instead of percentage

* changes requested by Piotr

---------

Co-authored-by: Lucia Anna Tarasovicova <lucia.anna.husova@cern.ch>
  • Loading branch information
lhusova and Lucia Anna Tarasovicova authored Jul 25, 2024
1 parent 04ad10c commit f6820b5
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 49 deletions.
4 changes: 4 additions & 0 deletions Modules/CTP/include/CTP/RawDataQcTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ class CTPRawDataReaderTask final : public TaskInterface
std::unique_ptr<TH1DRatio> mHistoClassRatios = nullptr; // histogram with ctp class ratios to MB
std::unique_ptr<TH1D> mHistoMTVXBC = nullptr; // histogram of BC positions to check LHC filling scheme
int mRunNumber;
int indexTvx = -1;
static const int ninps = o2::ctp::CTP_NINPUTS + 1;
static const int nclasses = o2::ctp::CTP_NCLASSES + 1;
long int mTimestamp;
std::string classNames[nclasses];
int mIndexMBclass = -1; // index for the MB ctp class, which is used as scaling for the ratios
};

Expand Down
24 changes: 13 additions & 11 deletions Modules/CTP/include/CTP/RawDataReaderCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ class RawDataReaderCheck : public o2::quality_control::checker::CheckInterface
private:
int getRunNumberFromMO(std::shared_ptr<MonitorObject> mo);
int checkChange(TH1D* mHist, TH1D* mHistPrev);
int checkChangeOfRatio(TH1D* mHist, TH1D* mHistPrev, TH1D* mHistAbs);
Quality setQualityResult(std::vector<int>& vBad, std::vector<int>& vMedium);
void clearIndexVectors();
long int mTimestamp;
float mThreshold = -1; // threshold for BCs
float mThresholdRateBad; // threshold for the relative change in ctp input and class rates
float mThresholdRateMedium; // threshold for the relative change in ctp input and class rates
float mThresholdRateRatioBad; // threshold for the relative change in ctp input and class ratios
float mThresholdRateRatioMedium; // threshold for the relative change in ctp input and class ratios
bool mFlagRatio = false; // flag that a ratio plot is checked
bool mFlagInput = false; // flag that an input plot is checked
TH1D* mHistInputPrevious = nullptr; // histogram storing ctp input rates from previous cycle
TH1D* mHistClassesPrevious = nullptr; // histogram storing ctp class rates from previous cycle
TH1D* mHistInputRatioPrevious = nullptr; // histogram storing ctp input ratios to MB from previous cycle
TH1D* mHistClassRatioPrevious = nullptr; // histogram storing ctp class ratios to MB from previous cycle
float mThreshold = -1; // threshold for BCs
float mThresholdRateBad; // threshold for the relative change in ctp input and class rates
float mThresholdRateMedium; // threshold for the relative change in ctp input and class rates
float mThresholdRateRatioBad; // threshold for the relative change in ctp input and class ratios
float mThresholdRateRatioMedium; // threshold for the relative change in ctp input and class ratios
bool mFlagRatio = false; // flag that a ratio plot is checked
bool mFlagInput = false; // flag that an input plot is checked
TH1D* mHistInputPrevious = nullptr; // histogram storing ctp input rates from previous cycle
TH1D* mHistClassesPrevious = nullptr; // histogram storing ctp class rates from previous cycle
TH1D* mHistInputRatioPrevious = nullptr; // histogram storing ctp input ratios to MB from previous cycle
TH1D* mHistClassRatioPrevious = nullptr;
TH1D* mHistAbsolute = nullptr; // histogram storing ctp class ratios to MB from previous cycle
std::vector<int> mVecGoodBC; // vector of good BC positions
std::vector<int> mVecMediumBC; // vector of medium BC positions, we expect a BC at this position, but inputs are below mThreshold
std::vector<int> mVecBadBC; // vector of bad BC positions, we don't expect a BC at this position, but inputs are abow mThreshold
Expand Down
38 changes: 30 additions & 8 deletions Modules/CTP/src/RawDataQcTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ CTPRawDataReaderTask::~CTPRawDataReaderTask()
void CTPRawDataReaderTask::initialize(o2::framework::InitContext& /*ctx*/)
{
ILOG(Debug, Devel) << "initialize CTPRawDataReaderTask" << ENDM; // QcInfoLogger is used. FairMQ logs will go to there as well.
int ninps = o2::ctp::CTP_NINPUTS + 1;
int nclasses = o2::ctp::CTP_NCLASSES + 1;
int norbits = o2::constants::lhc::LHCMaxBunches;
mHistoInputs = std::make_unique<TH1DRatio>("inputs", "Input Rates; Input ; Rate [kHz]", ninps, 0, ninps, true);
mHistoClasses = std::make_unique<TH1DRatio>("classes", "Class Rates; Index; Rate [kHz]", nclasses, 0, nclasses, true);
mHistoClasses = std::make_unique<TH1DRatio>("classes", "Class Rates; Class; Rate [kHz]", nclasses, 0, nclasses, true);
mHistoInputs->SetStats(0);
mHistoClasses->SetStats(0);
mHistoMTVXBC = std::make_unique<TH1D>("bcMTVX", "BC position of MTVX", norbits, 0, norbits);
mHistoInputRatios = std::make_unique<TH1DRatio>("inputRatio", "Input Ratio to MTVX; Input; Ratio;", ninps, 0, ninps, true);
mHistoClassRatios = std::make_unique<TH1DRatio>("classRatio", "Class Ratio to MB; Index; Ratio", nclasses, 0, nclasses, true);
mHistoClassRatios = std::make_unique<TH1DRatio>("classRatio", "Class Ratio to MB; Class; Ratio", nclasses, 0, nclasses, true);
getObjectsManager()->startPublishing(mHistoInputs.get());
getObjectsManager()->startPublishing(mHistoClasses.get());
getObjectsManager()->startPublishing(mHistoClassRatios.get());
Expand All @@ -56,6 +54,11 @@ void CTPRawDataReaderTask::initialize(o2::framework::InitContext& /*ctx*/)

mDecoder.setDoLumi(1);
mDecoder.setDoDigits(1);
for (size_t i = 0; i < nclasses; i++) {
classNames[i] = "";
}
mHistoClassRatios.get()->GetXaxis()->CenterLabels(true);
mHistoClasses.get()->GetXaxis()->CenterLabels(true);
}

void CTPRawDataReaderTask::startOfActivity(const Activity& activity)
Expand Down Expand Up @@ -99,9 +102,9 @@ void CTPRawDataReaderTask::startOfActivity(const Activity& activity)
if (ok) {
// get the index of the MB reference class
ILOG(Info, Support) << "CTP config found, run:" << run << ENDM;
// std::vector<o2::ctp::CTPClass> ctpcls = CTPconfig.getCTPClasses();
std::vector<o2::ctp::CTPClass> ctpcls = ctpconfigdb->getCTPClasses();
for (size_t i = 0; i < ctpcls.size(); i++) {
classNames[i] = ctpcls[i].name.c_str();
if (ctpcls[i].name.find(MBclassName) != std::string::npos) {
mIndexMBclass = ctpcls[i].getIndex() + 1;
break;
Expand All @@ -113,6 +116,27 @@ void CTPRawDataReaderTask::startOfActivity(const Activity& activity)
if (mIndexMBclass == -1) {
mIndexMBclass = 1;
}
std::string nameInput = mCustomParameters["MBinputName"];
if (nameInput.empty()) {
nameInput = "MTVX";
}
indexTvx = o2::ctp::CTPInputsConfiguration::getInputIndexFromName(nameInput);
if (indexTvx == -1) {
indexTvx = 3; // 3 is the MTVX index
}
for (int i = 0; i < nclasses; i++) {
if (classNames[i] == "") {
mHistoClasses.get()->GetXaxis()->SetBinLabel(i + 1, Form("%i", i + 1));
mHistoClassRatios.get()->GetXaxis()->SetBinLabel(i + 1, Form("%i", i + 1));
} else {
mHistoClasses.get()->GetXaxis()->SetBinLabel(i + 1, Form("%s", classNames[i].c_str()));
mHistoClassRatios.get()->GetXaxis()->SetBinLabel(i + 1, Form("%s", classNames[i].c_str()));
}
}
mHistoClasses.get()->GetXaxis()->SetLabelSize(0.025);
mHistoClasses.get()->GetXaxis()->LabelsOption("v");
mHistoClassRatios.get()->GetXaxis()->SetLabelSize(0.025);
mHistoClassRatios.get()->GetXaxis()->LabelsOption("v");
}

void CTPRawDataReaderTask::startOfCycle()
Expand All @@ -132,9 +156,7 @@ void CTPRawDataReaderTask::monitorData(o2::framework::ProcessingContext& ctx)
o2::framework::InputRecord& inputs = ctx.inputs();
mDecoder.decodeRaw(inputs, filter, outputDigits, lumiPointsHBF1);

//reading the ctp inputs and ctp classes
std::string nameInput = "MTVX";
auto indexTvx = o2::ctp::CTPInputsConfiguration::getInputIndexFromName(nameInput);
// reading the ctp inputs and ctp classes
for (auto const digit : outputDigits) {
uint16_t bcid = digit.intRecord.bc;
if (digit.CTPInputMask.count()) {
Expand Down
69 changes: 47 additions & 22 deletions Modules/CTP/src/RawDataReaderCheck.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// ROOT
#include <TH1.h>
#include <TLatex.h>
#include <TMath.h>
#include <DataFormatsParameters/GRPLHCIFData.h>
#include <DataFormatsQualityControl/FlagType.h>
#include <DetectorsBase/GRPGeomHelper.h>
Expand All @@ -38,27 +39,28 @@ void RawDataReaderCheck::configure()
{
// reading the parameters from the config.json
// if not available, setting a default value
std::string param = mCustomParameters.atOrDefaultValue("thresholdRateBad", "0.15");
// the threshold values are nSigma
std::string param = mCustomParameters.atOrDefaultValue("thresholdRateBad", "3");
mThresholdRateBad = std::stof(param);
if (mThresholdRateBad > 1 || mThresholdRateBad < 0) {
mThresholdRateBad = 0.15;
if (mThresholdRateBad > 4 || mThresholdRateBad < 0) {
mThresholdRateBad = 3;
}

param = mCustomParameters.atOrDefaultValue("thresholdRateMedium", "0.1");
param = mCustomParameters.atOrDefaultValue("thresholdRateMedium", "2");
mThresholdRateMedium = std::stof(param);
if (mThresholdRateMedium > 1 || mThresholdRateMedium < 0) {
mThresholdRateMedium = 0.1;
if (mThresholdRateMedium > 4 || mThresholdRateMedium < 0) {
mThresholdRateMedium = 2;
}

param = mCustomParameters.atOrDefaultValue("thresholdRateRatioBad", "0.1");
param = mCustomParameters.atOrDefaultValue("thresholdRateRatioBad", "3");
mThresholdRateRatioBad = std::stof(param);
if (mThresholdRateRatioBad > 1 || mThresholdRateRatioBad < 0) {
mThresholdRateRatioBad = 0.1;
if (mThresholdRateRatioBad > 4 || mThresholdRateRatioBad < 0) {
mThresholdRateRatioBad = 3;
}
param = mCustomParameters.atOrDefaultValue("thresholdRateRatioMedium", "0.05");
mThresholdRateRatioBad = std::stof(param);
if (mThresholdRateRatioMedium > 1 || mThresholdRateRatioMedium < 0) {
mThresholdRateRatioMedium = 0.05;
param = mCustomParameters.atOrDefaultValue("thresholdRateRatioMedium", "2");
mThresholdRateRatioMedium = std::stof(param);
if (mThresholdRateRatioMedium > 4 || mThresholdRateRatioMedium < 0) {
mThresholdRateRatioMedium = 2;
}
}

Expand Down Expand Up @@ -104,10 +106,11 @@ Quality RawDataReaderCheck::check(std::map<std::string, std::shared_ptr<MonitorO
delete mHistInputPrevious;
result.set(setQualityResult(mVecIndexBad, mVecIndexMedium));
}
mHistAbsolute = (TH1D*)h->Clone();
mHistInputPrevious = (TH1D*)h->Clone();
} else if (mo->getName() == "inputRatio") {
if (mHistInputRatioPrevious) {
checkChange(h, mHistInputRatioPrevious);
checkChangeOfRatio(h, mHistInputRatioPrevious, mHistAbsolute);
delete mHistInputRatioPrevious;
result.set(setQualityResult(mVecIndexBad, mVecIndexMedium));
}
Expand All @@ -118,10 +121,11 @@ Quality RawDataReaderCheck::check(std::map<std::string, std::shared_ptr<MonitorO
delete mHistClassesPrevious;
result.set(setQualityResult(mVecIndexBad, mVecIndexMedium));
}
mHistAbsolute = (TH1D*)h->Clone();
mHistClassesPrevious = (TH1D*)h->Clone();
} else if (mo->getName() == "classRatio") {
if (mHistClassRatioPrevious) {
checkChange(h, mHistClassRatioPrevious);
checkChangeOfRatio(h, mHistClassRatioPrevious, mHistAbsolute);
delete mHistClassRatioPrevious;
result.set(setQualityResult(mVecIndexBad, mVecIndexMedium));
}
Expand All @@ -139,14 +143,34 @@ int RawDataReaderCheck::checkChange(TH1D* mHist, TH1D* mHistPrev)
/// this function check how much the rates differ from previous cycle
float thrBad = mThresholdRateBad;
float thrMedium = mThresholdRateMedium;
if (mFlagRatio) {
thrBad = mThresholdRateRatioBad;
thrMedium = mThresholdRateRatioMedium;
for (size_t i = 1; i < mHist->GetXaxis()->GetNbins() + 1; i++) { // Check how many inputs/classes changed more than a threshold value
double val = mHist->GetBinContent(i);
double valPrev = mHistPrev->GetBinContent(i);
double relDiff = (valPrev != 0 || val != 0) ? (val - valPrev) / TMath::Sqrt(val) : 0;
if (TMath::Abs(relDiff) > thrBad) {
mVecIndexBad.push_back(i - 1);
} else if (TMath::Abs(relDiff) > thrMedium) {
mVecIndexMedium.push_back(i - 1);
}
}
return 0;
}
int RawDataReaderCheck::checkChangeOfRatio(TH1D* mHist, TH1D* mHistPrev, TH1D* mHistAbs)
{
/// this function check how much the rates differ from previous cycle
float thrBad = mThresholdRateRatioBad;
float thrMedium = mThresholdRateRatioMedium;
int binMB;
for (int i = 1; i < mHist->GetXaxis()->GetNbins() + 1; i++) {
if (mHist->GetBinContent(i) == mHistPrev->GetBinContent(i) && mHist->GetBinContent(i) == 1) {
binMB = i;
break;
}
}
for (size_t i = 1; i < mHist->GetXaxis()->GetNbins() + 1; i++) { // Check how many inputs/classes changed more than a threshold value
double val = mHist->GetBinContent(i);
double valPrev = mHistPrev->GetBinContent(i);
double relDiff = (valPrev != 0) ? (val - valPrev) / valPrev : 0;
double relDiff = (val != 0 || mHistAbs->GetBinContent(i) != 0) ? (val - valPrev) / (val * TMath::Sqrt(1 / mHistAbs->GetBinContent(binMB) + 1 / mHistAbs->GetBinContent(i))) : 0;
if (TMath::Abs(relDiff) > thrBad) {
mVecIndexBad.push_back(i - 1);
} else if (TMath::Abs(relDiff) > thrMedium) {
Expand Down Expand Up @@ -242,20 +266,21 @@ void RawDataReaderCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality che
}
h->GetXaxis()->SetLabelSize(0.045);
h->GetXaxis()->LabelsOption("v");
h->GetXaxis()->CenterLabels(true);
}
if (checkResult == Quality::Bad) {
msg->SetTextColor(kRed);
msg->SetNDC();
h->GetListOfFunctions()->Add(msg->Clone());
msg = std::make_shared<TLatex>(0.45, 0.75, Form("Number of %s with big %s rate change: %lu", groupName.c_str(), relativeness.c_str(), mVecIndexBad.size()));
msg = std::make_shared<TLatex>(0.45, 0.70, Form("Number of %s with big %s rate change: %lu", groupName.c_str(), relativeness.c_str(), mVecIndexBad.size()));
msg->SetTextSize(0.03);
msg->SetNDC();
h->GetListOfFunctions()->Add(msg->Clone());
for (size_t i = 0; i < mVecIndexBad.size(); i++) {
if (mFlagInput) {
msg = std::make_shared<TLatex>(0.45, 0.7 - i * 0.05, Form("Check %s %s", ctpinputs[mVecIndexBad[i]], groupName.c_str()));
msg = std::make_shared<TLatex>(0.45, 0.65 - i * 0.05, Form("Check %s %s", ctpinputs[mVecIndexBad[i]], groupName.c_str()));
} else {
msg = std::make_shared<TLatex>(0.45, 0.7 - i * 0.05, Form("Check %s with Index: %d", groupName.c_str(), mVecIndexBad[i]));
msg = std::make_shared<TLatex>(0.45, 0.65 - i * 0.05, Form("Check %s %s", groupName.c_str(), h->GetXaxis()->GetBinLabel(mVecIndexBad[i] + 1)));
}
msg->SetTextSize(0.03);
msg->SetNDC();
Expand Down
Loading

0 comments on commit f6820b5

Please sign in to comment.