TH1::GetQuantiles() gives wrong value for 100 percentile?

{
  TCanvas *c = new TCanvas("c", "c"); c->Divide(1, 2);
  TH1F *hist = new TH1F("hist", "hist", 10, 0., 100.);
  hist->FillRandom("pol0", 10000); c->cd(1); hist->Draw(); c->cd(0);
  const int nq = 100;
  double qnv[nq]; // position where to compute the quantiles
  for(int j = 0; j < nq; j++) qnv[j] = double(j + 1) / double(nq);
  double qn[nq]; // array to contain the quantiles
  hist->GetQuantiles(nq, qn, qnv);
  for(int j = 0; j < nq; j++) std::cout << j + 1 << " : " << qn[j] << "\n";
  TGraph *g = new TGraph(nq, qnv, qn); g->SetTitle("quantiles nonlinearity");
  double xl = hist->GetXaxis()->GetXmin(), xr = hist->GetXaxis()->GetXmax();
  for(int j = 0; j < nq; j++) g->GetY()[j] -= g->GetX()[j] * (xr - xl) + xl;
  g->GetHistogram()->GetXaxis()->Set(100, 0., 1.);
  c->cd(2); g->Draw("A*"); gPad->SetGridx(); c->cd(0);
}
1 Like