Dear experts,
I am trying to return TH1F from a function but it was returning me type “PyROOT_NoneType”. For this I searched and fixed this issue using link [1] & [2].
But, later when I am going to save the histogram using
c1.SaveAs("test.pdf")
Then it is giving me error:
c1.SaveAs("test.pdf");
SystemError: void TPad::SaveAs(const char* filename = "", const char* option = "") =>
problem in C++; program state has been reset
Please let me know how I can fix this. you can see part of my code [3]
with regards,
Ram
===============
[1] Returning TH1F from function
[2] NoneType Feturned from Function that returns TH1F
[3] code:
def aQGC_GetHisto(plot_info, key1, ColNum):
file1 = ROOT.TFile(plot_info["file_name"][0])
tree1 = file1.Get(plot_info["tree_folder"] + plot_info["tree_name"])
hist = ROOT.TH1F()
hist1 = ROOT.TH1F("hist1", "Test", plot_info["nbin"], plot_info["xmin"], plot_info["xmax"])
tree1.Draw(plot_info["tree_var"][0] + ">>hist1","LHEWeights["+str(key1)+"]","",1000)
return hist1
def aQGC_plotting (plot_info, aQGC_key, aQGC_val, outputNameString):
c1 = getCanvas()
legend = ROOT.TLegend(.8 ,.60 ,1.0 ,.900)
legend.SetFillColor(ROOT.kWhite)
hist = ROOT.TH1F()
print type(hist)
for i in range(0,1):
hist = aQGC_GetHisto(plot_info,aQGC_key[i],i)
print "hist type : ",type(hist)
legend.AddEntry(hist, aQGC_val[i].replace("_m"," = ").replace("p",".").replace("_0"," = 0"))
if i==0:
hist.Draw()
else:
hist.Draw("sames")
legend.Draw("same")
#setTDRStyle(c1, 1, 13, plot_info["printCMS"])
hist1.GetXaxis().SetTitle(plot_info["xlabel"])
if plot_info["ylabel"] == "":
plot_info["ylabel"] = "Events / %s GeV" % int(hist1.GetBinWidth(1))
hist1.GetYaxis().SetTitle(plot_info["ylabel"])
c1.SaveAs("test.pdf")