Segmentation violation when compiling code using Minuit2

Hello,

I am trying to compile a rather complex code which minimizes a set of parameters using Minuit2

I define my minimization function as suggested in the tutorials:

// for e.g. 5 parameters
double parStart[5] = {}
ROOT::Math::Functor fcn(chi2Function,5);
ROOT::Fit::Fitter  fitter;

fitter.SetFCN(fcn, parStart);

Everything else in my code compiles (seemingly) well. The problem appears only when it runs the minimization, i.e. the problematic line is

bool ok = fitter.FitFCN();

The error I get depends on the version of ROOT, which I find a bit strange:

ROOT 6.18/00

*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f331a65d4fc in waitpid () from /lib64/libc.so.6
#1  0x00007f331a5daf62 in do_system () from /lib64/libc.so.6
#2  0x00007f331c9df00c in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/views/LCG_100/x86_64-centos7-gcc10-opt/lib/libCore.so
#3  0x00007f331c9dc615 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/views/LCG_100/x86_64-centos7-gcc10-opt/lib/libCore.so
#4  <signal handler called>
#5  0x00007f330113121c in ROOT::Minuit2::mneigen(double*, unsigned int, unsigned int, unsigned int, double*, double) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#6  0x00007f33010d6373 in ROOT::Minuit2::eigenvalues(ROOT::Minuit2::LASymMatrix const&) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#7  0x00007f3301108402 in ROOT::Minuit2::MnPosDef::operator()(ROOT::Minuit2::MinimumError const&, ROOT::Minuit2::MnMachinePrecision const&) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#8  0x00007f33010f8ca6 in ROOT::Minuit2::MnHesse::operator()(ROOT::Minuit2::MnFcn const&, ROOT::Minuit2::MinimumState const&, ROOT::Minuit2::MnUserTransformation const&, unsigned int) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#9  0x00007f330110de47 in ROOT::Minuit2::MnSeedGenerator::operator()(ROOT::Minuit2::MnFcn const&, ROOT::Minuit2::GradientCalculator const&, ROOT::Minuit2::MnUserParameterState const&, ROOT::Minuit2::MnStrategy const&) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#10 0x00007f330111a1e3 in ROOT::Minuit2::ModularFunctionMinimizer::Minimize(ROOT::Minuit2::FCNBase const&, ROOT::Minuit2::MnUserParameterState const&, ROOT::Minuit2::MnStrategy const&, unsigned int, double) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#11 0x00007f33010dc5b7 in ROOT::Minuit2::Minuit2Minimizer::Minimize() () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#12 0x00007f331b4e394e in ROOT::Fit::Fitter::DoMinimization(ROOT::Math::IBaseFunctionMultiDimTempl<double> const*) () from /cvmfs/sft.cern.ch/lcg/views/LCG_100/x86_64-centos7-gcc10-opt/lib/libMathCore.so
#13 0x00007f331b093673 in main (argc=1, argv=0x7ffed7a77448) at /pbs/home/j/jstafoya/ATLAS_LAr_Calibration/resolution_correction/src/main.cpp:1575
#14 0x00007f331a5ba555 in __libc_start_main () from /lib64/libc.so.6
#15 0x0000000000401089 in _start ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007f330113121c in ROOT::Minuit2::mneigen(double*, unsigned int, unsigned int, unsigned int, double*, double) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#6  0x00007f33010d6373 in ROOT::Minuit2::eigenvalues(ROOT::Minuit2::LASymMatrix const&) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#7  0x00007f3301108402 in ROOT::Minuit2::MnPosDef::operator()(ROOT::Minuit2::MinimumError const&, ROOT::Minuit2::MnMachinePrecision const&) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#8  0x00007f33010f8ca6 in ROOT::Minuit2::MnHesse::operator()(ROOT::Minuit2::MnFcn const&, ROOT::Minuit2::MinimumState const&, ROOT::Minuit2::MnUserTransformation const&, unsigned int) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#9  0x00007f330110de47 in ROOT::Minuit2::MnSeedGenerator::operator()(ROOT::Minuit2::MnFcn const&, ROOT::Minuit2::GradientCalculator const&, ROOT::Minuit2::MnUserParameterState const&, ROOT::Minuit2::MnStrategy const&) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#10 0x00007f330111a1e3 in ROOT::Minuit2::ModularFunctionMinimizer::Minimize(ROOT::Minuit2::FCNBase const&, ROOT::Minuit2::MnUserParameterState const&, ROOT::Minuit2::MnStrategy const&, unsigned int, double) const () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#11 0x00007f33010dc5b7 in ROOT::Minuit2::Minuit2Minimizer::Minimize() () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.24.00-a725e/x86_64-centos7-gcc10-opt/lib/libMinuit2.so
#12 0x00007f331b4e394e in ROOT::Fit::Fitter::DoMinimization(ROOT::Math::IBaseFunctionMultiDimTempl<double> const*) () from /cvmfs/sft.cern.ch/lcg/views/LCG_100/x86_64-centos7-gcc10-opt/lib/libMathCore.so
#13 0x00007f331b093673 in main (argc=1, argv=0x7ffed7a77448) at /pbs/home/j/jstafoya/ATLAS_LAr_Calibration/resolution_correction/src/main.cpp:1575
#14 0x00007f331a5ba555 in __libc_start_main () from /lib64/libc.so.6
#15 0x0000000000401089 in _start ()
===========================================================

ROOT 6.20/00

fit: /pbs/throng/ccin2p3/support/gadrat/software/centos-7-x86_64/root/root/math/minuit2/inc/Minuit2/LASymMatrix.h:226: double& ROOT::Minuit2::LASymMatrix::operator()(unsigned int, unsigned int): Assertion `row<fNRow && col < fNRow' failed.
Aborted

Is this a bug in the Minuit2 library?

Or am I somehow missing some flag in my Makefile?

I am attaching my Makefile here in case it is useful. Makefile.txt (1.3 KB)

Thanks in advance!
Juan

Hi @taf,

I am inviting @moneta to this topic as he may help here. Nonetheless, we would probably need a minimal reproducer of the issue.

Cheers,
J.

Hi @jalopezg,

Certainly, I am attaching here a slight variation on the fitCircle example given in the ROOT tutorials:
Makefile.txt (1.3 KB)
main.cpp (2.6 KB)

(I had to add a .txt in the Makefile so I can upload it, you may need to remove it before running it)
In order to reproduce my problem, you just have compile it using make, and run ./bin/fit

.
After doing more checks, I have managed to narrow down the problem:

Lookin at main.cpp, it seems like line 64:
minOpt.SetStrategy(2);

is incompatible with setting all the FCN parameters as constant (lines 67,68,69):

fitter.Config().ParSettings(0).SetStepSize(0);
fitter.Config().ParSettings(1).SetStepSize(0);
fitter.Config().ParSettings(2).SetStepSize(0);

That is, if you comment either of the lines above, the code runs with no issues. I don’t know if this is expected behaviour.

In case it is relevant, some times I need to set the step of all parameters to 0 so that nothing is fitted with fitter.FitFCN(), which allows me to quickly check the code following the minimization.

Cheers,
Juan

Hi,

I am not sure I understand what you are trying to do. .Why are you setting all 3 step sizes and.or setting the parameter as constants ?
If you are doing it, there is nothing to be minimised, your function is a constant

Lorenzo

Hi @moneta ,

I agree this is not a conventional approach. Since the minimization takes a lot of time for my particular study, sometimes I need to set all the parameters as constants as a (maybe not so elegant) workaround to exit the fit after just one call and quickly check the rest of my code.

It is not really a problem anymore since I managed to isolate the problematic lines after I created this thread, but I still am a bit surprised the culprit was minOpt.SetStrategy(2).

Juan

Hi,

If all your parameters are constant you should just evaluate the function, but not call FitFCN.
I can try to understand why there is a segmentation violation instead of an error message and an early exit of FitFCN with an error/warning message

Lorenzo

Indeed, I just tried fitter.EvalFCN() and this does the trick. Thanks for the remark!

Juan

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