I am using Minuit with pyroot. I have learnt how to define a function in python and pass it to the fitting method, using ROOT::Fit::Fitter for example. Now I would like to use all the functionality provided by Minuit to minimize chi2 and estimate the best fit and error bars. I have found all the information about the TMinuit class in
Now I wondering if anyone has a tutorial or a working example I can use as a template for doing such analysis, plotting contours etc. I have googled it and surprisingly I haven’t found much material about minuit in C++.
This example is for the TMinuit class. This is a low level class and we recommend to use either the ROOT::Math::Fitter class or, if you want something at lower level, the ROOT::Math::Minimiser.
Examples are also in tutorials in $(ROOTSYS)/tutorials/fit/ but in C++, it should be easy to convert them Python.
Direct links are:
I have already performed the fit using ROOT::MATH::Fitter class in python, and it works.
I think the minimizer class is something I may use. I would need specifically to draw contours of the chi2 for arbitrary values of the chi2 (Contours from minos for arbitrary sigma level), and you mentioned that I could use ROOT::Math::MinimizerOptions::SetDefaultErrorDef( value). Now it is not clear to me if I should use then the minimizer class to draw the contours or the TMinuit class. (Do I understand correctly that the classes T<Something> are considered low level?)
@moneta I have found some sample code Numerical Minimization with ROOT::Math::Functor and I am able to run it. If I change min = ROOT.Math.Factory.CreateMinimizer("GSLMultiMin", "BFGS") to min = ROOT.Math.Factory.CreateMinimizer("Minuit2", "") I get an error:
min.SetMaxFunctionCalls(1000000)
ReferenceError: attempt to access a null-pointer
but min = ROOT.Math.Factory.CreateMinimizer("Minuit", "") works. Is it obvious? any explanation?
I have changed ROOT.Math.MinimizerOptions.SetDefaultErrorDef(chi2_contour2) with minimum.SetErrorDef(chi2_contour2) and it produces two distinct contours (using either chi2_contour2 or chi2_contour3 ). It is not clear to me if SetErrorDef takes as input the same quantity of SetDefaultErrorDef, as I do not find any documentation, I suppose I should look into the source code then. In particular it is not clear if the input should be the value of the chi2 or the probability or some multiplicative factor of sigma
EDIT: from https://root.cern.ch/download/minuit.pdf section 3.3.8 and table 7.1 I would understand that ERRDEF is actually the UP parameter that is the difference between the chi2 I am interested in and the minimum chi2
for likelihood fits, and the same without 0.5 for chi^2 fits, and N is the is the number of standard deviations (sigmas) you want to plot the contour at.