# TH1 methods can't find correct minimum and maximum values for a filled histogram

**URL:** <https://root-forum.cern.ch/t/th1-methods-cant-find-correct-minimum-and-maximum-values-for-a-filled-histogram/42894>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [December 29, 2020, 9:04pm UTC](https://root-forum.cern.ch/t/th1-methods-cant-find-correct-minimum-and-maximum-values-for-a-filled-histogram/42894 "2020-12-29T21:04:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jemarq04](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@jemarq04](https://root-forum.cern.ch/u/jemarq04)\
**Post date:** [December 29, 2020, 9:04pm UTC](https://root-forum.cern.ch/t/th1-methods-cant-find-correct-minimum-and-maximum-values-for-a-filled-histogram/42894/1 "2020-12-29T21:04:45Z")

</div>

I was trying to compare a pair of histograms by drawing on the same canvas, but I needed to resize. When resizing, I found that none of the TH1 methods were giving me accurate values. For instance, all of the following methods returned 0:

```auto
hist->GetXaxis()->GetXmin();
hist->GetXaxis()->GetXmax();
hist->GetMinimum();
hist->GetMaximum();

```

and the FindFirstBinAbove and FindLastBinAbove methods from [this thread](https://root-forum.cern.ch/t/getminumum-value-x-axis-for-th1/24424) return -1, as though it were an empty histogram. I checked on a TBrowser, and the histogram is filled and has 1000 entries. Is there something wrong here?

I’ve loaded my testing code and a root file containing the histogram:

```auto
#include <iostream>
#include "TFile.h"
#include "TH1.h"
using namespace std;

int main(){
	TFile *f = new TFile("temp.root");
	if (f == NULL) return 0;
	TH1F *hist = (TH1F*)f->Get("EBRecHits");
	cout << "Entries : " << hist->GetEntries() << endl;
	cout << "GetXmin() : " << hist->GetXaxis()->GetXmin() << endl;
	cout << "GetXmax() : " << hist->GetXaxis()->GetXmax() << endl;
	cout << "FindFirstBinAbove()	: " << hist->FindFirstBinAbove() << endl;
	cout << "FindLastBinAbove()	: " << hist->FindLastBinAbove() << endl;
	cout << "GetMinimum() : " << hist->GetMinimum() << endl;
	cout << "GetMaximum() : " << hist->GetMaximum() << endl;
}

```

[temp.root](https://root-forum.cern.ch/uploads/short-url/dqqDznAogYtLZ0vY8ZZVg1cggy6.root) (5.9 KB)

(It should be mentioned that I created these histograms originally with my limits as 0 so that it would automatically resize as it was filled. Could this be affecting the results of the methods?)

Edit: I should also mention that I know that GetMinimum() and GetMaximum() will not be returning the same value as GetXmin and GetXmax, but I was still shocked at getting zero values for those as well.

* * *

_ROOT Version:_ ROOT 6.02/05  
_Compiler:_ GCC 4.9.1

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 29, 2020, 11:25pm UTC](https://root-forum.cern.ch/t/th1-methods-cant-find-correct-minimum-and-maximum-values-for-a-filled-histogram/42894/2 "2020-12-29T23:25:32Z")

</div>

```cpp
hist->BufferEmpty(-1); // (-1) or maybe (1) ???
std::cout << hist->GetBinContent(hist->GetMinimumBin()) << std::endl;
std::cout << hist->GetBinContent(hist->GetMaximumBin()) << std::endl;

```

---

<div class="post-metadata">

**Author:** ![jemarq04](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@jemarq04](https://root-forum.cern.ch/u/jemarq04)\
**Post date:** [December 30, 2020, 6:08pm UTC](https://root-forum.cern.ch/t/th1-methods-cant-find-correct-minimum-and-maximum-values-for-a-filled-histogram/42894/3 "2020-12-30T18:08:55Z")

</div>

The `BufferEmpty(-1)` call worked perfectly! Thank you so much!
