Can't reproduce fit function with returned fit parameters in RooFit

I am creating a PDF that’s a sum of a Gaussian and a Landau with a fraction f applied to the Landau:

wks->factory(“Gaussian::gausSIG(Mjj,mGSIG[38.32,38.092,38.548],wGSIG[7.0,0,16])”); //Create Gaussian with mean and width [init, min, max]
wks->factory(“Landau ::landSIG(Mjj,mLSIG[82,43,121],wLSIG[100,0,400])”);
wks->factory(“SUM::pdfSIG(gausSIG,fSIG[0.70612,0.693,0.719]*landSIG)”);

Then I fit the data and get back the fit values for means, widths and f:

 RooFitResult *fr = wks->pdf("pdfSIG")->fitTo(*wks->data("totalDataSet"+signal),RooFit::Save()); //Fit to preselected data
  fr->Print("v");

The data and the fit are plotted:
wks->data(“totalDataSet”+signal)->plotOn(plotT,RooFit::DataError(RooAbsData::SumW2));
wks->pdf(“pdfSIG”)->plotOn(plotT,RooFit::Name(“totalFit”));

But if I take the fit values from the print statement above and try to recreate the Gassian+Landau:

  TF1 f6("f6","[6]*([0]*TMath::Landau(x,[1],[2])+[3]*TMath::Gaus(x,[4],[5]))",0,100);
  f6.SetParameters(0.719,83.207,28.335, 0.281,38.548,7.6509,1.8);

(the 1.8 is a guess at the overall norm factor)
I get the red curve in this figure (the blue is the output of the fit). The Gaussian is low and the Landau is high, so it’s not the norm factor.

Any suggestions would be appreciated.

Hi,

The SUM operator in RooFit performs a normalised sum of the two pdf’s in the given range while in the TF1 this is not the case. Even if you use the gaussian normalised form (e.g. TMath::Gaus(x, mean. sigma, true) or ROOT::Math::normal_pdf(x, sigma, mean) ) they will one normalised in the [-inf, +inf] range and not in the limited one of the observables.

The solution is to use the TF1NormSum class or (if using the master) the new introduced NSUM operator in TF1.
See the tutorial fitNormSum.C if using version <=6.10
https://root.cern.ch/doc/master/fitNormSum_8C.html

or if using the master

 TF1 f6("f6", "NSUM([a0] * landau, [a1] * gaus)", 0, 100);
 f6.SetParameters(0.719,0.281,83.207,28.335,38.548,7.6509);

Best Regards

Lorenzo

Thank you. This is very helpful.

I am having trouble still following the tutorial for TF1NormSum, because these lines:
TF1 *f_cb = new TF1(“MyCrystalBall”,“crystalball”,-5.,5.);
TF1 *f_exp = new TF1(“MyExponential”,“expo”,-5.,5.);

f_exp-> SetParameters(1.,-0.3);
f_cb -> SetParameters(1,signal_mean,0.3,2,1.5);
// CONSTRUCTION OF THE TF1NORMSUM OBJECT …
// 1) :
TF1NormSum *fnorm_exp_cb = new TF1NormSum(f_cb,f_exp,nsig,nbkg);
// 4) :
TF1 * f_sum = new TF1(“fsum”, *fnorm_exp_cb, -5., 5., fnorm_exp_cb->GetNpar());
f_sum->Draw();

draws a flat line at zero. It seems to need a SetParameters for the combined function before the Draw(), even though the component functions have their own SetParameters, and I thought the coefficients for the sum are set in TF1NormSum as nsig and nbkg.

HI,

Yes you need to set the parameters in the TF1, as shown in the tutorial, by doing

f_sum->SetParameters( fnorm_exp_cb->GetParameters().data() );

Lorenzo

Thank you for the help.

-Tony

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