Skip to content

Commit 13d7f36

Browse files
authored
[Common] enable log scale in refernce comparator plots (#2657)
A new boolean configuration parameter for the ReferenceComparatorTask allows to display the histogram values (Y axis for 1-D histograms and Z axis for 2-D histograms) in log scale. This does not affect the ratio plot, which is always displayed in linear scale.
1 parent a4635f3 commit 13d7f36

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

Modules/Common/include/Common/ReferenceComparatorPlot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ReferenceComparatorPlot
4343
bool scaleReference,
4444
bool drawRatioOnly,
4545
double legendHeight,
46+
bool logScale,
4647
const std::string& drawOption1D,
4748
const std::string& drawOption2D);
4849
virtual ~ReferenceComparatorPlot() = default;

Modules/Common/include/Common/ReferenceComparatorTaskConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ struct ReferenceComparatorTaskConfig : quality_control::postprocessing::PostProc
5050
std::string drawOption1D{ "HIST" };
5151
// ROOT option to be used for drawing 2-D plots ("COLZ" by default)
5252
std::string drawOption2D{ "COLZ" };
53+
// wether to draw the values axis in log scale (Y axis for 1-D plots and Z axis for 2-D plots)
54+
bool logScale{ false };
5355
// list of QCDB objects in this group
5456
std::vector<std::string> objects;
5557
};

Modules/Common/src/ReferenceComparatorPlot.cxx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
200200
bool scaleReference,
201201
bool drawRatioOnly,
202202
double legendHeight,
203+
bool logScale,
203204
const std::string& drawOption)
204-
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference), mLegendHeight(legendHeight)
205+
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference), mLegendHeight(legendHeight), mLogScale(logScale)
205206
{
206207
float labelSize = 0.04;
207208

@@ -357,6 +358,9 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
357358
double histMax = (mLegendHeight > 0) ? (1.0 + mLegendHeight) * max : 1.05 * max;
358359
mPlot->SetMaximum(histMax);
359360
mReferencePlot->SetMaximum(histMax);
361+
if (mPadHist) {
362+
mPadHist->SetLogy(mLogScale ? kTRUE : kFALSE);
363+
}
360364

361365
mRatioPlot->Reset();
362366
mRatioPlot->Add(mPlot.get());
@@ -379,6 +383,7 @@ class ReferenceComparatorPlotImpl1D : public ReferenceComparatorPlotImpl
379383
std::shared_ptr<TPaveText> mHistogramTitle;
380384
std::shared_ptr<TLegend> mHistogramLegend;
381385
double mLegendHeight;
386+
bool mLogScale;
382387
};
383388

384389
template <class HIST>
@@ -390,8 +395,9 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
390395
const std::string& outputPath,
391396
bool scaleReference,
392397
bool drawRatioOnly,
398+
bool logScale,
393399
const std::string& drawOption)
394-
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference)
400+
: ReferenceComparatorPlotImpl(referenceHistogram, scaleReference), mLogScale(logScale)
395401
{
396402
if (!referenceHistogram) {
397403
return;
@@ -509,6 +515,13 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
509515

510516
copyAndScaleHistograms(histogram, referenceHistogram, mPlot.get(), mReferencePlot.get(), getScaleReference());
511517

518+
if (mPadHist) {
519+
mPadHist->SetLogz(mLogScale ? kTRUE : kFALSE);
520+
}
521+
if (mPadHistRef) {
522+
mPadHistRef->SetLogz(mLogScale ? kTRUE : kFALSE);
523+
}
524+
512525
mRatioPlot->Reset();
513526
mRatioPlot->Add(mPlot.get());
514527
mRatioPlot->Divide(mReferencePlot.get());
@@ -525,6 +538,7 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl
525538
std::shared_ptr<HIST> mReferencePlot;
526539
std::shared_ptr<HIST> mRatioPlot;
527540
std::shared_ptr<TPaveText> mQualityLabel;
541+
bool mLogScale;
528542
};
529543

530544
ReferenceComparatorPlot::ReferenceComparatorPlot(TH1* referenceHistogram,
@@ -533,27 +547,28 @@ ReferenceComparatorPlot::ReferenceComparatorPlot(TH1* referenceHistogram,
533547
bool scaleReference,
534548
bool drawRatioOnly,
535549
double legendHeight,
550+
bool logScale,
536551
const std::string& drawOption1D,
537552
const std::string& drawOption2D)
538553
{
539554
// histograms with integer values are promoted to floating point or double to allow correctly scaling the reference and computing the ratios
540555

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

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

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

555570
if (referenceHistogram->InheritsFrom("TH2I") || referenceHistogram->InheritsFrom("TH2D")) {
556-
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2D>>(referenceHistogram, referenceRun, outputPath, scaleReference, drawRatioOnly, drawOption2D);
571+
mImplementation = std::make_shared<ReferenceComparatorPlotImpl2D<TH2D>>(referenceHistogram, referenceRun, outputPath, scaleReference, drawRatioOnly, logScale, drawOption2D);
557572
}
558573
}
559574

Modules/Common/src/ReferenceComparatorTask.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ void ReferenceComparatorTask::initialize(quality_control::postprocessing::Trigge
154154
group.normalizeReference,
155155
group.drawRatioOnly,
156156
group.legendHeight,
157+
group.logScale,
157158
group.drawOption1D,
158159
group.drawOption2D);
159160
auto* outObject = mHistograms[fullPath]->getMainCanvas();

Modules/Common/src/ReferenceComparatorTaskConfig.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ ReferenceComparatorTaskConfig::ReferenceComparatorTaskConfig(std::string name, c
3636
dataGroupConfig.second.get<bool>("drawRatioOnly", false),
3737
dataGroupConfig.second.get<double>("legendHeight", 0.2),
3838
dataGroupConfig.second.get<std::string>("drawOption1D", "HIST"),
39-
dataGroupConfig.second.get<std::string>("drawOption2D", "COLZ")
39+
dataGroupConfig.second.get<std::string>("drawOption2D", "COLZ"),
40+
dataGroupConfig.second.get<bool>("logScale", false)
4041
};
4142
if (const auto& inputObjects = dataGroupConfig.second.get_child_optional("inputObjects"); inputObjects.has_value()) {
4243
for (const auto& inputObject : inputObjects.value()) {

doc/PostProcessing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ The input MonitorObjects to be processed are logically divided in **dataGroups**
604604
* `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
605605
* `drawOption1D`: the ROOT draw option to be used for the 1-D histograms
606606
* `drawOption2D`: the ROOT draw option to be used for the 2-D histograms
607+
* `logScale`: boolean parameter specifying wether to draw the value axis in log or linear scale (default is `false`)
607608

608609
The input objects are searched within the `inputPath`, and the output plots are stored inside the `outputPath`.
609610
It is also possible to optionally specify a different path for the reference objects, via the `referencePath` parameter. If not given, the `referencePath` will coincide with the `inputPath`.
@@ -694,6 +695,7 @@ In the example configuration below, the relationship between the input and outpu
694695
"legendHeight": "0.2",
695696
"drawOption1D": "E",
696697
"drawOption2D": "COL",
698+
"logScale": "false",
697699
"inputObjects": [
698700
"TrackEta",
699701
"TrackEtaPhi"

0 commit comments

Comments
 (0)