Discussion:
arrays in pyroot
Salvador Marti
2014-10-08 13:01:05 UTC
Permalink
Hi

i've just started using pyroot. I can define, fill and plot histograms.
So far so good.

However I found a difficulty and I need help.

I need to plot a TPolyLine with 5 points and I do the following:

xmod = [0., 0., 0., 0., 0.]
ymod = [0., 0., 0., 0., 0.]
# in between I compute the values
mypoly = TPolyLine(5, xmod, ymod)

And I got this error message:

TypeError: none of the 5 overloaded methods succeeded. Full details:
TPolyLine::TPolyLine() =>
takes at most 0 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Option_t* option = "") =>
takes at most 2 arguments (3 given)
TPolyLine::TPolyLine(const TPolyLine& polyline) =>
takes at most 1 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Float_t* x, Float_t* y, Option_t*
option = "") =>
could not convert argument 3
TPolyLine::TPolyLine(Int_t n, Double_t* x, Double_t* y, Option_t*
option = "") =>
could not convert argument 2

It looks like this is not the way to pass an array. What's the right way?

Thanks
Salva
Clement Helsens
2014-10-08 13:08:36 UTC
Permalink
Hello,

you should do something like:

========
from array import array
xmod = array( 'f', [0., 0., 0., 0., 0.])
ymod = array( 'f', [0., 0., 0., 0., 0.])
mypoly = TPolyLine(5, xmod, ymod)
========

cheers,
Clement

Le 8 oct. 2014 à 15:01, Salvador Marti <***@ific.uv.es<mailto:***@ific.uv.es>> a écrit :

Hi

i've just started using pyroot. I can define, fill and plot histograms. So far so good.

However I found a difficulty and I need help.

I need to plot a TPolyLine with 5 points and I do the following:

xmod = [0., 0., 0., 0., 0.]
ymod = [0., 0., 0., 0., 0.]
# in between I compute the values
mypoly = TPolyLine(5, xmod, ymod)

And I got this error message:

TypeError: none of the 5 overloaded methods succeeded. Full details:
TPolyLine::TPolyLine() =>
takes at most 0 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Option_t* option = "") =>
takes at most 2 arguments (3 given)
TPolyLine::TPolyLine(const TPolyLine& polyline) =>
takes at most 1 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Float_t* x, Float_t* y, Option_t* option = "") =>
could not convert argument 3
TPolyLine::TPolyLine(Int_t n, Double_t* x, Double_t* y, Option_t* option = "") =>
could not convert argument 2

It looks like this is not the way to pass an array. What's the right way?

Thanks
Salva
Sebastien Binet
2014-10-08 13:09:05 UTC
Permalink
Salva,


On Wed, Oct 8, 2014 at 3:01 PM, Salvador Marti
Post by Clement Helsens
Hi
i've just started using pyroot. I can define, fill and plot histograms. So
far so good.
However I found a difficulty and I need help.
xmod = [0., 0., 0., 0., 0.]
ymod = [0., 0., 0., 0., 0.]
# in between I compute the values
mypoly = TPolyLine(5, xmod, ymod)
TPolyLine::TPolyLine() =>
takes at most 0 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Option_t* option = "") =>
takes at most 2 arguments (3 given)
TPolyLine::TPolyLine(const TPolyLine& polyline) =>
takes at most 1 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Float_t* x, Float_t* y, Option_t* option =
"") =>
could not convert argument 3
TPolyLine::TPolyLine(Int_t n, Double_t* x, Double_t* y, Option_t* option =
"") =>
could not convert argument 2
It looks like this is not the way to pass an array. What's the right way?
a (pure) python list does not have the same memory layout than a C-array.
TPolyLine c-tor expects the latter.

so:
# from stdlib
from array import array
xmod = array("f", [0.0]*5)
ymod = array("f", [0.0]*5)
mypoly = ROOT.TPolyLine(5, xmod, ymod)

hth,
-s
Post by Clement Helsens
Thanks
Salva
Sebastien Binet
2014-10-08 13:13:03 UTC
Permalink
Post by Sebastien Binet
Salva,
On Wed, Oct 8, 2014 at 3:01 PM, Salvador Marti
Post by Clement Helsens
Hi
i've just started using pyroot. I can define, fill and plot histograms. So
far so good.
However I found a difficulty and I need help.
xmod = [0., 0., 0., 0., 0.]
ymod = [0., 0., 0., 0., 0.]
# in between I compute the values
mypoly = TPolyLine(5, xmod, ymod)
TPolyLine::TPolyLine() =>
takes at most 0 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Option_t* option = "") =>
takes at most 2 arguments (3 given)
TPolyLine::TPolyLine(const TPolyLine& polyline) =>
takes at most 1 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Float_t* x, Float_t* y, Option_t* option =
"") =>
could not convert argument 3
TPolyLine::TPolyLine(Int_t n, Double_t* x, Double_t* y, Option_t* option =
"") =>
could not convert argument 2
It looks like this is not the way to pass an array. What's the right way?
a (pure) python list does not have the same memory layout than a C-array.
TPolyLine c-tor expects the latter.
# from stdlib
from array import array
xmod = array("f", [0.0]*5)
ymod = array("f", [0.0]*5)
mypoly = ROOT.TPolyLine(5, xmod, ymod)
also, you might want to have a look at rootpy, a more pythonic wrapper
(on top of PyROOT and numpy) for ROOT:
http://rootpy.github.io/root_numpy/

-s
Salvador Marti
2014-10-08 13:15:09 UTC
Permalink
Thanks to all that replied. It works.

beer++;
Salva
Post by Sebastien Binet
Salva,
On Wed, Oct 8, 2014 at 3:01 PM, Salvador Marti
Post by Clement Helsens
Hi
i've just started using pyroot. I can define, fill and plot histograms. So
far so good.
However I found a difficulty and I need help.
xmod = [0., 0., 0., 0., 0.]
ymod = [0., 0., 0., 0., 0.]
# in between I compute the values
mypoly = TPolyLine(5, xmod, ymod)
TPolyLine::TPolyLine() =>
takes at most 0 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Option_t* option = "") =>
takes at most 2 arguments (3 given)
TPolyLine::TPolyLine(const TPolyLine& polyline) =>
takes at most 1 arguments (3 given)
TPolyLine::TPolyLine(Int_t n, Float_t* x, Float_t* y, Option_t* option =
"") =>
could not convert argument 3
TPolyLine::TPolyLine(Int_t n, Double_t* x, Double_t* y, Option_t* option =
"") =>
could not convert argument 2
It looks like this is not the way to pass an array. What's the right way?
a (pure) python list does not have the same memory layout than a C-array.
TPolyLine c-tor expects the latter.
# from stdlib
from array import array
xmod = array("f", [0.0]*5)
ymod = array("f", [0.0]*5)
mypoly = ROOT.TPolyLine(5, xmod, ymod)
hth,
-s
Post by Clement Helsens
Thanks
Salva
Jochen Kerdels
2014-10-08 13:06:48 UTC
Permalink
Hi Salva,

first thing: I know essentially nothing about Python, so the following is an intuitive guess:

I would try to use a root-Class like TArrayD and then get the Pointer to the underlying array
from there, e.g.:

xmod = TArrayD(5);
ymod = TArrayD(5);

// fill values with AddAt
xmod.AddAt(2.345.,1)
xmod.AddAt(1.222.,2)
...

// get the poly
mypoly = TPolyLine(5,xmod.GetArray(),ymod.GetArray())



Maybe this works...

Cheers,
Jochen
Post by Clement Helsens
Hi
i've just started using pyroot. I can define, fill and plot histograms. So far so good.
However I found a difficulty and I need help.
xmod = [0., 0., 0., 0., 0.] ymod = [0., 0., 0., 0., 0.] # in between I compute the values mypoly = TPolyLine(5, xmod, ymod)
TypeError: none of the 5 overloaded methods succeeded. Full details: TPolyLine::TPolyLine() => takes at most 0 arguments (3 given) TPolyLine::TPolyLine(Int_t n, Option_t* option = "") => takes at most 2 arguments (3 given) TPolyLine::TPolyLine(const TPolyLine& polyline) => takes at most 1
arguments (3 given) TPolyLine::TPolyLine(Int_t n, Float_t* x, Float_t* y, Option_t* option = "") => could not convert argument 3 TPolyLine::TPolyLine(Int_t n, Double_t* x, Double_t* y, Option_t* option = "") => could not convert argument 2
It looks like this is not the way to pass an array. What's the right way?
Thanks Salva
- --
Jochen Kerdels

Tel.: +49 2331 987-4187

Lehrgebiet Mensch-Computer-Interaktion
Prof. Dr. Gabriele Peters

FernUniversität in Hagen
Fakultät für Mathematik und Informatik
Lehrgebiet Mensch-Computer-Interaktion
Universitätsstr. 1
D-58097 Hagen
Germany
Loading...