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)