Skip to content

Commit a531cdf

Browse files
committed
[hist] Improve limits of THLimitsFinder.
THLimitsFinder sometimes removes the first/last bin of an axis range. Here, it is ensured that the min and max of a buffered range is part of the axis range, and not removed by accident. This fixes issues with TTree::Draw such as the one described in https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862/
1 parent d11aef6 commit a531cdf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

hist/hist/src/THLimitsFinder.cxx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,16 @@ void THLimitsFinder::Optimize(Double_t A1, Double_t A2, Int_t nold ,
337337
Int_t oldnbins = nbins;
338338

339339
Double_t atest = BinWidth*0.0001;
340-
//if (TMath::Abs(BinLow-A1) >= atest) { BinLow += BinWidth; nbins--; } //replaced by Damir in 3.10/02
341-
//if (TMath::Abs(BinHigh-A2) >= atest) { BinHigh -= BinWidth; nbins--; } //by the next two lines
342-
if (al-BinLow >= atest) { BinLow += BinWidth; nbins--; }
343-
if (BinHigh-ah >= atest) { BinHigh -= BinWidth; nbins--; }
340+
if (al - BinLow >= atest && al < BinLow + BinWidth) {
341+
// Suppress the first bin, but only if al doesn't fall into it
342+
BinLow += BinWidth;
343+
nbins--;
344+
}
345+
if (BinHigh - ah >= atest && BinHigh - BinWidth > ah) {
346+
// Suppress the last bin, but only if ah doesn't fall into it
347+
BinHigh -= BinWidth;
348+
nbins--;
349+
}
344350
if (!optionTime && BinLow >= BinHigh) {
345351
//this case may happen when nbins <=5
346352
BinLow = oldBinLow;

0 commit comments

Comments
 (0)