Retrieving the number of iterations a fit required

ROOT Version: 6.18.04b
Platform: SL6/7
Compiler: g++7.3

I’m trying to fit a PMT pulse charge distribution function but, despite ongoing efforts, it seems one TF1 does not fit all. By itself this is tolerable, since the fits that fail are generally ones where no useful information is present. The issue is that these fits ‘fail’ by simply going on trying to fit forever, until my grid computing job gets killed. This is a poor use of resources, bad for my grid priority, and means that none of my results up to that point get copied out of the grid node.

From the documentation on TH1::Fit it says:

ROOT::Math::MinimizerOptions ( can be used also to set other default options, like maximum number of function calls.

It seems like limiting the maximum number of iterations would be a suitable way to exit these fits after some maximum duration (although a time may be more ideal, since I don’t know how long each iteration may take…) but I have no idea what number of iterations I would typically expect to be required. Is there a way to retrieve the number of iterations a fit required upon success, so that I can profile a range of acceptable values and place a suitable limit?

N.B. As much as it would be the “correct” approach, I’m not looking to debug exactly where the fit is getting stuck right now. The fitting function is a complicated user-defined one and I don’t have the time for such an involved effort right now. I’m just looking for a quick and dirty “OK, you tried, it’s time to move on to the next histogram.” :slight_smile:

If you pass the option “S” to the TH1::Fit call, then store the fit result pointer, you can call the NCalls() method to get the number of times the TF1 had to be called. I think this should be proportional to the number of iterations.

Ah perfect, that’s where it is! Thankyou!

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