Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Modules/Common/etc/reference-comparator-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"outputPath": "Tracks/WithCuts",
"normalizeReference": "true",
"drawRatioOnly": "false",
"legendHeight": "0.2",
"drawOption1D": "E",
"drawOption2D": "COL",
"inputObjects": [
Expand Down Expand Up @@ -78,6 +79,7 @@
"default": {
"moduleName" : "QualityControl",
"comparatorName" : "o2::quality_control_modules::common::ObjectComparatorChi2",
"ratioPlotRange" : "0.5",
"threshold" : "0.5"
}
}
Expand Down
9 changes: 8 additions & 1 deletion Modules/Common/include/Common/ReferenceComparatorPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ class ReferenceComparatorPlot
/// \param drawRatioOnly if true only the ratio between current and reference plot is draw, otherwise also the individual plots are drawn in addition
/// \param drawOption1D ROOT draw option to be used for 1-D plots
/// \param drawOption2D ROOT draw option to be used for 2-D plots
ReferenceComparatorPlot(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption1D, const std::string& drawOption2D);
ReferenceComparatorPlot(TH1* referenceHistogram,
int referenceRun,
const std::string& outputPath,
bool scaleReference,
bool drawRatioOnly,
double legendHeight,
const std::string& drawOption1D,
const std::string& drawOption2D);
virtual ~ReferenceComparatorPlot() = default;

TObject* getMainCanvas();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct ReferenceComparatorTaskConfig : quality_control::postprocessing::PostProc
bool normalizeReference{ false };
// wether to only draw the current/reference ratio, or the inidividual histograms as well
bool drawRatioOnly{ false };
// space reserved for the legend above the histograms, in fractions of the pad height
double legendHeight{ 0.2 };
// ROOT option to be used for drawing 1-D plots ("HIST" by default)
std::string drawOption1D{ "HIST" };
// ROOT option to be used for drawing 2-D plots ("COLZ" by default)
Expand Down
60 changes: 48 additions & 12 deletions Modules/Common/src/ReferenceComparatorPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <TH2.h>
#include <TCanvas.h>
#include <TPaveText.h>
#include <TLegend.h>

namespace o2::quality_control_modules::common
{
Expand Down Expand Up @@ -192,8 +193,14 @@ template <class HIST>
class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
{
public:
ReferenceComparatorPlotImpl1D(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption)
: ReferenceComparatorPlotImpl(scaleReference)
ReferenceComparatorPlotImpl1D(TH1* referenceHistogram,
int referenceRun,
const std::string& outputPath,
bool scaleReference,
bool drawRatioOnly,
double legendHeight,
const std::string& drawOption)
: ReferenceComparatorPlotImpl(scaleReference), mLegendHeight(legendHeight)
{
float labelSize = 0.04;

Expand Down Expand Up @@ -268,11 +275,21 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
mReferencePlot->SetOption((drawOption + "SAME").c_str());
mReferencePlot->Draw((drawOption + "SAME").c_str());

if (!drawRatioOnly && mLegendHeight > 0) {
mHistogramLegend = std::make_shared<TLegend>(0.2, 0.91, 0.8, 0.98);
mHistogramLegend->SetNColumns(2);
mHistogramLegend->SetBorderSize(0);
mHistogramLegend->SetFillStyle(0);
mHistogramLegend->AddEntry(mPlot.get(), "current run", "l");
mHistogramLegend->AddEntry(mReferencePlot.get(), TString::Format("reference run %d", referenceRun), "l");
mHistogramLegend->Draw();
}

// histogram with current/reference ratio
mPadHistRatio->cd();
mRatioPlot = createHisto1D<HIST>((canvasName + "_hist_ratio").c_str(), "", referenceHistogram);
if (drawRatioOnly) {
mRatioPlot->SetTitle(referenceHistogram->GetTitle());
mRatioPlot->SetTitle(TString::Format("%s (ref. %d)", referenceHistogram->GetTitle(), referenceRun));
mRatioPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
mRatioPlot->GetYaxis()->SetTitle("current / reference");
} else {
Expand Down Expand Up @@ -316,7 +333,7 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
mHistogramTitle->SetFillStyle(0);
mHistogramTitle->SetTextAlign(22);
mHistogramTitle->SetTextFont(42);
mHistogramTitle->AddText(referenceHistogram->GetTitle());
mHistogramTitle->AddText(TString::Format("%s (ref. %d)", referenceHistogram->GetTitle(), referenceRun));
mHistogramTitle->Draw();
}
}
Expand All @@ -334,6 +351,11 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl

copyAndScaleHistograms(hist, referenceHistogram, mPlot.get(), mReferencePlot.get(), getScaleReference());

double max = std::max(mPlot->GetMaximum(), mReferencePlot->GetMaximum());
double histMax = (mLegendHeight > 0) ? (1.0 + mLegendHeight) * max : 1.05 * max;
mPlot->SetMaximum(histMax);
mReferencePlot->SetMaximum(histMax);

mRatioPlot->Reset();
mRatioPlot->Add(mPlot.get());
mRatioPlot->Divide(mReferencePlot.get());
Expand All @@ -353,13 +375,20 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
std::shared_ptr<TLine> mBorderRight;
std::shared_ptr<TPaveText> mQualityLabel;
std::shared_ptr<TPaveText> mHistogramTitle;
std::shared_ptr<TLegend> mHistogramLegend;
double mLegendHeight;
};

template <class HIST>
class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
{
public:
ReferenceComparatorPlotImpl2D(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption)
ReferenceComparatorPlotImpl2D(TH1* referenceHistogram,
int referenceRun,
const std::string& outputPath,
bool scaleReference,
bool drawRatioOnly,
const std::string& drawOption)
: ReferenceComparatorPlotImpl(scaleReference)
{
if (!referenceHistogram) {
Expand Down Expand Up @@ -427,7 +456,7 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
// histogram from the reference run
mPadHistRef->cd();
mReferencePlot = createHisto2D<HIST>((canvasName + "_hist_ref").c_str(),
TString::Format("%s (reference)", referenceHistogram->GetTitle()),
TString::Format("%s (ref. %d)", referenceHistogram->GetTitle(), referenceRun),
referenceHistogram);
mReferencePlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
mReferencePlot->GetYaxis()->SetTitle(referenceHistogram->GetYaxis()->GetTitle());
Expand All @@ -438,7 +467,7 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
// histogram with current/reference ratio
mPadHistRatio->cd();
mRatioPlot = createHisto2D<HIST>((canvasName + "_hist_ratio").c_str(),
TString::Format("%s (ratio)", referenceHistogram->GetTitle()),
TString::Format("%s (ratio wrt %d)", referenceHistogram->GetTitle(), referenceRun),
referenceHistogram);
mRatioPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
mRatioPlot->GetYaxis()->SetTitle(referenceHistogram->GetYaxis()->GetTitle());
Expand Down Expand Up @@ -495,26 +524,33 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
std::shared_ptr<TPaveText> mQualityLabel;
};

ReferenceComparatorPlot::ReferenceComparatorPlot(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption1D, const std::string& drawOption2D)
ReferenceComparatorPlot::ReferenceComparatorPlot(TH1* referenceHistogram,
int referenceRun,
const std::string& outputPath,
bool scaleReference,
bool drawRatioOnly,
double legendHeight,
const std::string& drawOption1D,
const std::string& drawOption2D)
{
// histograms with integer values are promoted to floating point or double to allow correctly scaling the reference and computing the ratios

// 1-D histograms
if (referenceHistogram->InheritsFrom("TH1C") || referenceHistogram->InheritsFrom("TH1S") || referenceHistogram->InheritsFrom("TH1F")) {
mImplementation = std::make_shared<ReferenceComparatorPlotImpl1D<TH1F>>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption1D);
mImplementation = std::make_shared<ReferenceComparatorPlotImpl1D<TH1F>>(referenceHistogram, referenceRun, outputPath, scaleReference, drawRatioOnly, legendHeight, drawOption1D);
}

if (referenceHistogram->InheritsFrom("TH1I") || referenceHistogram->InheritsFrom("TH1D")) {
mImplementation = std::make_shared<ReferenceComparatorPlotImpl1D<TH1D>>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption1D);
mImplementation = std::make_shared<ReferenceComparatorPlotImpl1D<TH1D>>(referenceHistogram, referenceRun, outputPath, scaleReference, drawRatioOnly, legendHeight, drawOption1D);
}

// 2-D histograms
if (referenceHistogram->InheritsFrom("TH2C") || referenceHistogram->InheritsFrom("TH2S") || referenceHistogram->InheritsFrom("TH2F")) {
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2F>>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption2D);
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2F>>(referenceHistogram, referenceRun, outputPath, scaleReference, drawRatioOnly, drawOption2D);
}

if (referenceHistogram->InheritsFrom("TH2I") || referenceHistogram->InheritsFrom("TH2D")) {
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2D>>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption2D);
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2D>>(referenceHistogram, referenceRun, outputPath, scaleReference, drawRatioOnly, drawOption2D);
}
}

Expand Down
12 changes: 7 additions & 5 deletions Modules/Common/src/ReferenceComparatorTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "Common/ReferenceComparatorTask.h"
#include "Common/ReferenceComparatorPlot.h"
#include "Common/Utils.h"
#include "QualityControl/ReferenceUtils.h"
#include "QualityControl/QcInfoLogger.h"
#include "QualityControl/MonitorObject.h"
Expand Down Expand Up @@ -104,10 +105,10 @@ void ReferenceComparatorTask::initialize(quality_control::postprocessing::Trigge
mHistograms.clear();

auto& qcdb = services.get<repository::DatabaseInterface>();
mNotOlderThan = std::stoi(getCustomParameter(mCustomParameters, "notOlderThan", trigger.activity, "120"));
mReferenceRun = std::stoi(getCustomParameter(mCustomParameters, "referenceRun", trigger.activity, "0"));
mIgnorePeriodForReference = std::stoi(getCustomParameter(mCustomParameters, "ignorePeriodForReference", trigger.activity, "1")) != 0;
mIgnorePassForReference = std::stoi(getCustomParameter(mCustomParameters, "ignorePassForReference", trigger.activity, "1")) != 0;
mNotOlderThan = getFromExtendedConfig<int>(trigger.activity, mCustomParameters, "notOlderThan", 120);
mReferenceRun = getFromExtendedConfig<int>(trigger.activity, mCustomParameters, "referenceRun", 0);
mIgnorePeriodForReference = getFromExtendedConfig<bool>(trigger.activity, mCustomParameters, "ignorePeriodForReference", true);
mIgnorePassForReference = getFromExtendedConfig<bool>(trigger.activity, mCustomParameters, "ignorePassForReference", true);

ILOG(Info, Devel) << "Reference run set to '" << mReferenceRun << "' for activity " << trigger.activity << ENDM;

Expand Down Expand Up @@ -149,9 +150,10 @@ void ReferenceComparatorTask::initialize(quality_control::postprocessing::Trigge
plotVec.push_back(fullPath);

// create and store the plotter object
mHistograms[fullPath] = std::make_shared<ReferenceComparatorPlot>(referenceHistogram, fullOutPath,
mHistograms[fullPath] = std::make_shared<ReferenceComparatorPlot>(referenceHistogram, mReferenceRun, fullOutPath,
group.normalizeReference,
group.drawRatioOnly,
group.legendHeight,
group.drawOption1D,
group.drawOption2D);
auto* outObject = mHistograms[fullPath]->getMainCanvas();
Expand Down
1 change: 1 addition & 0 deletions Modules/Common/src/ReferenceComparatorTaskConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ReferenceComparatorTaskConfig::ReferenceComparatorTaskConfig(std::string name, c
dataGroupConfig.second.get<std::string>("outputPath"),
dataGroupConfig.second.get<bool>("normalizeReference", false),
dataGroupConfig.second.get<bool>("drawRatioOnly", false),
dataGroupConfig.second.get<double>("legendHeight", 0.2),
dataGroupConfig.second.get<std::string>("drawOption1D", "HIST"),
dataGroupConfig.second.get<std::string>("drawOption2D", "COLZ")
};
Expand Down
9 changes: 7 additions & 2 deletions doc/FLPsuite.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ The configuration looks like
"referenceRun" : "500",
"moduleName" : "QualityControl",
"comparatorName" : "o2::quality_control_modules::common::ObjectComparatorChi2",
"threshold" : "0.5"
"threshold" : "0.2",
"ratioPlotRange" : "0.5",
"ignorePeriodForReference" : "true",
"ignorePassForReference" : "true"
}
},
"PHYSICS": {
Expand All @@ -168,7 +171,9 @@ The configuration looks like
The check needs the following parameters
* `referenceRun` to specify what is the run of reference and retrieve the reference data.
* `comparatorName` to decide how to compare, see below for their descriptions.
* `threshold` to specifie the value used to discriminate between good and bad matches between the histograms.
* `threshold` to specify the value used to discriminate between good and bad matches between the histograms.
* `ratioPlotRange` to specify a custom vertical scale for the ratio plot. The vertical values are between 1.0 - range and 1.0 + range.
* `ignorePeriodForReference`, `ignorePassForReference`: boolean flags specifying wether to ignore the period or pass names of the reference run; needed for comparing runs from different periods and/or reconstruction passes.

Three comparators are provided:

Expand Down
11 changes: 7 additions & 4 deletions doc/PostProcessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,15 @@ This post-processing task draws a given set of plots in comparison with their co
Currently the source of reference data is specified as a run-type and beam-type specific `referenceRun` number. This will be modified once a centralized way of accessing reference plots will become available in the framework.
The `notOlderThan` option allows to ignore monitor objects that are older than a given number of seconds. A value of -1 means "no limit".
The `ignorePeriodForReference` and `ignorePassForReference` boolean parameters control whether the period and/or pass names should be matched or not when querying the reference plots from the database.
A value of `"1"` (default) means that the reference plots are not required to match the period and/or pass names of the current run, while a value of `"0"` means that the reference plot is retrieved only if the corresponding period and/or pass names match those of the current run.
A value of `"true"` (default) means that the reference plots are not required to match the period and/or pass names of the current run, while a value of `"false"` means that the reference plot is retrieved only if the corresponding period and/or pass names match those of the current run.

The input MonitorObjects to be processed are logically divided in **dataGroups**. Each group is configured via the following parameters:

* `inputPath`: path in the QCDB where the input objects are located
* `referencePath` (optional): specifies the path for the reference objects, if not set the `inputPath` is used
* `outputPath`: path in the QCDB where the output objects are stored
* `drawRatioOnly`: boolean parameter specifying wether to only draw the ratio plots, or the current/reference comparisons as well
* `legendHeight`: space reserved for the legend above the histograms, in fractions of the pad height; if the height is set to zero, the legend is not shown
* `drawOption1D`: the ROOT draw option to be used for the 1-D histograms
* `drawOption2D`: the ROOT draw option to be used for the 2-D histograms

Expand Down Expand Up @@ -609,8 +610,8 @@ In the example configuration below, the relationship between the input and outpu
"default": {
"notOlderThan" : "300",
"referenceRun" : "551875",
"ignorePeriodForReference": "1",
"ignorePassForReference": "1"
"ignorePeriodForReference": "true",
"ignorePassForReference": "true"
}
},
"PHYSICS": {
Expand All @@ -627,6 +628,7 @@ In the example configuration below, the relationship between the input and outpu
"outputPath": "Tracks/WithCuts",
"normalizeReference": "true",
"drawRatioOnly": "false",
"legendHeight": "0.2",
"drawOption1D": "E",
"drawOption2D": "COL",
"inputObjects": [
Expand Down Expand Up @@ -660,7 +662,8 @@ In the example configuration below, the relationship between the input and outpu
"comparatorName" : "o2::quality_control_modules::common::ObjectComparatorChi2",
"threshold" : "0.5",
"threshold:TrackEta" : "0.2",
"rangeX:TrackEta" : "-3.5,-2.5"
"rangeX:TrackEta" : "-3.5,-2.5",
"ratioPlotRange" : "0.5"
}
}
},
Expand Down