RooAddPdf "value is Not-a-Number, forcing value to zero"

Hello,

I’m encountering a problem using RooFit in ROOT-5.28.00. I’m trying to define a extended LL fit model being the sum of a CrystalBall and an exponential but the fits don’t work and I’m getting strange messages such as :

“RooAddPdf::Trial_TotModel[ Trial_SigPdf + Trial_BkgPdf ] = [#0] WARNING:InputArguments – RooExtendPdf::expectedEvents(Trial_SigPdf) WARNING: RooExtendPdf needs non-null normalization set to calculate fraction in range 0x1f4a5f0. Results may be nonsensical
[#0] WARNING:Eval – RooExtendPdf(Trial_SigPdf) WARNING: nExpected = 100 / 0 for nset = ()
[#0] WARNING:InputArguments – RooExtendPdf::expectedEvents(Trial_BkgPdf) WARNING: RooExtendPdf needs non-null normalization set to calculate fraction in range 0x1f4a5f0. Results may be nonsensical
[#0] ERROR:Eval – RooAbsReal::logEvalError(Trial_TotModel) evaluation error,
origin : RooAddPdf::Trial_TotModel[ Trial_SigPdf + Trial_BkgPdf ]
message : p.d.f value is Not-a-Number (-nan), forcing value to zero
server values: !refCoefNorm=(), !pdfs=(Trial_SigPdf = 0,Trial_BkgPdf = 7.38906), !coefficients=()”

Could anyone please give me some help on that ? I’ve put a minimal example.

Thank you in advance, Olivier.

//Minimal example :
//--------------------------------
RooWorkspace * rooWorkspace = new RooWorkspace(“workspace”);
RooRealVar * x = new RooRealVar(“x”,“x”,0.,200.);
rooWorkspace->import(*x);

//Models for the trials
//Model function
RooRealVar Trial_mean2(“Trial_mean2”,“Trial_mean2”,9.5,7,12);
RooRealVar Trial_ResSigma(“Trial_ResSigma”,“Trial_ResSigma”,2.3,0., 10.);
RooRealVar Trial_alfa (“Trial_alfa”,“Trial_alfa”,1.6,0.1,10.);
RooRealVar Trial_n(“Trial_n”,“Trial_n”,2.3,0.1,10.);
RooCBShape* Trial_ResModel= new RooCBShape (“Trial_ResModel”,“Trial_ResModel”,*x, Trial_mean2, Trial_ResSigma, Trial_alfa, Trial_n);
//By default, background is modeled by an exponential
RooRealVar Trial_bgExpParam(“Trial_bgExpParam”, “Trial_bgExpParam”,0.02,0.,0.5);
RooExponential * Trial_BkgModel = new RooExponential(“Trial_BkgModel”,“Trial_BkgModel”,*x,Trial_bgExpParam);

x->setRange(“integralRange”, 8., 11.); //define the signal range
RooRealVar* Trial_Nsig= new RooRealVar (“Trial_Nsig”,“Trial_Nsig”, 100., 1.,1e4);
RooRealVar* Trial_Nbkg= new RooRealVar (“Trial_Nbkg”,“Trial_Nbkg”, 50. , 1.,1e4);
RooExtendPdf* Trial_ExtendedSigPdf = new RooExtendPdf(“Trial_SigPdf”,“Trial_SigPdf”, *Trial_ResModel,Trial_Nsig, “integralRange”);
RooExtendPdf
Trial_ExtendedBkgPdf = new RooExtendPdf(“Trial_BkgPdf”,“Trial_BkgPdf”, *Trial_BkgModel,Trial_Nbkg, “integralRange”);
RooAddPdf
Trial_TotModel = new RooAddPdf(“Trial_TotModel”,“Trial_TotModel”,RooArgList(*Trial_ExtendedSigPdf,*Trial_ExtendedBkgPdf));
rooWorkspace->import(*Trial_TotModel);

rooWorkspace->Print();

Hi,

I’m getting the same warning/error for my fit. I’m using root 5.32.00-rc2 (compiled with gcc 4.6.1, on Ubuntu 11.10). I do the following:

int dilepton_mass_fitter_y3s()
{
  TFile * file_1 = new TFile("../rootout/force_cms/systematic_studies_0/fcm_0/plot1_Run7_type12_pidopt1.root");
  TH1D *  hist   = static_cast<TH1D*>(file_1->Get("dileptonmass0_mmnopid"));
  hist->GetYaxis()->SetLabelSize(0.02);
  RooRealVar x("dilepton mass","dilepton mass/#sqrt{s}",0.88,1.03);
  RooDataHist dh("dh","dh",x,hist);

  RooRealVar mean("mean", "mean", 0.99, 0.98, 1.01);
  RooRealVar sigma("sigma", "sigma", 0.001,0.0, 0.1);
  RooRealVar alpha("alpha", "alpha", 1.2, 0.9, 2.0);
  RooRealVar n("n","n", 1, 0, 100);
  
  RooCBShape cball("cball", "Crystal Ball Shape", x, mean, sigma, alpha, n);

  RooRealVar mean_y2("mean_y2", "mean_y2", 0.965, 0.96, 0.97);
  RooRealVar sigma_y2("sigma_y2", "sigma_y2", 0.05, 0.0, 0.1);
  RooGaussian gauss_y2("gauss_y2", "gauss_y2", x, mean_y2, sigma_y2);

  RooRealVar mean_y1("mean_y1", "mean_y1", 0.91, 0.88, 0.93);
  RooRealVar sigma_y1("sigma_y1", "sigma_y1", 0.05, 0.0, 0.1);
  RooGaussian gauss_y1("gauss_y1", "gauss_y1", x, mean_y1, sigma_y1);

  RooRealVar nsig("nsig",  "#Upsilon (3S) events",1000,0.,100000) ; 
  RooRealVar nsig1("nsig1","#Upsilson (1S) events",400,0.,100000) ;
  RooRealVar nsig2("nsig2","#Upsilson (2S) events",400,0.,100000) ;
  //RooRealVar nsig3("nsig3","#Upsilson (3S) events",400,0.,100000) ;


//  RooRealVar mean_y3("mean_y3", "mean_y3", 1.00, 0.96, 1.04);
//  RooRealVar sigma_y3("sigma_y3", "sigma_y3", 0.05,0.0, 0.1);
//  RooGaussian gauss_y3("gauss_y3", "gauss_y3", x, mean_y3, sigma_y3);
//  RooAddPdf sum("sum", "cb+g1+g2+g3", RooArgList(cball,gauss_y1,gauss_y2,gauss_y3), RooArgList(nsig,nsig1,nsig2,nsig3));
  RooAddPdf sum("sum", "cb+g1+g2", RooArgList(cball,gauss_y1,gauss_y2), RooArgList(nsig,nsig1,nsig2));

  sum.fitTo(dh, Range(0.88,1.03), Extended(true));
  //cball.fitTo(dh, Range(0.96,1.04));

  RooPlot * frame = x.frame(Name("frame"), Title("Dilepton Mass"));
  frame->SetLabelSize(0.02);
  frame->GetYaxis()->SetLabelSize(0.025);
  frame->GetYaxis()->SetTitleSize(0.04);
  dh.plotOn(frame, DataError(RooAbsData::SumW2)) ;
  sum.plotOn(frame);


  frame->Draw();
  gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.5);
  gPad->SaveAs("dilepton_mass/dilepton_mass_y3s.eps");
  gPad->SaveAs("dilepton_mass/dilepton_mass_y3s.png");

  RooArgSet * params = sum.getParameters(x);
  params->printLatex();
  
  return 0;
}

I’ve narrowed the problematic bit of code to:

sum.fitTo(dh, Range(0.88,1.03), Extended(true));

If I changed Extended(true) to Extended(false), the macro runs and produces a fit. I’m unsure if this is a general problem with using the Extended(true) – or if I’m just not doing the fit properly.

Cheers,

Greg
dilepton_extended_true.txt.gz (22.9 KB)
dilepton_extended_false.txt (13.8 KB)

Greg, may I ask you to remove “Range” from your macro?
sum.fitTo(dh,Extended(true));
Does it help to get rid of errors?
I’ve switched to new root (and roofit 3.50) and get strange nan’s with my macro (everything was good with root 5.30.02).
When I don’t use “Range” option everything gets better.
No idea how these nan’s can be obtained. I’ll try to reproduce my problem with a minimal amount of code.

Hi,

Thanks, that appears to work. To summarize the change, I did the following:

sum.fitTo(dh, Range(0.88,1.03), Extended(true), SumW2Error(kTRUE));

becomes:

sum.fitTo(dh, Extended(true), SumW2Error(kTRUE));

With that, the Extended fit converged properly and didn’t complain about NaN issues.

Cheers and Thanks,

-Greg

[quote=“zwe32”]Greg, may I ask you to remove “Range” from your macro?
sum.fitTo(dh,Extended(true));
Does it help to get rid of errors?
I’ve switched to new root (and roofit 3.50) and get strange nan’s with my macro (everything was good with root 5.30.02).
When I don’t use “Range” option everything gets better.
No idea how these nan’s can be obtained. I’ll try to reproduce my problem with a minimal amount of code.[/quote]

OK, I believe we’ve found a bug.
For my purposes, the “Range” feature is a mandatory and I’m not ready to reject it.
Hope to reproduce it and make a bug report soon.