I have two files with histograms I want to add. Both files are created the same way, just extracting data from two different trees. The problem is when I want to add the two histograms, I get an error saying “Attempt to add histograms with different axis limits - trying to use TH1::Merge
Error in TH2D::Merge: Cannot merge histograms - limits are inconsistent:
first: (1, 0.000000, 1.000000), second: (100, -60.000000, 62.000000)”
That error message is displayed when I read the histograms from files using TH1::Get, but when I use TH1::Clone, I get: “Attempt to add histograms with different number of bins - trying to use TH1::Merge
Error in TH1D::Merge: Attempt to merge object of class: ??1 to a TH1D”
I cannot understand why this is happening since both histograms are defined the same way:
When I load the two files and do the TH1::GetSize, it returns the same size, 54 for both.
The error message explicitly mentions a “TH2D” while you talk about “TH1D”.
So, it seems to me that you try to add two different types of histograms.
Try something like:
and see what they really contain.
Sorry, I just copied a wrong line, since I’m trying to perform the same operation with two 2d histograms, but get the same error message.
I’m attaching my files and the script I’m using.
mergeRBBwithAll.C (3.21 KB)
RBBhistogram.root (117 KB)
AllButRBBhistogram.root (160 KB)
All four “TH2D” have different “axis limits” in both files.
mergeRBBwithAll.C (3.48 KB)
Thanks a lot for your reply.
I see that you changed my code quite a bit. Can you quickly explain to me why my version of the code didn’t work, even though the TH1D’s had the same number of bins? I know that TH2D’s are not exactly the same, I didn’t really expect it to work for them.
First of all … TFile::Clone clones the file itself (not the histogram in it).