Variable binning (irregular bin size) 1 D histogram filling

Hi,

I would like to get help for filling 1 D histogram with variable binning & irregular bin size from another 1D histogram’s bin contents with regular binning.
More specifically,
I have 2D scattering plot and get 1 D histogram with FitSlicesY. Now this 1 D histogram with regular bin size has to be converted into another histogram with desired variable (irregular) bin size within the range.

Can anybody please point me an example?
Thanks

see documentation of TH1::Rebin

// -case 2 xbins!=0 // a new histogram is created (you should specify newname). // The parameter is the number of variable size bins in the created histogram. // The array xbins must contain ngroup+1 elements that represent the low-edge // of the bins. // If the original histogram has errors stored (via Sumw2), the resulting // histograms has new errors correctly calculated. // // examples: if h1 is an existing TH1F histogram with 100 bins // Double_t xbins[25] = {...} array of low-edges (xbins[25] is the upper edge of last bin // h1->Rebin(24,"hnew",xbins); //creates a new variable bin size histogram hnew

Rene

Hi Rene,
Thanks. But, upto creating the histogram with desired binning is fine but filling correctly is a problem for me.

double xbin[9]={20,30,40,50,75,100,200,350,2000};
int nbins = LeptonInvPtResVPtGen_Scatter4_2->GetNbinsX();
TH1F* GR = new TH1F("","" ,8, xbin );

HERE, I need HELP. It is not correct what I am trying to do but recreates the original.

for (int ibin = 1; ibin <= nbins; ibin++) {
double GR_bin_4 = LeptonInvPtResVPtGen_Scatter4_2->GetBinContent(ibin);
double GR_bin_4_error = LeptonInvPtResVPtGen_Scatter4_2->GetBinError(ibin);

GR->SetBinContent(ibin,GR_bin_4);
GR->SetBinError(ibin, GR_bin_4_error);

GR->Draw();
}

adding to my previous reply.

TH1F *hnew = LeptonInvPtResVPtGen_Scatter4_2->Rebin(8,“hnew”,xbin);
hnew->Draw();

New histogram gives greater value than the original value in the range (even from the highest bin) for a modified bin size.
eg.
Original histo has 4% -4.5% for 200-360 in 4 bins
Modified histo has 10.5 % for 200-350 in 1 bin

That’s where I see the problem when I simply do rebin. Could you please clarify it?
Thanks

Could you post a small root file containing your histogram before rebinning?

Rene

Here is my root files attached.
Please have a look.

test.root has 2D scattering plot of name LeptonInvPtResVPtGen_Scatter4
Then I FitSlicesY and get 1D LeptonInvPtResVPtGen_Scatter4_2 (saved as test_sigma.root)
It has to be rebinned (irregular bin size).

Thanks
test_sigma.root (15.5 KB)
test.root (647 KB)

I do not understand your rebinning!
The slice “LeptonInvPtResVPtGen_Scatter4_2” has a bin-width of 40, the first bin is from 20->60 and the second from 60->100.
Now you try to rebin into a new histogram where the 1st bin is from 20->30 and the second from 30->40. The rebinning makes sense only when the bin edges are identical. For example you could define the 1st bin going from 20->100 and the 2nd from 100->400.
In your comparison you should also take into account the normalization, ie divide by the bin-width.

Rene

Thanks.
Finally, I defined the required binning in the original script so that my original root file has the histogram filled accordingly.
No rebinning …
Thanks again