Hello to everybody,

I would like to ask you a question about the possibility to set some “logical” constraints in ROOT on the fit parameters. Let’s make an example, I have the following function:

y(x) = Aexp(-Bx) + Cexp(-Dx)

where I want to fix A and C, and have B and D as fit parameters. Let’s assume that I don’t know which values to expect for B and D, but I know that D cannot be greater than B. Is it possible to set this kind of limit in ROOT?

Thank you all,

best regards

One solution is to define your function like that

[code]Double_t func(Double_t *x, Double_t *par) {
Double_t x = x;
Double_t A = par;
Double_t B = par;
Double_t C = par;
Double_t D = par;

if(D>B) return 1000000; //put here a very big number (the fit function will diverge when D will be greater than B
return Aexp(-Bx) + Cexp(-Dx);
}[/code]

You can also reformat your equation so that a limit can be applied:
Aexp(-Bx) + Cexp(-BnewD*x);
where 0 < newD < 1 and your previous D = B * newD

``````Double_t func(Double_t *x, Double_t *par) {
Double_t x = x;
Double_t A = par;
Double_t B = par;
Double_t C = par;
Double_t D = par;

return A*exp(-B*x) + C*exp(-B*newD*x);
}``````