Home | News | Documentation | Download

Basic Roofit fit

Can anyone suggest a simple code to fit data to a user-defined function in RooFit. The function is not normalized in my case.
Function is of the form

===========================================
Double_t fitnew(Double_t *x, Double_t *par){ 
  Double_t pi = TMath::Pi();
  Double_t volume = par[0];
  Double_t temp   = par[1];
  Double_t    q   = par[2];
  Double_t m = 0.139;
  int g = 1;
  
  Double_t norm = g*volume/(2.0*2.0*2.0*pi*pi*pi);
  Double_t y = q-1.0;
  Double_t mt = sqrt(m*m+x[0]*x[0]);         
  Double_t f1 = TMath::Power((1+ (y*mt/temp)),-q/y);
  Double_t f2 = norm*mt*f1;
  
  return f2;
}
=================================================

and the data is

======================================================================
Double_t xbin[40] = {0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80,0.85, 0.90, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.5, 5.0};

Double_t y[39] = {1810.0, 1509.0, 1226.0, 985.5, 791.4, 644.1, 526.6, 433.1, 358.5, 298.5, 250.2, 210.9, 178.4, 151.4, 129.3, 110.9, 94.85, 75.5, 56.54, 42.52, 31.96, 24.34, 18.52, 14.29, 11.03, 8.641, 6.72, 4.683, 2.865, 1.774, 1.107, 0.6974, 0.4408, 0.2836, 0.1851, 0.1222, 0.08176, 0.0425, 0.01805};
Double_t y_err[39] = {243.01851, 171.00292, 121.00413, 89.30358, 67.60362, 54.00333, 43.80285, 35.80223, 29.60270, 24.50183, 20.50219, 17.20261, 14.50137, 12.30162, 10.50190, 9.00222, 7.70187, 6.12081, 4.59088, 3.47051, 2.61030, 2.00039, 1.57028, 1.21037, 0.93021, 0.72927, 0.56722, 0.39306, 0.24003, 0.14803, 0.09202, 0.05781, 0.03642, 0.02341, 0.01521, 0.01001, 0.00667, 0.00345, 0.00146};
===========================================================

I have managed to nicely fit the function in normal root with chi2/NDF value of around 1 but I want to try the RooFit
I have written the code for roofit generating PDF using
RooClassFactory::makePdf
but the fit is really bad with chi2/NDF value around 300
I guess this difference is because the makePDF class normalizes the PDF function on its own.

Perhaps @moneta can help?

Hi,
Yes RooFit will normalize the pdf. If you want to just fit a function using a chi2, there is no need to use RooFit, I would continue using ROOT in this case.
Also when fitting you should make sure that you use the provided errors. I think the chi2 fit in RooFit uses by default the expected errors computed from the function value. This might explains the difference.

Best regards

Lorenzo

1 Like

Thanks @moneta and @jblomer for the help.

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