Fitting histogram errors

Dear rooters,

I am facing a strange issue when I try to
fit some histogram with a custom made function. Globally, the fit provides good results, very consistent with what I expect and with other experimental data. But I notice an intermittent error dealing with Fatal in : storage area overwritten. Here is the output of the error I can see :

FCN=90.3587 FROM HESSE STATUS=NOT POSDEF 31 CALLS 207 TOTAL
EDM=9.80156e-14 STRATEGY= 1 ERR MATRIX NOT POS-DEF
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 -1.56127e-05 2.42892e-08 3.72236e-12 -3.20897e+01
2 p1 5.59907e-03 3.48026e-06 1.33492e-09 -2.97977e-01
3 p2 -7.14542e-01 3.96131e-04 1.70360e-07 -2.62362e-03
4 p3 3.66635e+01 4.14804e-02 8.74126e-06 -1.90331e-05
5 p4 -5.47678e+02 2.38374e+00 3.63694e-04 1.62159e-08
E_1: 55 backgrd_E_1: 96.0044 Max_E_1: 134.97 max_peak_E_1: 38.9656
E_2: 60.9091 backgrd_E_2: 84.8945 Max_E_2: 88.3056 max_peak_E_2: 3.41114
FCN=2.47081 FROM MIGRAD STATUS=CONVERGED 875 CALLS 876 TOTAL
EDM=4.34333e-08 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 2.2 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 -8.12563e-06 1.98654e-06 2.85970e-09 3.99707e+03
2 p1 3.00569e-03 6.54098e-04 -8.83948e-07 3.42187e+01
3 p2 -3.93076e-01 7.74112e-02 9.52132e-05 2.32789e-01
4 p3 2.01342e+01 3.84243e+00 -4.12519e-03 2.41401e-04
5 p4 -2.63851e+02 6.55240e+01 5.88068e-02 -3.93476e-05
6 p5 4.84356e+01 7.28583e+00 -8.67274e-03 -6.86276e-05
7 p6 5.43893e+01 4.74220e-01 3.59787e-04 -6.56050e-06
8 p7 3.04316e+00 5.89669e-01 1.49985e-03 -8.35512e-04
9 p8 1.84284e+01 6.60498e+00 -1.68915e-02 -4.31161e-05
10 p9 3.61887e+00 1.12930e+00 8.38908e-04 -1.37695e-04
Fatal in : storage area overwritten
aborting
#0 0x00007fe46cfce07a in __GI___waitpid (pid=6166, stat_loc=stat_loc
entry=0x7ffe735defc0, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:29
#1 0x00007fe46cf46fbb in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007fe46ecdb9dd in TUnixSystem::StackTrace() () from /home/linux/Bin/root/root-6.10.02/lib/libCore.so
#3 0x00007fe46ec169ba in DefaultErrorHandler(int, bool, char const*, char const*) () from /home/linux/Bin/root/root-6.10.02/lib/libCore.so
#4 0x00007fe46ec16352 in ErrorHandler () from /home/linux/Bin/root/root-6.10.02/lib/libCore.so
#5 0x00007fe46ec1684f in Fatal(char const*, char const*, …) () from /home/linux/Bin/root/root-6.10.02/lib/libCore.so
#6 0x00007fe46dd8c180 in operator delete(void*) () from /home/linux/Bin/root/root-6.10.02/lib/libNew.so
#7 0x00007fe46ba74dcf in ROOT::Fit::FitResult::~FitResult() () from /home/linux/Bin/root/root-6.10.02/lib/libMathCore.so
#8 0x00007fe46e5daa6b in std::_Sp_counted_ptr<TFitResult*, (__gnu_cxx::_Lock_policy)2>::_M_dispose() () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#9 0x00007fe46ba8ea4a in ROOT::Fit::Fitter::~Fitter() () from /home/linux/Bin/root/root-6.10.02/lib/libMathCore.so
#10 0x00007fe46e5d42a2 in std::_Sp_counted_ptr<ROOT::Fit::Fitter*, (__gnu_cxx::_Lock_policy)2>::_M_dispose() () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#11 0x00007fe46e67573a in TBackCompFitter::~TBackCompFitter() () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#12 0x00007fe46e675789 in TBackCompFitter::~TBackCompFitter() () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#13 0x00007fe46e5df7b7 in TFitResultPtr HFit::Fit(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#14 0x00007fe46e5d3b3a in ROOT::Fit::FitObject(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#15 0x00007fe46e6c8613 in TH1::Fit(TF1*, char const*, char const*, double, double) () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#16 0x00007fe46e6c7889 in TH1::Fit(char const*, char const*, char const*, double, double) () from /home/linux/Bin/root/root-6.10.02/lib/libHist.so
#17 0x0000000000404b91 in main ()

Does anyone can provide some hint about this ?

Thanks for your support,

best regards,

Loic

This indicates a double delete and/or read of un-initialized memory.

To investigate further, we would need to see the failing code.

Even better you can run valgrind (for example valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp root.exe -b -l -q myMacro.C which might tell us exactly what the problem is.

Cheers,
Philippe.

Hello Philippe,

I ran valgrind yesterday. Log file is attached to this post.

Here is an extract of my code:

Double_t BackGrd(Double_t *x, Double_t *par) {

return par[0]*x[0]*x[0]*x[0]*x[0]+par[1]*x[0]*x[0]*x[0]+par[2]*x[0]*x[0]+par[3]*x[0]+par[4];

}

Double_t fit_peak_1(Double_t *x, Double_t *par) {

Double_t arg=x[0]-par[1];
Double_t sig=par[2];
return par[0] * TMath::Exp(-0.5*arg*arg/sig/sig);

}

Double_t fit_peak_2(Double_t *x, Double_t *par) {

Double_t arg=x[0]-67.0/1.1;
Double_t sig=par[1];
return par[0] * TMath::Exp(-0.5*arg*arg/sig/sig);

}

Double_t fit_fnc(Double_t *x, Double_t *par){

return BackGrd(x,par)+fit_peak_1(x,&par[5])+fit_peak_2(x,&par[8]);

}

Nrj_1D[300]->Fit(“BACKGRD”,“0”,“L”,30,120);

  Double_t par_0=BACKGRD->GetParameter(0);
  Double_t par_1=BACKGRD->GetParameter(1);
  Double_t par_2=BACKGRD->GetParameter(2);
  Double_t par_3=BACKGRD->GetParameter(3);
  Double_t par_4=BACKGRD->GetParameter(4);
  
  
  Double_t E_1=Nrj_1D[300]->GetMaximumBin();;
  Double_t backgrd_E_1=par_0*E_1*E_1*E_1*E_1+par_1*E_1*E_1*E_1+par_2*E_1*E_1+par_3*E_1+par_4;
  Double_t Max_E_1=Nrj_1D[300]->GetMaximum();
  Double_t max_peak_E_1=Max_E_1-backgrd_E_1;
  
  Double_t E_2=67/1.1;
  Double_t backgrd_E_2=par_0*E_2*E_2*E_2*E_2+par_1*E_2*E_2*E_2+par_2*E_2*E_2+par_3*E_2+par_4;
  
  Double_t Max_E_2=Nrj_1D[300]->GetBinContent((Int_t)E_2+1);
  Double_t max_peak_E_2=Max_E_2-backgrd_E_2;
  
  cout<<"E_1: "<<E_1<<" backgrd_E_1: "<<backgrd_E_1<<" Max_E_1: "<<Max_E_1<<" max_peak_E_1: "<<max_peak_E_1<<endl;
  cout<<"E_2: "<<E_2<<" backgrd_E_2: "<<backgrd_E_2<<" Max_E_2: "<<Max_E_2<<" max_peak_E_2: "<<max_peak_E_2<<endl;
  
  TF1* Fit_FNC=new TF1("Fit_FNC", fit_fnc, 30.,120.,10);
  Fit_FNC->SetParameters(par_0,par_1,par_2,par_3,par_4,max_peak_E_1,E_1,3.,max_peak_E_2,3.);      
  Fit_FNC->SetNpx(1001);
  
   
  
  Nrj_1D[300]->Fit(Fit_FNC,"0","L",30,120);
  Fit_FNC->SetLineColor(1);
  Fit_FNC->Draw("same");		
	
TF1* Photo_Peak=new TF1("Photo_Peak",fit_peak_1,0,128,3);
Photo_Peak->SetParameter(0,Fit_FNC->GetParameter(5));
Photo_Peak->SetParameter(1,Fit_FNC->GetParameter(6));
Photo_Peak->SetParameter(2,Fit_FNC->GetParameter(7));
Photo_Peak->SetLineColor(2);
Photo_Peak->Draw("same");
Photo_Peak->SetNpx(1001);

Whatever the type of fitting function I select, incluted predefined functions, I get this intermittent failure.

Apparently I miss something, probably too obvious, but I do not get its nature yet.

Thanks for your support,

Best regards,

Loic
output.tar.gz (1.1 MB)

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