Histogram entries

Hi guys,
I have a question about how to get the total number of entries from an histo related to the distribution of energy. If I want to take the entries of an histrogram only if the energy is larger than 0, how can I do?
Generally speaking, I want to take the total number of entries only if I have a non null energy deposit.

thanks

May be something like that:

TH1F *hist = ...;
int totalEntries = 0;
for (int i = 1; i <= hist->GetNbinsX(); i++) {
    if (hist->GetBinContent(i) > 0) {
        totalEntries += hist->GetBinContent(i);
    }
}

?

It is unclear what you have and what you want.
Is it a 1-D, 2-D, or 3-D histogram?
Is the “energy” the histogram’s “x-axis”?
Has your histogram any bins with “negative content”?

Hi @Wile_E_Coyote ,

I have a given number of 1D histos. The X axis has only positive values starting from 0 up to a maximum value. Each histogram has a total number of entries equal to 65k, but for some histos all these entries are equal to 0, so the histo is empty. What I want to do is taking the number of entries from each histo.
If I simply use the command GetEntries() I get the same number 65000 for all of them. But I am interested only in the histrograms with non null entries.

histo->Integral() /* default range = all bins */
histo->Integral(2, histo->GetNbinsX()) /* skip the first bin (which starts from x = 0.) */
histo->Integral(histo->FindFixBin(0.) + 1, histo->GetNbinsX()) /* bins with x > 0. */

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.