How to count no. of entries per bin in a histogram?

Dear All,
I want to count entries corresponding to each bin so that I can have idea which decay mode is contributing how much to the backgrounds. Could you please help me out with some sample code ?

Thanks.


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


TH1::GetBinContent

Thanks for your reply. I am trying this hist1->GetBinContent(100);.
But it gives me nothing.
Shall I apply inside for loop ?

I want all the bin numbers to be printed with corresponding entries.
Please feel free to update my code.
modeadz.C (426 Bytes)

Your histogram has 80 bins in total, and you try to get the contents of the bin 100?

It seem to me that you want:
hist1->GetBinContent(hist1->FindFixBin(100.))

No, it is not showing me anything extra. I tried with hist1->GetBinContent(hist1->FindFixBin(100.));.
Just drawing the hist1 but not giving any extra information.

Thanks

Why would it show anything?
It seems to me you want:
std::cout << hist... << std::endl;

Right !
How can I apply a counter here so that it can keep on printing entries for all bins.

Thanks.

for (int i = 1; i <= hist1->GetNbinsX(); i++) std::cout << hist1->GetBinContent(i) << std::endl;

1 Like

Thanks a lot. It did work.

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