You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[hist] Improve calculation of TAxis::FindBin(x) when x is at the bin 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
// NOTE: This should not be allowed for Alphanumeric histograms,
292
291
// but it is heavily used (legacy) in the TTreePlayer to fill alphanumeric histograms.
293
292
// but in case of alphanumeric do-not extend the axis. It makes no sense
294
293
if (IsAlphanumeric() && gDebug) Info("FindBin","Numeric query on alphanumeric axis - Sorting the bins or extending the axes / rebinning can alter the correspondence between the label and the bin interval.");
295
294
if (x < fXmin) { //*-* underflow
296
-
bin = 0;
295
+
Int_t bin = 0;
297
296
if (fParent == nullptr) return bin;
298
297
if (!CanExtend() || IsAlphanumeric() ) return bin;
299
298
((TH1*)fParent)->ExtendAxis(x,this);
300
299
returnFindFixBin(x);
301
300
} elseif ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN)
302
-
bin = fNbins+1;
301
+
Int_t bin = fNbins+1;
303
302
if (fParent == nullptr) return bin;
304
303
if (!CanExtend() || IsAlphanumeric() ) return bin;
305
304
((TH1*)fParent)->ExtendAxis(x,this);
306
305
returnFindFixBin(x);
307
-
} else {
308
-
if (!fXbins.fN) { //*-* fix bins
309
-
bin = 1 + int (fNbins*(x-fXmin)/(fXmax-fXmin) );
310
-
} else { //*-* variable bin sizes
311
-
//for (bin =1; x >= fXbins.fArray[bin]; bin++);
312
-
bin = 1 + TMath::BinarySearch(fXbins.fN,fXbins.fArray,x);
0 commit comments