From c0804a2ed4f1e3469e97bb26063fcc7aeca2d92b Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Mon, 10 Feb 2025 17:29:01 +0100 Subject: [PATCH 1/2] [hist] in TTree::Draw, last bin should include vmax values Fixes https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862 --- hist/hist/src/THLimitsFinder.cxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hist/hist/src/THLimitsFinder.cxx b/hist/hist/src/THLimitsFinder.cxx index 528b08303f651..5b469c7092830 100644 --- a/hist/hist/src/THLimitsFinder.cxx +++ b/hist/hist/src/THLimitsFinder.cxx @@ -401,5 +401,12 @@ void THLimitsFinder::OptimizeLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, if (xmin +nbins*bw < umax) {nbins++; xmax = xmin +nbins*bw;} if (xmin > umin) {nbins++; xmin = xmax -nbins*bw;} } + else { + xmax = std::max(xmax + 1e-12, std::nextafter(xmax,INFINITY)); + // If we put the upper bin limit directly at xmax, then all values at xmax will go into the overflow and will be invisible. + // So shift it slightly to the right, by at least 1e-12. + // Otherwise, it still does not plot the max data it with the reproducer at https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862 + // probably due to some extra double rounding precision loss in subsequent operations. + } newbins = nbins; } From 0d576839bcf1d5e509fac0c8585ccb3355d0138c Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Tue, 11 Feb 2025 10:28:08 +0100 Subject: [PATCH 2/2] [hist] make shift specific to the scale and clarify comment --- hist/hist/src/THLimitsFinder.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hist/hist/src/THLimitsFinder.cxx b/hist/hist/src/THLimitsFinder.cxx index 5b469c7092830..0d991d31000f1 100644 --- a/hist/hist/src/THLimitsFinder.cxx +++ b/hist/hist/src/THLimitsFinder.cxx @@ -402,11 +402,11 @@ void THLimitsFinder::OptimizeLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, if (xmin > umin) {nbins++; xmin = xmax -nbins*bw;} } else { - xmax = std::max(xmax + 1e-12, std::nextafter(xmax,INFINITY)); + xmax = std::max(xmax + 1e-15*(xmax - xmin), std::nextafter(xmax,INFINITY)); // If we put the upper bin limit directly at xmax, then all values at xmax will go into the overflow and will be invisible. - // So shift it slightly to the right, by at least 1e-12. + // So shift it slightly to the right, by at least 1e-12 when hist_xlow=-1000, hist_xup=0 and nbins = 100. // Otherwise, it still does not plot the max data it with the reproducer at https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862 - // probably due to some extra double rounding precision loss in subsequent operations. + // due to the rounding in TAxis::FindBin line: bin = 1 + int (fNbins*(x-fXmin)/(fXmax-fXmin) );. } newbins = nbins; }