Iterative fitting vs one by one

Dear root developers

I am trying to fit 10 RooDataSet’s iteratively without having to construct the PDF every time in the loop. For this reason I am updating the PDF observable with the RooRealVar from the data set, I am creating the RooAbsReal object with the createNLL method and I am fitting the data set with migrad and subsequently I call hesse. At the end of each loop I am setting the PDF variables to their initial values and their errors to 0 so that RooFit calculates the step size from the variable ranges. The fit I am performing is an unbinned extended maximum likelihood fit.
What I observe is that the iterative method works (fit converges), but there are differences in the fit logs when I am running the fit only the data set stand alone (without iterations over the other datasets). Therefore I have a few question.

  1. What is the counter value in the minuit output? I see that although I am deleting the minimizer in every iteration the fits somehow know that a previous call to minuit was performed.
  2. I see (in the fitlogs attached) that the same fit, with the same model and the same dataset, and the same starting point converges to the same point but with different fit steps. (In the iterative method the function calls are more than in the one off fitting).
  3. Why is the FCN value different between the two fits?
  4. Is there a way, so I can fit mutliple data sets without having to re-construct the PDF in every iteration?
    The ROOT version I am using is: 6.20.06-x86_64-centos7-gcc8-opt
    I am attaching also the macro that produces the different fit logs.

Thanks a lot in advance
–John

standaloneFit.txt (8.8 KB)
iterativeFitLog.txt (12.7 KB)
testIterativeFit.C (3.3 KB)

@jonas can you please take a look whenever you will have a time? Thank you!

Hi @ixiotidi, sorry for the late answer!

To really understand what’s going on here, it would be useful if you can also upload the script to reproduce your standaloneFix.txt because it’s not completely clear to me how you do that “standalone” fit. Do you still have that script?

Cheers,
Jonas

Hi @jonas

thanks for the reply the script is the same I posted. You just need to set the value of starting the loop to 9 so that it runs only once on the last dataset in the vector. I think I have the comment as well in the code there. The variable is oneFit = 9.

Cheers
—John

Thanks for the clarification! I understand better now.

Your confusion comes from the starting parameters not being the same in the standalone and iterative fit.
In your script, nGaus and nCheb set to 25 and 30 for the first fit, which are the same values you used to generated the dataset. That’s why your “standalone” fit converges faster. For the subsequent iterations, you set nGaus and nCheb to 100 and 200. If I set them to 100 and 200 also for the fist fit in line 67 and 70 in your script, then the fits converge with the same number of iterations.

About the minuit output: here the problem is that ROOT instantiates a global TMinuit object called gMinuit that is also used by RooFit. That’s why the counter is not cleared, because even though you create new RooMinimizers there all use the same instance gMinuit.

What I would do here to reset minuit would be to delete gMinuite and construct it again at the beginning of your fitSample function:

delete gMinuit;
gMinuit = new TMinuit{};

With resetting gMinuit and taking consistent starting parameters, there is no difference at all anymore between the logs of the iterative fit and the standalone fit. I hope this helps you and you can now do your fits without reconstructing the PDF in every iteration!

Jonas

Hi @jonas

sorry for not spotting the wrong values! Thanks a lot about the clarification I think that is exactly solving my issue!

Cheers
—John

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