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

**URL:** <https://root-forum.cern.ch/t/fill-style-does-not-display-correctly-when-using-rdataframe-histo1d-with-event-weight/33765>\
**Category:** ROOT\
**Tags:** rdataframe, python, hist\
**Created:** [April 25, 2019, 2:15pm UTC](https://root-forum.cern.ch/t/fill-style-does-not-display-correctly-when-using-rdataframe-histo1d-with-event-weight/33765 "2019-04-25T14:15:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Charman](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/thomas_charman/32/19394_2.png) [@Thomas\_Charman](https://root-forum.cern.ch/u/Thomas_Charman)\
**Post date:** [April 25, 2019, 2:15pm UTC](https://root-forum.cern.ch/t/fill-style-does-not-display-correctly-when-using-rdataframe-histo1d-with-event-weight/33765/1 "2019-04-25T14:15:18Z")

</div>

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:

```auto
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

* * *

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [April 25, 2019, 6:56pm UTC](https://root-forum.cern.ch/t/fill-style-does-not-display-correctly-when-using-rdataframe-histo1d-with-event-weight/33765/2 "2019-04-25T18:56:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thomas\_Charman](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/thomas_charman/32/19394_2.png) [@Thomas\_Charman](https://root-forum.cern.ch/u/Thomas_Charman)\
**Post date:** [April 25, 2019, 7:38pm UTC](https://root-forum.cern.ch/t/fill-style-does-not-display-correctly-when-using-rdataframe-histo1d-with-event-weight/33765/3 "2019-04-25T19:38:19Z")

</div>

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](https://root-forum.cern.ch/t/thstack-not-filling-histograms-with-color/24577) that the solution is to change:

```auto
hs.Draw()

```

to

```auto
hs.Draw("hist")

```

Thanks very much for you help in solving my issue!

Cheers,  
Tom

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [April 26, 2019, 8:30am UTC](https://root-forum.cern.ch/t/fill-style-does-not-display-correctly-when-using-rdataframe-histo1d-with-event-weight/33765/4 "2019-04-26T08:30:28Z")

</div>

Hi Tom,

thanks for following up! Frankly you did everything by yourself 🙂

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 10, 2019, 8:30am UTC](https://root-forum.cern.ch/t/fill-style-does-not-display-correctly-when-using-rdataframe-histo1d-with-event-weight/33765/5 "2019-05-10T08:30:32Z")

</div>

Closed on May 10, 2019, 8:30am UTC

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