GetEntries for a sub-range of a histogram

hi all,

i have a root file which only contains TH2F histograms, and i need to know how many entries there are for a subset of one of the axis.

in my case, the range of the histogram is x=(0,100), y=(0,7), but i only want to know how many entries there are in x=(20,30), y=(0,7).

i’ve tried many combinations of GetEntries(), SetLimits(), Integrate(), but nothing has worked (and the latter is not so useful for me, as the entries have weights != 1)

is there a simple way (e.g., an argument in GetEntries()), which i can use to return the number of entries for a sub-range? please note that i do not have access to the program which created the histograms, so i cannot re-fill them in the range that i would like.

many thanks in advance,

I don’t think it’s possible.

do you know if it’s possible to loop through the entries in the histogram and then determine if they fall within a given range? this would be far slower, but would achieve the result i need.

HIstograms have bins. Each bin is a single value (i.e. the bin’s contents). You can get the integral of bin contents in a given bin range. See and/or