Re: Extracting sub-histogram?
Rene Brun (Rene.Brun@cern.ch)
Thu, 12 Mar 1998 11:00:27 +0100
Fred Gray wrote:
>
> 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;
> }
I agree that this kind of function would be useful.
However, in the implementation one has to consider 1-D, 2-D and 3-D
histograms with fix or variable bin sizes and also profile histograms.
The input should be bin numbers and not boundary values on the axis.
Rene Brun