From 19c8e8835348b64a77dd2fb5c40e5f2a0632e651 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 30 Jan 2025 18:16:21 +0100 Subject: [PATCH] [hist] fix regression in AddBinContentND and add test Fixes https://github.com/root-project/root/issues/17552 --- hist/hist/inc/TH2.h | 6 ++++++ hist/hist/inc/TH3.h | 6 ++++++ hist/hist/test/test_TH1.cxx | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/hist/hist/inc/TH2.h b/hist/hist/inc/TH2.h index 9a5e890bd49a8..e06bf6fb27001 100644 --- a/hist/hist/inc/TH2.h +++ b/hist/hist/inc/TH2.h @@ -159,6 +159,7 @@ class TH2C : public TH2, public TArrayC { void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH2::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -200,6 +201,7 @@ class TH2S : public TH2, public TArrayS { void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH2::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -241,6 +243,7 @@ class TH2I : public TH2, public TArrayI { void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH2::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -280,6 +283,7 @@ class TH2L : public TH2, public TArrayL64 { ~TH2L() override; void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH2::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -326,6 +330,7 @@ class TH2F : public TH2, public TArrayF { /// Passing an out-of-range bin leads to undefined behavior void AddBinContent(Int_t bin, Double_t w) override {fArray[bin] += Float_t (w);} + using TH2::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -373,6 +378,7 @@ class TH2D : public TH2, public TArrayD { /// Passing an out-of-range bin leads to undefined behavior void AddBinContent(Int_t bin, Double_t w) override {fArray[bin] += Double_t (w);} + using TH2::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; diff --git a/hist/hist/inc/TH3.h b/hist/hist/inc/TH3.h index f62d35430b071..962e38e80c091 100644 --- a/hist/hist/inc/TH3.h +++ b/hist/hist/inc/TH3.h @@ -175,6 +175,7 @@ class TH3C : public TH3, public TArrayC { void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH3::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -213,6 +214,7 @@ class TH3S : public TH3, public TArrayS { void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH3::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -251,6 +253,7 @@ class TH3I : public TH3, public TArrayI { void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH3::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -289,6 +292,7 @@ class TH3L : public TH3, public TArrayL64 { ~TH3L() override; void AddBinContent(Int_t bin) override; void AddBinContent(Int_t bin, Double_t w) override; + using TH3::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -333,6 +337,7 @@ class TH3F : public TH3, public TArrayF { /// Passing an out-of-range bin leads to undefined behavior void AddBinContent(Int_t bin, Double_t w) override {fArray[bin] += Float_t (w);} + using TH3::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; @@ -376,6 +381,7 @@ class TH3D : public TH3, public TArrayD { /// Passing an out-of-range bin leads to undefined behavior void AddBinContent(Int_t bin, Double_t w) override {fArray[bin] += Double_t (w);} + using TH3::AddBinContent; void Copy(TObject &hnew) const override; void Reset(Option_t *option="") override; void SetBinsLength(Int_t n=-1) override; diff --git a/hist/hist/test/test_TH1.cxx b/hist/hist/test/test_TH1.cxx index 00e400133f653..3ab0a241e5a70 100644 --- a/hist/hist/test/test_TH1.cxx +++ b/hist/hist/test/test_TH1.cxx @@ -75,3 +75,18 @@ TEST(TH1, DumpOutput) const std::string output = testing::internal::GetCapturedStdout(); EXPECT_TRUE(output.find(line_fArray) != std::string::npos) << "Could not find '" << line_fArray << "' in the multiline output '" << output; } + + +// https://github.com/root-project/root/issues/17552 +TEST(TH1, AddBinContent) +{ + TH1F h1("h1", "h1", 10, 0, 1); + h1.AddBinContent(1,1.); + EXPECT_FLOAT_EQ(h1.GetBinContent(1),1.); + TH2F h2("h2", "h2", 10, 0, 1, 2, 0, 3); + h2.AddBinContent(1,1,1.); + EXPECT_FLOAT_EQ(h2.GetBinContent(1,1),1.); + TH3F h3("h3", "h3", 5, 0, 1, 2, 0, 2, 2, 0, 3);; + h3.AddBinContent(1,1,1,1.); + EXPECT_FLOAT_EQ(h3.GetBinContent(1,1,1),1.); +} \ No newline at end of file