TF2 in pyroot

Hi,

I have some code which makes a simple TF1 object in pyroot and am trying to extrapolate it to a TF2 object but coming across a few issues. I think it is a fairly simple problem… The code hopefully explains itself,


print '1D function'

def myFunc(x):
    return x[0]

fa1 = TF1('fa1', myFunc, 0., 10.)
print fa1.Eval(5.)

print '\n2D function'

def myFunc2D(x, y):
    return x[0] * y[0]

fa2 = TF2('fa2', myFunc2D, 0., 10., 0., 10.)
print fa2.Eval(5., 5.)

output

1D function
5.0

2D function
TypeError: myFunc2D() takes exactly 2 arguments (1 given)
Traceback (most recent call last):
  File "test.py", line 36, in <module>
    print fa3.Eval(5., 5.)
Exception: TFN python function call failed (C++ exception)

any ideas?

thanks

David

I should add that passing the function as a string

"myFunc(x,y)"

instead of a “pointer” does work but I need to have the function declared in the ROOT scope?

ROOT.myFunc != None

and I don’t know how to do that

Hi,

from a quick look, I’d say that this:def myFunc2D(x, y): return x[0] * y[0]
should have been:def myFunc2D(x): return x[0] * x[1]
Cheers,
Wim

it works, thanks