How to make TH3 histograms with variable bin edges


I have been working a long time now with TH2 histograms with variable bin widths, i.e.

          Double_t edges[5]= {0, 1, 2, 4, 8};
          TH2D * h2 = new TH2D("h2", "h2", 4, edges, 100, 0 , 5); 

which works perfectly fine. However, if I try doing something similar with a TH3 histogram it doesn’t seem to work:

TH3D * h3 = new TH3D("h3", "h3", 4, edges, 100, 0 , 5, 100, 0, 5);

Is there a reason why such a constructor doesn’t seem to exist and do you have a workaround?

@moneta can explain I am sure.


There are no constructor in TH3 taking an axis with fixed bins and one with variable ones. It is just a question of coding all the different cases. Maybe we could add it, but the obvious workaround is to create 3 axes with variable bins, although in your case the y and z axis will have all same bin width:

TAxis tmp(100,0,5); 
double edgesYZ[101]; 
for (int i = 0; i < 101; i++) { 
    edgesXY[i] = tmp.GetBinUpEdge(i); 
TH3 * h3 = new TH3D("h3","h3",4,edges, 100, edgesXY, 100, edgesXY); 



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