I am interested in searching the first bin above a given threashold for a given peak. I am awar about the FindFirstBinAbove function. However, if I use it, I get a value for the whole histogram.
Instead, I would like to get the bin in a given range such as between 2000 and 4000 as shown below:
TH1::FindFirstBinAbove could be easily modified and submitted as a pull request. Or it could be used as a framework for a custom function. Here is the modified function:
Int_t TH1::FindFirstBinAbove(Double_t threshold, Int_t axis, Int_t firstBin=1, Int_t lastBin=-1) const
{
if (fBuffer) ((TH1*)this)->BufferEmpty();
if (axis != 1) {
Warning("FindFirstBinAbove","Invalid axis number : %d, axis x assumed\n",axis);
axis = 1;
}
if (lastBin < 0 || lastBin > fXaxis.GetNbins()) {
lastBin = fXaxis.GetNbins();
}
for (Int_t bin=firstBin;bin<=lastBin;bin++) {
if (RetrieveBinContent(bin) > threshold) return bin;
}
return -1;
}
You can do it since you have already almost done the job. Note that the patch should also apply for at least TH1::FindLastBinAbove. We may also consider to do the same for TH2::FindFirstBinAbove and TH3::FindFirstBinAbove.
If you are too busy, I can submit the pull request.