Segmentation Violation when using TTree.Draw then TGraph constructor

I’m trying to move over some C root code into python with PyRoot. I populate a TTree using ReadFile and then want to plot TGraphs that are generated from cuts of the data in the TTree. In C, I achieved that behavior by drawing the TTree with the desired cuts and the goff option, and then I created a TGraph using the TTree::GetV1() and GetV2() functions. Here’s the snippet:

int n1 = t1->Draw("X:Y", "Z==1", "goff");
TGraph *graph1 = new TGraph(n1, t1->GetV2(), t1->GetV1());

In Python I’m trying to implement the same strategy with the following code:

numPoints = myTree.Draw("X:Y", "Z==1", "goff")

v2=myTree.GetV2()
v1=myTree.GetV1()

print("test")
graph = TGraph(numPoints, v2, v1)
print("did we break yet?")

which prints “test” and then throws a segmentation violation with what seems to be an unhelpful stack trace (with my level of understanding). But here is the error:

*** Break *** segmentation violation Generating stack trace... 0x00007f4c72b54510 in PyROOT::TMethodHolder::ConvertAndSetArgs(_object*, PyROOT::TCallContext*) + 0xb0 from /usr/lib/root/libPyROOT.so 0x00007f4c72b611ba in PyROOT::TConstructorHolder::Call(PyROOT::ObjectProxy*, _object*, _object*, PyROOT::TCallContext*) + 0x8a from /usr/lib/root/libPyROOT.so 0x00007f4c72b7edac in <unknown> from /usr/lib/root/libPyROOT.so 0x00007f4c73d22528 in PyObject_Call at /build/python/src/Python-3.4.3/Objects/abstract.c:2041 from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73d79bc0 in <unknown> from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73d77636 in <unknown> from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73d22528 in PyObject_Call at /build/python/src/Python-3.4.3/Objects/abstract.c:2041 from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73dd44ea in PyEval_EvalFrameEx at /build/python/src/Python-3.4.3/Python/ceval.c:4466 from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73dd7947 in PyEval_EvalCodeEx at /build/python/src/Python-3.4.3/Python/ceval.c:3588 from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73dd79eb in PyEval_EvalCode at /build/python/src/Python-3.4.3/Python/ceval.c:781 from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73df37d4 in <unknown> from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73df5945 in PyRun_FileExFlags at /build/python/src/Python-3.4.3/Python/pythonrun.c:2133 from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73df6923 in PyRun_SimpleFileExFlags at /build/python/src/Python-3.4.3/Python/pythonrun.c:1606 from /usr/lib/libpython3.4m.so.1.0 0x00007f4c73e0caac in Py_Main at /build/python/src/Python-3.4.3/Modules/main.c:319 from /usr/lib/libpython3.4m.so.1.0 0x00005565657a5c06 in main + 0x166 from python 0x00007f4c73721790 in __libc_start_main + 0xf0 from /usr/lib/libc.so.6 0x00005565657a5ca9 in _start + 0x29 from python

Any idea what’s going on here? Is there a better way to achieve the behavior I’m looking for?

Thanks!!

Hi,

I don’t see why it would not work the way you expect. Also, ConvertAndSetArgs is a very simple function that loops over the arguments given and has converter objects do the actual work. Hence in case of problems, I’d expect that in any of those converters, not in ConvertAndSetArgs.

Would need the tree in question for a reproducer. If you can provide that, please post a bug report on sft.its.cern.ch/jira/browse/ROOT as I have zero time atm. for PyROOT.

Cheers,
Wim

[quote=“wlav”]Hi,

I don’t see why it would not work the way you expect. Also, ConvertAndSetArgs is a very simple function that loops over the arguments given and has converter objects do the actual work. Hence in case of problems, I’d expect that in any of those converters, not in ConvertAndSetArgs.

Would need the tree in question for a reproducer. If you can provide that, please post a bug report on sft.its.cern.ch/jira/browse/ROOT as I have zero time atm. for PyROOT.

Cheers,
Wim[/quote]

Thank you very much for the quick reply. I’ll test it out on another machine and then submit a bug report if I have the same problem.