TGraph


class description - source file - inheritance tree

class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarker


    protected:
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) public:
TGraph TGraph() TGraph TGraph(Int_t n) TGraph TGraph(Int_t n, Float_t* x, Float_t* y) TGraph TGraph(Int_t n, Double_t* x, Double_t* y) TGraph TGraph(TGraph&) virtual void ~TGraph() virtual void Browse(TBrowser* b) static TClass* Class() void ComputeLogs(Int_t npoints, Int_t opt) virtual void ComputeRange(Double_t& xmin, Double_t& ymin, Double_t& xmax, Double_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 DrawGraph(Int_t n, Double_t* x, Double_t* y, Option_t* option) virtual void DrawPanel() virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py) virtual void Fit(const char* formula, Option_t* option, Option_t* goption) virtual void Fit(TF1* f1, Option_t* option, Option_t* goption) virtual void FitPanel() virtual Double_t GetErrorX(Int_t bin) const virtual Double_t GetErrorY(Int_t bin) const TF1* GetFunction(const char* name) const TH1F* GetHistogram() const TList* GetListOfFunctions() const Int_t GetN() const virtual void GetPoint(Int_t i, Double_t& x, Double_t& y) Double_t* GetX() const TAxis* GetXaxis() const Double_t* GetY() const TAxis* GetYaxis() const virtual void InitExpo() virtual void InitGaus() virtual void InitPolynom() virtual TClass* IsA() const virtual void Paint(Option_t* chopt) virtual void PaintGraph(Int_t npoints, Double_t* x, Double_t* y, Option_t* option) virtual void PaintGrapHist(Int_t npoints, Double_t* x, Double_t* y, Option_t* option) virtual void Print(Option_t* chopt) const static void RemoveFunction(TGraph* gr, TObject* obj) virtual void SavePrimitive(ofstream& out, Option_t* option) virtual void Set(Int_t n) virtual void SetMaximum(Double_t maximum = -1111) virtual void SetMinimum(Double_t minimum = -1111) virtual void SetPoint(Int_t i, Double_t x, Double_t y) virtual void SetTitle(const char* title) virtual void ShowMembers(TMemberInspector& insp, char* parent) void Smooth(Int_t npoints, Double_t* x, Double_t* y, Int_t drawtype) virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b) virtual void UseCurrentStyle() void Zero(Int_t& k, Double_t AZ, Double_t BZ, Double_t E2, Double_t& X, Double_t& Y, Int_t maxiterations)

Data Members

protected:
Int_t fNpoints Number of points Double_t* fX [fNpoints] array of X points Double_t* fY [fNpoints] 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 Double_t fMinimum Minimum value for plotting along y Double_t fMaximum Maximum value for plotting along y public:
static const enum TObject:: kClipFrame static const enum TObject:: kFitInit


See also

TCutG, TGraphAsymmErrors, TGraphErrors

Class Description

   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*");
}

/*

*/



TGraph(): TNamed(), TAttLine(), TAttFill(), TAttMarker()
*-*-*-*-*-*-*-*-*-*-*Graph default constructor-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*                  =========================

TGraph(Int_t n) : TNamed("Graph","Graph"), TAttLine(), TAttFill(), TAttMarker()
 constructor with only the number of points set
 the arrsys x and y will be set later

TGraph(Int_t n, Float_t *x, Float_t *y) : TNamed("Graph","Graph"), TAttLine(), TAttFill(), TAttMarker()
*-*-*-*-*-*-*-*-*-*-*Graph normal constructor with floats-*-*-*-*-*-*-*-*-*
*-*                  ========================

TGraph(Int_t n, Double_t *x, Double_t *y) : TNamed("Graph","Graph"), TAttLine(), TAttFill(), TAttMarker()
*-*-*-*-*-*-*-*-*-*-*Graph normal constructor with doubles-*-*-*-*-*-*-*-*
*-*                  ========================


~TGraph()
*-*-*-*-*-*-*-*-*-*-*Graph default destructor-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*                  =======================

void Browse(TBrowser *)

void ComputeRange(Double_t &, Double_t &, Double_t &, Double_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 DrawGraph(Int_t n, Double_t *x, Double_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(const char *fname, Option_t *option, Option_t *)
*-*-*-*-*-*Fit this graph with function with name fname*-*-*-*-*-*-*-*-*-*
*-*        ============================================
  interface to TF1::Fit(TF1 *f1...

void Fit(TF1 *f1, Option_t *option, Option_t *)
*-*-*-*-*-*-*-*-*-*-*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");

   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

void FitPanel()
*-*-*-*-*-*-*Display a panel with all graph fit options*-*-*-*-*-*
*-*          ==========================================

   See class TFitPanel for example

Double_t GetErrorX(Int_t) const
    This function is called by GraphFitChisquare.
    It always returns a negative value. Real implementation in TGraphErrors

Double_t GetErrorY(Int_t) const
    This function is called by GraphFitChisquare.
    It always returns a negative value. Real implementation in TGraphErrors

TF1* GetFunction(const char *name) const
*-*-*-*-*Return pointer to function with name*-*-*-*-*-*-*-*-*-*-*-*-*
*-*      ===================================

 Functions such as TGraph::Fit store the fitted function in the list of
 functions of this graph.

TH1F* GetHistogram() const
    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, Double_t &x, Double_t &y)
*-*-*-*-*-*-*-*-*-*-*Get x and y values for point number i*-*-*-*-*-*-*-*-*
*-*                  =====================================

TAxis* GetXaxis() const
 Get x axis of the graph.

TAxis* GetYaxis() const
 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



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


void Paint(Option_t *option)
*-*-*-*-*-*-*-*-*-*-*Draw this graph with its current attributes*-*-*-*-*-*-*
*-*                  ===========================================

void PaintGraph(Int_t npoints, Double_t *x, Double_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[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



void PaintGrapHist(Int_t npoints, Double_t *x, Double_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 *) const
*-*-*-*-*-*-*-*-*-*-*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 Set(Int_t n)
 Set number of points in the graph
 Existing coordinates are preserved
 New coordinates above fNpoints are preset to 0.

void SetMaximum(Double_t maximum)

void SetMinimum(Double_t minimum)

void SetPoint(Int_t i, Double_t x, Double_t y)
*-*-*-*-*-*-*-*-*-*-*Set x and y values for point number i*-*-*-*-*-*-*-*-*
*-*                  =====================================

void SetTitle(const char* title)

void Smooth(Int_t npoints, Double_t *x, Double_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 UseCurrentStyle()
 Set current style settings in this graph
 This function is called when either TCanvas::UseCurrentStyle
 or TROOT::ForceStyle have been invoked.

void Zero(Int_t &k,Double_t AZ,Double_t BZ,Double_t E2,Double_t &X,Double_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() const
              Int_t GetN() const
          Double_t* GetX() const
          Double_t* GetY() const
            TClass* Class()
            TClass* IsA() const
               void ShowMembers(TMemberInspector& insp, char* parent)
               void StreamerNVirtual(TBuffer& b)
             TGraph TGraph(TGraph&)


Author: Rene Brun, Olivier Couet 12/12/94
Last update: root/graf:$Name: $:$Id: TGraph.cxx,v 1.26 2000/12/15 12:05:24 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *


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.