FindFirstBinBelow

Hi, I am desiring of TH1::FindFirstBinBelow and FindLastBinBelow methods for my TH2. I know it’s probably not common enough to actually implement such methods for TH1, but I am wondering what is the best recommended procedure for finding the relevant bin numbers.

I am currently trying a thing where I do h->Scale(-1), then use FindFirstBinAbove with -1* the value I actually want, then h->Scale(-1) again. Unfortunately strange things happen when using Scale like this, e.g. the histogram fMinimum and fMaximum are changed, and zero bins are treated differently when the histogram is negated.

Is there an easy way to get access to the array of bin contents for a TH1, like for a TGraph::GetX() method? Then I could use an std:: algorithm. If necessary I’ll do a classic loop over integers from 0 to h->GetNbinsX(), but hopefully there is a more standard way.

Jean-François

I ended up implementing standalone functions that take TH2 * to do this. I just copied the code from the original FindFirstBinAbove methods and adapted them for a passed TH2 *. In case anyone is looking for something similar in the future, the implementation is here:

https://bazaar.launchpad.net/~jfcaron/+junk/Proto2BeamTest2/view/270/Utility.C#L388