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

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:

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

and the FindFirstBinAbove and FindLastBinAbove methods from this thread 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:

#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 (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


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

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