Problem with pyROOT equivalent of working CINT script

Hello ROOTers

I’ve encounterd a problem with pyROOT that I don’t understand.

Here is a simple demo program written for the ROOT CINT interpreter. It works and produces a display with some red and blue dots.

void surface_demo3() {

// create and put some numbers in first TNtuple
TNtuple T(“T”,“3-d tests”,“x:y:z”);
Float_t x,y,z;
x = 0.9; y = 0.85; z = 0.9;
T.Fill(x,y,z);
x = 0.95; y = 0.9; z = 0.95;
T.Fill(x,y,z);
x = 0.85; y = 0.8; z = 0.85;
T.Fill(x,y,z);
x = 0.925; y = 0.85; z = 0.925;
T.Fill(x,y,z);
x = 0.75; y = 0.8; z = 0.75;
T.Fill(x,y,z);
x = -0.9; y = -0.85; z = 0.9;
T.Fill(x,y,z);
x = -0.95; y = -0.9; z = 0.95;
T.Fill(x,y,z);
x = -0.85; y = -0.8; z = 0.85;
T.Fill(x,y,z);
x = -0.925; y = -0.85; z = 0.925;
T.Fill(x,y,z);
x = -0.75; y = -0.8; z = 0.75;
T.Fill(x,y,z);
// create and put some numbers in second TNtuple
TNtuple T1(“T”,“3-d tests”,“x:y:z”);
x = 0.2; y = 0.4; z = 0.3;
T1.Fill(x,y,z);
x = 0.2; y = -0.2; z = 0.4;
T1.Fill(x,y,z);
x = 0.1; y = 0.2; z = 0.5;
T1.Fill(x,y,z);

TCanvas *c1 = new TCanvas(“c1”,“test”,10,10,1100,900);
TH3F *h3 = new TH3F(“h3”,“test 3-d”,30,-1,1,30,-1,1,50,0,2);
h3->SetMarkerColor(kRed);
h3->SetFillColor(kBlue);
h3->SetMarkerSize(1);
h3->SetMarkerStyle(20);
// draw contents of first TNtuple
T.Draw(“z:y:x>>h3”,"",“scat”);

TH3F *h4 = new TH3F(“h4”,“test 3-d”,30,-1,1,30,-1,1,50,0,2);
h4->SetMarkerColor(kBlue);
h4->SetFillColor(kBlue);
h4->SetMarkerSize(1);
h4->SetMarkerStyle(20);
// draw contents of second TNtuple in same display as first TNtuple
T1.Draw(“z:y:x>>h4”,"",“same”);
}

Here is what (I think) should be the equivalent pyROOT script

from ROOT import gROOT, TCanvas, TNtuple, TF2, TH3F
gROOT.Reset()

T = TNtuple(“T”,“3-d tests”,“x:y:z”);
x = 0.9; y = 0.85; z = 0.9;
T.Fill(x,y,z);
x = 0.95; y = 0.9; z = 0.95;
T.Fill(x,y,z);
x = 0.85; y = 0.8; z = 0.85;
T.Fill(x,y,z);
x = 0.925; y = 0.85; z = 0.925;
T.Fill(x,y,z);
x = 0.75; y = 0.8; z = 0.75;
T.Fill(x,y,z);

x = -0.9; y = -0.85; z = 0.9;
T.Fill(x,y,z);
x = -0.95; y = -0.9; z = 0.95;
T.Fill(x,y,z);
x = -0.85; y = -0.8; z = 0.85;
T.Fill(x,y,z);
x = -0.925; y = -0.85; z = 0.925;
T.Fill(x,y,z);
x = -0.75; y = -0.8; z = 0.75;
T.Fill(x,y,z);
T1 = TNtuple(“T1”,“3-d tests”,“x:y:z”);
x = 0.2; y = 0.4; z = 0.3;
T1.Fill(x,y,z);
x = 0.2; y = -0.2; z = 0.4;
T1.Fill(x,y,z);
x = 0.1; y = 0.2; z = 0.5;
T1.Fill(x,y,z);

c1 = TCanvas(“c1”,“test”,10,10,1100,900);
h3 = TH3F(“h3”,“test 3-d”,30,-1,1,30,-1,1,50,0,2);
h3.SetMarkerColor(2);
h3.SetFillColor(4);
h3.SetMarkerSize(1);
h3.SetMarkerStyle(20);

the script fails at the following line

T.Draw(“z:y:x>>h3”,"",“scat”);

h4 = TH3F(“h4”,“test 3-d”,30,-1,1,30,-1,1,50,0,2);
h4.SetMarkerColor(4);
h4.SetFillColor(2);
h4.SetMarkerSize(1);
h4.SetMarkerStyle(20);
T1.Draw(“z:y:x>>h4”,"",“same”);

Sadly, however when I run this through the python interpreter (python 2.3.4) the script
ignominiously collapses with the following when the script tries to run
the T.Draw(“z:y:x>>h3”,"",“scat”) command.

Since I have to use pyROOT for my actual application, is there a fix or a
workaround that I can use?

Thanks

Tony Willis

*** Break *** floating point exception
Generating stack trace…
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
/usr/bin/addr2line: python: No such file or directory
0x40478228 in PyROOT::MethodHolder::setMethodArgs(_object*, int) + 0x11a from /usr/local/ROOT/lib/root/libPyROOT.so
0x404787f9 in PyROOT::MethodHolder::operator()(_object*, _object*) + 0x4d from /usr/local/ROOT/lib/root/libPyROOT.so
0x4047596b in PyROOT::MethodDispatcher::operator()(_object*, _object*) + 0xcf from /usr/local/ROOT/lib/root/libPyROOT.so
0x4047576e in PyROOT::MethodDispatcher::invoke(_object*, _object*, _object*) + 0x2a from /usr/local/ROOT/lib/root/libPyROOT.so
0x080ed7b0 in PyCFunction_Call + 0x50 from python
0x0805b17c in PyObject_Call + 0x1c from python
0x080a50ef in from python
0x080a4d9b in from python
0x080a33f4 in from python
0x080a3f26 in PyEval_EvalCodeEx + 0x46a from python
0x080a64b2 in PyEval_EvalCode + 0x22 from python
0x080cbb39 in from python
0x080cb39d in PyRun_SimpleFileExFlags + 0x195 from python
0x08054d32 in Py_Main + 0x482 from python
0x080548ab in main + 0x17 from python
0x420156a4 in __libc_start_main + 0xe4 from /lib/tls/libc.so.6
0x08054805 in wait + 0x61 from python

Tony,

I’m sure a workaround can be found, but for that I do need to know:

a) which version of ROOT (or PyROOT) you are using
b) on which platform you are running

Without that information, I can do little. ATLAS, for example, still uses a
version of PyROOT that was released with SEAL well over a year ago. You
can imagine that that version is quite different from the current one, which
has been continually developed.

Also, there might be platform specific problems, or even problems for a
given compiler, so I need that information as well before I can give you
a detailed workaround.

For now, all I can say is that your code as above works just fine on
MacOS-X, HEAD PyROOT …

Btw., I don’t think the call “gROOT.Reset()” is necessary (you don’t do it
in the CINT script either).

Best regards,
Wim

Hi

I am using a 1.7 GHz Dell latitude 600 laptop PC with:

Linux Red Hat 9

python 2.3.4
root v4.01.02
These two packages were compiled with gcc 3.2.2

I can succesfullly run the python scripts in the root ‘tutorials’ directory.

Tony

I am posting the following on behalf of Wim Lavrijsen who cannot connect
today to this Forum.
Could you please inform Tony Willis that the easiest workaround is to use "1"
as the selection expression for Draw()? Ie.:

T.Draw(“z:y:x>>h3”,“1”,“scat”);

The problem is reproducable under Linux, not under MacOS.

Thanks,
Wim

Meanwhile Wim has fixed the error in CVS.

Rene

Wim and Rene

Thank you for your fast diagnosis and response!

Cheers

Tony