Pyroot plotting 2 different histograms from different files on the same canvas

Hi,

I am trying to plot 2 histograms that are on different root file on the same canvas.

tree1.Draw(‘Electron.Eta’)
tree1.Draw(‘Electron.Phi’,‘Same’)

If two different histograms are on the same file, I am able to plot them together like above example.

tree1.Draw(‘Electron.Eta’)
tree2.Draw(‘Electron.Eta’,‘Same’)

But in this example, I cannot plot them together. Histograms are in the branch of the TTree. I couldn’t find any other method to plot the histograms, and with this method I am able to plot them, but I cannot plot them together. How can I fix this problem or do you suggest me any other method? Thank you in advance.

1 Like

Hi,

I would propose to address this question with RDataFrame, the modern way of dealing with ROOT columnar data, like TTrees.

df = ROOT.RDataFrame("myTreeName", "myFileName.root")
h1 = df.Histo1d("Electron.Eta")
h2 = df.Histo1d("Electron.Phi")

h1.Draw()
h2.Draw("Same")

Assuming that plotting eta and phi on the same canvas is the desired objective.

Cheers,
D

1 Like

With this method I can plot them on the same canvas. Thank you so much!

1 Like

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