Fill style does not display correctly when using RDataFrame.Histo1D with event weight

Hi,

I have an issue where using RDataFrame.histo1D(model, vName, wName) results in the fill style of a histogram being displayed incorrectly.

I am using pyROOT with python 2.7.15.

Here is a standalone working example:

import sys
sys.argv.append('-b')
import ROOT

def fill_tree(treeName, fileName, N):
    tdf = ROOT.ROOT.RDataFrame(N)
    tdf.Define("b1", "(double) tdfentry_")\
       .Define("b2", "(int) tdfentry_ * tdfentry_")\
       .Define("b3", "(double) tdfentry_").Snapshot(treeName, fileName)

treeName = "myTree"
fileName = "myfile.root"
fill_tree(treeName, fileName, 1000)

fileName = "myfile2.root"
fill_tree(treeName, fileName, 100)

fileName = "myfile3.root"
fill_tree(treeName, fileName, 100)

fileName = "myfile4.root"
fill_tree(treeName, fileName, 1000)

test_chains = {}
test_chains['cat_1'] = ROOT.TChain("myTree")
test_chains['cat_1'].Add("myfile.root")
test_chains['cat_1'].Add("myfile2.root")

test_chains['cat_2'] = ROOT.TChain("myTree")
test_chains['cat_2'].Add("myfile3.root")
test_chains['cat_2'].Add("myfile4.root")

h = ROOT.TH1D('h', 'h', 100, 0., 1000.)
h_model = ROOT.RDF.TH1DModel(h)

c = ROOT.TCanvas('c', 'c', 900, 960)
c.Draw()
legend = ROOT.TLegend(0.7, 0.8, 0.9, 0.9)
legend.SetBorderSize(1)
hs = ROOT.THStack('hs', 'hs')
colors = [ROOT.kRed, ROOT.kBlue, ROOT.kMagenta, ROOT.kGreen, ROOT.kCyan]
color_idx = 0
RDF = ROOT.ROOT.RDataFrame
for _type, chain in test_chains.iteritems():
    c.cd()
    d1 = RDF(chain)
    #h1 = d1.Histo1D(h_model, 'b1') # switch this line for the one below to see correct filling
    h1 = d1.Histo1D(h_model, 'b1', 'b3')
    h1 = h1.Clone()
    print("{} histogram has {} entries".format(_type, h1.GetEntries()))
    h1.SetFillColor(colors[color_idx])
    h1.SetLineColor(colors[color_idx])
    color_idx = (color_idx + 1) % len(colors)
    legend.AddEntry(h1, '{}'.format(_type), "f")
    hs.Add(h1)
    hs.Draw()
    legend.Draw()
    #c.Update()
    #c.Draw()
    #c.SaveAs('test.pdf')

hs.Draw()
legend.Draw()
c.Update()
c.Draw()
c.SaveAs('test.pdf')
c.Close()
exit(0)

It is perhaps worth noting that when the column selected as wName is filled with ones the filling behaviour works as intended.

Is this behaviour expected or should this be reported as a bug?

Thanks,
Thomas


ROOT Version: 6.14/04
Platform: SL6
Compiler: 6.2.0


Hi Thomas,

thanks for the example.
Is RDF really a necessary ingredient of this unexpected behaviour or can the reproducer be further slimmed down? I suspect this is just due to the THStack and weighted histos.

Cheers,
D

Hi Danilo,

You are of course correct.

I was not aware that this subtly existed with weighted histograms and THStack objects.

I see from this other post that the solution is to change:

hs.Draw()

to

hs.Draw("hist")

Thanks very much for you help in solving my issue!

Cheers,
Tom

Hi Tom,

thanks for following up! Frankly you did everything by yourself :slight_smile:

Cheers,
D

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