Adding histograms with different axis limits


I am trying to subtract two histograms that exist as leaves of a TTree. I am having trouble with the binning.

TH1F genMEThist = (TH1F)gPad->GetPrimitive(“genMET”);
TH1F patMEThist = (TH1F)gPad->GetPrimitive(“patMET”);

TH1F diff = (*genMEThist)-(*patMEThist);
Warning in TH1F::Add Attempt to add histograms with different axis limits

The Warning is valid because both plots have 100 bins, but genMEThist max input is 110 and patMEThist max is 138. So it is just subtracting by bin number, not by actual input, and the bin size of each histogram is different.

I thought to just rebin one to the bins of the other and then define a new TH1F from the rebin.

Int_t i=0;
Int_t nbins=101;
Double_t xbinsgen[101];


TH1F patMEThistRebin=(TH1F)patMEThist->Rebin(nbins-1,“patMEThistRebin”,xbinsgen);

TH1F diff2 = (*genMEThist)-(*patMEThistRebin)
still gives same error.

I realize that the binning is not the only problem here, the actual axis limits also need to line up. But I am stuck here. Any help or a simpler method would be very much appreciated.

Thanks in advance!

p.s. I am using
ROOT 5.22/00a (branches/v5-22-00-patches@27437, Jul 21 2009, 01:05:00 on linux)

CINT/ROOT C/C++ Interpreter version 5.16.29,

if you want to add, compare histograms, you should force a common binning, eg when creating them