Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hist] fix regression in AddBinContentND and add test #17578

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hist/hist/inc/TH2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions hist/hist/inc/TH3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions hist/hist/test/test_TH1.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "gtest/gtest.h"

#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TH1F.h"
#include "THLimitsFinder.h"

Expand Down Expand Up @@ -75,3 +77,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.);
}
Loading