Skip to content

Commit 1e86782

Browse files
committed
[Python][UHI] Fix SetBins call in SliceHistoInPlace for histograms with infinite bin edges
1 parent e327ff0 commit 1e86782

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

hist/hist/inc/TH1.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,19 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
214214

215215
// Compute new bin counts and edges
216216
std::array<Int_t, kMaxDim> nBins{}, totalBins{};
217-
std::array<Double_t, kMaxDim> lowEdge{}, upEdge{};
217+
std::array<std::vector<Double_t>, kMaxDim> edges;
218218
for (decltype(ndim) d = 0; d < ndim; ++d) {
219219
const auto &axis = (d == 0 ? fXaxis : d == 1 ? fYaxis : fZaxis);
220220
auto start = std::max(1, args[d * 2]);
221221
auto end = std::min(axis.GetNbins() + 1, args[d * 2 + 1]);
222222
nBins[d] = end - start;
223-
lowEdge[d] = axis.GetBinLowEdge(start);
224-
upEdge[d] = axis.GetBinLowEdge(end);
225223
totalBins[d] = axis.GetNbins() + 2;
226224
args[2 * d] = start;
227225
args[2 * d + 1] = end;
226+
// Compute new edges
227+
for (int b = start; b <= end; ++b)
228+
edges[d].push_back(axis.GetBinLowEdge(b));
229+
edges[d].push_back(axis.GetBinUpEdge(end));
228230
}
229231

230232
// Compute layout sizes for slice
@@ -271,13 +273,10 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
271273
dataArray = newArr;
272274

273275
// Reconfigure Axes
274-
if (ndim == 1) {
275-
this->SetBins(nBins[0], lowEdge[0], upEdge[0]);
276-
} else if (ndim == 2) {
277-
this->SetBins(nBins[0], lowEdge[0], upEdge[0], nBins[1], lowEdge[1], upEdge[1]);
278-
} else if (ndim == 3) {
279-
this->SetBins(nBins[0], lowEdge[0], upEdge[0], nBins[1], lowEdge[1], upEdge[1], nBins[2], lowEdge[2],
280-
upEdge[2]);
276+
switch (ndim) {
277+
case 1: this->SetBins(nBins[0], edges[0].data()); break;
278+
case 2: this->SetBins(nBins[0], edges[0].data(), nBins[1], edges[1].data()); break;
279+
case 3: this->SetBins(nBins[0], edges[0].data(), nBins[1], edges[1].data(), nBins[2], edges[2].data()); break;
281280
}
282281

283282
// Update the statistics

0 commit comments

Comments
 (0)