PyROOT DrawClonePad seg fault

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.Divide(padx, pady)
    rootfile = ROOT.TFile.Open(rootfile_name)
    pads = [rootfile.Get(padname) for padname in padnames]
    for i,p in enumerate(pads):

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/", 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/", line 732, in make_can
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

Maybe @etejedor can help


Do you have any more details of the stack trace that is generated? Perhaps @couet can comment if he sees any problem in the logic itself.

Also, would it be possible for you to run this with a newer ROOT version? Say 6.24?

Thanks for the replies but I got frustrated and abandoned using ROOT for this step. There are simply too many issues involving python’s garbage collection to ensure stability for other users of the code I’m writing. I instead save the individual figures out as PNG and PDF and then use Pillow to arrange them in a grid.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.