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

Hello,
I am trying to draw a histogram with variable binning as follows -

double bins[44] = {12.0, 12.5, 13.0, 13.6, 14.2, 14.8, 15.4, 16.1, 16.8, 17.5,
18.3, 19.1, 19.9, 20.8, 21.7, 22.7, 23.7, 24.7, 25.8, 26.9,
28.1, 29.4, 30.7, 32.1, 33.5, 35.0, 36.6, 38.2, 39.9, 41.7,
43.6, 45.6, 47.7, 49.8, 52.0, 54.3, 56.8, 59.4, 62.1, 64.9,
67.8, 70.9, 74.1, 77.0};

TH1D* h_dataAR1 = new TH1D(“h_dataAR1”,“h_dataAR1”,44, bins);

But it gives the error -
Error in TAxis::TAxis::Set: bins must be in increasing order
Error in TCanvas::Range: illegal world coordinates range: x1=13.500000, y1=-9.959344, x2=-1.500000, y2=89.634086
Error in TCanvas::RangeAxis: illegal axis coordinates range: xmin=12.000000, ymin=0.000000, xmax=0.000000, ymax=79.674742
Error in TGraphPainter::PaintGrapHist: X must have N+1 values with option N

I cannot find any error in the binning I defined, it is in increasing order, I am not sure what exactly is going wrong here.
Any leads are appreciated.
Best,
Shreya

See the documentation:
“xbins array of low-edges for each bin. This is an array of size nbins+1”
So you need to specify 43 (nbins) in h_dataAR1, or add the 1 missing bin edge to bins.

Thanks a lot ! It works now :slight_smile:
best,
Shreya

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.