Root Manual Website, example for creating variable bins histogram

Hello,

I came across a piece of code on the root manual webpage for histograms ( Histograms - ROOT ), that may not be correct. You can find there the lines

   double binEdges[] = { 0.0, 0.2, 0.5, 1., 2., 4. };
   TH1* h1 = new TH1D("h1", "h1 title", 6, binEdges );
   TH2* h2 = new TH2D("h2", "h2 title", 6, binEdges , 30, -1.5, 3.5);

as example for creating histograms with variable bin size. Running this, I end up with the error

Error in TAxis::TAxis::Set: bins must be in increasing order

(using ROOT 6.34.04). This is because the size of the binEdges array and the number of x-bins do not match the constructor of TH1 and TH2. Changing the number of xbins from 6 to 5 works. It would be great if that could be corrected :).

Thank you !

Yes that’s a mistake. We will modify it.

This PR fixes the problem: Fix an histogramming example by couet · Pull Request #1154 · root-project/web · GitHub

Thanks to have seen it !

1 Like