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,
297
296
// but it is heavily used (legacy) in the TTreePlayer to fill alphanumeric histograms.
298
297
// but in case of alphanumeric do-not extend the axis. It makes no sense
299
298
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.");
300
299
if (x < fXmin) { //*-* underflow
301
-
bin = 0;
300
+
Int_t bin = 0;
302
301
if (fParent == nullptr) return bin;
303
302
if (!CanExtend() || IsAlphanumeric() ) return bin;
304
303
((TH1*)fParent)->ExtendAxis(x,this);
305
304
returnFindFixBin(x);
306
305
} elseif ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN)
307
-
bin = fNbins+1;
306
+
Int_t bin = fNbins+1;
308
307
if (fParent == nullptr) return bin;
309
308
if (!CanExtend() || IsAlphanumeric() ) return bin;
310
309
((TH1*)fParent)->ExtendAxis(x,this);
311
310
returnFindFixBin(x);
312
-
} else {
313
-
if (!fXbins.fN) { //*-* fix bins
314
-
bin = 1 + int (fNbins*(x-fXmin)/(fXmax-fXmin) );
315
-
} else { //*-* variable bin sizes
316
-
//for (bin =1; x >= fXbins.fArray[bin]; bin++);
317
-
bin = 1 + TMath::BinarySearch(fXbins.fN,fXbins.fArray,x);
0 commit comments