Hello kind ROOT experts, hopefully this is just a stupid problem. But i am trying to get a Tlegend to show up in my output canvas which i save as a png or in a macro and neither works. Here is my code :
import math
import os
from glob import glob
from ROOT import *
import rootlogon
from pyroot_helpers import *
from plot_formatter import *
from ROOT import SetOwnership
.
.
.
c = TCanvas()
f = TFile(“npv.root”)
h_hnpv= get_hist(f,‘fakeRate_%s_%s’%(ratetype,central),’%s/MCsub_%s’%(dn_rates,central))
h_lnpv = get_hist(f,‘fakeRate_%s_%s’%(ratetype2,central),’%s/%s/MCsub_%s’%(plottype,ratetype2,central))
l = ROOT.TLegend(0.5,0.5,0.5,0.5)
SetOwnership( l, 0 ) # 0 = release (not keep), 1 = keep #Saw this on a previous root help post
l.SetLineColor(0)
l.SetFillColor(0)
l.SetShadowColor(0)
l.AddEntry(h_hnpv,‘FF with npv > 15’,‘l’)
l.AddEntry(h_lnpv,‘FF with npv < 15’,‘l’)
h_hnpv.Draw(‘p’)
h_lnpv.Draw(‘p,same’)
l.Draw(‘same’)
c.SaveAs(‘pup.C’)
#c.SaveAs(‘pup.png’)
f.Close()
As you can see i tried this SetOwnership function as i had seen someone else had a problem with thison ROOT Topics, but alas it did not work.
Cheers,
Anthony