I was doing THstack plots in a for loop, where the histograms h1,h2,h3 are drawn from RDataFrame. After the loop, I want to do some fine tuning on some plots.
This is the working part of my code:
c1 = r.TCanvas("c1","c1 title",1500,1200)
c1.Divide(3,3)
h1 = df.Histo1D("var1")
h2 = df.Histo1D("var2")
h3 = df.Histo1D("var3")
hs1_list = [] # save objects in the for loop, to ease restyle later
for i in range(9):
c1.cd(i+1)
varname = varnames[i]
hs = r.THStack("hs1{}".format(i+1),par_list[i][0])
hs1_list.append(hs)
hs.Add(h1.GetPtr())
hs.Add(h2.GetPtr())
hs.Add(h3.GetPtr())
hs.DrawClone("nostack HIST E")
# fine tune some plots
hs1_list[0].GetXaxis().SetRangeUser(0,3100)
c1.Draw()
The hs1_list[0].GetXaxis().SetRangeUser(0,3100) line throw an error: ReferenceError: attempt to access a null-pointer
sorry for not being able to include the full code.
Could anyone help me on that ?
_ROOT Version: 6.24 (PyROOT via conda)
_Platform:Centos7
_Compiler: gcc9
I wrote in Python, so the hs1_list should be initialized automatically. I use hs1_list to store 9 (pointers? i think) of the THStack generated in the for loop. I tested to change the Xaxis range only for the 1st THStack (hs1_list[0]) before drawing the whole canvas.
I tried use Draw() in stead of DrawClone() in the for loop, and it worked.
But in the previous similar plots, DrawClone() must be used otherwise it only plot the last plot in the ```for`` loop. Surprisingly, it worked in this case.