Extracting sub-histogram?

Fred Gray (fgray@alecto.physics.uiuc.edu)
Wed, 11 Mar 1998 15:33:59 -0600 (CST)


I'm looking for a way to extract a subset of the bins of one histogram into
a new histogram. I have a histogram which represents a signal waveform, and
I would like to be able to examine the signal over particular time intervals.

I've written a function to do this myself, but I suspect that this might be of
sufficiently general utility that there would be a cleaner way of doing it.
If not, please allow me to suggest it for future inclusion in the TH1 class.

Here's the function that I wrote, in case it's of use to you. Thanks for your
help!

TH1F *ExtractHistogram(TH1F *src, Text_t *name, Text_t *title,
Float_t min, Float_t max)
{
TAxis *axis = src->GetXaxis();
Int_t minBin = axis->FindBin(min);
Int_t maxBin = axis->FindBin(max);
Int_t nbins = maxBin - minBin + 1;

min = src->GetBinLowEdge(minBin);
max = src->GetBinLowEdge(maxBin+1);

TH1F *dst = new TH1F(name, title, nbins, min, max);

for(Int_t i = 1; i < nbins+1; i++)
{
dst->SetBinContent(i, src->GetBinContent(i+minBin));
}

return dst;
}

-------------------------------------------------------------------------------
-- Fred Gray Graduate Student --
-- fgray@physics.uiuc.edu Department of Physics --
-- University of Illinois at Urbana-Champaign --
-------------------------------------------------------------------------------