TRatioPlot weird behaviour in division

Dear Rooters,

I encountered some weird results while trying to construct some ratio plots using the TRatioPlot class. I’m using pyroot to construct histograms from lists/numpy arrays and, depending on how I define the bin contents, I get some pretty weird results. Consider this example:

arr1 = np.array([1,2,3,4])
arr2 = 1.5 * arr1

h1 = ROOT.TH1D( ROOT.TVectorD(len(arr1),arr1.astype(np.float64)) )
h2 = ROOT.TH1D( ROOT.TVectorD(len(arr2),arr2.astype(np.float64)) )

rpl = ROOT.TRatioPlot( h1, h2 )
ri = rpl.GetCalculationOutputGraph()

c=ROOT.TCanvas()
ri.Draw('ap')
c.Draw()

Now, I understand that the default method used is the TGraphAsymmErrors::Divide function which tries to estimate an efficiency rather than calculate the simple ratio. If I wanted to calcluate the latter I can use the “divsym” option in TRatioPlot and get a constant 0.6666… as one would expect. What irks me is that the result of the default calculation of the ratio depends on the values of the histogram bin errors. This detail is particularly hard to spot as the result with and without the ‘divsym’ option is identical in most other cases – eg. when the histogram bin contents are integer numbers. I believe most users wanting to use the TRatioPlot would incorrently assume that it only uses the histogram bin contents to calculate the ratio. I suggest there should be a sentence added to the documentation to help other users avoid this pitfall.

Cheers,
Alex


ROOT Version: 6.26
Platform: linux
Compiler: Not Provided


May be @moneta can help.

Hi,

Apologies for the late reply. The problem is that in TGraphAsymmErrors::Divide the bin histogram counted as rounded. This is happening because the histogram is considered unweighted, although the bin content is not an integer. This is a bug in teh way the histogram is handled there, I will provide a PR fixing this. As a workaround just do for example this (set correctly the error for the scaled histogram):

for i in range(0, 4): 
  h2.SetBinError(i+1,1.5 * h1.GetBInError(i+1))

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.