Adding histograms with different X ranges

Hi, Rooters,

I have a root file contains three histograms, two of them have same X range, [0,2]KeV, the bin number is 200.
The third one has a range of [0,10]KeV, with 1000 bins. For the third one, the meaningful data range is [0,2]KeV.

I need to add these three histograms up. I’m asking the possibility of truncating the third histogram to the same range as the other two. After doing this, I think it’s easy to add the three histograms up by applying TH1::Add().

Or, is there any other solution to add three histograms up ?

Thanks !

Best,
Junhui

Hi,

This has been solved by reading the third histogram in [0,2]KeV then SetBinContent().

Best,
Junhui

Hello, I now have a similiar problem. I have two histograms, one is from 0-3 MeV, 1000bins and the other one is form 0 to 10 MeV, 1000 bins. I need to add the first one to the second one. If you remember it, could please describe a detailed solution. I would be very thankful.

If what I suggested you in the other post does not work (ie: Merge) then you should loop on the histograms bins and use SetBinContent as suggested by @junhui.private