Hallo,
I am looking for a way to add two histograms with correctly calculated errors. Since I have low statistics in each bin, I prefer the Possion errors that RooFit calculates for the bins.
Now I have also weights for each histogram and I want to have them considered as well (compare adding two TH1 histograms with weights with and with calling TH::Sumw2() before).
Here is my simple example with two histograms with one bin with a content of 100 (to simplify things and it’s in python):
test1=TH1F("test1","test1",10,-5,5)
test1.SetBinContent(5,100)
test2=TH1F("test2","test2",10,-5,5)
test2.SetBinContent(5,100)
x=RooRealVar("x","x",-5,5)
rtest1=RooDataHist("rtest1","rtest1",RooArgList(x),test1)
xframe=x.frame()
rtest1.plotOn(xframe,RooTreeData.PlotOpt())
xframe.Draw()
rtest2=RooDataHist("rtest2","rtest2",RooArgList(x),test2)
xframe=x.frame()
rtest2.plotOn(xframe,RooTreeData.PlotOpt())
xframe.Draw()
rtest1.add(rtest2,0,weight=0.5)
xframe=x.frame()
rtest1.plotOn(xframe,RooTreeData.PlotOpt())
xframe.Draw()
This doesn’t seem to work, I get in bin #5 an entry of 200 (should be 150). If a replace the last lines with
rtest2=RooDataHist("rtest2","rtest2",RooArgList(x),test2,0.5)
xframe=x.frame()
rtest2.plotOn(xframe,RooTreeData.PlotOpt())
xframe.Draw()
rtest1.add(rtest2)
xframe=x.frame()
rtest1.plotOn(xframe,RooTreeData.PlotOpt())
xframe.Draw()
I can already see in the plot of rtest2, that the error is sqrt(50), not sqrt(100)*0.5. Adding to rtest1 does not calculate correctly the error, too (despite the fact that the error of rhist2 was wrong in the first place).
What did I forget?
Thanks
Duc