Plot convolution functions with pyroot

Dear experts, I’m encountering issues plotting the convolution form of two analytical functions with pyroot, I would like to ask for your kind help:

E.g. in this simple example:

import ROOT

def pyf_tf1_identity(x, p):
    return x[0]
def pyf_tf1_suqare(x, p):
    return x[0]*x[0]

c = ROOT.TCanvas( 'c', 'canv', 600, 400 )
c.SetGrid()

f1 = ROOT.TF1("tf1_identity", pyf_tf1_identity, 0.0, 1.0)
f1.SetLineColor(ROOT.kRed)
f2= ROOT.TF1("tf1_suqare", pyf_tf1_suqare, 0.0, 1.0)
f2.SetLineColor(ROOT.kViolet)
f1.Draw()
f2.Draw("same")

fconv = ROOT.TF1Convolution(f1, f2, 0, 2, True)
fconv.SetRange(0., 2.);
f0 = ROOT.TF1("fdata", fconv, 0, 1, fconv.GetNpar())
f0.SetLineColor(ROOT.kBlack)
f0.Draw("same")

c.Draw()

I couldn’t draw f0, and the error log give:
TypeError: void TCanvas::Draw(const char* option = “”) =>
TypeError: double TF1Convolution::operator()(const double* x, const double* p) =>
TypeError: could not convert argument 2 (could not convert argument to buffer or nullptr)

Hello,

I don’t see any problem in the code, @moneta do you know why this error can happen?

The call to TF1Convolution::operator() seems to be triggered by TCanvas::Draw and it does not seem to happen from Python.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.