Reset to 0 top "N" bits in a TH1x

___Hi, I have a histogram with, say, 100 bins containing from 0 to N entries each.
What I would like to do, is reset to 0 only the, say, 10 most populated bins.
How can I do that? Thanks!

Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34
Platform: Xubuntu Linux
Compiler: some gcc (latest, presumably)


Just to be clear: I could of course make a vector with GetBinContent, sort it, find the greatest N values, go back to their bins with some mechanism (another vector?)etc. etc. That’s trivial (and tiresome to code) but I am sure there is a more intelligent way to do it. That’s what I am asking.
Thanks again!

for (int i = 0; i < 10; i++) h->SetBinContent(h->GetMaximumBin(), 0.);

Brilliant! Thanks!!!

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