Rebinning variable-binsize weighted histo

I’m struggling to rebin a variable bin-sized histogram and getting the errors right. The histogram has been created by adding up other histos, each with a weight, with TH1::Add(histo, weight).

So I want to rebin (i.e. merging a few bins), and I found this link which suggests how to do this for a variable-bin-sized axis (post 2 by Rene) TH1 Weighted Fill. Problem with errors and draw. This will assure the contents are correct, but not the errors. Is there a way to do this?

EDIT: There’s a way to do this automatically with 1D histos (Rebin(Int_t ngroup, const char* newname, Double_t* xbins)) but this is not valid for 2D histos.

Hi,
Rebinning one or both axis of a 2D histogram by passing an array of bin edges is not supported. It is for for the 1-dimensional histogram using TH1::Rebin when passing an array xbins, see
root.cern.ch/root/html/TH1.html#TH1:Rebin

If you are willing to extend the 1d code to make it working for the 2D case, I am happy to include it in ROOT

Best Regards

Lorenzo

I am faced with this same problem, it would be great to have a 2D version of the variable bin width rebin that is available for 1D histograms. In principal it seems like it wouldn’t be hard to implement, since a 2D histogram is just an array of 1D histograms, it’s just a matter of chopping the 2D one up, rebining them using the existing 1D function, and merging them again.