vecchi
February 17, 2023, 9:32am
1
Dear experts,
I would like to define a fit function as follows:

F(x) = w0 * F0(x,par0) + w1 * F1(x,par0,par1) + w2 * F2(x, par0,par1) + w3 * F3(x, par0,par1)

where:

w# are the weights of the F# components
par# is a set of parameters
F0 is an analytical function
F1 is an analytical function that shares some parameters with F0 (par0)
F2 is the convolution of F1 with itself
F3 is the convolution of F1 and F2
I know how to build individually F0, F1, F2 and F3, but I don’t know how to make the different functions to share the common parameters.
Do you think it is possible? Are there any examples?

Thanks,
Stefania

yus
February 17, 2023, 10:51am
2
Hi Stefania,

for simplicity, let’s assume the following:

F0(x, par0) = 5*x + par0
F1(x, par0, par1) = F0 * par1
F2(x, par0, par1) = F1*42
F3(x, par0, par1) = F1 + F2
then we can define F(x) as follows:

```
TString F0 = "(5*x + [0])";
TString F1 = Form("%s*[1]", F0.Data());
TString F2 = Form("%s*42", F1.Data());
TString F3 = Form("(%s + %s)", F1.Data(), F2.Data());
TF1* myFit = new TF1("myFit", Form("w0*%s + w1*%s + w2*%s + w3*%s", F0.Data(), F1.Data(), F2.Data(), F3.Data()));
```

```
{
TF1 *f0 = new TF1("F0", "[0] * x"); // f0->Print();
TF1 *f1 = new TF1("F1", "pol1"); // f1->Print();
TF1 *f2 = new TF1("F2", "cheb1"); // f2->Print();
TF1 *f3 = new TF1("F3", "expo"); // f3->Print();
TF1 *f = new TF1("F", "[w0] * F0(x, [par0]) + [w1] * F1(x, [par0], [par1]) + [w2] * F2(x, [par0], [par1]) + [w3] * F3(x, [par0], [par1])");
f->Print();
}
```

system
Closed
March 3, 2023, 10:58am
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.