Dear root experts,
I implemented a double-sided crystal ball function to be used to fit a histogram.
I based on this article page 10 to implement my code: https://dash.harvard.edu/bitstream/handle/1/29362185/1606.03833.pdf?sequence=1
The code seems to work but I am not satisfied with the fit results, I was expected to be able to fit the right tail of the histogram for instance given the high number of parameters that one can tune to adjust the fit. So I was wondering if someone more experienced on fitting could help.
I am attaching the code, the input histogram and the result I got.
Thanks.
The code can be run by just: root -l tmp.C
DSCBFit.pdf (20.4 KB) signal_50_400_Nominal_reco_m4l_output_combined.root (382.7 KB) ___
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.5*t*t);
}
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.5*alpha_l*alpha_l)*pow(fact1THihgerAlphaH*fact1THihgerAlphaH, -n_h);
}
return N*result;
}
void tmp()
{
TCanvas *c1 = new TCanvas("c1","c1",700,500);
TPad* thePad = (TPad*)c1->cd();
TFile *f = new TFile("signal_50_400_Nominal_reco_m4l_output_combined.root");
TH1F *hpx = (TH1F*)f->Get("havgM_all");
TF1 *fitDSCB = new TF1("fitDSCB",DoubleSidedCrystalballFunction, 255,420, 7);
hpx->GetYaxis()->SetRangeUser(0, 30);
gStyle->SetOptFit(1);
fitDSCB->SetParameters(1, 2, 2, 1, hpx->GetMean(), hpx->GetRMS(),hpx->Integral(255, 425));
fitDSCB->SetParNames ("alpha_{low}","alpha_{high}","n_{low}", "n_{high}", "mean", "sigma", "Norm");
hpx->Fit(fitDSCB, "", "", 255, 420);
Double_t chi2 = fitDSCB->GetChisquare();
cout << "chi2 = " << chi2 << endl;
hpx->Draw("func");
hpx->GetXaxis()->SetRangeUser(200, 550);
thePad->Print("DSCBFit.pdf");
}
ROOT Version: 6.18/04
Built for macosx64 on Sep 11 2019, 15:38:23
From tags/v6-18-04@v6-18-04