RooFit to TF1 problem

Dear experts,

  I am trying to use RooFit for fitting a histogram (already weighted and sumw2() is used while filling).  I do the following in my code:
  1. Fit a histogram (with in some range ) with a pdf “f1_Fit”
  2. Take this f1_Fit and generate a toy
  3. fit the toy with a different pdf “test_Fit”


  • Now at step-1 my fit get converge but I see that fitted function is always above the input histogram when I plot them(black dots and blue line once plotted from attached code). I tried varying fit parameter but of no help and it seems its just normalization issue as shapes looks quite similar.

  • The 2nd problem is at step-3. I make transfer from RooFit to TF1 object so that I could get the shape uncertainty in each bin using test_Fit->InegralError(…) method which I need for my study. But when I print the bin-by-bin value using Eval() method from this fit function I see that its nowhere near the input histogram values. I print them in same bin and at the bin center. Although I expected them to be a bit different due to above problem at step-1 but they look completely off. On the other hand the toy data and fit to it looks fine (green dot and green dashed line if one runs the attached script.).

    I have attached the testFit.C and input root file here in case you would like to see it. I will appreciate any help on this.


testFit.C (5.04 KB)
testFile.root (4.86 KB)


From th original pdf as a normalised function you can get a TF1. Then in order to use as a function you need to scale by the integral on the data set you observe. So you would need to scale the TF1 by the number of events and the bin width.

Best Regards


Thanks Lorenzo!
I think you were referring to my 2nd query. I didn’t understand completely your suggestions specially regarding the binwidth because I have RooDataHist with variable binning. OR you meant while trying to get integral in each bin I should scale the TF1 value by (bin_entries/binwidth) where bin_entries should be the number of events from my input histogram(in this case toy dataset I generated)?

Best Regards,