Hi,
I am having trouble drawing legend, legend does not get drawn if I put the Draw statement in a function, though it does draw if the Draw statement is outside.
A simple example is
from ROfrom ROOT import *
file=TFile("SingleTopNtuple/SingleTop.ntuple.TDR_012.root")
tree=file.Get("UserData")
histo=TH1F("histo","", 100, -5,5)
tree.Draw("elec_eta>>histo", "")
legend=TLegend(0.6,0.6,0.8,0.8)
legend.AddEntry(histo, histo.GetName(), "l")
legend.Draw()
This does what I expect it to do. Draw histogram and legend. Now the following
from ROOT import *
file=TFile("SingleTopNtuple/SingleTop.ntuple.TDR_012.root")
tree=file.Get("UserData")
def fun():
histo=TH1F("histo","", 100, -5,5)
tree.Draw("elec_eta>>histo", "")
legend=TLegend(0.6,0.6,0.8,0.8)
legend.AddEntry(histo, histo.GetName(), "l")
legend.Draw()
fun()
does not draw the legend, only the histogram.
A workaround is
from ROOT import *
file=TFile("SingleTopNtuple/SingleTop.ntuple.TDR_012.root")
tree=file.Get("UserData")
def fun():
histo=TH1F("histo","", 100, -5,5)
tree.Draw("elec_eta>>histo", "")
legend=TLegend(0.6,0.6,0.8,0.8)
legend.AddEntry(histo, histo.GetName(), "l")
return legend
leg=fun()
leg.Draw()
this works the same as the first example.
Why does the second not work?
Thank you for your help.
Cheers
Akira