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[0];
      Double_t f = 1 + 0.5*(TMath::Erf((x-par[0])/par[1]);
      if(xx > par[2]) {
            f = (1 + 0.5*(TMath::Erf((x-par[0])/par[1])) * (par[3]*x + par[4]);
      }
      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[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;
}

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