Skip to content

Commit 2af8981

Browse files
authored
[Common] added reference run number to ReferenceComparator plots (#2569)
The number of the reference run is reported both in the title of the ratio plot, and in a legend at the top of the superimposed histograms.
1 parent 904a8bf commit 2af8981

8 files changed

Lines changed: 82 additions & 24 deletions

Modules/Common/etc/reference-comparator-example.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"outputPath": "Tracks/WithCuts",
4848
"normalizeReference": "true",
4949
"drawRatioOnly": "false",
50+
"legendHeight": "0.2",
5051
"drawOption1D": "E",
5152
"drawOption2D": "COL",
5253
"inputObjects": [
@@ -78,6 +79,7 @@
7879
"default": {
7980
"moduleName" : "QualityControl",
8081
"comparatorName" : "o2::quality_control_modules::common::ObjectComparatorChi2",
82+
"ratioPlotRange" : "0.5",
8183
"threshold" : "0.5"
8284
}
8385
}

Modules/Common/include/Common/ReferenceComparatorPlot.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ class ReferenceComparatorPlot
3737
/// \param drawRatioOnly if true only the ratio between current and reference plot is draw, otherwise also the individual plots are drawn in addition
3838
/// \param drawOption1D ROOT draw option to be used for 1-D plots
3939
/// \param drawOption2D ROOT draw option to be used for 2-D plots
40-
ReferenceComparatorPlot(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption1D, const std::string& drawOption2D);
40+
ReferenceComparatorPlot(TH1* referenceHistogram,
41+
int referenceRun,
42+
const std::string& outputPath,
43+
bool scaleReference,
44+
bool drawRatioOnly,
45+
double legendHeight,
46+
const std::string& drawOption1D,
47+
const std::string& drawOption2D);
4148
virtual ~ReferenceComparatorPlot() = default;
4249

4350
TObject* getMainCanvas();

Modules/Common/include/Common/ReferenceComparatorTaskConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct ReferenceComparatorTaskConfig : quality_control::postprocessing::PostProc
4444
bool normalizeReference{ false };
4545
// wether to only draw the current/reference ratio, or the inidividual histograms as well
4646
bool drawRatioOnly{ false };
47+
// space reserved for the legend above the histograms, in fractions of the pad height
48+
double legendHeight{ 0.2 };
4749
// ROOT option to be used for drawing 1-D plots ("HIST" by default)
4850
std::string drawOption1D{ "HIST" };
4951
// ROOT option to be used for drawing 2-D plots ("COLZ" by default)

Modules/Common/src/ReferenceComparatorPlot.cxx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <TH2.h>
2727
#include <TCanvas.h>
2828
#include <TPaveText.h>
29+
#include <TLegend.h>
2930

3031
namespace o2::quality_control_modules::common
3132
{
@@ -192,8 +193,14 @@ template <class HIST>
192193
class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
193194
{
194195
public:
195-
ReferenceComparatorPlotImpl1D(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption)
196-
: ReferenceComparatorPlotImpl(scaleReference)
196+
ReferenceComparatorPlotImpl1D(TH1* referenceHistogram,
197+
int referenceRun,
198+
const std::string& outputPath,
199+
bool scaleReference,
200+
bool drawRatioOnly,
201+
double legendHeight,
202+
const std::string& drawOption)
203+
: ReferenceComparatorPlotImpl(scaleReference), mLegendHeight(legendHeight)
197204
{
198205
float labelSize = 0.04;
199206

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

278+
if (!drawRatioOnly && mLegendHeight > 0) {
279+
mHistogramLegend = std::make_shared<TLegend>(0.2, 0.91, 0.8, 0.98);
280+
mHistogramLegend->SetNColumns(2);
281+
mHistogramLegend->SetBorderSize(0);
282+
mHistogramLegend->SetFillStyle(0);
283+
mHistogramLegend->AddEntry(mPlot.get(), "current run", "l");
284+
mHistogramLegend->AddEntry(mReferencePlot.get(), TString::Format("reference run %d", referenceRun), "l");
285+
mHistogramLegend->Draw();
286+
}
287+
271288
// histogram with current/reference ratio
272289
mPadHistRatio->cd();
273290
mRatioPlot = createHisto1D<HIST>((canvasName + "_hist_ratio").c_str(), "", referenceHistogram);
274291
if (drawRatioOnly) {
275-
mRatioPlot->SetTitle(referenceHistogram->GetTitle());
292+
mRatioPlot->SetTitle(TString::Format("%s (ref. %d)", referenceHistogram->GetTitle(), referenceRun));
276293
mRatioPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
277294
mRatioPlot->GetYaxis()->SetTitle("current / reference");
278295
} else {
@@ -316,7 +333,7 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
316333
mHistogramTitle->SetFillStyle(0);
317334
mHistogramTitle->SetTextAlign(22);
318335
mHistogramTitle->SetTextFont(42);
319-
mHistogramTitle->AddText(referenceHistogram->GetTitle());
336+
mHistogramTitle->AddText(TString::Format("%s (ref. %d)", referenceHistogram->GetTitle(), referenceRun));
320337
mHistogramTitle->Draw();
321338
}
322339
}
@@ -334,6 +351,11 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
334351

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

354+
double max = std::max(mPlot->GetMaximum(), mReferencePlot->GetMaximum());
355+
double histMax = (mLegendHeight > 0) ? (1.0 + mLegendHeight) * max : 1.05 * max;
356+
mPlot->SetMaximum(histMax);
357+
mReferencePlot->SetMaximum(histMax);
358+
337359
mRatioPlot->Reset();
338360
mRatioPlot->Add(mPlot.get());
339361
mRatioPlot->Divide(mReferencePlot.get());
@@ -353,13 +375,20 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
353375
std::shared_ptr<TLine> mBorderRight;
354376
std::shared_ptr<TPaveText> mQualityLabel;
355377
std::shared_ptr<TPaveText> mHistogramTitle;
378+
std::shared_ptr<TLegend> mHistogramLegend;
379+
double mLegendHeight;
356380
};
357381

358382
template <class HIST>
359383
class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
360384
{
361385
public:
362-
ReferenceComparatorPlotImpl2D(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption)
386+
ReferenceComparatorPlotImpl2D(TH1* referenceHistogram,
387+
int referenceRun,
388+
const std::string& outputPath,
389+
bool scaleReference,
390+
bool drawRatioOnly,
391+
const std::string& drawOption)
363392
: ReferenceComparatorPlotImpl(scaleReference)
364393
{
365394
if (!referenceHistogram) {
@@ -427,7 +456,7 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
427456
// histogram from the reference run
428457
mPadHistRef->cd();
429458
mReferencePlot = createHisto2D<HIST>((canvasName + "_hist_ref").c_str(),
430-
TString::Format("%s (reference)", referenceHistogram->GetTitle()),
459+
TString::Format("%s (ref. %d)", referenceHistogram->GetTitle(), referenceRun),
431460
referenceHistogram);
432461
mReferencePlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
433462
mReferencePlot->GetYaxis()->SetTitle(referenceHistogram->GetYaxis()->GetTitle());
@@ -438,7 +467,7 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
438467
// histogram with current/reference ratio
439468
mPadHistRatio->cd();
440469
mRatioPlot = createHisto2D<HIST>((canvasName + "_hist_ratio").c_str(),
441-
TString::Format("%s (ratio)", referenceHistogram->GetTitle()),
470+
TString::Format("%s (ratio wrt %d)", referenceHistogram->GetTitle(), referenceRun),
442471
referenceHistogram);
443472
mRatioPlot->GetXaxis()->SetTitle(referenceHistogram->GetXaxis()->GetTitle());
444473
mRatioPlot->GetYaxis()->SetTitle(referenceHistogram->GetYaxis()->GetTitle());
@@ -495,26 +524,33 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
495524
std::shared_ptr<TPaveText> mQualityLabel;
496525
};
497526

498-
ReferenceComparatorPlot::ReferenceComparatorPlot(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption1D, const std::string& drawOption2D)
527+
ReferenceComparatorPlot::ReferenceComparatorPlot(TH1* referenceHistogram,
528+
int referenceRun,
529+
const std::string& outputPath,
530+
bool scaleReference,
531+
bool drawRatioOnly,
532+
double legendHeight,
533+
const std::string& drawOption1D,
534+
const std::string& drawOption2D)
499535
{
500536
// histograms with integer values are promoted to floating point or double to allow correctly scaling the reference and computing the ratios
501537

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

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

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

516552
if (referenceHistogram->InheritsFrom("TH2I") || referenceHistogram->InheritsFrom("TH2D")) {
517-
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2D>>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption2D);
553+
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2D>>(referenceHistogram, referenceRun, outputPath, scaleReference, drawRatioOnly, drawOption2D);
518554
}
519555
}
520556

Modules/Common/src/ReferenceComparatorTask.cxx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "Common/ReferenceComparatorTask.h"
1919
#include "Common/ReferenceComparatorPlot.h"
20+
#include "Common/Utils.h"
2021
#include "QualityControl/ReferenceUtils.h"
2122
#include "QualityControl/QcInfoLogger.h"
2223
#include "QualityControl/MonitorObject.h"
@@ -104,10 +105,10 @@ void ReferenceComparatorTask::initialize(quality_control::postprocessing::Trigge
104105
mHistograms.clear();
105106

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

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

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

151152
// create and store the plotter object
152-
mHistograms[fullPath] = std::make_shared<ReferenceComparatorPlot>(referenceHistogram, fullOutPath,
153+
mHistograms[fullPath] = std::make_shared<ReferenceComparatorPlot>(referenceHistogram, mReferenceRun, fullOutPath,
153154
group.normalizeReference,
154155
group.drawRatioOnly,
156+
group.legendHeight,
155157
group.drawOption1D,
156158
group.drawOption2D);
157159
auto* outObject = mHistograms[fullPath]->getMainCanvas();

Modules/Common/src/ReferenceComparatorTaskConfig.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ReferenceComparatorTaskConfig::ReferenceComparatorTaskConfig(std::string name, c
3434
dataGroupConfig.second.get<std::string>("outputPath"),
3535
dataGroupConfig.second.get<bool>("normalizeReference", false),
3636
dataGroupConfig.second.get<bool>("drawRatioOnly", false),
37+
dataGroupConfig.second.get<double>("legendHeight", 0.2),
3738
dataGroupConfig.second.get<std::string>("drawOption1D", "HIST"),
3839
dataGroupConfig.second.get<std::string>("drawOption2D", "COLZ")
3940
};

doc/FLPsuite.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ The configuration looks like
153153
"referenceRun" : "500",
154154
"moduleName" : "QualityControl",
155155
"comparatorName" : "o2::quality_control_modules::common::ObjectComparatorChi2",
156-
"threshold" : "0.5"
156+
"threshold" : "0.2",
157+
"ratioPlotRange" : "0.5",
158+
"ignorePeriodForReference" : "true",
159+
"ignorePassForReference" : "true"
157160
}
158161
},
159162
"PHYSICS": {
@@ -168,7 +171,9 @@ The configuration looks like
168171
The check needs the following parameters
169172
* `referenceRun` to specify what is the run of reference and retrieve the reference data.
170173
* `comparatorName` to decide how to compare, see below for their descriptions.
171-
* `threshold` to specifie the value used to discriminate between good and bad matches between the histograms.
174+
* `threshold` to specify the value used to discriminate between good and bad matches between the histograms.
175+
* `ratioPlotRange` to specify a custom vertical scale for the ratio plot. The vertical values are between 1.0 - range and 1.0 + range.
176+
* `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.
172177

173178
Three comparators are provided:
174179

doc/PostProcessing.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,15 @@ This post-processing task draws a given set of plots in comparison with their co
530530
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.
531531
The `notOlderThan` option allows to ignore monitor objects that are older than a given number of seconds. A value of -1 means "no limit".
532532
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.
533-
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.
533+
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.
534534

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

537537
* `inputPath`: path in the QCDB where the input objects are located
538538
* `referencePath` (optional): specifies the path for the reference objects, if not set the `inputPath` is used
539539
* `outputPath`: path in the QCDB where the output objects are stored
540540
* `drawRatioOnly`: boolean parameter specifying wether to only draw the ratio plots, or the current/reference comparisons as well
541+
* `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
541542
* `drawOption1D`: the ROOT draw option to be used for the 1-D histograms
542543
* `drawOption2D`: the ROOT draw option to be used for the 2-D histograms
543544

@@ -609,8 +610,8 @@ In the example configuration below, the relationship between the input and outpu
609610
"default": {
610611
"notOlderThan" : "300",
611612
"referenceRun" : "551875",
612-
"ignorePeriodForReference": "1",
613-
"ignorePassForReference": "1"
613+
"ignorePeriodForReference": "true",
614+
"ignorePassForReference": "true"
614615
}
615616
},
616617
"PHYSICS": {
@@ -627,6 +628,7 @@ In the example configuration below, the relationship between the input and outpu
627628
"outputPath": "Tracks/WithCuts",
628629
"normalizeReference": "true",
629630
"drawRatioOnly": "false",
631+
"legendHeight": "0.2",
630632
"drawOption1D": "E",
631633
"drawOption2D": "COL",
632634
"inputObjects": [
@@ -660,7 +662,8 @@ In the example configuration below, the relationship between the input and outpu
660662
"comparatorName" : "o2::quality_control_modules::common::ObjectComparatorChi2",
661663
"threshold" : "0.5",
662664
"threshold:TrackEta" : "0.2",
663-
"rangeX:TrackEta" : "-3.5,-2.5"
665+
"rangeX:TrackEta" : "-3.5,-2.5",
666+
"ratioPlotRange" : "0.5"
664667
}
665668
}
666669
},

0 commit comments

Comments
 (0)