Rebin histogram to a variable bin size

Hello,

I searched this forum for previous posts but did not get something which specifically answers this:
is it possible using TH1::Rebin() to rebin a histogram having uniform bin sizes to a histogram with varibale bin size (of course each new bin size being an integral multiple of the old bin size)?

The ROOT documentation seems to hint that it is possible, but doing it has no effects on the bin size of the histo I
want to rebin and no error thrown up.

Code:

TH1F* h1 = new TH1F(“h1”,“h1”,250,0.,250.);
// Fill h1
Double_t newBins[7] = {0.,10.,20.,40.,60.,200.,250.};
h1->Rebin(6,“hnew”,newBins);
h1->Draw();

I tried this in ROOT 5.18 as well as 5.26.

Thanks,

Devdatta.

Hi,

In your case, a new histogram is created (see documentation for more details), use:H1F* h1 = new TH1F("h1","h1",250,0.,250.); // Fill h1 Double_t newBins[7] = {0.,10.,20.,40.,60.,200.,250.}; hnew = h1->Rebin(6,"hnew",newBins); hnew->Draw();Cheers,
Philippe.

1 Like

Hi Philippe,

Thanks for pointing out. The documentation seems to be quite explicit, on a second look.

Best regards,