Creating an Histo1D with bins of different size

Hi to everybody, I’ve created an histogram Histo1D from an RDataframe called df, using the following definition:
histo = df.Histo1D((“Histogram”,“Histogram_background”, 40, 0., 0.2),‘DNN’,‘weight’)
The histogram has 40 bins between 0 and 0.2.
For graphic reasons, I’d like to change this code with the definition of the Histo1D with bin of different size, defining the sizes for every bin. Anyone has some advices?
I’m currently using python.
Cheers, Michele

You can use this constructor.

The definition is the same also for RDataframe.Histo1D? Because I think RDataframe hasn’t the attribute TH1D.

That first argument to Histo1D is of type TH1DModel, which also supports that construction with a list of bin widths.

I am not 100% sure what’s the simplest way to pass that array of doubles in PyROOT, but if you have any issue we can certainly provide an example.

I’m currently defining the array as:
bins=[0.002,0.003,0.005,0.007,0.008]
and the Histo1D as:
histo1 = df.Histo1D((“Histogram1”,“Histogram_background”, 5, bins),‘DNN’,‘weight’)

The error presented is ‘TypeError: can not resolve method template call for ‘Histo1D’’

Alright, example coming up xD

So, since the C++ signature wants an array (double *), from Python you can pass a numpy array or an array.array, but not a list:

model = ROOT.TH1DModel("h","h",3,np.array([1.,2.,3.,4.]))
ROOT.RDataFrame(10).Histo1D(model, "rdfentry_")

I hope this helps!
Enrico

Thanks, I will try!