Skip to content

Commit ee6bf7b

Browse files
authored
[hist] fix underflow case and document
1 parent 5744009 commit ee6bf7b

File tree

5 files changed

+34
-49
lines changed

5 files changed

+34
-49
lines changed

hist/hist/src/TAxis.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ Int_t TAxis::GetLast() const
477477

478478
////////////////////////////////////////////////////////////////////////////////
479479
/// Return center of bin
480+
///
481+
/// If fXmin is -inf, it will return -nan even if fXmax is finite
482+
/// If fXmax is +inf, it will return +inf even if fXmin is finite
480483

481484
Double_t TAxis::GetBinCenter(Int_t bin) const
482485
{

hist/hist/src/TH1Merger.cxx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -716,17 +716,14 @@ Bool_t TH1Merger::AutoP2Merge()
716716
Int_t jbin = fH0->FindBin(xu);
717717
auto eps = 1e-12;
718718
if (jbin == fH0->GetXaxis()->GetNbins() + 1) {
719-
// if upper edge is infinite, the bin center is infinite no matter what low edge is,
719+
// if upper edge is infinite, the bin center is +infinite no matter what low edge is,
720720
// so FindBin is in overflow since bin goes from [lower edge, infinite)
721-
// Check the low edge instead of the bin center in that case
721+
// if lower edge is -infinite, the bin center is -nan no matter what upper edge is,
722+
// so FindBin is also in overflow (not underflow)
723+
// Check close to the lower or upper edges instead of the bin center in these cases
722724
if (std::isinf(hist->GetXaxis()->GetBinUpEdge(ibin))) {
723725
jbin = fH0->GetXaxis()->FindBin(hist->GetXaxis()->GetBinLowEdge(ibin) + eps);
724-
}
725-
} else if (jbin == 0) {
726-
// if lower edge is -infinite, the bin center is -infinite no matter what upper edge is,
727-
// so FindBin is in underflow bin which goes from [-inf, -inf)
728-
// Check the upper edge instead of the bin center in that case
729-
if (std::isinf(hist->GetXaxis()->GetBinLowEdge(ibin))) {
726+
} else if (std::isinf(hist->GetXaxis()->GetBinLowEdge(ibin))) {
730727
jbin = fH0->GetXaxis()->FindBin(hist->GetXaxis()->GetBinUpEdge(ibin) - eps);
731728
}
732729
}

hist/hist/src/TH1Merger.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@ class TH1Merger {
5151
auto binOut = outAxis.FindBin(inAxis.GetBinCenter(ibin));
5252
auto eps = 1e-12;
5353
if (binOut == outAxis.GetNbins() + 1) {
54-
// if upper edge is infinite, the bin center is infinite no matter what low edge is,
54+
// if upper edge is infinite, the bin center is +infinite no matter what low edge is,
5555
// so FindBin is in overflow since bin goes from [lower edge, infinite)
56-
// Check the low edge instead of the bin center in that case
56+
// if lower edge is -infinite, the bin center is -nan no matter what upper edge is,
57+
// so FindBin is also in overflow (not underflow)
58+
// Check close to the lower or upper edges instead of the bin center in these cases
5759
if (std::isinf(inAxis.GetBinUpEdge(ibin))) {
5860
binOut = outAxis.FindBin(inAxis.GetBinLowEdge(ibin) + eps);
59-
}
60-
} else if (binOut == 0) {
61-
// if lower edge is -infinite, the bin center is -infinite no matter what upper edge is,
62-
// so FindBin is in underflow bin which goes from [-inf, -inf)
63-
// Check the upper edge instead of the bin center in that case
64-
if (std::isinf(inAxis.GetBinLowEdge(ibin))) {
61+
} else if (std::isinf(inAxis.GetBinLowEdge(ibin))) {
6562
binOut = outAxis.FindBin(inAxis.GetBinUpEdge(ibin) - eps);
6663
}
6764
}

hist/hist/src/TH2.cxx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,17 +2296,14 @@ TH1D *TH2::DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbi
22962296
Int_t binOut = h1->GetXaxis()->FindBin(outAxis->GetBinCenter(outbin));
22972297
auto eps = 1e-12;
22982298
if (binOut == h1->GetXaxis()->GetNbins() + 1) {
2299-
// if upper edge is infinite, the bin center is infinite no matter what low edge is,
2299+
// if upper edge is infinite, the bin center is +infinite no matter what low edge is,
23002300
// so FindBin is in overflow since bin goes from [lower edge, infinite)
2301-
// Check the low edge instead of the bin center in that case
2301+
// if lower edge is -infinite, the bin center is -nan no matter what upper edge is,
2302+
// so FindBin is also in overflow (not underflow)
2303+
// Check close to the lower or upper edges instead of the bin center in these cases
23022304
if (std::isinf(outAxis->GetBinUpEdge(outbin))) {
23032305
binOut = h1->GetXaxis()->FindBin(outAxis->GetBinLowEdge(outbin) + eps);
2304-
}
2305-
} else if (binOut == 0) {
2306-
// if lower edge is -infinite, the bin center is -infinite no matter what upper edge is,
2307-
// so FindBin is in underflow bin which goes from [-inf, -inf)
2308-
// Check the upper edge instead of the bin center in that case
2309-
if (std::isinf(outAxis->GetBinLowEdge(outbin))) {
2306+
} else if (std::isinf(outAxis->GetBinLowEdge(outbin))) {
23102307
binOut = h1->GetXaxis()->FindBin(outAxis->GetBinUpEdge(outbin) - eps);
23112308
}
23122309
}

hist/hist/src/TH3.cxx

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,17 +2061,14 @@ TH1D *TH3::DoProject1D(const char* name, const char * title, const TAxis* projX,
20612061
Int_t ix = h1->FindBin(projX->GetBinCenter(ixbin));
20622062
auto eps = 1e-12;
20632063
if (ix == h1->GetNbinsX() + 1) {
2064-
// if upper edge is infinite, the bin center is infinite no matter what low edge is,
2064+
// if upper edge is infinite, the bin center is +infinite no matter what low edge is,
20652065
// so FindBin is in overflow since bin goes from [lower edge, infinite)
2066-
// Check the low edge instead of the bin center in that case
2066+
// if lower edge is -infinite, the bin center is -nan no matter what upper edge is,
2067+
// so FindBin is also in overflow (not underflow)
2068+
// Check close to the lower or upper edges instead of the bin center in these cases
20672069
if (std::isinf(projX->GetBinUpEdge(ixbin))) {
20682070
ix = h1->FindBin(projX->GetBinLowEdge(ixbin) + eps);
2069-
}
2070-
} else if (ix == 0) {
2071-
// if lower edge is -infinite, the bin center is -infinite no matter what upper edge is,
2072-
// so FindBin is in underflow bin which goes from [-inf, -inf)
2073-
// Check the upper edge instead of the bin center in that case
2074-
if (std::isinf(projX->GetBinLowEdge(ixbin))) {
2071+
} else if (std::isinf(projX->GetBinLowEdge(ixbin))) {
20752072
ix = h1->FindBin(projX->GetBinUpEdge(ixbin) - eps);
20762073
}
20772074
}
@@ -2286,17 +2283,14 @@ TH2D *TH3::DoProject2D(const char* name, const char * title, const TAxis* projX,
22862283
Int_t ix = h2->GetYaxis()->FindBin(projX->GetBinCenter(ixbin));
22872284
auto eps = 1e-12;
22882285
if (ix == h2->GetYaxis()->GetNbins() + 1) {
2289-
// if upper edge is infinite, the bin center is infinite no matter what low edge is,
2286+
// if upper edge is infinite, the bin center is +infinite no matter what low edge is,
22902287
// so FindBin is in overflow since bin goes from [lower edge, infinite)
2291-
// Check the low edge instead of the bin center in that case
2288+
// if lower edge is -infinite, the bin center is -nan no matter what upper edge is,
2289+
// so FindBin is also in overflow (not underflow)
2290+
// Check close to the lower or upper edges instead of the bin center in these cases
22922291
if (std::isinf(projX->GetBinUpEdge(ixbin))) {
22932292
ix = h2->GetYaxis()->FindBin(projX->GetBinLowEdge(ixbin) + eps);
2294-
}
2295-
} else if (ix == 0) {
2296-
// if lower edge is -infinite, the bin center is -infinite no matter what upper edge is,
2297-
// so FindBin is in underflow bin which goes from [-inf, -inf)
2298-
// Check the upper edge instead of the bin center in that case
2299-
if (std::isinf(projX->GetBinLowEdge(ixbin))) {
2293+
} else if (std::isinf(projX->GetBinLowEdge(ixbin))) {
23002294
ix = h2->GetYaxis()->FindBin(projX->GetBinUpEdge(ixbin) - eps);
23012295
}
23022296
}
@@ -2305,17 +2299,14 @@ TH2D *TH3::DoProject2D(const char* name, const char * title, const TAxis* projX,
23052299
if ( projY->TestBit(TAxis::kAxisRange) && ( iybin < iymin || iybin > iymax )) continue;
23062300
Int_t iy = h2->GetXaxis()->FindBin( projY->GetBinCenter(iybin) );
23072301
if (iy == h2->GetXaxis()->GetNbins() + 1) {
2308-
// if upper edge is infinite, the bin center is infinite no matter what low edge is,
2309-
// so FindBin is in overflow since bin goes from [lower edge, infinite)
2310-
// Check the low edge instead of the bin center in that case
2302+
// if upper edge is infinite, the bin center is +infinite no matter what low edge is,
2303+
// so FindBin is in overflow since bin goes from [lower edge, infinite)
2304+
// if lower edge is -infinite, the bin center is -nan no matter what upper edge is,
2305+
// so FindBin is also in overflow (not underflow)
2306+
// Check close to the lower or upper edges instead of the bin center in these cases
23112307
if (std::isinf(projY->GetBinUpEdge(iybin))) {
23122308
iy = h2->GetXaxis()->FindBin(projY->GetBinLowEdge(iybin) + eps);
2313-
}
2314-
} else if (iy == 0) {
2315-
// if lower edge is -infinite, the bin center is -infinite no matter what upper edge is,
2316-
// so FindBin is in underflow bin which goes from [-inf, -inf)
2317-
// Check the upper edge instead of the bin center in that case
2318-
if (std::isinf(projY->GetBinLowEdge(iybin))) {
2309+
} else if (std::isinf(projY->GetBinLowEdge(iybin))) {
23192310
iy = h2->GetXaxis()->FindBin(projY->GetBinUpEdge(iybin) - eps);
23202311
}
23212312
}

0 commit comments

Comments
 (0)