Fitting to user defined function

I am new to ROOT so I don’t understand some of the conventions, yet.

I am trying to fit a signal with gAsin(phi*time), where g and phi are parameters and A and time are arrays.

TF1 *fit = new TF1(“fit”,"[0]Acos([1]*x)",1.0e-6,3.50e-6);.

It doesn’t work. It says Ais a bad numerical expression.
Also when I define an array as “time” and have no x?

TF1 *fit = new TF1(“fit”,"[0]Acos([1]*time)",1.0e-6,3.50e-6);. It says time is a bad numerical expression.

I am at a loss as to how to fix this.

Thanks

I assume that you have an array of N points A[i],time[i].
In this case create a TGraph g(n,time,A), then fit this graph with your function, something like

TGraph g(n,time,A); TF1 *fit = new TF1("fit","[0]*cos([1]*x)",1.0e-6,3.50e-6); double g0 = initial value for parameter g double phi0 = initial value for parameter phi fit->SetParameters(g0,phi0); g.Fit(fit);
Rene