Hi @couet,
Thank you for your reply. This was my code with just a Crystal ball function fit:
ch->Draw("H_mass>>H_m", tcut);
TH1F *H_m = (TH1F*)gDirectory->Get("H_m");
gStyle->SetOptFit(111111);
double mean = H_m->GetMean();
TF1 *f_cb= new TF1("MyCrystalBall","crystalball",80,160);
f_cb -> SetParameters(1,mean,0.3,2,1.5);
f_cb->SetLineColor(kRed);
H_m->Fit(f_cb,"R");
And it worked nice, but I was told to make a double-sided Crystal Ball (CB) function fit and I tried following: i created a file for CB function and then included it in the main file. The code is following (I took it from the root forum):
double DoubleSidedCrystalballFunction(double *x, double *par)
{
double alpha_l = par[0];
double alpha_h = par[1];
double n_l = par[2];
double n_h = par[3];
double mean = par[4];
double sigma = par[5];
double N = par[6];
float t = (x[0]-mean)/sigma;
double result;
double fact1TLessMinosAlphaL = alpha_l/n_l;
double fact2TLessMinosAlphaL = (n_l/alpha_l) - alpha_l -t;
double fact1THihgerAlphaH = alpha_h/n_h;
double fact2THigherAlphaH = (n_h/alpha_h) - alpha_h +t;
if (-alpha_l <= t && alpha_h >= t)
{
result = exp(-0.5tt);
}
else if (t < -alpha_l)
{
result = exp(-0.5*alpha_l*alpha_l)*pow(fact1TLessMinosAlphaL*fact2TLessMinosAlphaL, -n_l);
}
else if (t > alpha_h)
{
result = exp(-0.5alpha_halpha_h)pow(fact1THihgerAlphaHfact2THigherAlphaH, -n_h);
}
return N*result;
}
And I call this function in the main .C file as follows:
TF1 *f_cb= new TF1("DoubleSidedCrystalballFunction",DoubleSidedCrystalballFunction,40,200);
f_cb->SetParameters(1,2,2,1, H_m->GetMean(), H_m->GetRMS(), H_m->Integral(40,200));
f_cb->SetParNames ("alpha_{low}","alpha_{high}","n_{low}", "n_{high}", "mean", "sigma", "Norm");
f_cb->SetLineColor(kRed);
H_m->Fit(f_cb,"","",40,180);
However this does not work, I do not see any fit… I know that the initial parameters have to be reasonable, however I do not know how to choose “reasonable” parameters for my case…
If you have some example of implementing double sided CB function fit, it would be very helpful!
I hope I managed to explain my problem in detail. Thank you for your time and help!!
Let me know if I can give you any kind of further information that may be helpful.