Change histogram binning using array

Dear expert,
I have an histogram, then I want to change it binning using an array. I saw the SetBins method but when I use it, the histogram is empty. Do you see what is wrong or how can I do that? I made a small code (1).

void test(){

TH1D *hist = new TH1D(“h”, “h”, 100, -20, 20);

hist->FillRandom(“gaus”, 10000);

double bin[]{-20, -18, -15, 0, 10, 20};

hist->SetBins(5, bin);



What’s lost is lost: TH1::SetBins

Dear Coyote,
ok, then how can I change the binning? I need bins which vary so Rebin will not work.

I have no idea what you are trying to do.
Simply create your histogram with your preferred binning and then fill it.

The histogram keeps no memory of the data-points that filled it, so there is no way to “keep the same points but change the binning”. The information you would need is lost. The only operation that one can perform on bins is to merge them together, that is well-defined.

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