Skip to content

Commit

Permalink
[hist] fine-tune getquantile computation
Browse files Browse the repository at this point in the history
Fixes #12251
  • Loading branch information
ferdymercury authored and dpiparo committed Nov 6, 2024
1 parent 0bead59 commit 5def356
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions hist/hist/src/TH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4635,13 +4635,34 @@ Int_t TH1::GetQuantiles(Int_t n, Double_t *xp, const Double_t *p)

for (i = 0; i < nq; i++) {
ibin = TMath::BinarySearch(nbins,fIntegral,prob[i]);
while (ibin < nbins-1 && fIntegral[ibin+1] == prob[i]) {
if (fIntegral[ibin+2] == prob[i]) ibin++;
else break;
if (fIntegral[ibin] == prob[i]) {
if (prob[i] == 0.) {
for (; ibin+1 <= nbins && fIntegral[ibin+1] == 0.; ++ibin) {

}
xp[i] = fXaxis.GetBinUpEdge(ibin);
}
else if (prob[i] == 1.) {
xp[i] = fXaxis.GetBinUpEdge(ibin);
}
else {
// Find equal integral in later bins (ie their entries are zero)
Double_t width = 0;
for (Int_t j = ibin+1; j <= nbins; ++j) {
if (prob[i] == fIntegral[j]) {
width += fXaxis.GetBinWidth(j);
}
else
break;
}
xp[i] = width == 0 ? fXaxis.GetBinCenter(ibin) : fXaxis.GetBinUpEdge(ibin) + width/2.;
}
}
else {
xp[i] = GetBinLowEdge(ibin+1);
const Double_t dint = fIntegral[ibin+1]-fIntegral[ibin];
if (dint > 0) xp[i] += GetBinWidth(ibin+1)*(prob[i]-fIntegral[ibin])/dint;
}
xp[i] = GetBinLowEdge(ibin+1);
const Double_t dint = fIntegral[ibin+1]-fIntegral[ibin];
if (dint > 0) xp[i] += GetBinWidth(ibin+1)*(prob[i]-fIntegral[ibin])/dint;
}

if (!p) delete [] prob;
Expand Down

0 comments on commit 5def356

Please sign in to comment.