# Function to change TF1 fit behaviour after passing x value

Hi all,

I am trying to write my own fit function that behaves like an error function up to a certain point in x (to be decided by the fit) and then an error function convoluted with an exponential after this point x - however I am not sure how to code this. So far I have:

``````   Double_t myfunction(Double_t *x, Double_t *par)
{
Float_t xx =x;
Double_t f = 1 + 0.5*(TMath::Erf((x-par)/par);
if(xx > par) {
f = (1 + 0.5*(TMath::Erf((x-par)/par)) * (par*x + par);
}
return f;
}
``````

but I expect this not to work - I don’t know how to handle the point where it should change from one function to the other. Any suggestions?

Thanks,
Hardeep

I don’t really know what you’re trying to achieve. Try (note that this function is discontinuous at x = p -> see the jump in its value): [code]#include “TMath.h”
#include “TF1.h”

Double_t myfunction(Double_t *x, Double_t *p)
{
if (p == 0.0) return 0.0; // just a precaution
Double_t f = 1.0 + 0.5 * TMath::Erf((x - p) / p);
if(x > p) f *= p * x + p;
return f;
}

void trial(void)
{
TF1 *f = new TF1(“f”, myfunction, 0.0, 10.0, 5);
f->SetNpx(10000);
f->SetParameters(1.1, 2.2, 3.3, 4.4, 5.5);
f->Draw();
}[/code]

Hi,

Forgive me if I was not clear - I am essentially trying to perform a fit to an efficiency that initially behaves like an error function (TMath::Erf), but then somewhere along that error function, the efficiency begins to fall off again. At the point where the efficiency falls off again I want the fit function to remain continuous but behave like (TMath::Erf * (-mx +c)) or (TMath::Erf * TMath::Exp).

What I have not worked out is how to get the fit function to determine where this transition should be based on the data points and then how to get it to perform the different behaviours before and after this transition point.

Hope this adds clarity to the situation.

Hardeep