Hi Anna,
Thanks for your response. [By the way, I’m using ROOT 5.08/00 on Debian linux).
I’m glad you could verify it was singular matrices that were causing the problem. Do you think it would be useful if there was a warning message printed by the fitter in these cases, to warn the user?
I switched to the linear fitter now, so I generate data with a TF2 and fit it with a TLinearFitter - a little awkward, but it seems to work. The problem is that I get a crash with EvalRobust, as I reported in another thread. See the traceback & macro below.
I was also curious what if there is a way to get parameter errors and chisquare when using the linear fitter. Using the macro below with “Eval” instead of “EvalRobust” works great, but the algorithm doesn’t compute errors directly.
Cheers,
Chris
root [6] .x linearFit.C
Input params
0 -3.92085
1 0.874751
2 -1.81027
3 -3.53562
4 -2.00777
5 -4.59299
*** Break *** segmentation violation
Generating stack trace…
0xffffe420 in
0x40b5918a in TFormula::EvalPar(double const*, double const*) + 0x4e from /usr/lib/root/libHist.so.5.08
0x41fa7413 in TLinearFitter::CStep(int, int, double*, int*, int*, int, int) + 0xe2d from /usr/lib/root/5.08/libMinuit.so
0x41fa49d5 in TLinearFitter::EvalRobust(double) + 0x281 from /usr/lib/root/5.08/libMinuit.so
0x41fce154 in from /usr/lib/root/5.08/libMinuit.so
0x40880571 in G__ExceptionWrapper + 0x5d from /usr/lib/root/libCint.so.5.08
0x409339a4 in G__call_cppfunc + 0x30e from /usr/lib/root/libCint.so.5.08
0x409207eb in G__interpret_func + 0x8ab from /usr/lib/root/libCint.so.5.08
0x40906989 in G__getfunction + 0x1c3d from /usr/lib/root/libCint.so.5.08
0x409a5e74 in G__getstructmem + 0xb9e from /usr/lib/root/libCint.so.5.08
0x4099d0fc in G__getvariable + 0x7b8 from /usr/lib/root/libCint.so.5.08
0x408fbd0c in G__getitem + 0x6dc from /usr/lib/root/libCint.so.5.08
0x408fa22a in G__getexpr + 0xc27e from /usr/lib/root/libCint.so.5.08
0x4094e9e2 in G__exec_function + 0x202 from /usr/lib/root/libCint.so.5.08
0x40956aef in G__exec_statement + 0x2a47 from /usr/lib/root/libCint.so.5.08
0x409223bc in G__interpret_func + 0x247c from /usr/lib/root/libCint.so.5.08
0x409070aa in G__getfunction + 0x235e from /usr/lib/root/libCint.so.5.08
0x408fbd97 in G__getitem + 0x767 from /usr/lib/root/libCint.so.5.08
0x408fa22a in G__getexpr + 0xc27e from /usr/lib/root/libCint.so.5.08
0x408edad2 in G__calc_internal + 0x312 from /usr/lib/root/libCint.so.5.08
0x4095d19b in G__process_cmd + 0x2359 from /usr/lib/root/libCint.so.5.08
0x4021b9cc in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x136 from /usr/lib/root/libCore.so.5.08
0x4021bb5d in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) + 0x4f from /usr/lib/root/libCore.so.5.08
0x40150319 in TApplication::ProcessFile(char const*, int*) + 0x9d5 from /usr/lib/root/libCore.so.5.08
0x4014f8c1 in TApplication::ProcessLine(char const*, bool, int*) + 0x5f9 from /usr/lib/root/libCore.so.5.08
0x414ae978 in TRint::HandleTermInput() + 0x24e from /usr/lib/root/libRint.so.5.08
0x414ad205 in TTermInputHandler::Notify() + 0x27 from /usr/lib/root/libRint.so.5.08
0x414af5aa in TTermInputHandler::ReadNotify() + 0x14 from /usr/lib/root/libRint.so.5.08
0x402bb852 in TUnixSystem::CheckDescriptors() + 0x166 from /usr/lib/root/libCore.so.5.08
0x402ba697 in TUnixSystem::DispatchOneEvent(bool) + 0x185 from /usr/lib/root/libCore.so.5.08
0x401d0f44 in TSystem::InnerLoop() + 0x22 from /usr/lib/root/libCore.so.5.08
0x401d0eda in TSystem::Run() + 0x80 from /usr/lib/root/libCore.so.5.08
0x4015061b in TApplication::Run(bool) + 0x37 from /usr/lib/root/libCore.so.5.08 0x414ae2de in TRint::Run(bool) + 0x44c from /usr/lib/root/libRint.so.5.08
0x08048e64 in main + 0x90 from /usr/bin/root.exe
0x4161de36 in __libc_start_main + 0xc6 from /lib/libc.so.6
0x08048d31 in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x3d from /usr/bin/root.exe
Root > Function linearFit() busy flag cleared
void linearFit() {
const Char_t *funcString=
"1 “
”++ x ++ y “
”++ x^2 ++ x *y ++ y^2 ";
const Int_t n(100);
Double_t min(0),max(5000);
TF2 func(“func”,funcString,min,max,min,max);
TRandom rand;
cout << "Input params " << endl;
for (Int_t i=0; i<func.GetNpar(); ++i ) {
Double_t value=rand.Uniform(-5,5);
cout << i << " " << value << endl;
func.SetParameter( i, value );
}
TLinearFitter fitter(2,funcString);
Double_t x[2],y;
for (Int_t i=0; i<n; ++i ) {
x[0]= rand.Uniform(min,max);
x[1]= rand.Uniform(min,max);
y= func.Eval(x[0],x[1]) + rand.Gaus(0,10);
fitter.AddPoint(x,y);
}
fitter.EvalRobust();
// print the output – errors are zero w/ linear fitter :-/
for ( Int_t i=0; i<func.GetNpar(); ++i ) {
printf(“par[%2i] %9.4g %9.4g\n”, i,
func.GetParameter(i),
func.GetParError(i));
}
// dump the chisquare, too
printf(“chisquare= %9.4f\n”, func.GetChisquare() );
}