Division of 2 TH1Ds with weighted entries

Hi all,
With ROOT 5.10/00, I construct two TH1Ds, apply ::Sumw2() on them, fill them with entries of various weights, try to divide one of the TH1Ds by the other (ResultingTH1D.Divide(…,…,1.,1.,“b”)), get ResultingTH1D which is empty.

When I save the 2 inital filled TH1Ds in a .root, retrieve them from the .root file and make the division operation, ResultingTH1D is filled but the weights applied on the events seem to be not considered when building the error bars.

May you help?
Cheers,
Ludovic

Please post a file containing your 2 histograms and a few lines script showing what you do.

Rene

Hi,
In attached files :

  • histos.root contains the initial TH1Ds,
  • histosDIV.C computes the division of a TH1D by another one.

I observe that the vertical error bars of the ResultingTH1D when using ROOT 5.10 and 5.14 are slightly different. With the first version, the error bars are equal to the error bars when weights are not considered.
May I rely on the error bars by ROOT 5.14?

Each inital TH1D was filled with various weights.

With both versions, when I construct the two initial TH1Ds, apply ::Sumw2() on them, fill them with entries of various weights, try to divide one of the TH1Ds by the other (ResultingTH1D.Divide(…,…,1.,1.,“b”)) in a same .C (without retrieving the TH1Ds from a .root file), ResultingTH1D is empty.
Cheers,
Ludovic
histosDIV.C (3.18 KB)
histos.root (6.65 KB)

You must call TH1::Sumw2 on at least on your histograms before making the division.
see modified file in the attachment
see doc of TH1::Divide at: root.cern.ch/root/html/TH1.html#TH1:Divide

Rene
histosDIV.C (3.28 KB)

I called TH1::Sumw2 on the inital histograms before filling them.
When I call TH1::Sumw2 on the histogram which will contain the result of the division of an initial histogram by another one, then error bars are the same as before (when TH1::Sumw2 not called).
Ludovic

Hi,

division of weighted histograms with binomial statistics (option “b”) has been implemented only since ROOT version 5.14. In older vrsions errors are the same as when weights are not considered (as you noticed).

See for example root.cern.ch/phpBB2/viewtopic.php?t=3753 on the same topic.

Best Regards

Lorenzo

Hi Lorenzo,

Isn’t
fSumw2.fArray[bin] = TMath::Abs( ( (1-2w)e1e1 + wwe2e2 )/(b2*b2) ); (with e1 and e2 the bin errors for histogram 1 and 2)
correct in case of entries in an initial histogram with a constant weight, uncorrect in case (my case) the weights of the entries in the histogram vary?

Why the following behaviour? ->
With ROOT 5.10 and ROOT 5.14, when I construct the two initial TH1Ds, apply ::Sumw2() on them, fill them with entries of various weights, try to divide one of the TH1Ds by the other (ResultingTH1D.Divide(…,…,1.,1.,“b”)) in a same .C (without retrieving the TH1Ds from a .root file), ResultingTH1D is empty.

Cheers,
Ludovic

Hi Ludovic,

I think the formula is correct if we neglect the errors in the weight itself. They don’t need to be constant event by event.

Concerning your second point, can you send me the macro showing me that the resulting TH1D is empty, I haven’t noticed this behaviour,

Cheers

Lorenzo

Hi,
I made a mistake, I did TFile::Write() before the division, not after.
Cheers,
Ludovic