RootFit Warning Plotting

Hi,
I’m a beginner in ROOT. The ROOT version is ROOT 6.24/08. The platform is Linux and Compiler is C++.
When I use RooFit to fit data, some warning message occurs:

WARNING:Plotting -- At observable [x]=3.67 RooRealIntegral::total_Norm[psi3686][ total_Norm(psi3686) ]
     function value is NAN @ !sumList=(), !intList=(), !anaList=(), !jacList=(), !facList=(), !func=total=nan/1, !sumCat=()
RooChebychev::bkg[ x=psi3686 coefList=(c2) ]
     p.d.f value is less than zero (-0.167746), trying to recover @ x=psi3686=3.67, coefList=(c2 = 1.16775 +/- 0.00143608)
RooAddPdf::total[ Nsig * gaus1 + Nbg * bkg ]
     p.d.f value is Not-a-Number @ !refCoefNorm=(psi3686 = 3.67), !pdfs=(gaus1 = 0.122661/0.0139807,bkg = -0.167746/0.05), !coefficients=(Nsig = 15.4678 +/- 4.55331,Nbg = 18.5275 +/- 4.87752)"

But it’s strange than the fit status shows OK. By the way, I use Gaussian function to fit signal and polynomial or Chebychev( Both of them I have tried) to fit background.
my code :

void fit_data(){
   
    TString inputfile = "...";
 
    /*TChain chain("Psi3686"); 
    chain.Add("");
   */
    //***** fit value ***********************************************************
    double x_min = 3.67;
    double x_max = 3.72;
    int n_bins = 50;
    RooRealVar psi3686("psi3686","M_{Psi(3686)}",x_min,x_max,"GeV/c^{2}");
    //** signal ******************************************************************
    RooRealVar mean1("mean1", "",          3.68610e+00, 3.2, 4);
    RooRealVar sigma1("sigma1", "",        8.3e-03, 5e-03, 1.2e-02);
    RooGaussian gaus1("gaus1", "gaus1", psi3686, mean1, sigma1);
    //**  background ******************************************************************
    RooRealVar c2("c2","coeffiicient #2",-0.1,-3000,3000) ;
    RooChebychev bkg("bkg","background p.d.f",psi3686,RooArgList(c2));

    /*RooRealVar p0("p0", "poly 0", 0, -10.,10) ;
    RooRealVar p1("p1", "poly 1", 0, -10.,10) ;
    RooRealVar p2("p2", "poly 2", 0, -10.,10) ;
    RooPolynomial bkg("bkg", "bkg PDF", psi3686, RooArgList(p0,p1,p2));*/
    
    //** total **************************************************************
    RooRealVar Nsig("Nsig", "", 10, 0, 1000000);
    RooRealVar Nbg("Nbg", "", 10,0,    1000000);
    RooAddPdf total("total", "total", RooArgList(gaus1, bkg), RooArgList(Nsig, Nbg));

    //****************************************************************************
    //  data
    //****************************************************************************
    TFile *file = new TFile(inputfile );
    TTree *tree = (TTree*)file->Get("Psi3686");
    RooDataSet *dataset_var = new RooDataSet("dataset_var", "data variable",tree, psi3686);
    
    //RooDataSet *dataset_var = new RooDataSet("dataset_var", "data variable", &chain, psi3686);
    //****************************************************************************
    //  PERFORM A  FIT  and   PLOT THE RESULTS
    //****************************************************************************
    RooFitResult *fit_res_all = total.fitTo( *dataset_var, Extended(1));
    //****************************************************************************
    RooPlot *frame = psi3686.frame(Bins(n_bins), Title("normal fit"));
    dataset_var->plotOn(frame, Binning(n_bins), LineColor(kBlack), Name("data"));
    total.plotOn(frame, LineColor(kBlue), Name("model"));
    //total.plotOn(frame, Components("gaus1"), LineStyle(2),LineColor(2));
    total.plotOn(frame, Components("bkg"), LineStyle(2),LineColor(1));
    
    frame->GetXaxis()->SetTitle("M_{psi3686 }(GeV/c^{2})");
    frame->GetYaxis()->SetTitle(Form("Events/%.3f GeV/c^{2}", (x_max - x_min) / n_bins));
    frame->GetXaxis()->CenterTitle();
    frame->GetYaxis()->CenterTitle();
    
    TCanvas *c1 = new TCanvas("c1", "c1", 800, 600);
    c1->cd();
    frame->Draw();

    // ****************label****************************
    TLatex latex;
    latex.SetNDC();
    latex.SetTextSize(0.03);
    latex.SetTextAlign(11); 
    latex.DrawLatex(0.7, 0.85, Form("Nbg = %.4f +/- %.4f", Nbg.getVal(), Nbg.getError()));
    latex.DrawLatex(0.7, 0.8, Form("Nsig = %.4f +/- %.4f", Nsig.getVal(), Nsig.getError()));
    latex.DrawLatex(0.7, 0.75, Form("mean1 = %.4f +/- %.4f", mean1.getVal(), mean1.getError()));
    latex.DrawLatex(0.7, 0.7, Form("sigma1 = %.4f +/- %.4f", sigma1.getVal(), sigma1.getError())); 
    
    c1->SaveAs("fit.jpg");
}

Sincerely thanks for any suggestions!

Dear Yanpeng,

Welcome to the ROOT community!
Thanks for sharing the code and messages printed during the fit. This kind of outputs are typically a symptom of a fit which has a hard time converging. Perhaps a different functional form or more sensitive initial parameters values could help.

Cheers,
Danilo

Thanks for your suggestions! I meet another question:

WARNING:Eval -- RooAbsPdf::getLogVal(total) WARNING: large likelihood value: 3.96579e+09

So,do you have any suggestions? :thinking:

Hi,

Thanks for sharing. It really seems your fit is unstable, besides improving your model and initial parameters values, I am afraid I would not know what to suggest: it does not seem to be an issue of ROOT.

Cheers,
Danilo