Rebin TH axis

Hello ROOTers

This may be a silly question but I didn’t manage to grab any answer from
forums nor ROOT tutorials.

During execution of my analysis algorithm I fill a TH2D histo with N bins.
At the end of this program I want to rebin the x axis of this histogram to have
n bins (n<N) with different width size but equal statistic content.

Ex:
TH2D h(“h”, “A 2D histo”, Nx, xMin, xMax, Ny, yMin, yMax );
/// loop on events
for ( … )
{
//…
h->Fill( x, y );
}

/// Build an array of bins with equal statistic content
double binArray[nx];
buildBinArray( binArray );

/// Want to do something like :
h->RebinXaxisAccordingTo( binArray );

Is there a way to use the same histogram along the whole program or have to
use a temporary histogram and then to make the one with the variable bin width from
the later (building a double array[n], instantiating the new TH2D histo, etc…) ?

I am using ROOT 3.04/02, I know this is a rather old version but this is the one packaged with the current ATLAS analysis framework release.

Cheers,

Sebastien.

Hi Sebastien,

You have to create a new histogram with the new bins specification, then loop on all bins of the original histogram and fill
the new histogram.

Rene Brun

Ok,

Thanks a lot for this quick reply.

Sebastien