From 2d9f4cbe9b63ca1d738d3bbfe35cd39818e747c2 Mon Sep 17 00:00:00 2001 From: aferrero2707 Date: Tue, 1 Oct 2024 10:32:01 +0200 Subject: [PATCH] [Common] correctly handle integer histograms in reference comparator (#2444) The reference comparator code is extended to handle histograms with integer values, by internally converting them to floating-point such that the normalization and ratios are computed correctly --- Modules/Common/src/ReferenceComparatorPlot.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Modules/Common/src/ReferenceComparatorPlot.cxx b/Modules/Common/src/ReferenceComparatorPlot.cxx index 21685dcad4..91c9d9a218 100644 --- a/Modules/Common/src/ReferenceComparatorPlot.cxx +++ b/Modules/Common/src/ReferenceComparatorPlot.cxx @@ -497,19 +497,23 @@ class ReferenceComparatorPlotImpl2D : public ReferenceComparatorPlotImpl ReferenceComparatorPlot::ReferenceComparatorPlot(TH1* referenceHistogram, const std::string& outputPath, bool scaleReference, bool drawRatioOnly, const std::string& drawOption1D, const std::string& drawOption2D) { - if (referenceHistogram->IsA() == TClass::GetClass() || referenceHistogram->InheritsFrom("TH1F")) { + // 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>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption1D); } - if (referenceHistogram->IsA() == TClass::GetClass() || referenceHistogram->InheritsFrom("TH1D")) { + if (referenceHistogram->InheritsFrom("TH1I") || referenceHistogram->InheritsFrom("TH1D")) { mImplementation = std::make_shared>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption1D); } - if (referenceHistogram->IsA() == TClass::GetClass() || referenceHistogram->InheritsFrom("TH2F")) { + // 2-D histograms + if (referenceHistogram->InheritsFrom("TH2C") || referenceHistogram->InheritsFrom("TH2S") || referenceHistogram->InheritsFrom("TH2F")) { mImplementation = std::make_shared>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption2D); } - if (referenceHistogram->IsA() == TClass::GetClass() || referenceHistogram->InheritsFrom("TH2D")) { + if (referenceHistogram->InheritsFrom("TH2I") || referenceHistogram->InheritsFrom("TH2D")) { mImplementation = std::make_shared>(referenceHistogram, outputPath, scaleReference, drawRatioOnly, drawOption2D); } }