Subtracting Histograms

Hi,

I have a macro running that reads a root file and gets the histograms then I stack the multiple histograms.
I want to take the first histogram and subtract it from the second histogram and plots the difference on a separate canvas. I use the this code below to plot the difference but it always plots the first histogram and not the difference.

[code]TCanvas*c1 = new TCanvas(“c1”, “Subtraction”);

h1.Add(h2, -1);
h1->Draw();[/code] 

I’m really stuck here and I am new with ROOT and any help will be appreciated. Thank you.

Leo.

Attach your ROOT file with histograms here.

Thanks for your reply.

I think the problem is the number of bins. They are different from each histogram.
I need to find a way to normalize the bins for it to subtract from eachother.
I’ll try to work this by myself I see how far I get.

Sorry for the late reply.

Leo

Hi,

The problem is definitely the difference in the number of bins.

I was thinking that:
1.) I need to be able to get number of bins for the first histogram
2.) Compare it to the other histograms, if the other histograms bins are smaller add bins to them equal to the first histogram.
Then I think when I now subtract the histograms, it should work.

If I’m correct with my thinking then I really need help, [-o< I do not know how to even start modifying the code for (1.) and (2.)
I have attached my macro and the root file is too big to attach, use this link to download it : drive.google.com/a/leptosense.c … sp=sharing
firstHisto.C (2.52 KB)