MnMigrad() return c++ seg-fault in PyROOT


I want to use ROOT.Minuit2 for fitting data. However, when I execute MnMigrad() in PyROOT, Jupyter console displays c++ segmentation fault error. How to fix under my code ?

class MyFCN(Minuit2.FCNBase):
    def __init__(self):
        pass
    def __call__(self, params):
        return 1.

fcn = MyFCN()
param = Minuit2.MnUserParameters()
param.Add("test1",0.01, 0.01)
param.Add("test2",0.01, 0.01)
param.Add("test3",0.01, 0.01)
migrad = Minuit2.MnMigrad(fcn, param,3)
migrad()

Error massage is here.

SegmentationViolation Traceback (most recent call last)
/var/folders/gf/kt47jhy56f7ch38t9ft4hhfm0000gn/T/ipykernel_19839/3223852618.py in
9 param.Add(“test3”,0.01, 0.01)
10 migrad = Minuit2.MnMigrad(fcn, param,3)
—> 11 migrad()
SegmentationViolation: ROOT::Minuit2::FunctionMinimum ROOT::Minuit2::MnApplication::operator()(unsigned int maxfcn = 0, double tolerance = 0.10000000000000001) =>
SegmentationViolation: segfault in C++; program state was reset

ROOT Version: JupyROOT 6.22/08
Platform: macOS Catalina 10.15.7


@moneta do you see any problem in this code? Is this how one would do this in C++? Is there any alternative?

Hi,
It should work in C++, see for example root/DemoGaussSim.cxx at master · root-project/root · GitHub.

As a workaround I would use the Minimizer interface, see the tutorial
https://root.cern.ch/doc/master/NumericalMinimization_8C.html

Lorenzo

I think you need to at least implement the Up method, which is pure virtual in FCNBase. Not sure if there are other required methods as well.

Cheers,
Enrico

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