Skip to content

Commit

Permalink
[Common] set ratio plot Y range from preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
aferrero2707 committed Sep 23, 2024
1 parent 50e7152 commit a56f2b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Modules/Common/include/Common/ReferenceComparatorCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ReferenceComparatorCheck : public o2::quality_control::checker::CheckInter

private:
Quality getSinglePlotQuality(std::shared_ptr<MonitorObject> mo, ObjectComparatorInterface* comparator, std::string& message);
void drawHorizontalRange(const std::string& moName, TCanvas* canvas, const Quality& quality);
void beautifyRatioPlot(const std::string& moName, TH1* ratioPlot, const Quality& quality);

std::map<std::string, Quality> mQualityFlags;
std::map<std::string, std::shared_ptr<TPaveText>> mQualityLabels;
Expand All @@ -63,6 +63,7 @@ class ReferenceComparatorCheck : public o2::quality_control::checker::CheckInter
bool mIgnorePeriodForReference{ true }; /// whether to specify the period name in the reference run query
bool mIgnorePassForReference{ true }; /// whether to specify the pass name in the reference run query
size_t mReferenceRun;
double mRatioPlotRange{ 0 };
/// cached reference MOs
std::unordered_map<std::string, std::shared_ptr<MonitorObject>> mReferencePlots;
/// collection of object comparators with plot-specific settings
Expand Down
33 changes: 19 additions & 14 deletions Modules/Common/src/ReferenceComparatorCheck.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Common/ReferenceComparatorCheck.h"
#include "QualityControl/ReferenceUtils.h"
#include "Common/TH1Ratio.h"
#include "Common/Utils.h"
#include "QualityControl/MonitorObject.h"
#include "QualityControl/Quality.h"
#include "QualityControl/QcInfoLogger.h"
Expand Down Expand Up @@ -47,11 +48,12 @@ void ReferenceComparatorCheck::configure()

void ReferenceComparatorCheck::startOfActivity(const Activity& activity)
{
mComparatorModuleName = mCustomParameters.atOptional("moduleName", activity).value_or("");
mComparatorClassName = mCustomParameters.atOptional("comparatorName", activity).value_or("");
mReferenceRun = std::stoi(mCustomParameters.atOptional("referenceRun", activity).value_or("0"));
mIgnorePeriodForReference = std::stoi(mCustomParameters.atOptional("ignorePeriodForReference", activity).value_or("1")) != 0;
mIgnorePassForReference = std::stoi(mCustomParameters.atOptional("ignorePassForReference", activity).value_or("1")) != 0;
mComparatorModuleName = getFromExtendedConfig<std::string>(activity, mCustomParameters, "moduleName", "");
mComparatorClassName = getFromExtendedConfig<std::string>(activity, mCustomParameters, "comparatorName", "");
mReferenceRun = getFromExtendedConfig<int>(activity, mCustomParameters, "referenceRun", 0);
mIgnorePeriodForReference = getFromExtendedConfig<bool>(activity, mCustomParameters, "ignorePeriodForReference", true);
mIgnorePassForReference = getFromExtendedConfig<bool>(activity, mCustomParameters, "ignorePassForReference", true);
mRatioPlotRange = getFromExtendedConfig<double>(activity, mCustomParameters, "ratioPlotRange", mRatioPlotRange);

mActivity = activity;

Expand Down Expand Up @@ -328,19 +330,19 @@ static void setQualityLabel(TCanvas* canvas, const Quality& quality)
}
}

void ReferenceComparatorCheck::drawHorizontalRange(const std::string& moName, TCanvas* canvas, const Quality& quality)
void ReferenceComparatorCheck::beautifyRatioPlot(const std::string& moName, TH1* ratioPlot, const Quality& quality)
{
if (!canvas) {
return;
}

// get the plot with the current/reference ratio from the canvas
auto ratioPlot = getRatioPlotFromCanvas(canvas);
// currently the range indicator is only implemented for 1-D histograms
if (!ratioPlot || ratioPlot->InheritsFrom("TH2")) {
return;
}

// set vertical range according to preferences
if (mRatioPlotRange > 0) {
ratioPlot->SetMinimum(1.0 - mRatioPlotRange);
ratioPlot->SetMaximum(1.0 + mRatioPlotRange);
}

// get the comparator associated to this plot
ObjectComparatorInterface* comparator{ nullptr };
auto moKey = getBaseName(moName);
Expand All @@ -360,7 +362,10 @@ void ReferenceComparatorCheck::drawHorizontalRange(const std::string& moName, TC
// draw an horizontal double arrow marking the X-axis range
double xMin = ratioPlot->GetXaxis()->GetBinLowEdge(ratioPlot->GetXaxis()->FindBin(rangeX->first));
double xMax = ratioPlot->GetXaxis()->GetBinUpEdge(ratioPlot->GetXaxis()->FindBin(rangeX->second - 1.0e-6));
auto arrow = new TArrow(xMin, 1.8, xMax, 1.8, 0.015, "<|>");
double yMin = ratioPlot->GetMinimum();
double yMax = ratioPlot->GetMaximum();
double yArrow = yMin + 0.1 * (yMax - yMin);
auto arrow = new TArrow(xMin,yArrow,xMax,yArrow,0.015,"<|>");
arrow->SetLineColor(getQualityColor(quality));
arrow->SetFillColor(getQualityColor(quality));
ratioPlot->GetListOfFunctions()->Add(arrow);
Expand All @@ -384,7 +389,7 @@ void ReferenceComparatorCheck::beautify(std::shared_ptr<MonitorObject> mo, Quali
setQualityLabel(canvas, quality);

// draw a double-arrow indicating the horizontal range for the check, if it is set
drawHorizontalRange(moName, canvas, quality);
beautifyRatioPlot(moName, getRatioPlotFromCanvas(canvas), quality);
} else {
// draw the quality label directly on the plot if the MO is an histogram
auto* th1 = dynamic_cast<TH1*>(mo->getObject());
Expand Down

0 comments on commit a56f2b6

Please sign in to comment.