Error merging histograms with "similar" x range

Hi all, having some issue with histogram adding. I keep getting the following error:

Info in <TH1D::Add>: Attempt to add histograms with different axis limits - trying to use TH1::Merge
Error in <Merge>: Cannot merge histograms - limits are inconsistent:
 first: SiPM_A_OR_D (100, 0.000000, 1.022260), second: SiPM_A_OR_D (100, 0.000000, 1.022260)

I assume one is actually 1.022260001 and the other is 1.022260002 or something. These are time stamps from our detector system and don’t always match up perfectly. Otherwise the histogram is identical. 100 bins, roughly the same range. What’s the best way to add these?

Cheers


Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.24
Platform: Ubuntu/C7
Compiler: Not Provided


If these are ordinary “fix bin sizes” histograms, you could simply “align” their axes (neglecting the “imperfect” time stamps) using:
SiPM_A_OR_D->GetXaxis()->SetLimits(0., 1.022260);
or:
SiPM_A_OR_D->GetXaxis()->Set(100, 0., 1.022260);

Thanks for the quick response…

Now will this truncate my histogram to match said axis or will it “squeeze” it into that window if that makes sense?

Lets say I have one histo in the range (0, 100) and another in the range (0,1000), both with 100 bins.

Can I then force set the range of the second one to (0, 100) and not have invalid results?

Cheers.

The trick I’ve shown redefines “xmin” and “xmax”, leaving the number of bins unchanged, so it “scales” the x-axis of the histogram.

If you now want to say that x=1000 in the second histogram directly corresponds to x=100 in the first one, then you can use this trick.

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