ROOT logo
// @(#)root/hist:$Id: TGraph.h 38549 2011-03-21 19:26:04Z pcanal $
// Author: Rene Brun, Olivier Couet   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGraph
#define ROOT_TGraph


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGraph                                                               //
//                                                                      //
// Graph graphics class.                                                //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TNamed
#include "TNamed.h"
#endif
#ifndef ROOT_TAttLine
#include "TAttLine.h"
#endif
#ifndef ROOT_TAttFill
#include "TAttFill.h"
#endif
#ifndef ROOT_TAttMarker
#include "TAttMarker.h"
#endif
#ifndef ROOT_TVectorFfwd
#include "TVectorFfwd.h"
#endif
#ifndef ROOT_TVectorDfwd
#include "TVectorDfwd.h"
#endif

class TBrowser;
class TAxis;
class TH1;
class TH1F;
class TCollection;
class TF1;
class TSpline;

#include "TFitResultPtr.h"

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

protected:

   Int_t              fMaxSize;   //!Current dimension of arrays fX and fY
   Int_t              fNpoints;   //Number of points <= fMaxSize
   Double_t          *fX;         //[fNpoints] array of X points
   Double_t          *fY;         //[fNpoints] array of Y points
   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

   static void        SwapValues(Double_t* arr, Int_t pos1, Int_t pos2);
   virtual void       SwapPoints(Int_t pos1, Int_t pos2);

   virtual Double_t **Allocate(Int_t newsize);
   Double_t         **AllocateArrays(Int_t Narrays, Int_t arraySize);
   virtual Bool_t     CopyPoints(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin);
   virtual void       CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin);
   Bool_t             CtorAllocate();
   Double_t         **ExpandAndCopy(Int_t size, Int_t iend);
   virtual void       FillZero(Int_t begin, Int_t end, Bool_t from_ctor = kTRUE);
   Double_t         **ShrinkAndCopy(Int_t size, Int_t iend);

public:
   // TGraph status bits
   enum {
      kClipFrame     = BIT(10),  // clip to the frame boundary
      kNotEditable   = BIT(18)   // bit set if graph is non editable
   };

   TGraph();
   TGraph(Int_t n);
   TGraph(Int_t n, const Int_t *x, const Int_t *y);
   TGraph(Int_t n, const Float_t *x, const Float_t *y);
   TGraph(Int_t n, const Double_t *x, const Double_t *y);
   TGraph(const TGraph &gr);
   TGraph& operator=(const TGraph&);
   TGraph(const TVectorF &vx, const TVectorF &vy);
   TGraph(const TVectorD &vx, const TVectorD &vy);
   TGraph(const TH1 *h);
   TGraph(const TF1 *f, Option_t *option="");
   TGraph(const char *filename, const char *format="%lg %lg", Option_t *option="");
   virtual ~TGraph();

   virtual void          Apply(TF1 *f);
   virtual void          Browse(TBrowser *b);
   virtual Double_t      Chisquare(const TF1 *f1) const;
   static Bool_t         CompareArg(const TGraph* gr, Int_t left, Int_t right);
   static Bool_t         CompareX(const TGraph* gr, Int_t left, Int_t right);
   static Bool_t         CompareY(const TGraph* gr, Int_t left, Int_t right);
   static Bool_t         CompareRadius(const TGraph* gr, Int_t left, Int_t right);
   virtual void          ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const;
   virtual Int_t         DistancetoPrimitive(Int_t px, Int_t py);
   virtual void          Draw(Option_t *chopt="");
   virtual void          DrawGraph(Int_t n, const Int_t *x, const Int_t *y, Option_t *option="");
   virtual void          DrawGraph(Int_t n, const Float_t *x, const Float_t *y, Option_t *option="");
   virtual void          DrawGraph(Int_t n, const Double_t *x=0, const Double_t *y=0, Option_t *option="");
   virtual void          DrawPanel(); // *MENU*
   virtual Double_t      Eval(Double_t x, TSpline *spline=0, Option_t *option="") const;
   virtual void          ExecuteEvent(Int_t event, Int_t px, Int_t py);
   virtual void          Expand(Int_t newsize);
   virtual void          Expand(Int_t newsize, Int_t step);
   virtual TObject      *FindObject(const char *name) const;
   virtual TObject      *FindObject(const TObject *obj) const;
   virtual TFitResultPtr Fit(const char *formula ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0); // *MENU*
   virtual TFitResultPtr Fit(TF1 *f1 ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0);
   virtual void          FitPanel(); // *MENU*
   Bool_t                GetEditable() const;
   TF1                  *GetFunction(const char *name) const;
   TH1F                 *GetHistogram() const;
   TList                *GetListOfFunctions() const { return fFunctions; }
   virtual Double_t      GetCorrelationFactor() const;
   virtual Double_t      GetCovariance() const;
   virtual Double_t      GetMean(Int_t axis=1) const;
   virtual Double_t      GetRMS(Int_t axis=1) const;
   Int_t                 GetMaxSize() const {return fMaxSize;}
   Int_t                 GetN() const {return fNpoints;}
   virtual Double_t      GetErrorX(Int_t bin) const;
   virtual Double_t      GetErrorY(Int_t bin) const;
   virtual Double_t      GetErrorXhigh(Int_t bin) const;
   virtual Double_t      GetErrorXlow(Int_t bin)  const;
   virtual Double_t      GetErrorYhigh(Int_t bin) const;
   virtual Double_t      GetErrorYlow(Int_t bin)  const;
   Double_t             *GetX()  const {return fX;}
   Double_t             *GetY()  const {return fY;}
   virtual Double_t     *GetEX() const {return 0;}
   virtual Double_t     *GetEY() const {return 0;}
   virtual Double_t     *GetEXhigh() const {return 0;}
   virtual Double_t     *GetEXlow()  const {return 0;}
   virtual Double_t     *GetEYhigh() const {return 0;}
   virtual Double_t     *GetEYlow()  const {return 0;}
   virtual Double_t     *GetEXlowd()  const {return 0;}
   virtual Double_t     *GetEXhighd() const {return 0;}
   virtual Double_t     *GetEYlowd()  const {return 0;}
   virtual Double_t     *GetEYhighd() const {return 0;}
   Double_t              GetMaximum()  const {return fMaximum;}
   Double_t              GetMinimum()  const {return fMinimum;}
   TAxis                *GetXaxis() const ;
   TAxis                *GetYaxis() const ;
   virtual Int_t         GetPoint(Int_t i, Double_t &x, Double_t &y) const;
   
   virtual void          InitExpo(Double_t xmin=0, Double_t xmax=0);
   virtual void          InitGaus(Double_t xmin=0, Double_t xmax=0);
   virtual void          InitPolynom(Double_t xmin=0, Double_t xmax=0);
   virtual Int_t         InsertPoint(); // *MENU*
   virtual Double_t      Integral(Int_t first=0, Int_t last=-1) const;
   virtual Bool_t        IsEditable() const {return !TestBit(kNotEditable);}
   virtual Int_t         IsInside(Double_t x, Double_t y) const;
   virtual void          LeastSquareFit(Int_t m, Double_t *a, Double_t xmin=0, Double_t xmax=0);
   virtual void          LeastSquareLinearFit(Int_t n, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin=0, Double_t xmax=0);
   virtual Int_t         Merge(TCollection* list);
   virtual void          Paint(Option_t *chopt="");
   void                  PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt);
   void                  PaintGrapHist(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt); 
   virtual void          PaintStats(TF1 *fit);
   virtual void          Print(Option_t *chopt="") const;
   virtual void          RecursiveRemove(TObject *obj);
   virtual Int_t         RemovePoint(); // *MENU*
   virtual Int_t         RemovePoint(Int_t ipoint);
   virtual void          SavePrimitive(ostream &out, Option_t *option = "");
   virtual void          SetEditable(Bool_t editable=kTRUE); // *TOGGLE* *GETTER=GetEditable
   virtual void          SetHistogram(TH1F *h) {fHistogram = h;}
   virtual void          SetMaximum(Double_t maximum=-1111); // *MENU*
   virtual void          SetMinimum(Double_t minimum=-1111); // *MENU*
   virtual void          Set(Int_t n);
   virtual void          SetPoint(Int_t i, Double_t x, Double_t y);
   virtual void          SetTitle(const char *title="");    // *MENU*
   virtual void          Sort(Bool_t (*greater)(const TGraph*, Int_t, Int_t)=&TGraph::CompareX,
                              Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111);
   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);

   ClassDef(TGraph,4)  //Graph graphics class
};

inline Double_t **TGraph::Allocate(Int_t newsize) {
   return AllocateArrays(2, newsize);
}

#endif
 TGraph.h:1
 TGraph.h:2
 TGraph.h:3
 TGraph.h:4
 TGraph.h:5
 TGraph.h:6
 TGraph.h:7
 TGraph.h:8
 TGraph.h:9
 TGraph.h:10
 TGraph.h:11
 TGraph.h:12
 TGraph.h:13
 TGraph.h:14
 TGraph.h:15
 TGraph.h:16
 TGraph.h:17
 TGraph.h:18
 TGraph.h:19
 TGraph.h:20
 TGraph.h:21
 TGraph.h:22
 TGraph.h:23
 TGraph.h:24
 TGraph.h:25
 TGraph.h:26
 TGraph.h:27
 TGraph.h:28
 TGraph.h:29
 TGraph.h:30
 TGraph.h:31
 TGraph.h:32
 TGraph.h:33
 TGraph.h:34
 TGraph.h:35
 TGraph.h:36
 TGraph.h:37
 TGraph.h:38
 TGraph.h:39
 TGraph.h:40
 TGraph.h:41
 TGraph.h:42
 TGraph.h:43
 TGraph.h:44
 TGraph.h:45
 TGraph.h:46
 TGraph.h:47
 TGraph.h:48
 TGraph.h:49
 TGraph.h:50
 TGraph.h:51
 TGraph.h:52
 TGraph.h:53
 TGraph.h:54
 TGraph.h:55
 TGraph.h:56
 TGraph.h:57
 TGraph.h:58
 TGraph.h:59
 TGraph.h:60
 TGraph.h:61
 TGraph.h:62
 TGraph.h:63
 TGraph.h:64
 TGraph.h:65
 TGraph.h:66
 TGraph.h:67
 TGraph.h:68
 TGraph.h:69
 TGraph.h:70
 TGraph.h:71
 TGraph.h:72
 TGraph.h:73
 TGraph.h:74
 TGraph.h:75
 TGraph.h:76
 TGraph.h:77
 TGraph.h:78
 TGraph.h:79
 TGraph.h:80
 TGraph.h:81
 TGraph.h:82
 TGraph.h:83
 TGraph.h:84
 TGraph.h:85
 TGraph.h:86
 TGraph.h:87
 TGraph.h:88
 TGraph.h:89
 TGraph.h:90
 TGraph.h:91
 TGraph.h:92
 TGraph.h:93
 TGraph.h:94
 TGraph.h:95
 TGraph.h:96
 TGraph.h:97
 TGraph.h:98
 TGraph.h:99
 TGraph.h:100
 TGraph.h:101
 TGraph.h:102
 TGraph.h:103
 TGraph.h:104
 TGraph.h:105
 TGraph.h:106
 TGraph.h:107
 TGraph.h:108
 TGraph.h:109
 TGraph.h:110
 TGraph.h:111
 TGraph.h:112
 TGraph.h:113
 TGraph.h:114
 TGraph.h:115
 TGraph.h:116
 TGraph.h:117
 TGraph.h:118
 TGraph.h:119
 TGraph.h:120
 TGraph.h:121
 TGraph.h:122
 TGraph.h:123
 TGraph.h:124
 TGraph.h:125
 TGraph.h:126
 TGraph.h:127
 TGraph.h:128
 TGraph.h:129
 TGraph.h:130
 TGraph.h:131
 TGraph.h:132
 TGraph.h:133
 TGraph.h:134
 TGraph.h:135
 TGraph.h:136
 TGraph.h:137
 TGraph.h:138
 TGraph.h:139
 TGraph.h:140
 TGraph.h:141
 TGraph.h:142
 TGraph.h:143
 TGraph.h:144
 TGraph.h:145
 TGraph.h:146
 TGraph.h:147
 TGraph.h:148
 TGraph.h:149
 TGraph.h:150
 TGraph.h:151
 TGraph.h:152
 TGraph.h:153
 TGraph.h:154
 TGraph.h:155
 TGraph.h:156
 TGraph.h:157
 TGraph.h:158
 TGraph.h:159
 TGraph.h:160
 TGraph.h:161
 TGraph.h:162
 TGraph.h:163
 TGraph.h:164
 TGraph.h:165
 TGraph.h:166
 TGraph.h:167
 TGraph.h:168
 TGraph.h:169
 TGraph.h:170
 TGraph.h:171
 TGraph.h:172
 TGraph.h:173
 TGraph.h:174
 TGraph.h:175
 TGraph.h:176
 TGraph.h:177
 TGraph.h:178
 TGraph.h:179
 TGraph.h:180
 TGraph.h:181
 TGraph.h:182
 TGraph.h:183
 TGraph.h:184
 TGraph.h:185
 TGraph.h:186
 TGraph.h:187
 TGraph.h:188
 TGraph.h:189
 TGraph.h:190
 TGraph.h:191
 TGraph.h:192
 TGraph.h:193
 TGraph.h:194