Hi,
I have a problem with saving my own fitting function to a ROOT file: saved fuction does not respond to changing its parameters. Here is a short example:
testF1() {
TCanvas *c1 = new TCanvas("c1", "", -1);
c1->Divide(1,2);
c1->cd(1);
TF1 *f1 = new TF1("f1", N, 0, 10, 1);
f1->SetParameter(0, 0);
f1->Draw(); // all OK: y=sin(x)
TFile out("testF1.root", "recreate");
f1->Write();
out.Close();
c1->cd(2);
TFile in("testF1.root");
TF1 *f2 = (TF1*)in.Get("f1");
f2->SetParameter(0, 1); // has no effect!
f2->Draw(); // here is a problem: I get y=sin(x)+0 instead of y=sin(x)+1
in.Close();
}
Double_t N(Double_t *x, Double_t *par) {
return sin(x[0]) + par[0];
}
How do I save the function correctly to be able to change is’s parameters and get suitable answer?