Discussion:
[ROOT] Fitting TGraphErrors
OKUMURA, Akira
2009-02-24 11:45:22 UTC
Permalink
Hello ROOTers,

I attache an example of TGraphErrors::Fit. The left plot returns
reasonable chi^2/ndf, but the right side doesn't. The result depends
on the variable "kScale" in the macro.

The fitting results from the left and the right plots should be the
same value mathematically.

Am I doing something incorrect?

5.22.00 + Mac OS X 10.5.6

Regards,

OKUMURA, Akira ***@ceres.phys.s.u-tokyo.ac.jp
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Rene Brun
2009-02-24 12:03:02 UTC
Permalink
see comments in the doc of TGraph::Fit
http://root.cern.ch/root/html/TGraph.html#TGraph:Fit

Rene Brun
Post by OKUMURA, Akira
Hello ROOTers,
I attache an example of TGraphErrors::Fit. The left plot returns
reasonable chi^2/ndf, but the right side doesn't. The result depends
on the variable "kScale" in the macro.
The fitting results from the left and the right plots should be the
same value mathematically.
Am I doing something incorrect?
5.22.00 + Mac OS X 10.5.6
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
OKUMURA, Akira
2009-02-24 12:25:52 UTC
Permalink
Hello Rene,

Did you mention this?
=======
Note, that the linear fitter doesn't take into account the errors in
x. If errors in x are important, go through minuit (use option "F" for
polynomial fitting).
=======

I tried "F" option, but the result becomes chi^2/ndf = 0/0

Regards,

OKUMURA, Akira ***@ceres.phys.s.u-tokyo.ac.jp
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
see comments in the doc of TGraph::Fit
http://root.cern.ch/root/html/TGraph.html#TGraph:Fit
Rene Brun
Post by OKUMURA, Akira
Hello ROOTers,
I attache an example of TGraphErrors::Fit. The left plot returns
reasonable chi^2/ndf, but the right side doesn't. The result
depends on the variable "kScale" in the macro.
The fitting results from the left and the right plots should be the
same value mathematically.
Am I doing something incorrect?
5.22.00 + Mac OS X 10.5.6
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Lorenzo Moneta
2009-02-24 16:36:54 UTC
Permalink
Hi,

using option "F" in your particular case showed a problem. Thank you
for your example.
This is now fixed in the trunk version and your macro works fine.
What stated in the doc is correct, with the linear fitter error in X
are not taken into account when fitting a TGraphErrors

Best Regards

Lorenzo
Post by OKUMURA, Akira
Hello Rene,
Did you mention this?
=======
Note, that the linear fitter doesn't take into account the errors in
x. If errors in x are important, go through minuit (use option "F"
for polynomial fitting).
=======
I tried "F" option, but the result becomes chi^2/ndf = 0/0
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
see comments in the doc of TGraph::Fit
http://root.cern.ch/root/html/TGraph.html#TGraph:Fit
Rene Brun
Post by OKUMURA, Akira
Hello ROOTers,
I attache an example of TGraphErrors::Fit. The left plot returns
reasonable chi^2/ndf, but the right side doesn't. The result
depends on the variable "kScale" in the macro.
The fitting results from the left and the right plots should be
the same value mathematically.
Am I doing something incorrect?
5.22.00 + Mac OS X 10.5.6
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Rene Brun
2009-03-06 15:50:09 UTC
Permalink
You must upgrade your compiler to a more recent version like gcc3.4 or
gcc4.3
You cannot compile the latest versions of ROOT with an old compiler like
gcc3.2

Rene Brun
Hi all,
I have a server with Linux Red Hat 9.0 and gcc version 3.2.2 20030222 (Red
Hat Linux 3.2.2-5) with ROOT 4.00/04.
Now, for any works, we need to have a new version of ROOT, so I downloaded
the newest ROOT version root_v5.23.02.source.tar, but when I prove to
compile it I get the following (you can see in attachment the result files
for ./configure and make) errors.
Is there anyone that can help me ?
Thank in advance
Francesco.
OKUMURA, Akira
2009-06-28 15:30:31 UTC
Permalink
Hello Lorenzo,

I got a similar problem again when I fit a TGraphErrors with a
function "x**[0]". Would you check the attached macro, please? Most of
the code is the same as the previous one I sent in February.

Chi^2 often becomes "inf", but not always. Please run the macro
repeatedly if you get a proper result.

I am using the SVN HEAD on Leopard.

Regards,

OKUMURA, Akira ***@ceres.phys.s.u-tokyo.ac.jp
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Lorenzo Moneta
Hi,
using option "F" in your particular case showed a problem. Thank you
for your example.
This is now fixed in the trunk version and your macro works fine.
What stated in the doc is correct, with the linear fitter error in
X are not taken into account when fitting a TGraphErrors
Best Regards
Lorenzo
Post by OKUMURA, Akira
Hello Rene,
Did you mention this?
=======
Note, that the linear fitter doesn't take into account the errors
in x. If errors in x are important, go through minuit (use option
"F" for polynomial fitting).
=======
I tried "F" option, but the result becomes chi^2/ndf = 0/0
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
see comments in the doc of TGraph::Fit
http://root.cern.ch/root/html/TGraph.html#TGraph:Fit
Rene Brun
Post by OKUMURA, Akira
Hello ROOTers,
I attache an example of TGraphErrors::Fit. The left plot returns
reasonable chi^2/ndf, but the right side doesn't. The result
depends on the variable "kScale" in the macro.
The fitting results from the left and the right plots should be
the same value mathematically.
Am I doing something incorrect?
5.22.00 + Mac OS X 10.5.6
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Rene Brun
2009-06-28 17:13:08 UTC
Permalink
You are generating x values that may be negative !!!
then you evaluate an illegal function x**y with eg x=-1.11 and y=1.2
Fix your function or the x range.

Rene Brun
Post by OKUMURA, Akira
Hello Lorenzo,
I got a similar problem again when I fit a TGraphErrors with a
function "x**[0]". Would you check the attached macro, please? Most of
the code is the same as the previous one I sent in February.
Chi^2 often becomes "inf", but not always. Please run the macro
repeatedly if you get a proper result.
I am using the SVN HEAD on Leopard.
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Lorenzo Moneta
Hi,
using option "F" in your particular case showed a problem. Thank you
for your example.
This is now fixed in the trunk version and your macro works fine.
What stated in the doc is correct, with the linear fitter error in X
are not taken into account when fitting a TGraphErrors
Best Regards
Lorenzo
Post by OKUMURA, Akira
Hello Rene,
Did you mention this?
=======
Note, that the linear fitter doesn't take into account the errors in
x. If errors in x are important, go through minuit (use option "F"
for polynomial fitting).
=======
I tried "F" option, but the result becomes chi^2/ndf = 0/0
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
see comments in the doc of TGraph::Fit
http://root.cern.ch/root/html/TGraph.html#TGraph:Fit
Rene Brun
Post by OKUMURA, Akira
Hello ROOTers,
I attache an example of TGraphErrors::Fit. The left plot returns
reasonable chi^2/ndf, but the right side doesn't. The result
depends on the variable "kScale" in the macro.
The fitting results from the left and the right plots should be
the same value mathematically.
Am I doing something incorrect?
5.22.00 + Mac OS X 10.5.6
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
OKUMURA, Akira
2009-06-28 22:32:08 UTC
Permalink
Hello Rene,

you are right. I expected that chi^2 was calculated using only xerror,
but as you mentioned, it seems that an inverse function does not
always work in the fitting method. I will modify the code. Thanks a lot.

Regards,

OKUMURA, Akira ***@ceres.phys.s.u-tokyo.ac.jp
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
You are generating x values that may be negative !!!
then you evaluate an illegal function x**y with eg x=-1.11 and y=1.2
Fix your function or the x range.
Rene Brun
Post by OKUMURA, Akira
Hello Lorenzo,
I got a similar problem again when I fit a TGraphErrors with a
function "x**[0]". Would you check the attached macro, please? Most
of the code is the same as the previous one I sent in February.
Chi^2 often becomes "inf", but not always. Please run the macro
repeatedly if you get a proper result.
I am using the SVN HEAD on Leopard.
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Lorenzo Moneta
Hi,
using option "F" in your particular case showed a problem. Thank
you for your example.
This is now fixed in the trunk version and your macro works fine.
What stated in the doc is correct, with the linear fitter error
in X are not taken into account when fitting a TGraphErrors
Best Regards
Lorenzo
Post by OKUMURA, Akira
Hello Rene,
Did you mention this?
=======
Note, that the linear fitter doesn't take into account the errors
in x. If errors in x are important, go through minuit (use option
"F" for polynomial fitting).
=======
I tried "F" option, but the result becomes chi^2/ndf = 0/0
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
see comments in the doc of TGraph::Fit
http://root.cern.ch/root/html/TGraph.html#TGraph:Fit
Rene Brun
Post by OKUMURA, Akira
Hello ROOTers,
I attache an example of TGraphErrors::Fit. The left plot
returns reasonable chi^2/ndf, but the right side doesn't. The
result depends on the variable "kScale" in the macro.
The fitting results from the left and the right plots should be
the same value mathematically.
Am I doing something incorrect?
5.22.00 + Mac OS X 10.5.6
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Rene Brun
2009-06-29 05:25:22 UTC
Permalink
The computation of the chisquare requires of course to call the function
in the fitting range.

Rene Brun
Post by OKUMURA, Akira
Hello Rene,
you are right. I expected that chi^2 was calculated using only xerror,
but as you mentioned, it seems that an inverse function does not
always work in the fitting method. I will modify the code. Thanks a lot.
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
You are generating x values that may be negative !!!
then you evaluate an illegal function x**y with eg x=-1.11 and y=1.2
Fix your function or the x range.
Rene Brun
Post by OKUMURA, Akira
Hello Lorenzo,
I got a similar problem again when I fit a TGraphErrors with a
function "x**[0]". Would you check the attached macro, please? Most
of the code is the same as the previous one I sent in February.
Chi^2 often becomes "inf", but not always. Please run the macro
repeatedly if you get a proper result.
I am using the SVN HEAD on Leopard.
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Lorenzo Moneta
Hi,
using option "F" in your particular case showed a problem. Thank
you for your example.
This is now fixed in the trunk version and your macro works fine.
What stated in the doc is correct, with the linear fitter error in
X are not taken into account when fitting a TGraphErrors
Best Regards
Lorenzo
Post by OKUMURA, Akira
Hello Rene,
Did you mention this?
=======
Note, that the linear fitter doesn't take into account the errors
in x. If errors in x are important, go through minuit (use option
"F" for polynomial fitting).
=======
I tried "F" option, but the result becomes chi^2/ndf = 0/0
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Post by Rene Brun
see comments in the doc of TGraph::Fit
http://root.cern.ch/root/html/TGraph.html#TGraph:Fit
Rene Brun
Post by OKUMURA, Akira
Hello ROOTers,
I attache an example of TGraphErrors::Fit. The left plot returns
reasonable chi^2/ndf, but the right side doesn't. The result
depends on the variable "kScale" in the macro.
The fitting results from the left and the right plots should be
the same value mathematically.
Am I doing something incorrect?
5.22.00 + Mac OS X 10.5.6
Regards,
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
Loading...