TFitter Minuit Execute Command TypeError: 'int' object is not iterable

I need your help

I am fitting data with minuit in ROOT in python enviroment (jupyter notebook)

My PDF is an exponential:

def pdf(x, *x0):
    f=(1/x0[0])*np.exp(-x/x0[0])
    return f

I define the Likelihodd function:

def LHM(*x0):
    n= invariant_mass.GetNbinsX()
    f=1
    for i in n:
        frec= invariant_mass.GetBinContent()
        x = invariant_mass.GetBinCenter()
        
        f = f*(pdf(x,*x0))**(frec)
    
    f=-2*np.log(f)
    
    return f       

The minuit fitting procedure:

minuit= ROOT.TVirtualFitter.Fitter(0,3)
minuit.SetParameter(0,"lambda",10,0.01,0,0)
minuit.SetFCN(LHM)
arglist = np.empty(100)
arglist[0]=0.0
minuit.ExecuteCommand("SET PRINT", arglist,1)

The problem begins here:

arglist[0]=500.0
arglist[1]=0.01

minuit.ExecuteCommand("MIGRAD", arglist, 2)

The problem is the third argument the int “2”. This is the error message:

TypeError                                 Traceback (most recent call last)
Cell In[411], line 8
      5 arglist[0]=500.0
      6 arglist[1]=0.01
----> 8 minuit.ExecuteCommand("MIGRAD", arglist, 2)

TypeError: int TFitter::ExecuteCommand(const char* command, double* args, int nargs) =>
    TypeError: 'int' object is not iterable

 **********
 **   60 **MINIMIZE         500        0.01
 **********

I have tried putting an int in C++ type, range(2), and other options, but none of them seem to work. I would appretiate your help.

Hi @Omar_Medina,

First of all, welcome to the ROOT forum! I guess @moneta can help with this.

Cheers,
J.

1 Like

Hi,
I think this is due to some issues in PyROOT to understand this interface. Since we do not recommend anymore to use the TFitter interface, but the ROOT::Math::Minimizer interface, you should use that one hen you just want to minimize a user provided function.
We have a Python example for it in the tutorial NumericalMinimization.py

Lorenzo

1 Like

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