Histo with variable bin size

Hi,

I’d like to create a histogram with variable bin sizes, so I tried to do something like:

bins = [10., 11., 12.] #lower edges of bins
h = TH1F(“h”, “h”, 2, bins)

I get the error:
TypeError: none of the 6 overloaded methods succeeded. Full details:
TH1F::TH1F() =>
takes at most 0 arguments (4 given)
TH1F::TH1F(const char* name, const char* title, Int_t nbinsx, const Float_t* xbins) =>
could not convert argument 4

but I thought that PyROOT would be able to convert my array bins[] into an array of floats. Is there any way around this?

Thanks,
Eric

Eric,

a python list is internally completely different than a C++ array. For now, the solution is to use a python array, which does have internally the same structure:from array import array bins = array( 'f', [10.,11.,12.] ) h = TH1F( 'h', 'h', 2, bins )
HTH,
Wim

1 Like

Thanks Wim, that worked.

Eric