Adding two histograms with errors and weights

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

Could you provide a concrete and running script showing the problem.
Your example shows code that cannot be executed like

x=RooRealVar("x","x",-5,5) rtest1=RooDataHist("rtest1","rtest1",RooArgList(x),test1)

Rene

Hallo,

so the adding of the two histogram seems to work correct now, then still the wrong error calculation remains. Here is the C-version of the code:

TH1F* test1=new TH1F("test1","test1",10,-5,5)
test1->SetBinContent(5,100)
TH1F* test2=new TH1F("test2","test2",10,-5,5)
test2->SetBinContent(5,100)

RooRealVar x("x","x",-5,5)
RooDataHist rtest1("rtest1","rtest1",x,test1)
RooPlot* xframe=x->frame()
rtest1->plotOn(xframe)
xframe->Draw()

RooDataHist rtest2("rtest2","rtest2",x,test2,0.5)
RooPlot* xframe=x->frame()

rtest2->plotOn(xframe)
xframe->Draw()

rtest1->add(rtest2)
RooPlot* xframe=x->frame()
rtest1->plotOn(xframe)
xframe->Draw()

With histogram TH1F I would just do TH1F->Sumw2() before a add the histograms. I cannot find something similar for RooDataHist.

Duc

Wouter will answer your point about RooDataHist once he will be back.

Rene

Hi,

To show the sum-of-weights errors when you plot a RooDataHist you should
specify that in the RooDataHist::plotOn call, i.e.

using namespace RooFit ;
rtest2.plotOn(xframe,DataError(RooAbsData::SumW2)) ;

Wouter