Subtraction of 2D histograms

Hi rooters,
Please you guys should help me with how I can subtract: I have an already fill 2D h1 and h2 both with bin 0 to 1000. I want to subtract only bin 0 to 800 of h2 from h1.
Thanks so much and looking forward to your response

The easiest way might be to clone the histogram you want to subtract, set the bins above 800 to zero, and then perform the subtraction as usual. @couet may have a better suggestion for how to do this, though.

Yes I saw your post and I had the same idea in mind and could not think of a better way to do it.

You can also create a new empty histogram with the same binning as h1 and h2. Loop over the first 800 bins and for each bin do:

h3->SetBinContent(i)(h2->GetBinContent(i)-h1GetBinContent(i);

May be @moneta has a better idea.

Hi,
I think what has been suggested is the best you can do.
The only comment I have is that if you are looping on the bin contents yourself and subtract the content, you might want also to set the correct bin error, using SetBinError.
If you follow the first procedure, it will be computed automatically

Lorenzo

Thanks alot. I will try it out

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