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:

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

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

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.