Crash while TGraphErrors fitting

Hi…
I am trying to fit the TGraphErrors with a TF1 . Form of TF1 is
F§ = Integration of f(p,q,r,s) over q , r and s . The integration is performed using AdapticeIntegratorMultiDim class . When I calculate this integral for single value (or array of values) of p , I don’t have problem. However as soon as i convert the Integration function into TF1 , and try to fit the TGraphErrors I get crash with following error

 *** Break *** bus error



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x0000003156abaf3a in waitpid () from /lib64/libc.so.6
#1  0x0000003156a4175e in do_system () from /lib64/libc.so.6
#2  0x00007ff6d295e466 in TUnixSystem::StackTrace() () from /home/chinmay/ROOTv5.34/root/lib/libCore.so
#3  0x00007ff6d2960ca3 in TUnixSystem::DispatchSignals(ESignals) () from /home/chinmay/ROOTv5.34/root/lib/libCore.so
#4  <signal handler called>
#5  0x00007ff6cf049f0d in ROOT::Math::AdaptiveIntegratorMultiDim::DoIntegral(double const*, double const*, bool) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#6  0x00000000004068ef in ROOT::Math::AdaptiveIntegratorMultiDim::Integral (this=0x7fff76d4edb0, xmin=0x60b3b0 <a>, xmax=0x60b190 <b>) at /home/chinmay/ROOTv5.34/root/include/Math/AdaptiveIntegratorMultiDim.h:74
#7  0x0000000000405aae in TBW (par=0x1439a90, err=0x7fff76d4ee40) at test.C:68
#8  0x0000000000405be3 in fitf (xv=0x13a88d0, par=0x1439a90) at test.C:82
#9  0x00007ff6d10271b2 in TF1::EvalPar(double const*, double const*) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#10 0x00007ff6cf04358b in ROOT::Fit::FitUtil::EvaluateChi2(ROOT::Math::IParametricFunctionMultiDim const&, ROOT::Fit::BinData const&, double const*, unsigned int&) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#11 0x00007ff6ce7eed77 in TMinuitMinimizer::Fcn(int&, double*, double&, double*, int) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#12 0x00007ff6ce7d4127 in TMinuit::Eval(int, double*, double&, double*, int) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#13 0x00007ff6ce7dd768 in TMinuit::mnline(double*, double, double*, double, double) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#14 0x00007ff6ce7da36e in TMinuit::mnmigr() () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#15 0x00007ff6ce7ea9c3 in TMinuit::mnexcm(char const*, double*, int, int&) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#16 0x00007ff6ce7f13d0 in TMinuitMinimizer::Minimize() () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#17 0x00007ff6cf03ac59 in ROOT::Fit::Fitter::DoMinimization(ROOT::Math::IBaseFunctionMultiDim const*) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#18 0x00007ff6cf03cc84 in ROOT::Fit::Fitter::DoLeastSquareFit(ROOT::Fit::BinData const&) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#19 0x00007ff6d0f4b709 in TFitResultPtr HFit::Fit<TGraph>(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#20 0x00007ff6d0f43a7a in ROOT::Fit::FitObject(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#21 0x00007ff6d0f7cfd6 in TGraph::Fit(TF1*, char const*, char const*, double, double) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#22 0x00007ff6d0f7ba96 in TGraph::Fit(char const*, char const*, char const*, double, double) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#23 0x0000000000405f57 in main () at test.C:133
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://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  0x00007ff6cf049f0d in ROOT::Math::AdaptiveIntegratorMultiDim::DoIntegral(double const*, double const*, bool) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#6  0x00000000004068ef in ROOT::Math::AdaptiveIntegratorMultiDim::Integral (this=0x7fff76d4edb0, xmin=0x60b3b0 <a>, xmax=0x60b190 <b>) at /home/chinmay/ROOTv5.34/root/include/Math/AdaptiveIntegratorMultiDim.h:74
#7  0x0000000000405aae in TBW (par=0x1439a90, err=0x7fff76d4ee40) at test.C:68
#8  0x0000000000405be3 in fitf (xv=0x13a88d0, par=0x1439a90) at test.C:82
#9  0x00007ff6d10271b2 in TF1::EvalPar(double const*, double const*) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#10 0x00007ff6cf04358b in ROOT::Fit::FitUtil::EvaluateChi2(ROOT::Math::IParametricFunctionMultiDim const&, ROOT::Fit::BinData const&, double const*, unsigned int&) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#11 0x00007ff6ce7eed77 in TMinuitMinimizer::Fcn(int&, double*, double&, double*, int) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#12 0x00007ff6ce7d4127 in TMinuit::Eval(int, double*, double&, double*, int) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#13 0x00007ff6ce7dd768 in TMinuit::mnline(double*, double, double*, double, double) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#14 0x00007ff6ce7da36e in TMinuit::mnmigr() () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#15 0x00007ff6ce7ea9c3 in TMinuit::mnexcm(char const*, double*, int, int&) () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#16 0x00007ff6ce7f13d0 in TMinuitMinimizer::Minimize() () from /home/chinmay/ROOTv5.34/root/lib/libMinuit.so
#17 0x00007ff6cf03ac59 in ROOT::Fit::Fitter::DoMinimization(ROOT::Math::IBaseFunctionMultiDim const*) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#18 0x00007ff6cf03cc84 in ROOT::Fit::Fitter::DoLeastSquareFit(ROOT::Fit::BinData const&) () from /home/chinmay/ROOTv5.34/root/lib/libMathCore.so
#19 0x00007ff6d0f4b709 in TFitResultPtr HFit::Fit<TGraph>(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#20 0x00007ff6d0f43a7a in ROOT::Fit::FitObject(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#21 0x00007ff6d0f7cfd6 in TGraph::Fit(TF1*, char const*, char const*, double, double) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#22 0x00007ff6d0f7ba96 in TGraph::Fit(char const*, char const*, char const*, double, double) () from /home/chinmay/ROOTv5.34/root/lib/libHist.so
#23 0x0000000000405f57 in main () at test.C:133
===========================================================

I m attaching the code here. do:

 g++ test.C -I/Path/to/Root/include  -L/Path/to/root/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lMathMore -lThread -pthread -lm -ldl -rdynamic  -lMinuit -g -o test 

./test 

basically, as long as i dont try to fit, things work fine .

Don’t call your programs “test” (“test” is a builtin command in sh / bash / …).

I renamed your “test.C” into “mytest.C” and then:
root-config --cxx --cflags -O2 -W -Wall -o mytest mytest.C root-config --libs
returns:
mytest.C: In function ‘int main()’:
mytest.C:91: warning: unused variable ‘pt’
mytest.C:111: warning: unused variable ‘err’
mytest.C:113: warning: unused variable ‘yield’

Check that these messages are not related to some source code bugs (e.g. misspelling of variables’ names).

When I then run:
./mytest
I often get something like:
Number of function calls 99957 … Result = nan Status = 1

You need to protect your code so that no “NaN” (“not a number”) happen.
For example, you may need to “SetParLimits” on your parameters and/or protect your fitting function so that it always checks the “validity” of parameters and that it always returns a “reasonable” result.

Well, chinmay typed “./test” to execute his program… so it is fine.
But I agree with you “test” is not a good name.

Thanks… setting the parameter limits worked :slight_smile: … sorry for what eventually turns out to be silly mistake… :frowning:
also, I will remember about the not naming codes ‘test’ …