-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hist] Improve calculation of
TAxis::FindBin(x)
when x is at the bi…
…n edges When x is at the bin edge values numerical error can cause the computation of the bin to be the one before (or after). Correct for this case assuming the bin edge are computed as in `TH1::getBinLowEdge` and `TH1::GetBinUpEdge`. It is clear that the bin edge values are represented as floating point, so depending on how they are computed they can be sometime different. However, it is better to have teh consistency to return the correct value when computed as internally in TAxis. This should fix teh problem reported in https://root-forum.cern.ch/t/bug-in-taxis-findbin/57210 and #14091
- Loading branch information
Showing
4 changed files
with
62 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "TAxis.h" | ||
|
||
|
||
TEST(TAxis, FindBinExact) | ||
{ | ||
//Test the case where bin edges are exactly represented as floating points | ||
TAxis ax(88, 1010, 1098); | ||
for (int i = 1; i <= ax.GetNbins(); i++) { | ||
double x = ax.GetBinLowEdge(i); | ||
EXPECT_EQ(i, ax.FindBin(x)); | ||
EXPECT_EQ(i, ax.FindFixBin(x)); | ||
x = ax.GetBinUpEdge(i); | ||
EXPECT_EQ(i+1, ax.FindBin(x)); | ||
x -= x * std::numeric_limits<double>::epsilon(); | ||
EXPECT_EQ(i, ax.FindBin(x)); | ||
} | ||
} | ||
TEST(TAxis, FindBinApprox) | ||
{ | ||
TAxis ax(90, 0. , 10.); | ||
for (int i = 1; i <= ax.GetNbins(); i++) { | ||
double x = ax.GetBinLowEdge(i); | ||
EXPECT_EQ(i, ax.FindBin(x)); | ||
EXPECT_EQ(i, ax.FindFixBin(x)); | ||
x = ax.GetBinUpEdge(i); | ||
EXPECT_EQ(i+1, ax.FindBin(x)); | ||
x -= x * std::numeric_limits<double>::epsilon(); | ||
EXPECT_EQ(i, ax.FindBin(x)); | ||
} | ||
} |