Segfault on TRatioPlot::DrawClone()

Hi all,

I wrote a python function to read histograms from a file, create TRatioPlots and then return a list containing the canvases with the diagrams, see below. It should return a list with the canvases that I then save as pdf files in another part of the script, because TRatioPlot does not have a Print()-method, thus I cannot save them as pdfs.

To my understanding, I have to call TRatioPlot::DrawClone() to achieve this, but before that I have to call TRatioPlot::Draw() so I can set axis labels and ranges. When callling DrawClone() after that, ROOT segfaults. Do you understand why? Code and stack trace below, input file attached.

Cheers,

jndrf


_ROOT Version:/cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/bin/root
_Platform: Linux 2.6.32-754.6.3.el6.x86_64
_Compiler: gcc 6.2


import ROOT

def MakeStackedHistograms(rootfile):
    ROOT.gROOT.SetBatch(True)
    inputhists = set([])
    canvates = []
    for key in rootfile.GetListOfKeys():
        parts = key.GetName().split('_')
        inputhists.add('_'.join(parts[:-1]))

    for hist in inputhists:
        cv = ROOT.TCanvas(hist, 'cv', 1000, 1000)
        cv.cd()
        cv.SetLogy()

        reco = getattr(rootfile, '_'.join([hist, 'reco']))
        truth = getattr(rootfile, '_'.join([hist, 'truth']))

        reco.SetTitle(' '.join(hist.split('_')))
        reco.SetLineColor(1)
        reco.SetStats(False)
        reco.GetXaxis().SetTitle(hist.split('_')[0])

        truth.SetTitle(' '.join(hist.split('_')))
        truth.SetLineColor(2)

        miny = min([reco.GetBinContent(reco.GetMinimumBin()), truth.GetBinContent(truth.GetMinimumBin())])
        maxy = max([reco.GetBinContent(reco.GetMaximumBin()), truth.GetBinContent(truth.GetMaximumBin())])

        if miny == 0:
            miny = 1000
        if (maxy/miny) < 2:
            maxy *= 5
            miny *= 0.2
            
        reco.GetYaxis().SetRangeUser(miny*0.9, maxy*1.1)

        ratio = ROOT.TRatioPlot(reco, truth, 'divsym')
        ratio.Draw()
        ratio.GetUpperRefYaxis().SetTitle('events')
        ratio.DrawClone()
        cv.Update()
        canvates.append(cv)

    return canvates


if __name__ == '__main__':

    import argparse
    parser = argparse.ArgumentParser()

    parser.add_argument('-o', help='output directory', type=str, default='')
    parser.add_argument('inputfile', help='Output File of TruthRecoComparator', type=str)

    args = parser.parse_args()

    histos = MakeStackedHistograms(ROOT.TFile(args.inputfile, 'READ'))

    if args.o != '':
        import os
        os.makedirs(args.o)
        for h in histos:
            h.SaveAs('{path}/{hist}.pdf'.format(path=args.o, hist=h.GetName()))
% python TRCPlotter.py TRC.root -o ~/trcplotter
1000 1.87088417662e+16

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
    import itertools

Thread 2 (Thread 0x7faed123c700 (LWP 28172)):
#0  0x0000003aef00da00 in sem_wait () from /lib64/libpthread.so.0
#1  0x00007faee9b422c8 in PyThread_acquire_lock () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#2  0x00007faee9aff7c6 in PyEval_RestoreThread () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:359
#3  0x00007faed127ed68 in time_sleep () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/Python/2.7.15/x86_64-slc6-gcc62-opt/lib/python2.7/lib-dynload/time.so
#4  0x00007faee9b08064 in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4372
#5  0x00007faee9b0a3ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#6  0x00007faee9a7fddd in function_call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#7  0x00007faee9a4eaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#8  0x00007faee9b04f67 in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4686
#9  0x00007faee9b063cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#10 0x00007faee9b063cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#11 0x00007faee9b0a3ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#12 0x00007faee9a7fd0c in function_call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#13 0x00007faee9a4eaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#14 0x00007faee9a5ffbc in instancemethod_call () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Objects/classobject.c:2600
#15 0x00007faee9a4eaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#16 0x00007faee9affea7 in PyEval_CallObjectWithKeywords () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4241
#17 0x00007faee9b481d2 in t_bootstrap () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#18 0x0000003aef007aa1 in start_thread () from /lib64/libpthread.so.0
#19 0x0000003aee8e8c4d in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7faee99cb700 (LWP 27427)):
#0  0x0000003aee8ac8dd in waitpid () from /lib64/libc.so.6
#1  0x0000003aee83e4e9 in do_system () from /lib64/libc.so.6
#2  0x0000003aee83e820 in system () from /lib64/libc.so.6
#3  0x00007faedf96eebd in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#4  0x00007faedf971624 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#5  <signal handler called>
#6  0x0000003aeeb8e5a8 in main_arena () from /lib64/libc.so.6
#7  0x00007faee1d48a46 in TRatioPlot::Draw(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#8  0x00007faedf85d219 in TObject::DrawClone(char const*) const () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#9  0x00007faee98dd049 in ?? ()
#10 0x000000000508e020 in ?? ()
#11 0x00007faedb1b8eb0 in TClingCallFunc::IFacePtr() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCling.so
#12 0x0000000004f82d60 in ?? ()
#13 0x00007ffff3541a50 in ?? ()
#14 0x00007faee32cdbf1 in FastCall(long, void*, void*, void*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#15 0x00007ffff3541b20 in ?? ()
#16 0x0000000005057a90 in ?? ()
#17 0x00007ffff3541a40 in ?? ()
#18 0x00007ffff3541a20 in ?? ()
#19 0x0000000000000008 in ?? ()
#20 0x00000000022a39b0 in ?? ()
#21 0x00007faedf8f7529 in _ZN10TClassEdit14ResolveTypedefB5cxx11EPKcb () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#22 0x00007faed126f5e0 in ?? ()
#23 0x00007ffff3541e10 in ?? ()
#24 0x0000000004f82d60 in ?? ()
#25 0x0000000000000041 in ?? ()
#26 0x00007faee32f5782 in PyROOT::TMethodHolder::CallSafe(void*, long, PyROOT::TCallContext*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#27 0x00007faee32f4b24 in PyROOT::TMethodHolder::Call(PyROOT::ObjectProxy*&, _object*, _object*, PyROOT::TCallContext*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#28 0x00007faee32d7d19 in PyROOT::(anonymous namespace)::mp_call(PyROOT::MethodProxy*, _object*, _object*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#29 0x00007faee9a4eaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#30 0x00007faee9b0602b in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4589
#31 0x00007faee9b063cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#32 0x00007faee9b0a3ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#33 0x00007faee9b0a4e9 in PyEval_EvalCode () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:669
#34 0x00007faee9b2e8ba in PyRun_FileExFlags () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#35 0x00007faee9b2fc95 in PyRun_SimpleFileExFlags () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#36 0x00007faee9b463d1 in Py_Main () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#37 0x0000003aee81ed20 in __libc_start_main () from /lib64/libc.so.6
#38 0x0000000000400641 in _start ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x0000003aeeb8e5a8 in main_arena () from /lib64/libc.so.6
#7  0x00007faee1d48a46 in TRatioPlot::Draw(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#8  0x00007faedf85d219 in TObject::DrawClone(char const*) const () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#9  0x00007faee98dd049 in ?? ()
#10 0x000000000508e020 in ?? ()
#11 0x00007faedb1b8eb0 in TClingCallFunc::IFacePtr() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCling.so
#12 0x0000000004f82d60 in ?? ()
#13 0x00007ffff3541a50 in ?? ()
#14 0x00007faee32cdbf1 in FastCall(long, void*, void*, void*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#15 0x00007ffff3541b20 in ?? ()
#16 0x0000000005057a90 in ?? ()
#17 0x00007ffff3541a40 in ?? ()
#18 0x00007ffff3541a20 in ?? ()
#19 0x0000000000000008 in ?? ()
#20 0x00000000022a39b0 in ?? ()
#21 0x00007faedf8f7529 in _ZN10TClassEdit14ResolveTypedefB5cxx11EPKcb () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#22 0x00007faed126f5e0 in ?? ()
#23 0x00007ffff3541e10 in ?? ()
#24 0x0000000004f82d60 in ?? ()
#25 0x0000000000000041 in ?? ()
#26 0x00007faee32f5782 in PyROOT::TMethodHolder::CallSafe(void*, long, PyROOT::TCallContext*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#27 0x00007faee32f4b24 in PyROOT::TMethodHolder::Call(PyROOT::ObjectProxy*&, _object*, _object*, PyROOT::TCallContext*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#28 0x00007faee32d7d19 in PyROOT::(anonymous namespace)::mp_call(PyROOT::MethodProxy*, _object*, _object*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libPyROOT.so
#29 0x00007faee9a4eaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#30 0x00007faee9b0602b in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4589
#31 0x00007faee9b063cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#32 0x00007faee9b0a3ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#33 0x00007faee9b0a4e9 in PyEval_EvalCode () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:669
#34 0x00007faee9b2e8ba in PyRun_FileExFlags () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#35 0x00007faee9b2fc95 in PyRun_SimpleFileExFlags () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#36 0x00007faee9b463d1 in Py_Main () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#37 0x0000003aee81ed20 in __libc_start_main () from /lib64/libc.so.6
#38 0x0000000000400641 in _start ()
===========================================================


Traceback (most recent call last):
  File "TRCPlotter.py", line 66, in <module>
    histos = MakeStackedHistograms(ROOT.TFile(args.inputfile, 'READ'))
  File "TRCPlotter.py", line 48, in MakeStackedHistograms
    ratio.DrawClone()
SystemError: TObject* TObject::DrawClone(const char* option = "") =>
    problem in C++; program state has been reset

TRC.root (30.2 KB)

Our graphics expert @couet will be back soon, I will let him comment.

In the meantime, I would try:

  • Do you need to call Draw and DrawClone after that? What happens if you just have one Draw?
  • If you need to draw twice, does it also crash if you call Draw and then Draw again?

Do you need to call Draw and DrawClone after that? What happens if you just have one Draw ?

In that case, all pdf files are written, but they only show the title and frame borders of the histogram and the ratio plot, no axis labels, contents or anything

if you need to draw twice, does it also crash if you call Draw and then Draw again?

Yes.

 *** Break *** segmentation violation
ESC[?1034h1000 1.87088417662e+16



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
    import itertools

Thread 2 (Thread 0x7f4ec8888700 (LWP 13213)):
#0  0x0000003aef00da00 in sem_wait () from /lib64/libpthread.so.0
#1  0x00007f4ee128e2c8 in PyThread_acquire_lock () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#2  0x00007f4ee124b7c6 in PyEval_RestoreThread () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:359
#3  0x00007f4ec888ad68 in time_sleep () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/Python/2.7.15/x86_64-slc6-gcc62-opt/lib/python2.7/lib-dynload/time.so
#4  0x00007f4ee1254064 in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4372
#5  0x00007f4ee12563ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#6  0x00007f4ee11cbddd in function_call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#7  0x00007f4ee119aaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#8  0x00007f4ee1250f67 in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4686
#9  0x00007f4ee12523cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#10 0x00007f4ee12523cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#11 0x00007f4ee12563ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#12 0x00007f4ee11cbd0c in function_call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#13 0x00007f4ee119aaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#14 0x00007f4ee11abfbc in instancemethod_call () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Objects/classobject.c:2600
#15 0x00007f4ee119aaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#16 0x00007f4ee124bea7 in PyEval_CallObjectWithKeywords () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4241
#17 0x00007f4ee12941d2 in t_bootstrap () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#18 0x0000003aef007aa1 in start_thread () from /lib64/libpthread.so.0
#19 0x0000003aee8e8c4d in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7f4ee1117700 (LWP 13185)):
#0  0x0000003aee8ac8dd in waitpid () from /lib64/libc.so.6
#1  0x0000003aee83e4e9 in do_system () from /lib64/libc.so.6
#2  0x0000003aee83e820 in system () from /lib64/libc.so.6
#3  0x00007f4ed70baebd in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#4  0x00007f4ed70bd624 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#5  <signal handler called>
#6  0x0000000000000061 in ?? ()
#7  0x00007f4ed701b8c6 in TList::FindObject(char const*) const () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#8  0x00007f4ed946c68f in TPad::GetFrame() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#9  0x00007f4ed946bcc3 in TPad::PaintPadFrame(double, double, double, double) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#10 0x00007f4ec7c42764 in THistPainter::Paint(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#11 0x00007f4ec7c1c826 in TGraphPainter::PaintGraph(TGraph*, int, double const*, double const*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#12 0x00007f4ec7c1602f in TGraphPainter::PaintGraphSimple(TGraph*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#13 0x00007f4ec7c23bbb in TGraphPainter::PaintGraphErrors(TGraph*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#14 0x00007f4ec7c27405 in TGraphPainter::PaintHelper(TGraph*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#15 0x00007f4ed9487a6c in TPad::Paint(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#16 0x00007f4ed946c34e in TPad::Draw(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#17 0x00007f4ed94948e4 in TRatioPlot::Draw(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#18 0x00007f4ee103003a in ?? ()
#19 0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x0000000000000061 in ?? ()
#7  0x00007f4ed701b8c6 in TList::FindObject(char const*) const () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#8  0x00007f4ed946c68f in TPad::GetFrame() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#9  0x00007f4ed946bcc3 in TPad::PaintPadFrame(double, double, double, double) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#10 0x00007f4ec7c42764 in THistPainter::Paint(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#11 0x00007f4ec7c1c826 in TGraphPainter::PaintGraph(TGraph*, int, double const*, double const*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#12 0x00007f4ec7c1602f in TGraphPainter::PaintGraphSimple(TGraph*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#13 0x00007f4ec7c23bbb in TGraphPainter::PaintGraphErrors(TGraph*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#14 0x00007f4ec7c27405 in TGraphPainter::PaintHelper(TGraph*, char const*) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libHistPainter.so
#15 0x00007f4ed9487a6c in TPad::Paint(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#16 0x00007f4ed946c34e in TPad::Draw(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#17 0x00007f4ed94948e4 in TRatioPlot::Draw(char const*) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#18 0x00007f4ee103003a in ?? ()
#19 0x0000000000000000 in ?? ()
===========================================================


Traceback (most recent call last):
  File "TRCPlotter.py", line 66, in <module>
    histos = MakeStackedHistograms(ROOT.TFile(args.inputfile, 'READ'))
  File "TRCPlotter.py", line 48, in MakeStackedHistograms
    ratio.Draw()
SystemError: void TRatioPlot::Draw(const char* chopt = "") =>
    problem in C++; program state has been reset

This morning I thought that my approach of storing the canvases in a vector and saving them later might be a bit too complicated so I tried to write the histograms right after they are created. It will now create and record the first histogram just fine, but then segfault on the second one. This does not depend on the order in which I read them from the file, if I skip the first, the formerly second will be printed just fine and the formerly third, now second one will cause a segfault.
My guess from the backtrace was that something in ROOT’s memory management scheme causes ratio not to be deleted and thus I change the old object in the second run of the loop instead of creating a new one. But since TRatioPlot does not have a SetDirectory() method, I couldn’t test this.

Edit: If I create the canvas inside the loop, it works.

import argparse
from os import makedirs
import ROOT

parser = argparse.ArgumentParser()

parser.add_argument('-o', help='output directory', type=str, default='')
parser.add_argument('inputfile', help='Output File of TruthRecoComparator', type=str)
args = parser.parse_args()

makedirs(args.o)

# ROOT.gROOT.SetBatch(True)
inputhists = set([])
canvates = []
cv = ROOT.TCanvas("cv", "cv", 1000, 1000)
cv.SetLogy()

rootfile = ROOT.TFile(args.inputfile, 'READ')

for key in rootfile.GetListOfKeys():
    parts = key.GetName().split('_')
    inputhists.add('_'.join(parts[:-1]))
    
for hist in inputhists:
    
    reco = getattr(rootfile, '_'.join([hist, 'reco']))
    truth = getattr(rootfile, '_'.join([hist, 'truth']))
    
    # print reco.Integral(), truth.Integral()
    
    reco.SetTitle(' '.join(hist.split('_')))
    reco.SetLineColor(1)
    reco.SetStats(False)
    reco.GetXaxis().SetTitle(hist.split('_')[0])
    
    truth.SetTitle(' '.join(hist.split('_')))
    truth.SetLineColor(2)
    
    miny = min([reco.GetBinContent(reco.GetMinimumBin()), truth.GetBinContent(truth.GetMinimumBin())])
    maxy = max([reco.GetBinContent(reco.GetMaximumBin()), truth.GetBinContent(truth.GetMaximumBin())])
    
    if miny == 0:
        miny = 1000
    if (maxy/miny) < 2:
        maxy *= 5
        miny *= 0.2
        
    print miny, maxy
    reco.GetYaxis().SetRangeUser(miny*0.9, maxy*1.1)
    
    ratio = ROOT.TRatioPlot(reco, truth, 'divsym')
    ratio.Draw()
    ratio.GetUpperRefYaxis().SetTitle('events')
    ratio.GetLowerRefYaxis().SetTitle('reco/truth')
    ratio.GetLowerRefYaxis().SetRangeUser(0, 2)
    ratio.GetXaxis().SetTitle(hist.split('_')[0])
    ratio.SetSeparationMargin(0)
    # cv.BuildLegend()
    cv.Update()
    path = '{path}/{hist}.pdf'.format(path=args.o, hist=hist)
    print path
    cv.SaveAs(path)
%python TRCPlotter.py TRC.root -o ~/TRC
1000 1.87088417662e+16
~/TRC/Pt_BTagged.pdf
Info in <TCanvas::Print>: pdf file ~/TRC/Pt_BTagged.pdf has been created
9.58537151665e+15 2.48540988686e+17
~/TRC/Phi.pdf

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
    import itertools

Thread 2 (Thread 0x7f02e4f66700 (LWP 18837)):
#0  0x0000003aef00da00 in sem_wait () from /lib64/libpthread.so.0
#1  0x00007f02fd87e2c8 in PyThread_acquire_lock () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#2  0x00007f02fd83b7c6 in PyEval_RestoreThread () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:359
#3  0x00007f02e4f68d68 in time_sleep () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/Python/2.7.15/x86_64-slc6-gcc62-opt/lib/python2.7/lib-dynload/time.so
#4  0x00007f02fd844064 in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4372
#5  0x00007f02fd8463ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#6  0x00007f02fd7bbddd in function_call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#7  0x00007f02fd78aaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#8  0x00007f02fd840f67 in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4686
#9  0x00007f02fd8423cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#10 0x00007f02fd8423cf in PyEval_EvalFrameEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4457
#11 0x00007f02fd8463ec in PyEval_EvalCodeEx () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:3604
#12 0x00007f02fd7bbd0c in function_call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#13 0x00007f02fd78aaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#14 0x00007f02fd79bfbc in instancemethod_call () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Objects/classobject.c:2600
#15 0x00007f02fd78aaf3 in PyObject_Call () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#16 0x00007f02fd83bea7 in PyEval_CallObjectWithKeywords () at /mnt/build/jenkins/workspace/lcg_release_latest/BUILDTYPE/Release/COMPILER/gcc62binutils/LABEL/slc6/build/externals/Python-2.7.15/src/Python/2.7.15/Python/ceval.c:4241
#17 0x00007f02fd8841d2 in t_bootstrap () from /cvmfs/sft.cern.ch/lcg/releases/Python/2.7.15-2cba0/x86_64-slc6-gcc62-opt/bin/../lib/libpython2.7.so.1.0
#18 0x0000003aef007aa1 in start_thread () from /lib64/libpthread.so.0
#19 0x0000003aee8e8c4d in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7f02fd707700 (LWP 18813)):
#0  0x0000003aee8ac8dd in waitpid () from /lib64/libc.so.6
#1  0x0000003aee83e4e9 in do_system () from /lib64/libc.so.6
#2  0x0000003aee83e820 in system () from /lib64/libc.so.6
#3  0x00007f02f3017ebd in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#4  0x00007f02f301a624 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#5  <signal handler called>
#6  0x00007f02f53ed71b in TRatioPlot::IsDrawn() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#7  0x00007f02f53f2d99 in TRatioPlot::RangeAxisChanged() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#8  0x00007f02fd61d02a in ?? ()
#9  0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f02f53ed71b in TRatioPlot::IsDrawn() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#7  0x00007f02f53f2d99 in TRatioPlot::RangeAxisChanged() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libGpad.so
#8  0x00007f02fd61d02a in ?? ()
#9  0x0000000000000000 in ?? ()
===========================================================


Traceback (most recent call last):
  File "TRCPlotter.py", line 63, in <module>
    cv.SaveAs(path)
SystemError: void TPad::SaveAs(const char* filename = "", const char* option = "") =>
    problem in C++; program state has been reset

Cheers,

jndrf

So that is actually what you want, right? Create a canvas per iteration and draw a ratio plot on it?

Yes. I still don’t think the code in the OP should cause a segfault, but I get what I need.

Ok, I consider it as solved.

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