Skip to content

Commit 7f706ca

Browse files
committed
[Common] added reference run number to ReferenceComparator plots
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 043f167 commit 7f706ca

File tree

7 files changed

+77
-23
lines changed

7 files changed

+77
-23
lines changed

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) {
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,10 @@ 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+
mPlot->SetMaximum(max * (1.0 + mLegendHeight));
356+
mReferencePlot->SetMaximum(max * (1.0 + mLegendHeight));
357+
337358
mRatioPlot->Reset();
338359
mRatioPlot->Add(mPlot.get());
339360
mRatioPlot->Divide(mReferencePlot.get());
@@ -353,13 +374,21 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
353374
std::shared_ptr<TLine> mBorderRight;
354375
std::shared_ptr<TPaveText> mQualityLabel;
355376
std::shared_ptr<TPaveText> mHistogramTitle;
377+
std::shared_ptr<TLegend> mHistogramLegend;
378+
double mLegendHeight;
356379
};
357380

358381
template <class HIST>
359382
class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
360383
{
361384
public:
362-
ReferenceComparatorPlotImpl2D(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption)
385+
ReferenceComparatorPlotImpl2D(TH1* referenceHistogram,
386+
int referenceRun,
387+
const std::string& outputPath,
388+
bool scaleReference,
389+
bool drawRatioOnly,
390+
double /*legendHeight*/, // currently not used for 2D plots
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, legendHeight, 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, legendHeight, 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/Advanced.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,10 @@ The configuration looks like
14301430
"referenceRun" : "500",
14311431
"moduleName" : "QualityControl",
14321432
"comparatorName" : "o2::quality_control_modules::common::ObjectComparatorChi2",
1433-
"threshold" : "0.5"
1433+
"threshold" : "0.2",
1434+
"ratioPlotRange" : "0.5",
1435+
"ignorePeriodForReference" : "true",
1436+
"ignorePassForReference" : "true"
14341437
}
14351438
},
14361439
"PHYSICS": {
@@ -1444,7 +1447,9 @@ The configuration looks like
14441447
The check needs the following parameters
14451448
- `referenceRun` to specify what is the run of reference and retrieve the reference data.
14461449
- `comparatorName` to decide how to compare, see below for their descriptions.
1447-
- `threshold` to specifie the value used to discriminate between good and bad matches between the histograms.
1450+
- `threshold` to specify the value used to discriminate between good and bad matches between the histograms.
1451+
- `ratioPlotRange` to specify a custom vertical scale for the ratio plot. The vertical values are between 1.0 - range and 1.0 + range.
1452+
- `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.
14481453

14491454
Three comparators are provided:
14501455
1. `o2::quality_control_modules::common::ObjectComparatorDeviation`: comparison based on the average relative deviation between the bins of the current and reference histograms; the `threshold` parameter represent in this case the maximum allowed deviation

doc/PostProcessing.md

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

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

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

@@ -595,8 +596,8 @@ In the example configuration below, the relationship between the input and outpu
595596
"default": {
596597
"notOlderThan" : "300",
597598
"referenceRun" : "551875",
598-
"ignorePeriodForReference": "1",
599-
"ignorePassForReference": "1"
599+
"ignorePeriodForReference": "true",
600+
"ignorePassForReference": "true"
600601
}
601602
},
602603
"PHYSICS": {

0 commit comments

Comments
 (0)