Dear experts,
I’ve been running into an issue when trying to open a file with multiple TCanvas objects that I’d like to plot together in sub-pads of a larger canvas. Possibly relevant is that the saved TCanvas objects also have two sub-pads with histograms and THStacks.
The relevant function I have is
def make_canvas(padnames, rootfile_name, padx, pady, width, height):
if len(padnames) == 1:
width = 800; height = 700; padx = 1; pady = 1
elif len(padnames) == 2:
width = 1200; height = 700; padx = 2; pady = 1
<...more of the same...>
canvas = ROOT.TCanvas(outname, outname, width, height)
canvas.cd()
canvas.Divide(padx, pady)
rootfile = ROOT.TFile.Open(rootfile_name)
pads = [rootfile.Get(padname) for padname in padnames]
for i,p in enumerate(pads):
p.SetSelectedPad(canvas.cd(i+1))
p.DrawClonePad()
It can be called like
padnames = ['postfit_projy0_CR_fail', 'postfit_projy1_CR_fail', 'postfit_projy2_CR_fail',
'postfit_projy0_CR_loose', 'postfit_projy1_CR_fail', 'postfit_projy2_CR_fail',
'postfit_projy0_CR_pass', 'postfit_projy1_CR_pass', 'postfit_projy2_CR_pass']
make_can('test', padnames, 'XHY_MX_2000_MY_800/plots_fit_b/pads_projections.root')
This works fine. The issue is that padnames
is built while doing other things (like making the single-plot TCanvases and putting them in pads_projections.root
) and its then that I get…
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
...
File "/uscms_data/d3/lcorcodi/2DAlphaDev/CMSSW_10_6_14/src/2DAlphabet/TwoDAlphabet/plot.py", line 761, in canvas_groups_projections
make_can(out_can_name, these_pads, '{d}/pads_projections.root'.format(d=d))
File "/uscms_data/d3/lcorcodi/2DAlphaDev/CMSSW_10_6_14/src/2DAlphabet/TwoDAlphabet/plot.py", line 732, in make_can
p.DrawClonePad()
SystemError: TObject* TCanvas::DrawClonePad() =>
problem in C++; program state has been reset
I’m able to both print (p)
and p.Print()
before doing DrawClonePad() so I know the canvas is accessible. I’m just not sure why DrawClonePad is having issues.
Thanks for any and all help!
ROOT Version: 6.14/09
Platform: Linux (Fermilab’s LPC)
Compiler: N/A