Adding 2 TFile histograms with different axis limits

Hi,

I’m trying to add 2 histograms that I extracted from a TFile, meaning that I do not get to define the axis limits/bins.

This is my C++ code:
NumHist_d04->Add(HHist_ggf_d04);
NumHist_d04->Divide(ZeeHist_d04);
TCanvas *c16 = new TCanvas(“c16”, “RMISS d04”, 700,500);
NumHist_d04->Draw();

This is the error that comes up on the terminal:
Info in TH1F::Add: Attempt to add histograms with different axis limits - trying to use TH1::Merge
Error in TH1F::Merge: Cannot merge histograms - limits are inconsistent:
first: (6, 0.000000, 3.141593), second: (6, 0.000000, 3.141593)

I tried to set the axis limits using
->GetXaxis()->SetRangeUser(0,TMath::Pi());
and also tried the SetUser and SetLimits() functions for the 2 histograms I am trying to add, but the same error comes up.

Please let me know if you can think of what the issue is, and how to fix it - thanks!

I guess you need (and make sure that “y-axes” have consistent “limits”, too ):

NumHist_d04->GetXaxis()->SetLimits(0, TMath::Pi());
HHist_ggf_d04->GetXaxis()->SetLimits(0, TMath::Pi());

Thanks for taking the time out to reply!

I’ve tried that function and it didn’t solve the error either. Interestingly enough, when I set the x-axis range from 0 to anything above 3.7, it still only ever plots to 3.7. I don’t know if this is because of the way I’m reading the file in a certain way that it doesn’t like to be tampered with?

For both histograms, check what you get from:

histo->GetNbinsX()
histo->GetNbinsY()

BTW. I think, if you use “SetRangeUser” then only this part of the histogram will be drawn, regardless of a new “SetLimits”.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.