PyROOT TF1 from a python member function

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, what is the equivalent python recipe?

Ernesto (1.47 KB)


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().