Open
Description
Check duplicate issues.
- Checked for duplicates
Description
Hello all,
It seems there is a bug in the TAxis::FindBin (Double_t x) method. When the joint script is executed, one can see that the bin number returned from ax->FindBin (ax->GetBinLowEdge (i)) is not always i as expected.
When looking at the code of TAxis::FindBin (ROOT: hist/hist/src/TAxis.cxx Source File line 314), the formula used to compute the bin number is subject to rounding errors. It should be corrected as propose in the joint script.
Daniel CUSSOL
Reproducer
File TAxisBug.C
#include "TAxis.h"
#include "Riostream.h"
#include "TROOT.h"
Int_t GetRightBin (TAxis *ax, Double_t x)
{
//
// Get correct bin number from x value for TAxis ax
//
Int_t retVal = 1+Int_t(ax->GetNbins()*(x-ax->GetXmin())/(ax->GetXmax()-ax->GetXmin()) + 0.5);
return retVal;
}
void TAxisBug (Int_t nBins = 30, Double_t xMin=3.0, Double_t xMax=6.0)
{
//
// Test TAxis bug
//
TAxis *ax=new TAxis (nBins, xMin, xMax);
cout << "Root version : " << gROOT->GetVersion() << endl;
for (Int_t i=1;i<=ax->GetNbins();i++)
{
cout << i << " => " << ax->FindBin (ax->GetBinLowEdge (i))
<< " : " <<
GetRightBin (ax, ax->GetBinLowEdge (i));
if (i != ax->FindBin (ax->GetBinLowEdge (i)))
{
cout << " <= Bug!!! ";
}
cout << endl;
}
cout << endl;
}
root TAxisBug.C+
ROOT version
from ROOT v6.24.00
Installation method
pre-built and binaries
Operating system
Ubuntu 22.04.3 LTS (Jammy Jellyfish)
Additional context
No response
Metadata
Metadata
Assignees
Type
Projects
Status
Issues