In trying to compare two histograms, I notice that when I change the limits of the histogram so that I can draw them on the same canvas that it changes their distribution and maxima. I thought maybe this was a problem with histograms, so I tried a THStack
but that gave me the same problems.
Is this a known problem with SetLimits()
? Is there some sort of workaround? I’ve put my code below to reproduce what’s showing two different maxima after the change in limits.
#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");
if (hist == NULL) return 0;
hist->BufferEmpty(-1);
cout << hist->GetMaximum() << endl;
hist->GetXaxis()->SetLimits(250, 950);
hist->BufferEmpty(-1);
cout << hist->GetMaximum() << endl;
return 0;
}
temp.root (6.1 KB)
I’ve tried using SetRangeUser()
, but that doesn’t change the limits and I get some incorrect histograms when drawn regularly and warnings when tried with a THStack
.
(I’m mostly concerned that the distribution was changing because I was under the impression that once the histogram is filled, the histogram is unaware of the specific bin contents and cannot redistribute like this. If this is wrong, it would explain my problem.)
hist.pdf (14.2 KB) histAfterLimits.pdf (14.1 KB)
Please read tips for efficient and successful posting and posting code
ROOT Version: ROOT 6.02/05
Compiler: GCC 4.9.1