The final value of RooRealVar is always equal to the initial value

Hi all,
I meet something unusual when I performing unbinned likelihood using roofit: Only the first parameters get changed and the others do not(always be in the initial values!)

But when I using binned likelihood fit(RooDataHist), the fit result is perfect and get no errors. I can’t figure out what reason it is.
The signal and background pdf are constructed by:

    RooRealVar mean("mean", "", 5280,5276,5282);
    RooRealVar sigma("sigma", "", 3,2,4);
    RooGaussian sigpdf("sigpdf", "", mass, mean, sigma);

    RooRealVar nsig("nsig", "", 2140,0,10000);
    // RooRealVar nbkg("nbkg", "", 11845, 0,12500);
    RooRealVar nbkg("nbkg", "", 0);
    RooRealVar frac("frac", "", 0, 1);
    // RooAddPdf allpdf("allpdf", "", RooArgList(sigpdf, pol), RooArgList(nsig, nbkg));
    RooAddPdf allpdf("allpdf", "", RooArgList(sigpdf), RooArgList(nsig));
    RooFitResult *result = allpdf.fitTo(*data,  RooFit::SumW2Error(kTRUE),RooFit::Save());

PS: the output when fitting with RooDataSet is:

     Floating Parameter  InitialValue    FinalValue +/-  Error     GblCorr.
  --------------------  ------------  --------------------------  --------
                  mean    5.2800e+03    5.2800e+03 +/-  0.00e+00  <none>
                  nsig    2.1400e+03    2.1400e+03 +/-  0.00e+00  <none>
                 sigma    3.0000e+00    3.0000e+00 +/-  0.00e+00  <none>
#0] WARNING:Minization -- RooMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-1e+30) to force MIGRAD to back out of this region. Error log follows
Parameter values: k0=0.8, nbkg=16250, nsig=1910.97
RooNLLVar::nll_allpdf_data[ paramSet=(k0,nbkg,nsig) ]
     function value is NAN @ paramSet=(k0 = 0.8 +/- 0.0420735,nbkg = 16250 +/- 5259.19,nsig = 1910.97 +/- 589.03)
RooAddPdf::allpdf[ nsig * sigpdf + nbkg * pol ]
     getLogVal() top-level p.d.f evaluates to zero @ !refCoefNorm=(), !pdfs=(sigpdf = 0/60469,pol = -nan/300), !coefficients=(nsig = 1910.97 +/- 589.03,nbkg = 16250 +/- 5259.19)

Here is the scripts and data set:

newfit.C (1.7 KB)
Processing: MCBu2L0pJpsi_all_newmass.root…

I find the reason:
The fit variable of some events are nan, which lead to errors. After removing such events, everything get fine.
Similar situation: Extended fit with RooHistPdf results in ‘function value is NAN’ - Newbie - ROOT Forum (

Thank you for letting us know. When you get pdf values as Nan you should get an error message from Roofit and one needs to take notice of these messages.



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