ProfileX of histogram can fit for pol3 but not pol5

Hello all,

I am fairly new to root, so I’m sorry if this is posted or something in the documentation. I got this 2D histogram that I shared here and tried to use it to fit for the first-order term of a pol5. I could fit without profileX but the Chi2/NDf is not ideal. I then tried to fit the profilX but a error message popped up saying the matrix is not positive definite. Weirdly enough, when I changed the fitting function from pol5 to pol3, it worked alright. The example code and outputs are pasted below. Does anyone have any insights of what might be happening here? All comments are appreciated.

Thanks!

TFile* rootfile = new TFile("example_hist.root");
h1=(TH2F*)rootfile->Get("hist3");
Prof1=(TProfile*)h1->ProfileX("prof_1",1,-1,"i");
pffit=(TFitResultPtr)Prof1->Fit("pol3","S");
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
****************************************
Minimizer is Linear / Migrad
Chi2                      =      809.476
NDf                       =          476
p0                        = -0.000387502   +/-   5.95421e-06
p1                        =  -0.00863839   +/-   0.000666944
p2                        =     0.171426   +/-   0.0115273
p3                        =      1.67383   +/-   0.45491
(TFitResultPtr &)
****************************************
Minimizer is Linear / Migrad
Chi2                      =      809.476
NDf                       =          476
p0                        = -0.000387502   +/-   5.95421e-06
p1                        =  -0.00863839   +/-   0.000666944
p2                        =     0.171426   +/-   0.0115273
p3                        =      1.67383   +/-   0.45491

pffit=(TFitResultPtr)Prof1->Fit("pol5","S");
Error in <TDecompChol::Decompose()>: matrix not positive definite
Error in <TDecompChol::Solve()>: Decomposition failed
Error in <TLinearFitter::Eval>: Matrix inversion failed
Warning in <Minimize>: TLinearFitter failed in finding the solution
/usr/include/c++/8/bits/stl_vector.h:1021: std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::front() const [with _Tp = double; _Alloc = std::allocator<double>; std::vector<_Tp, _Alloc>::const_reference = const double&]: Assertion '__builtin_expect(!this->empty(), true)' failed.

ROOT Version: v6-28-04
Platform: Linux
Compiler: Not Provided


The forum won’t let me upload the example root file. If anyone is interested, I can share it in other ways.

Hello @George_Sun, welcome to the ROOT Forum.

Let me ping @moneta and @jonas to try and help you out.

Hi @silverweed,
Since they are not responding, is there anyone else that might be able to help me with this?

Hello @George_Sun,

it would help to see what the histograms and the fit look like, but a typical problem could be empty bins that it tries to fit. Maybe you have to restrict the fit range to the bins that you are interested in?

You can also try other fit options, for example F or L to not use the linear fitter. You can find some details here

1 Like

Hello @StephanH ,

Thank you very much for the tips. The option W worked so I guess there were some empty bins that bother only pol5 but not pol3? Anyway, it works now, thanks again. I pasted screenshots of the histogram and the fitting with the option “W” below for reference.