Fit a crystalBall function to a histogram

Hi everybody ,
I want to fit a crystalBall function to my histogram. I run these codes:

void roofit() {
RooRealVar recoilMass(“recoilMass”, “recoilMass”, 2.7, 3.2);
RooRealVar mass(“mass”, “mass”, 2.7, 3.2);
TH1 eantieHist = createHist(“gamma_10000_300.root”, “photon”, “gamma_recoil_mass”);
RooRealVar mean(“mean”, “mean”, eantieHist->GetMean(), 2.7, 3.2);
RooRealVar sigma(“sigma”, “sigma”, eantieHist->GetRMS(), 0.0, 0.1);
RooRealVar alpha(“alpha”, “alpha”, -0.2889477486, -1.0, 0.0);
RooRealVar n(“n”, “n”, 15.18, 11.18,19.18);
RooRealVar constant(“constant”, “constant”, 789.0, 176.9,801.1);
RooCBShape crystalBall(“crystalBall”, “crystalBall”, recoilMass, mean, sigma, alpha, n);
RooAddPdf model(“model”, “model”, RooArgSet(crystalBall), RooArgList(constant));
RooDataHist eantieDataHist(“eantieDataHist”, “eantieDataHist”, recoilMass, Import(eantieHist));
RooFitResult
crystalBallFitRes = model.fitTo(eantieDataHist);
RooPlot
frame = recoilMass.frame(Title(“recoil mass”));
eantieDataHist.plotOn(frame);
model.plotOn(frame);
}

TH1* createHist(TString fileName, TString treeName, TString branchName) {

TFile *file = new TFile(fileName);
TTree *fit4c = (TTree*) file->Get(treeName);
Double_t metac;
fit4c->SetBranchAddress(branchName, &metac);

//create one histogram
TH1D *hist = new TH1D("signal", "signal", 100, 2.7, 3.2);

Int_t nentries = (Int_t) fit4c->GetEntries();
for (Int_t i = 0; i < nentries; i++) {
    fit4c->GetEntry(i);
    //fill the histogram with the destep entry
    hist->Fill(metac);
}
//hist->Draw();
return (hist);

}
but i couter with this warning:

[#0] WARNING:Minization -- RooMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-72548.6) to force MIGRAD to back out of this region. Error log follows
Parameter values: alpha=-0.691004, constant=799.358, mean=2.93951, n=18.9449, sigma=0.00217694
RooNLLVar::nll_model_eantieDataHist[ paramSet=(alpha,constant,mean,n,sigma) ]
     function value is NAN @ paramSet=(alpha = -0.691004,constant = 799.358,mean = 2.93951,n = 18.9449,sigma = 0.00217694)
RooAddPdf::model[ constant * crystalBall ]
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00674066), !coefficients=(constant = 799.358)

[#0] WARNING:Minization -- RooMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-65740.4) to force MIGRAD to back out of this region. Error log follows
Parameter values: alpha=-0.765336, constant=545.488, mean=2.99935, n=11.1808, sigma=0.00263731
RooNLLVar::nll_model_eantieDataHist[ paramSet=(alpha,constant,mean,n,sigma) ]
     function value is NAN @ paramSet=(alpha = -0.765336,constant = 545.488,mean = 2.99935,n = 11.1808,sigma = 0.00263731)
RooAddPdf::model[ constant * crystalBall ]
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00796657), !coefficients=(constant = 545.488)

[#0] WARNING:Minization -- RooMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-54072.7) to force MIGRAD to back out of this region. Error log follows
Parameter values: alpha=-0.529975, constant=796.314, mean=2.94278, n=17.8606, sigma=0.00364762
RooNLLVar::nll_model_eantieDataHist[ paramSet=(alpha,constant,mean,n,sigma) ]
     function value is NAN @ paramSet=(alpha = -0.529975,constant = 796.314,mean = 2.94278,n = 17.8606,sigma = 0.00364762)
RooAddPdf::model[ constant * crystalBall ]
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.0127535), !coefficients=(constant = 796.314)

[#0] WARNING:Minization -- RooMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-37659) to force MIGRAD to back out of this region. Error log follows
Parameter values: alpha=-0.922536, constant=801.055, mean=2.9367, n=18.8443, sigma=0.00204312
RooNLLVar::nll_model_eantieDataHist[ paramSet=(alpha,constant,mean,n,sigma) ]
     function value is NAN @ paramSet=(alpha = -0.922536,constant = 801.055,mean = 2.9367,n = 18.8443,sigma = 0.00204312)
RooAddPdf::model[ constant * crystalBall ]
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(crystalBall = 0/0.00573731), !coefficients=(constant = 801.055)


How can I fix this error ? ’
thanks for any help.

Hi ,

Probably your initial parameters are too far off and the fit does not work.
You should try to initialise them with better values.

However, if you want me to look at the code, you should post a running macro and the files needed to run it

Best Regards

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.