See also

A Graph is a graphics object made of two arrays X and Y
with npoints each.
This class supports essentially two graph categories:
- General case with non equidistant points
- Special case with equidistant points
The various format options to draw a Graph are explained in
TGraph::PaintGraph and TGraph::PaintGrapHist
These two functions are derived from the HIGZ routines IGRAPH and IGHIST
and many modifications.
The picture below has been generated by the following macro:
------------------------------------------------------------------
{
TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
Double_t x[100], y[100];
Int_t n = 20;
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
}
gr = new TGraph(n,x,y);
gr->Draw("AC*");
}
/*
*/

*-*-*-*-*-*-*-*-*-*-*Compute distance from point px,py to a graph*-*-*-*-*-*
*-* ===========================================
Compute the closest distance of approach from point px,py to this line.
The distance is computed in pixels units.

*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*
*-* =========================================
This member function is called when a graph is clicked with the locator
If Left button clicked on one of the line end points, this point
follows the cursor until button is released.
if Middle button clicked, the line is moved parallel to itself
until the button is released.

*-*-*-*-*-*-*-*-*-*-*Fit this graph with function f1*-*-*-*-*-*-*-*-*-*
*-* ==================================
f1 is an already predefined function created by TF1.
Predefined functions such as gaus, expo and poln are automatically
created by ROOT.
The list of fit options is given in parameter option.
option = "W" Set all errors to 1
= "U" Use a User specified fitting algorithm (via SetFCN)
= "Q" Quiet mode (minimum printing)
= "V" Verbose mode (default is between Q and V)
= "R" Use the Range specified in the function range
= "N" Do not store the graphics function, do not draw
= "0" Do not plot the result of the fit. By default the fitted function
is drawn unless the option"N" above is specified.
= "+" Add this new fitted function to the list of fitted functions
(by default, any previous function is deleted)
When the fit is drawn (by default), the parameter goption may be used
to specify a list of graphics options. See TGraph::Paint for a complete
list of these options.
In order to use the Range option, one must first create a function
with the expression to be fitted. For example, if your graph
has a defined range between -4 and 4 and you want to fit a gaussian
only in the interval 1 to 3, you can do:
TF1 *f1 = new TF1("f1","gaus",1,3);
graph->Fit("f1","R");
Setting initial conditions
==========================
Parameters must be initialized before invoking the Fit function.
The setting of the parameter initial values is automatic for the
predefined functions : poln, expo, gaus. One can however disable
this automatic computation by specifying the option "B".
You can specify boundary limits for some or all parameters via
f1->SetParLimits(p_number, parmin, parmax);
if parmin>=parmax, the parameter is fixed
Note that you are not forced to fix the limits for all parameters.
For example, if you fit a function with 6 parameters, you can do:
func->SetParameters(0,3.1,1.e-6,0.1,-8,100);
func->SetParLimits(4,-10,-4);
func->SetParLimits(5, 1,1);
With this setup, parameters 0->3 can vary freely
Parameter 4 has boundaries [-10,-4] with initial value -8
Parameter 5 is fixed to 100.
Changing the fitting function
=============================
By default the fitting function GraphFitChisquare is used.
To specify a User defined fitting function, specify option "U" and
call the following functions:
TVirtualFitter::Fitter(mygraph)->SetFCN(MyFittingFunction)
where MyFittingFunction is of type:
extern void MyFittingFunction(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag);
Associated functions
====================
One or more object (typically a TF1*) can be added to the list
of functions (fFunctions) associated to each graph.
When TGraph::Fit is invoked, the fitted function is added to this list.
Given a graph gr, one can retrieve an associated function
with: TF1 *myfunc = gr->GetFunction("myfunc");
Access to the fit results
=========================
If the graph is made persistent, the list of
associated functions is also persistent. Given a pointer (see above)
to an associated function myfunc, one can retrieve the function/fit
parameters with calls such as:
Double_t chi2 = myfunc->GetChisquare();
Double_t par0 = myfunc->GetParameter(0); //value of 1st parameter
Double_t err0 = myfunc->GetParError(0); //error on first parameter

*-*-*-*-*Return pointer to function with name*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ===================================
Functions such as TGraph::Fit store the fitted function in the list of
functions of this graph.

Returns a pointer to the histogram used to draw the axis
Takes into account the two following cases.
1- option 'A' was specified in TGraph::Draw. Return fHistogram
2- user had called TPad::DrawFrame. return pointer to hframe histogram

*-*-*-*-*-*-*-*Least squares lpolynomial fitting without weights*-*-*-*-*-*-*
*-* =================================================
n number of points to fit
m number of parameters
a array of parameters
based on CERNLIB routine LSQ: Translated to C++ by Rene Brun

*-*-*-*-*-*-*-*-*-*-*-*Control function to draw a graph*-*-*-*-*-*-*-*-*-*-*
*-* ================================
Draws one dimensional graphs. The aspect of the graph is done
according to the value of the chopt.
_Input parameters:
npoints : Number of points in X or in Y.
x[npoints] or x[2] : X coordinates or (XMIN,XMAX) (WC space).
y[npoints] or y[2] : Y coordinates or (YMIN,YMAX) (WC space).
chopt : Option.
chopt='L' : A simple polyline beetwen every points is drawn
chopt='F' : A fill area is drawn ('CF' draw a smooth fill area)
chopt='A' : Axis are drawn around the graph
chopt='C' : A smooth Curve is drawn
chopt='*' : A Star is plotted at each point
chopt='P' : Idem with the current marker
chopt='B' : A Bar chart is drawn at each point
chopt='1' : ylow=rwymin

*-*-*-*-*-*-*-*-*Control function to draw a graphistogram*-*-*-*-*-*-*-*-*-*
*-* ========================================
Draws one dimensional graphs. The aspect of the graph is done
according to the value of the chopt.
Input parameters:
npoints : Number of points in X or in Y.
X(N) or x[1] : X coordinates or (XMIN,XMAX) (WC space).
Y(N) or y[1] : Y coordinates or (YMIN,YMAX) (WC space).
chopt : Option.
chopt='R' : Graph is drawn horizontaly, parallel to X axis.
(default is vertically, parallel to Y axis)
If option R is selected the user must give:
2 values for Y (y[0]=YMIN and y[1]=YMAX)
N values for X, one for each channel.
Otherwise the user must give:
N values for Y, one for each channel.
2 values for X (x[0]=XMIN and x[1]=XMAX)
chopt='L' : A simple polyline beetwen every points is drawn
chopt='H' : An Histogram with equidistant bins is drawn
as a polyline.
chopt='F' : An histogram with equidistant bins is drawn
as a fill area. Contour is not drawn unless
chopt='H' is also selected..
chopt='N' : Non equidistant bins (default is equidistant)
If N is the number of channels array X and Y
must be dimensionned as follow:
If option R is not selected (default) then
the user must give:
(N+1) values for X (limits of channels).
N values for Y, one for each channel.
Otherwise the user must give:
(N+1) values for Y (limits of channels).
N values for X, one for each channel.
chopt='F1': Idem as 'F' except that fill area is no more
reparted arround axis X=0 or Y=0 .
chopt='C' : A smooth Curve is drawn.
chopt='*' : A Star is plotted at the center of each bin.
chopt='P' : Idem with the current marker
chopt='B' : A Bar chart with equidistant bins is drawn as fill
areas (Contours are drawn).

*-*-*-*-*-*-*-*-*-*-*-*Convert WC from Log scales*-*-*-*-*-*-*-*-*-*-*-*
*-* ==========================
Take the LOG10 of xwork and ywork according to the value of Options
and put it in xworkl and yworkl.
npoints : Number of points in xwork and in ywork.

*-*-*-*-*-*-*-*-*-*-*-*Smooth a curve given by N points*-*-*-*-*-*-*-*-*-*
*-* ================================
Underlaying routine for Draw based on the CERN GD3 routine TVIPTE
Author - Marlow etc. Modified by - P. Ward Date - 3.10.1973
This routine draws a smooth tangentially continuous curve through
the sequence of data points P(I) I=1,N where P(I)=(X(I),Y(I))
the curve is approximated by a polygonal arc of short vectors .
the data points can represent open curves, P(1) != P(N) or closed
curves P(2) == P(N) . If a tangential discontinuity at P(I) is
required , then set P(I)=P(I+1) . loops are also allowed .
Reference Marlow and Powell,Harwell report No.R.7092.1972
MCCONALOGUE,Computer Journal VOL.13,NO4,NOV1970PP392 6
_Input parameters:
npoints : Number of data points.
x : Abscissa
y : Ordinate
delta is the accuracy required in constructing the curve.
if it is zero then the routine calculates a value other-
wise it uses this value. (default is 0.0)

*-*-*-*-*-*-*-*-*-*-*-*Find zero of a continuous function*-*-*-*-*-*-*-*-*-*
*-* ==================================
Underlaying routine for PaintGraph
This function finds a real zero of the continuous real
function Y(X) in a given interval (A,B). See accompanying
notes for details of the argument list and calling sequence

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.