TGraph
class description - source file - inheritance tree
public:
TGraph TGraph(Int_t n, Float_t* x = 0, Float_t* y = 0)
TGraph TGraph()
TGraph TGraph(Int_t n, Double_t* x, Double_t* y)
TGraph TGraph(TGraph&)
virtual void ~TGraph()
virtual void Browse(TBrowser* b)
TClass* Class()
void ComputeLogs(Int_t npoints, Int_t opt)
virtual void ComputeRange(Float_t& xmin, Float_t& ymin, Float_t& xmax, Float_t& ymax)
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
virtual void Draw(Option_t* chopt)
virtual void DrawGraph(Int_t n, Float_t* x, Float_t* y, Option_t* option)
virtual void DrawPanel()
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual void Fit(Text_t* formula, Option_t* option, Option_t* goption)
virtual void FitPanel()
virtual Float_t GetErrorX(Int_t bin)
virtual Float_t GetErrorY(Int_t bin)
TH1F* GetHistogram()
TList* GetListOfFunctions()
Int_t GetN()
virtual void GetPoint(Int_t i, Float_t& x, Float_t& y)
Float_t* GetX()
TAxis* GetXaxis()
Float_t* GetY()
TAxis* GetYaxis()
virtual void InitExpo()
virtual void InitGaus()
virtual void InitPolynom()
virtual TClass* IsA() const
virtual void LeastSquareFit(Int_t n, Int_t m, Double_t* a)
virtual void LeastSquareLinearFit(Int_t ndata, Double_t& a0, Double_t& a1, Int_t& ifail)
virtual void Paint(Option_t* chopt)
virtual void PaintGraph(Int_t npoints, Float_t* x, Float_t* y, Option_t* option)
virtual void PaintGrapHist(Int_t npoints, Float_t* x, Float_t* y, Option_t* option)
virtual void Print(Option_t* chopt)
void RemoveFunction(TGraph* gr, TObject* obj)
virtual void SavePrimitive(ofstream& out, Option_t* option)
virtual void SetMaximum(Float_t maximum = -1111)
virtual void SetMinimum(Float_t minimum = -1111)
virtual void SetPoint(Int_t i, Float_t x, Float_t y)
virtual void SetTitle(const Text_t* title)
virtual void ShowMembers(TMemberInspector& insp, char* parent)
void Smooth(Int_t npoints, Float_t* x, Float_t* y, Int_t drawtype)
virtual void Streamer(TBuffer& b)
void Zero(Int_t& k, Float_t AZ, Float_t BZ, Float_t E2, Float_t& X, Float_t& Y, Int_t maxiterations)
protected:
Int_t fNpoints Number of points
Float_t* fX array of X points
Float_t* fY array of Y points
Option_t* fOption Axis options
TList* fFunctions Pointer to list of functions (fits and user)
TH1F* fHistogram Pointer to histogram used for drawing axis
Float_t fMaximum Maximum value for plotting along y
Float_t fMinimum Minimum value for plotting along y
See also
-
TCutG, TGraphAsymmErrors, TGraphErrors
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);
Float_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*");
}
/*
*/
TGraph(): TNamed(), TAttLine(), TAttFill(), TAttMarker()
*-*-*-*-*-*-*-*-*-*-*Graph default constructor-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =========================
TGraph(Int_t n, Float_t *x, Float_t *y)
: TNamed("Graph","Graph"), TAttLine(), TAttFill(), TAttMarker()
*-*-*-*-*-*-*-*-*-*-*Graph normal constructor-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ========================
TGraph(Int_t n, Double_t *x, Double_t *y)
: TNamed("Graph","Graph"), TAttLine(), TAttFill(), TAttMarker()
*-*-*-*-*-*-*-*-*-*-*Graph normal constructor-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ========================
~TGraph()
*-*-*-*-*-*-*-*-*-*-*Graph default destructor-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =======================
void Browse(TBrowser *)
void ComputeRange(Float_t &, Float_t &, Float_t &, Float_t &)
this function is dummy in TGraph, but redefined by TGraphErrors
void Draw(Option_t *option)
*-*-*-*-*-*-*-*-*-*-*Draw this graph with its current attributes*-*-*-*-*-*-*
*-* ==========================================
Options to draw a graph are described in TGraph::PaintGraph
Int_t DistancetoPrimitive(Int_t px, Int_t py)
*-*-*-*-*-*-*-*-*-*-*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.
void DrawGraph(Int_t n, Float_t *x, Float_t *y, Option_t *option)
*-*-*-*-*-*-*-*-*-*-*Draw this graph with new attributes*-*-*-*-*-*-*-*-*-*
*-* ===================================
void DrawPanel()
*-*-*-*-*-*-*Display a panel with all graph drawing options*-*-*-*-*-*
*-* ==============================================
void ExecuteEvent(Int_t event, Int_t px, Int_t py)
*-*-*-*-*-*-*-*-*-*-*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.
void Fit(Text_t *fname, Option_t *option, Option_t *)
*-*-*-*-*-*-*-*-*-*-*Fit this graph with function fname*-*-*-*-*-*-*-*-*-*
*-* ==================================
fname is the name of 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
= "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");
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.
void FitPanel()
*-*-*-*-*-*-*Display a panel with all graph fit options*-*-*-*-*-*
*-* ==========================================
See class TFitPanel for example
Float_t GetErrorX(Int_t)
This function is called by GraphFitChisquare.
It always returns a negative value. Real implementation in TGraphErrors
Float_t GetErrorY(Int_t)
This function is called by GraphFitChisquare.
It always returns a negative value. Real implementation in TGraphErrors
TH1F* GetHistogram()
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
void GetPoint(Int_t i, Float_t &x, Float_t &y)
*-*-*-*-*-*-*-*-*-*-*Get x and y values for point number i*-*-*-*-*-*-*-*-*
*-* =====================================
TAxis* GetXaxis()
Get x axis of the graph.
TAxis* GetYaxis()
Get y axis of the graph.
void InitGaus()
*-*-*-*-*-*Compute Initial values of parameters for a gaussian*-*-*-*-*-*-*
*-* ===================================================
void InitExpo()
*-*-*-*-*-*Compute Initial values of parameters for an exponential*-*-*-*-*
*-* =======================================================
void InitPolynom()
*-*-*-*-*-*Compute Initial values of parameters for a polynom*-*-*-*-*-*-*
*-* ===================================================
void LeastSquareFit(Int_t n, Int_t m, Double_t *a)
*-*-*-*-*-*-*-*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
(E.Keil. revised by B.Schorr, 23.10.1981.)
void LeastSquareLinearFit(Int_t ndata, Double_t &a0, Double_t &a1, Int_t &ifail)
*-*-*-*-*-*-*-*-*-*Least square linear fit without weights*-*-*-*-*-*-*-*-*
*-* =======================================
extracted from CERNLIB LLSQ: Translated to C++ by Rene Brun
(added to LSQ by B. Schorr, 15.02.1982.)
void Paint(Option_t *option)
*-*-*-*-*-*-*-*-*-*-*Draw this graph with its current attributes*-*-*-*-*-*-*
*-* ===========================================
void PaintGraph(Int_t npoints, Float_t *x, Float_t *y, Option_t *chopt)
*-*-*-*-*-*-*-*-*-*-*-*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(N) or X(2) : X coordinates or (XMIN,XMAX) (WC space).
Y(N) 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
void PaintGrapHist(Int_t npoints, Float_t *x, Float_t *y, Option_t *chopt)
*-*-*-*-*-*-*-*-*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).
void ComputeLogs(Int_t npoints, Int_t opt)
*-*-*-*-*-*-*-*-*-*-*-*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.
void Print(Option_t *)
*-*-*-*-*-*-*-*-*-*-*Print graph values*-*-*-*-*-*-*-*-*-*-*-*
*-* ==================
void RemoveFunction(TGraph *gr, TObject *obj)
Remove obj from the list of functions of the TGraph gr
this function is called by TF1 destructor
void SavePrimitive(ofstream &out, Option_t *option)
Save primitive as a C++ statement(s) on output stream out
void SetMaximum(Float_t maximum)
void SetMinimum(Float_t minimum)
void SetPoint(Int_t i, Float_t x, Float_t y)
*-*-*-*-*-*-*-*-*-*-*Set x and y values for point number i*-*-*-*-*-*-*-*-*
*-* =====================================
void SetTitle(const Text_t* title)
void Smooth(Int_t npoints, Float_t *x, Float_t *y, Int_t drawtype)
*-*-*-*-*-*-*-*-*-*-*-*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)
void Streamer(TBuffer &b)
Stream an object of class TGraph.
void Zero(Int_t &k,Float_t AZ,Float_t BZ,Float_t E2,Float_t &X,Float_t &Y
,Int_t maxiterations)
*-*-*-*-*-*-*-*-*-*-*-*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
Inline Functions
TList* GetListOfFunctions()
Int_t GetN()
Float_t* GetX()
Float_t* GetY()
TClass* Class()
TClass* IsA() const
void ShowMembers(TMemberInspector& insp, char* parent)
TGraph TGraph(TGraph&)
Author: Rene Brun, Olivier Couet 12/12/94
Last update: 2.23/07 22/10/99 09.21.53 by Rene Brun
Copyright (c) 1995-1999, The ROOT System, All rights reserved. *
ROOT page - Class index - Top of the page
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.