Skip to content

Commit 1703c54

Browse files
ferdymercuryguitargeek
authored andcommitted
[skip-ci] clarify behavior and rounding precision limitations of FindBin
See https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862/16
1 parent c92c055 commit 1703c54

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

hist/hist/src/TAxis.cxx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,18 @@ void TAxis::ExecuteEvent(Int_t event, Int_t px, Int_t py)
280280
}
281281

282282
////////////////////////////////////////////////////////////////////////////////
283-
/// Find bin number corresponding to abscissa x. NOTE: this method does not work with alphanumeric bins !!!
283+
/// Find bin number corresponding to abscissa `x`. NOTE: this method does not work with alphanumeric bins !!!
284284
///
285-
/// If x is underflow or overflow, attempt to extend the axis if TAxis::kCanExtend is true.
286-
/// Otherwise, return 0 or fNbins+1.
285+
/// If `x` is underflow or overflow, attempt to extend the axis if TAxis::kCanExtend is true.
286+
/// Otherwise, return `0` or `fNbins+1`.
287+
///
288+
/// @note The underflow bin (`0`) is for any `x` strictly smaller than `fXmin`,
289+
/// whereas the overflow bin (`nbins+1`) is for any `x` greater or equal than `fXmax`,
290+
/// as well as for `NaN`. The first regular bin (`1`) is for any `x`
291+
/// greater or equal than `fXmin` and strictly smaller than `fXmin + binwidth`, and so on.
292+
/// @note The bin assignment equation uses doubles, thus rounding errors are
293+
/// expected to appear at the edges. For example: `TAxis(1, -1., 0.).FindBin(-1e-17)`
294+
/// returns the overflow bin (`2`) rather than the theoretically correct bin (`1`).
287295

288296
Int_t TAxis::FindBin(Double_t x)
289297
{
@@ -406,17 +414,18 @@ Int_t TAxis::FindFixBin(const char *label) const
406414

407415

408416
////////////////////////////////////////////////////////////////////////////////
409-
/// Find bin number corresponding to abscissa x
417+
/// Find bin number corresponding to abscissa `x`
410418
///
411-
/// Identical to TAxis::FindBin except that if x is an underflow/overflow
419+
/// Identical to TAxis::FindBin except that if `x` is an underflow/overflow
412420
/// no attempt is made to extend the axis.
421+
/// @see TAxis::FindBin
413422

414423
Int_t TAxis::FindFixBin(Double_t x) const
415424
{
416425
Int_t bin;
417426
if (x < fXmin) { //*-* underflow
418427
bin = 0;
419-
} else if ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN
428+
} else if ( !(x < fXmax)) { //*-* overflow (note the way to catch NaN)
420429
bin = fNbins+1;
421430
} else {
422431
if (!fXbins.fN) { //*-* fix bins

0 commit comments

Comments
 (0)