Root crashes when doing a weighted likelihood fit

Hi!
I recently changed my laptop and installed a ‘new’ root version from source, and now when I try to run some code that used to run normally I obtain a crash each time I try to do a weighted likelihood fit. This happens with any weighted likelihood fit that I try. Here information about my setup

ROOT Version: 6.28/06
ubuntu 22.04
compiler gcc 11.4.0

Here a minimal example of code that crashes

void test(){                                                                                                                                                                                                
  TH1F* h = new TH1F("h","h",3,0,3);                                                                                                                                                                        
  for(int i = 0; i < 3; i++)h->Fill(0.5);                                                                                                                                                                   
  for(int i = 0; i < 4; i++)h->Fill(1.5);                                                                                                                                                                   
  for(int i = 0; i < 3; i++)h->Fill(2.5);                                                                                                                                                                   
                                                                                                                                                                                                            
  //This works                                                                                                                                                                                              
  std::cout << "Likelihood Fit:" << std::endl;                                                                                                                                                              
  h->Fit("pol0","L");                                                                                                                                                                                       
                                                                                                                                                                                                            
  //This dosn't                                                                                                                                                                                             
  h->Sumw2();                                                                                                                                                                                               
  h->Scale(10);                                                                                                                                                                                             
  std::cout << "Weighted Likelihood Fit:" << std::endl;                                                                                                                                                     
  h->Fit("pol0","WL");                                                                                                                                                                                      
}                                                                                                                                                                                                           
    

Here the output

Migue$ root -l test.C 
root [0] 
Processing test.C...
Likelihood Fit:
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
 FCN=0.0971242 FROM MIGRAD    STATUS=CONVERGED      23 CALLS          24 TOTAL
                     EDM=2.05901e-06    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           3.33182e+00   1.05361e+00   5.49072e-04  -1.36191e-03
                               ERR DEF= 0.5
Weighted Likelihood Fit:

 *** Break *** segmentation violation



===========================================================
There was a crash (#6 0x00007fe9698b41f4 in SigHandler(ESignals) () from /home/w78488mg/Public/root/root_install/lib/libCore.so).
This is the entire stack trace of all threads:
===========================================================
#0  0x00007fe968cea3ea in __GI___wait4 (pid=50535, stat_loc=stat_loc
entry=0x7ffdbce3c8d8, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1  0x00007fe968cea3ab in __GI___waitpid (pid=<optimised out>, stat_loc=stat_loc
entry=0x7ffdbce3c8d8, options=options
entry=0) at ./posix/waitpid.c:38
#2  0x00007fe968c50bdb in do_system (line=<optimised out>) at ../sysdeps/posix/system.c:171
#3  0x00007fe9698b878a in TUnixSystem::Exec(char const*) () from /home/w78488mg/Public/root/root_install/lib/libCore.so
#4  0x00007fe9698b90ac in TUnixSystem::StackTrace() () from /home/w78488mg/Public/root/root_install/lib/libCore.so
#5  0x00007fe9698bcf2f in TUnixSystem::DispatchSignals(ESignals) () from /home/w78488mg/Public/root/root_install/lib/libCore.so
#6  0x00007fe9698b41f4 in SigHandler(ESignals) () from /home/w78488mg/Public/root/root_install/lib/libCore.so
#7  0x00007fe9698bce2d in sighandler(int) () from /home/w78488mg/Public/root/root_install/lib/libCore.so
#8  0x00007fe9698ad09e in textinput::TerminalConfigUnix::HandleSignal(int) () from /home/w78488mg/Public/root/root_install/lib/libCore.so
#9  0x00007fe9698acd90 in (anonymous namespace)::TerminalConfigUnix__handleSignal(int) () from /home/w78488mg/Public/root/root_install/lib/libCore.so
#10 <signal handler called>
#11 0x00007fe941c2bd41 in ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> >::UseSumOfWeightSquare(bool) () from /home/w78488mg/Public/root/root_install/lib/libMathCore.so
#12 0x00007fe941c29557 in bool ROOT::Fit::Fitter::DoWeightMinimization<ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> > >(std::unique_ptr<ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> >, std::default_delete<ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> > > >, ROOT::Math::IBaseFunctionMultiDimTempl<double> const*) () from /home/w78488mg/Public/root/root_install/lib/libMathCore.so
#13 0x00007fe941c21565 in ROOT::Fit::Fitter::DoBinnedLikelihoodFit(bool, ROOT::EExecutionPolicy const&) () from /home/w78488mg/Public/root/root_install/lib/libMathCore.so
#14 0x00007fe940ec01f2 in ROOT::Fit::Fitter::LikelihoodFit(std::shared_ptr<ROOT::Fit::BinData> const&, bool, ROOT::EExecutionPolicy const&) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#15 0x00007fe940ec2a1f in TFitResultPtr HFit::Fit<TH1>(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#16 0x00007fe940ebe81a in ROOT::Fit::FitObject(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#17 0x00007fe940fed91d in TH1::Fit(TF1*, char const*, char const*, double, double) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#18 0x00007fe940fed770 in TH1::Fit(char const*, char const*, char const*, double, double) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#19 0x00007fe969d2738d in ?? ()
#20 0x00007fe94122e538 in vtable for TFitResultPtr () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#21 0x00007ffd00000000 in ?? ()
#22 0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#11 0x00007fe941c2bd41 in ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> >::UseSumOfWeightSquare(bool) () from /home/w78488mg/Public/root/root_install/lib/libMathCore.so
#12 0x00007fe941c29557 in bool ROOT::Fit::Fitter::DoWeightMinimization<ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> > >(std::unique_ptr<ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> >, std::default_delete<ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IBaseFunctionMultiDimTempl<double>, ROOT::Math::IParametricFunctionMultiDimTempl<double> > > >, ROOT::Math::IBaseFunctionMultiDimTempl<double> const*) () from /home/w78488mg/Public/root/root_install/lib/libMathCore.so
#13 0x00007fe941c21565 in ROOT::Fit::Fitter::DoBinnedLikelihoodFit(bool, ROOT::EExecutionPolicy const&) () from /home/w78488mg/Public/root/root_install/lib/libMathCore.so
#14 0x00007fe940ec01f2 in ROOT::Fit::Fitter::LikelihoodFit(std::shared_ptr<ROOT::Fit::BinData> const&, bool, ROOT::EExecutionPolicy const&) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#15 0x00007fe940ec2a1f in TFitResultPtr HFit::Fit<TH1>(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#16 0x00007fe940ebe81a in ROOT::Fit::FitObject(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#17 0x00007fe940fed91d in TH1::Fit(TF1*, char const*, char const*, double, double) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#18 0x00007fe940fed770 in TH1::Fit(char const*, char const*, char const*, double, double) () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#19 0x00007fe969d2738d in ?? ()
#20 0x00007fe94122e538 in vtable for TFitResultPtr () from /home/w78488mg/Public/root/root_install/lib/libHist.so
#21 0x00007ffd00000000 in ?? ()
#22 0x0000000000000000 in ?? ()
===========================================================

Does anyone know what could be happening?

Dear Miguel,

Thanks for the post. I am sorry to see you experienced this issue.
I can reproduce it even on the ROOT master. The tiniest reproducer I could come up with is the following:

  TH1F h("h","h",3,0,3);                                                                                                                                                                        
  h.FillRandom("gaus");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  h.Sumw2();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  h.Fit("pol0","WL");  

@moneta @jonas : do you understand what is going on?

Best,
Danilo

There is a bug introduced in 6.28. I will provide now a fix for the latest releases.

Lorenzo

Here is the PR fixing this issue: [math][fitter] Fix crash when doing a weighted likelihood fit by lmoneta · Pull Request #14459 · root-project/root · GitHub

1 Like

Hi Lorenzo,
thank you very much for the fix. What should I do to incorporate this to my local ROOT version?
Miguel

Yes, you can easily incorporate the small patch (see here) in your local ROOT installation, and then rebuild it from source.

Lorenzo

1 Like

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