FIT from txt file - Best fit function choice


_ROOT Version: Last
_Platform: Ubuntu 18
Compiler: Not Provided


Dear all,

I’m trying to perform a fit loading data from a txt file. Data are plotted in function of theta on the x axis, while the step parameter changes. I’m very new to Root and also reading the manual, it is not straightforward to understand what exactly do.
Data are very near to a Gaussian shape, but with a lower kurtosis. Since I need, in theory, to represent also asymmetry, I tried to fit with a Pearson distribution. Unfortunately fit tools doesn’t take into account of the uncertainty both on x and y in the fitting parameter evaluation. Since this is a theoretical response, it could be nice also to implement convolution between this fit and the detector response.
Can someone please give me some hint to perform this in root? (I don’t see any button to upload data).

Thank you.

Try to use one of:
TGraphErrors
TGraphAsymmErrors
TGraphBentErrors
and:
TGraph::Fit

Thank you for the reply. There isn’t a tutorials in which I can learn the structure of the program. I already tried to see how load data from tree tutorial, but it doesn’t work with mine.

TGraph::TGraph ( const char * filename, …
TGraphErrors::TGraphErrors ( const char * filename, …
TGraphAsymmErrors::TGraphAsymmErrors ( const char * filename, …

${ROOTSYS}/tutorials/graphs/*
${ROOTSYS}/tutorials/fit/*

I already saw the fit and roofit tutorials. But I always find tutorials in which data are generated inside and not loaded from outside. If I try to use “ReadFile(Form(”%sData.txt",dir.Data()),“x:y”); " as it is used in the tutorial Basic.C, it doesn’t work.

here are 2 blog posts of mine that were originally used for a comparison of C++/MINUIT and gonum/optimize:

(you can use them either to write your own C++ program or a Go one :P)

hth,
-s

This depends a bit on the data and its format in the text file.

If the uncertainties are due to variances of the data in the text file, use a TTree. You load your text file data into a TTree e.g. by TTree::ReadFile() as shown in tutorials/tree/basic2.C. Let us know which problems you see when running this.

If the data in the text file contains the uncertainties, read the data into a TGraphAsymmErrors. You can use its constructor that reads from a text file, specifying the format.

The second step is the fitting. For the TTree, and given that you want convolutions, maybe using RooFit would be the right thing to do. Let us know.

Else using the regular TFitPanel interactively (draw the TGraphAsymmErrors, right click it, and select “Fit”) should guide you! Let us know if you need some more detailed info!

Axel.

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