# FindFirstBinAbove for THStack

**URL:** <https://root-forum.cern.ch/t/findfirstbinabove-for-thstack/15589>\
**Category:** ROOT\
**Created:** [February 4, 2013, 6:53pm UTC](https://root-forum.cern.ch/t/findfirstbinabove-for-thstack/15589 "2013-02-04T18:53:21Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jfcaron](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jfcaron](https://root-forum.cern.ch/u/jfcaron)\
**Post date:** [February 4, 2013, 6:53pm UTC](https://root-forum.cern.ch/t/findfirstbinabove-for-thstack/15589/1 "2013-02-04T18:53:21Z")

</div>

Hi, I quite enjoy making histograms with a fixed bin width where I set the maximum/minimum bins to very large values to avoid overflows. E.g. in PyROOT:

```auto
binwidth = 0.1
minbin,maxbin = -1000,1000
nbins = (maxbin-minbin)/binwidth
h = ROOT.TH1F("h","h",nbins,minbin,maxbin)
```

Then to draw the histogram properly for looking at, I use:

```auto
firstbin = h.FindFirstBinAbove(0)
lastbin = h.FindLastBinAbove(0)
h.GetXaxis().SetRange(firstbin,lastbin)
```

I have now a THStack with multiple histograms in it, and it is tedious to have to create a set of first/last bins and SetRange to the minimum/maximum of those sets. Would it be possible to add a FindFirstBinAbove and FindLastBinAbove method to THStack that returns the first/last bin of any of the histograms contained therein? Or is there instead a better way to properly set the axis of a THStack such that only the range of populated bins are displayed?

Thanks,  
Jean-François

---

_[View the full topic](https://root-forum.cern.ch/t/findfirstbinabove-for-thstack/15589)._
