TH2F histogram rebinning with different bin sizes

I need to rebin a 2D histogram with different bin sizes and locations on the two different axis. I looked at the API and I see ways to set the number of bins different on each axis but not the ability to set the low and high bin borders like you can for a 1D histo. I see that it kind of exists for the 2D but it does not look like you can have two different setups, one for each axis. Is there an easy way to do this without having to rerun my program with a modified histogram invocation. Thanks for any help.

I am running root version


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.16/00 27 June 2007 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

Compiled on 16 July 2007 for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.16.21, June 22, 2007

The histogram is currently from 0 to 400 on each axis and even binnings with 40 bins. I would like the x axis to have three bins; 0 to 70, then 70 to 130 , and then finally 130 to 400. On the y axis I would like to have 0 to 50, then 50 to 100, and finally 100 to 400. Again, thanks for any help.

Justace

We do not have this functionality for 2-D histograms. But you can easily rebin by doing something like:

{ TH2 *old; //the original histogram //create a new TH2 with your bin arrays spec double xbins[4]={0,70,130,400}; double ybins[4]={0,50,100,400}; TH2F *h = new TH2F("oldrebin",old->GetTitle(),nx,xbins,ny,ybins); TAxis *xaxis = old->GetXaxis(); TAxis *yaxis = old->GetYaxis(); for (int j=1; j<=yaxis->GetNbins();j++) { for (int i=1; i<=xaxis->GetNbins();i++) { h->Fill(xaxis->GetBinCenter(i),yaxis->GetBinCenter(j),old->GetBinContent(i,j)); } } }

Rene

Thanks.

I should have thought to do that.
Is this a feture that will be included in future releases?

Justace

No plans for the time being.
In case you want to rebin both x and y axis, it is more efficient to do it in one single pass like shown in my example. In addition the UI could be quite complex, in particular in another user requests the same feature for 3-d histograms.

Rene