PyROOT TF1 from a python member function

Hi,
I have a simple PyROOT code where I want to draw a TF1 defined as a member function of a python class.
The code evaluates the function correctly when TF1::Eval() is called but it never evaluates the function if TF1::Draw() method is called.

I can redefine the member function (“SpreadY” in the code) as a class and use the call method, but my first choice would be to use as TF1 a member function as the parameters of the function are also data members of the class.

In case I should follow root.cern.ch/root/html/TF1.html#F5, what is the equivalent python recipe?

Ernesto
ToyPix_V2.py (1.47 KB)

Ernesto,

there are two issues: the TF1 in your case is a local variable, so it will be deleted once the function returns. You need to keep a reference to it, to keep it alive. The easiest is to explicitly create a TCanvas and then make the TF1 instance a data member of the created canvas.

Second, said TCanvas needs an Update().

HTH,
Wim