Variable bin size in TH2 histograms

Dear all,

I tried to create a TH2F histogram with a variable binning on the x-axis. Afterwards I simply plotted it in a canvas. In the root shell up to now it work, but when quitting root, root crashes completely with the error message:

*** glibc detected *** /opt/root_v5-26-00b/bin/root.exe: double free or corruption (!prev): 0x095633d8 ***

and then a huge list of backtraces.

I tried to create the histogram with the following code:

Float_t ptcalcbinning1[4] =  {0.5 ,1 ,2 ,5};
Float_t ptcalcbinning2[4] = {14,40,100,200};
Float_t ptcalcbinning3[5] = {1,15,28,43,53};
Double_t ptbinning[52];
ptbinning[0] = 0;
for ( int j = 0; j < 4 ; j ++ ){
	for ( int i = ptcalcbinning3[j]; i<ptcalcbinning3[j+1]; i++){ 
	ptbinning[i] = ptbinning[i-1] +	 ptcalcbinning1[j];

TH2F *Resolution_E_dPt_Ptrebin = new TH2F("Resolution_E_dPt_Ptrebin", "Electron Resolution dPt vs Pt ", 51, ptbinning , 200, -5., 5.) ;		

TCanvas * c1_2 = new TCanvas("c1_2","",10,10,500,500);  // gives the page size		

I am not sure whether I did something wrong. And actually I don’t have any clue where this error might come from. But I really need this variable binning. Therefore would anybody be so kind so send me an example. Or tell me were my code went wrong. Because if I try to plot it with the same code in a macro, what I would need, it crashes immediately. Can it be that it because the histogram is empty? The root version I am using is root v5-26-00b.


Can you post a small running script reproducing the problem ?

Yes, here it is. Run it and then quit root.

It will reproduce the error directly.
Regards Friederike
variablebinningTH2.C (673 Bytes)

I managed to reproduce the problem with the following macro.
The problem is not connected to the histogram. See comments in the macro:

   Float_t p1[4] =  {0.5 ,1 ,2 ,5};
   Float_t p2[4] = {14,40,100,200};            
   Float_t p3[5] = {1,15,28,43,53};
   Double_t bin[52]; // <==== Should be 53
   bin[0] = 0;
   for ( int j = 0; j < 4 ; j ++ ){
      for ( int i = p3[j]; i<p3[j+1]; i++){
        bin[i] = bin[i-1]; // i = 52 at some point

Thanks a lot! And sorry for such a stupid question.