TGraphAsymmErrors how to pass arrays


I have tried to follow various examples on how to pass arrays to TGraphAsymmErrors, but keep failing.

Now I try the following:

import numpy
Nbins = histo.GetNbinsX()
    vx = numpy.ndarray(Nbins+1.)
    vy = numpy.ndarray(Nbins+1.)
    vexl = numpy.ndarray(Nbins+1.)
    vexh = numpy.ndarray(Nbins+1.)
    veyl = numpy.ndarray(Nbins+1.)
    veyh = numpy.ndarray(Nbins+1.)

I then fill the arrays like the following

for i in range(Nbins):
vy[i] = some_value

And then I try to simply create my TGraphAsymmError object like this:

asymErr = TGraphAsymmErrors(vx,vy,vexl,vexh,veyl,veyh)

What am I missing? I get the following error message:

Thanks a lot!


I found the solution myself, I was just confused as to which constructor to actually call.

I need to call the one with number of array-elements indicated first, so instead of

asymErr = TGraphAsymmErrors(vx,vy,vexl,vexh,veyl,veyh)

I needed to do:

asymErr = TGraphAsymmErrors(Nbins,vx,vy,vexl,vexh,veyl,veyh)

:slight_smile: Thanks