Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TGraph.h
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun, Olivier Couet 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TGraph
13#define ROOT_TGraph
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TGraph //
19// //
20// Graph graphics class. //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TNamed.h"
25#include "TAttLine.h"
26#include "TAttFill.h"
27#include "TAttMarker.h"
28#include "TVectorFfwd.h"
29#include "TVectorDfwd.h"
30#include "TFitResultPtr.h"
31
32class TBrowser;
33class TAxis;
34class TH1;
35class TH1F;
36class TCollection;
37class TF1;
38class TSpline;
39class TList;
40
41class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
42
43protected:
44
45 Int_t fMaxSize; ///<!Current dimension of arrays fX and fY
46 Int_t fNpoints; ///< Number of points <= fMaxSize
47 Double_t *fX; ///<[fNpoints] array of X points
48 Double_t *fY; ///<[fNpoints] array of Y points
49 TList *fFunctions; ///< Pointer to list of functions (fits and user)
50 TH1F *fHistogram; ///< Pointer to histogram used for drawing axis
51 Double_t fMinimum; ///< Minimum value for plotting along y
52 Double_t fMaximum; ///< Maximum value for plotting along y
53 TString fOption; ///< Options used for drawing the graph
54
55 static void SwapValues(Double_t* arr, Int_t pos1, Int_t pos2);
56 virtual void SwapPoints(Int_t pos1, Int_t pos2);
57 virtual void UpdateArrays(const std::vector<Int_t> &sorting_indices, Int_t numSortedPoints, Int_t low);
58
59 virtual Double_t **Allocate(Int_t newsize);
60 Double_t **AllocateArrays(Int_t Narrays, Int_t arraySize);
61 virtual Bool_t CopyPoints(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin);
62 virtual void CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin);
65 virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor = kTRUE);
67 virtual Bool_t DoMerge(const TGraph * g);
68
69 void SaveHistogramAndFunctions(std::ostream &out, const char *varname, Option_t *option);
70
71public:
72 // TGraph status bits
74 kNoStats = BIT(9), ///< Don't draw stats box
75 kClipFrame = BIT(10), ///< Clip to the frame boundary
76 kResetHisto = BIT(17), ///< fHistogram must be reset in GetHistogram
77 kNotEditable = BIT(18), ///< Bit set if graph is non editable
78 kIsSortedX = BIT(19), ///< Graph is sorted in X points
79 kIsHighlight = BIT(20) ///< Bit set if graph is highlight
80 };
81
84 TGraph(Int_t n, const Int_t *x, const Int_t *y);
85 TGraph(Int_t n, const Float_t *x, const Float_t *y);
86 TGraph(Int_t n, const Double_t *x, const Double_t *y);
87 TGraph(Int_t n, const Double_t *y, Double_t start=0., Double_t step=1.);
88 TGraph(const TGraph &gr);
90 TGraph(const TVectorF &vx, const TVectorF &vy);
91 TGraph(const TVectorD &vx, const TVectorD &vy);
92 TGraph(const TH1 *h);
93 TGraph(const TF1 *f, Option_t *option="");
94 TGraph(const char *filename, const char *format="%lg %lg", Option_t *option="");
95 ~TGraph() override;
96
97 virtual void AddPoint(Double_t x, Double_t y) { SetPoint(fNpoints, x, y); } ///< Append a new point to the graph.
98 virtual void Add(TF1 *f, Double_t c1=1);
99 virtual void Apply(TF1 *f);
100 void Browse(TBrowser *b) override;
101 virtual Double_t Chisquare(TF1 *f1, Option_t *option="") const;
102 static Bool_t CompareArg(const TGraph* gr, Int_t left, Int_t right);
103 static Bool_t CompareX(const TGraph* gr, Int_t left, Int_t right);
104 static Bool_t CompareY(const TGraph* gr, Int_t left, Int_t right);
105 static Bool_t CompareRadius(const TGraph* gr, Int_t left, Int_t right);
108 void Draw(Option_t *chopt="") override;
109 virtual void DrawGraph(Int_t n, const Int_t *x, const Int_t *y, Option_t *option="");
110 virtual void DrawGraph(Int_t n, const Float_t *x, const Float_t *y, Option_t *option="");
111 virtual void DrawGraph(Int_t n, const Double_t *x=nullptr, const Double_t *y=nullptr, Option_t *option="");
112 virtual void DrawPanel(); // *MENU*
113 virtual Double_t Eval(Double_t x, TSpline *spline=nullptr, Option_t *option="") const;
114 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
115 virtual void Expand(Int_t newsize);
116 virtual void Expand(Int_t newsize, Int_t step);
117 TObject *FindObject(const char *name) const override;
118 TObject *FindObject(const TObject *obj) const override;
119 virtual TFitResultPtr Fit(const char *formula ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0); // *MENU*
120 virtual TFitResultPtr Fit(TF1 *f1 ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0);
121 virtual void FitPanel(); // *MENU*
123 TF1 *GetFunction(const char *name) const;
124 virtual TH1F *GetHistogram() const;
127 virtual Double_t GetCovariance() const;
128 virtual Double_t GetMean(Int_t axis=1) const;
129 virtual Double_t GetRMS(Int_t axis=1) const;
130 Int_t GetMaxSize() const {return fMaxSize;}
131 Int_t GetN() const {return fNpoints;}
132 virtual Double_t GetErrorX(Int_t bin) const;
133 virtual Double_t GetErrorY(Int_t bin) const;
134 virtual Double_t GetErrorXhigh(Int_t bin) const;
135 virtual Double_t GetErrorXlow(Int_t bin) const;
136 virtual Double_t GetErrorYhigh(Int_t bin) const;
137 virtual Double_t GetErrorYlow(Int_t bin) const;
138 Double_t *GetX() const {return fX;}
139 Double_t *GetY() const {return fY;}
140 virtual Double_t *GetEX() const {return nullptr;}
141 virtual Double_t *GetEY() const {return nullptr;}
142 virtual Double_t *GetEXhigh() const {return nullptr;}
143 virtual Double_t *GetEXlow() const {return nullptr;}
144 virtual Double_t *GetEYhigh() const {return nullptr;}
145 virtual Double_t *GetEYlow() const {return nullptr;}
146 virtual Double_t *GetEXlowd() const {return nullptr;}
147 virtual Double_t *GetEXhighd() const {return nullptr;}
148 virtual Double_t *GetEYlowd() const {return nullptr;}
149 virtual Double_t *GetEYhighd() const {return nullptr;}
150 Double_t GetMaximum() const {return fMaximum;}
151 Double_t GetMinimum() const {return fMinimum;}
152 TAxis *GetXaxis() const ;
153 TAxis *GetYaxis() const ;
154 char *GetObjectInfo(Int_t px, Int_t py) const override;
155 virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const;
156 virtual Double_t GetPointX(Int_t i) const;
157 virtual Double_t GetPointY(Int_t i) const;
158
159 virtual void InitExpo(Double_t xmin=0, Double_t xmax=0);
160 virtual void InitGaus(Double_t xmin=0, Double_t xmax=0);
162 virtual Int_t InsertPoint(); // *MENU*
163 virtual void InsertPointBefore(Int_t ipoint, Double_t x, Double_t y);
164 virtual Double_t Integral(Int_t first=0, Int_t last=-1) const;
165 virtual Bool_t IsEditable() const {return !TestBit(kNotEditable);}
166 virtual Bool_t IsHighlight() const { return TestBit(kIsHighlight); }
170 virtual Int_t Merge(TCollection* list);
171 virtual void MovePoints(Double_t dx, Double_t dy, Bool_t logx = kFALSE, Bool_t logy = kFALSE);
172 void Paint(Option_t *chopt="") override;
173 void PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt);
174 void PaintGrapHist(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt);
175 virtual void PaintStats(TF1 *fit);
176 void Print(Option_t *chopt="") const override;
177 void RecursiveRemove(TObject *obj) override;
178 virtual Int_t RemovePoint(); // *MENU*
179 virtual Int_t RemovePoint(Int_t ipoint);
180 void SavePrimitive(std::ostream &out, Option_t *option = "") override;
181 void SaveAs(const char *filename = "graph", Option_t *option = "") const override; // *MENU*
182 virtual void Scale(Double_t c1=1., Option_t *option="y"); // *MENU*
183 virtual void SetEditable(Bool_t editable=kTRUE); // *TOGGLE* *GETTER=GetEditable
184 virtual void SetHighlight(Bool_t set = kTRUE); // *TOGGLE* *GETTER=IsHighlight
185 virtual void SetHistogram(TH1F *h);
186 virtual void SetMaximum(Double_t maximum=-1111); // *MENU*
187 virtual void SetMinimum(Double_t minimum=-1111); // *MENU*
188 virtual void Set(Int_t n);
189 virtual void SetOption(Option_t *option = " ") { fOption = option; }
190 virtual void SetPoint(Int_t i, Double_t x, Double_t y);
191 virtual void SetPointX(Int_t i, Double_t x);
192 virtual void SetPointY(Int_t i, Double_t y);
193 void SetName(const char *name="") override; // *MENU*
194 void SetNameTitle(const char *name="", const char *title="") override;
195 virtual void SetStats(Bool_t stats=kTRUE); // *MENU*
196 void SetTitle(const char *title="") override; // *MENU*
197 virtual void Sort(Bool_t (*greater)(const TGraph*, Int_t, Int_t)=&TGraph::CompareX,
198 Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111);
199 void UseCurrentStyle() override;
200 void Zero(Int_t &k,Double_t AZ,Double_t BZ,Double_t E2,Double_t &X,Double_t &Y,Int_t maxiterations);
201
202 ClassDefOverride(TGraph, 5) // Graph graphics class
203};
204
205#endif
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
start
Definition Rotated.cxx:223
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
double Axis_t
Axis values type (double).
Definition RtypesCore.h:92
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
#define BIT(n)
Definition Rtypes.h:91
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
#define X(type, name)
char name[80]
Definition TGX11.cxx:148
float xmin
float ymin
float xmax
float ymax
TVectorT< Double_t > TVectorD
Definition TVectorDfwd.h:23
TVectorT< Float_t > TVectorF
Definition TVectorFfwd.h:23
Class to manage histogram axis.
Definition TAxis.h:32
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Collection abstract base class.
Definition TCollection.h:65
Definition TF1.h:182
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
virtual void DrawGraph(Int_t n, const Double_t *x=nullptr, const Double_t *y=nullptr, Option_t *option="")
virtual void AddPoint(Double_t x, Double_t y)
Append a new point to the graph.
Definition TGraph.h:97
Int_t fNpoints
Number of points <= fMaxSize.
Definition TGraph.h:46
virtual TFitResultPtr Fit(TF1 *f1, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
TGraph(const TGraph &gr)
void UseCurrentStyle() override
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
virtual void Expand(Int_t newsize)
Double_t * GetY() const
Definition TGraph.h:139
Int_t fMaxSize
!Current dimension of arrays fX and fY
Definition TGraph.h:45
virtual void SetPointX(Int_t i, Double_t x)
TString fOption
Options used for drawing the graph.
Definition TGraph.h:53
virtual void FillZero(Int_t begin, Int_t end, Bool_t from_ctor=kTRUE)
~TGraph() override
virtual void DrawGraph(Int_t n, const Float_t *x, const Float_t *y, Option_t *option="")
Double_t ** ShrinkAndCopy(Int_t size, Int_t iend)
virtual Int_t RemovePoint()
virtual Double_t * GetEXhighd() const
Definition TGraph.h:147
virtual Bool_t IsEditable() const
Definition TGraph.h:165
TGraph(const TVectorF &vx, const TVectorF &vy)
static Bool_t CompareX(const TGraph *gr, Int_t left, Int_t right)
TH1F * fHistogram
Pointer to histogram used for drawing axis.
Definition TGraph.h:50
virtual Int_t RemovePoint(Int_t ipoint)
void Paint(Option_t *chopt="") override
This method must be overridden if a class wants to paint itself.
EStatusBits
Definition TGraph.h:73
@ kNotEditable
Bit set if graph is non editable.
Definition TGraph.h:77
@ kIsHighlight
Bit set if graph is highlight.
Definition TGraph.h:79
@ kIsSortedX
Graph is sorted in X points.
Definition TGraph.h:78
@ kClipFrame
Clip to the frame boundary.
Definition TGraph.h:75
@ kResetHisto
fHistogram must be reset in GetHistogram
Definition TGraph.h:76
@ kNoStats
Don't draw stats box.
Definition TGraph.h:74
virtual void Expand(Int_t newsize, Int_t step)
virtual Bool_t DoMerge(const TGraph *g)
virtual Double_t GetMean(Int_t axis=1) const
virtual void InitGaus(Double_t xmin=0, Double_t xmax=0)
Double_t GetMinimum() const
Definition TGraph.h:151
virtual void DrawGraph(Int_t n, const Int_t *x, const Int_t *y, Option_t *option="")
void Print(Option_t *chopt="") const override
This method must be overridden when a class wants to print itself.
virtual Double_t * GetEYlow() const
Definition TGraph.h:145
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
virtual void SetStats(Bool_t stats=kTRUE)
virtual Double_t * GetEX() const
Definition TGraph.h:140
virtual void Add(TF1 *f, Double_t c1=1)
virtual void Scale(Double_t c1=1., Option_t *option="y")
static Bool_t CompareRadius(const TGraph *gr, Int_t left, Int_t right)
virtual void LeastSquareLinearFit(Int_t n, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin=0, Double_t xmax=0)
Double_t GetMaximum() const
Definition TGraph.h:150
virtual Double_t GetErrorXlow(Int_t bin) const
virtual void SetEditable(Bool_t editable=kTRUE)
Int_t GetN() const
Definition TGraph.h:131
TF1 * GetFunction(const char *name) const
virtual Double_t * GetEXlowd() const
Definition TGraph.h:146
virtual void DrawPanel()
virtual Double_t Eval(Double_t x, TSpline *spline=nullptr, Option_t *option="") const
Double_t * fY
[fNpoints] array of Y points
Definition TGraph.h:48
Bool_t CtorAllocate()
virtual Double_t GetErrorX(Int_t bin) const
virtual Double_t ** Allocate(Int_t newsize)
virtual Int_t InsertPoint()
virtual Double_t GetErrorY(Int_t bin) const
virtual Int_t IsInside(Double_t x, Double_t y) const
virtual void Set(Int_t n)
virtual Int_t Merge(TCollection *list)
char * GetObjectInfo(Int_t px, Int_t py) const override
Returns string containing info about the object at position (px,py).
Double_t ** AllocateArrays(Int_t Narrays, Int_t arraySize)
static Bool_t CompareY(const TGraph *gr, Int_t left, Int_t right)
TList * fFunctions
Pointer to list of functions (fits and user).
Definition TGraph.h:49
TGraph(const TF1 *f, Option_t *option="")
virtual Double_t * GetEYlowd() const
Definition TGraph.h:148
virtual void SetMinimum(Double_t minimum=-1111)
static Bool_t CompareArg(const TGraph *gr, Int_t left, Int_t right)
virtual void InsertPointBefore(Int_t ipoint, Double_t x, Double_t y)
virtual TH1F * GetHistogram() const
void Zero(Int_t &k, Double_t AZ, Double_t BZ, Double_t E2, Double_t &X, Double_t &Y, Int_t maxiterations)
void Browse(TBrowser *b) override
Browse object. May be overridden for another default action.
TList * GetListOfFunctions() const
Definition TGraph.h:125
virtual Double_t GetErrorXhigh(Int_t bin) const
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0)
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to an event at (px,py).
TGraph(Int_t n)
Double_t * GetX() const
Definition TGraph.h:138
void SaveAs(const char *filename="graph", Option_t *option="") const override
Save this object in the file specified by filename.
virtual Double_t GetCorrelationFactor() const
Int_t GetMaxSize() const
Definition TGraph.h:130
virtual Bool_t IsHighlight() const
Definition TGraph.h:166
virtual void SetPointY(Int_t i, Double_t y)
void SetName(const char *name="") override
Set the name of the TNamed.
virtual void SwapPoints(Int_t pos1, Int_t pos2)
virtual void PaintStats(TF1 *fit)
virtual Double_t Integral(Int_t first=0, Int_t last=-1) const
virtual Double_t * GetEYhighd() const
Definition TGraph.h:149
virtual void SetOption(Option_t *option=" ")
Definition TGraph.h:189
virtual Double_t GetRMS(Int_t axis=1) const
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
TAxis * GetXaxis() const
Bool_t GetEditable() const
virtual Double_t * GetEXhigh() const
Definition TGraph.h:142
virtual Double_t GetPointY(Int_t i) const
virtual Double_t * GetEYhigh() const
Definition TGraph.h:144
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
virtual Bool_t CopyPoints(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
virtual void FitPanel()
TGraph(Int_t n, const Double_t *y, Double_t start=0., Double_t step=1.)
Double_t ** ExpandAndCopy(Int_t size, Int_t iend)
void SaveHistogramAndFunctions(std::ostream &out, const char *varname, Option_t *option)
TGraph(const char *filename, const char *format="%lg %lg", Option_t *option="")
Double_t * fX
[fNpoints] array of X points
Definition TGraph.h:47
TAxis * GetYaxis() const
TObject * FindObject(const char *name) const override
Must be redefined in derived classes.
virtual Double_t GetCovariance() const
TGraph(const TVectorD &vx, const TVectorD &vy)
virtual Double_t Chisquare(TF1 *f1, Option_t *option="") const
virtual Double_t * GetEY() const
Definition TGraph.h:141
static void SwapValues(Double_t *arr, Int_t pos1, Int_t pos2)
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
virtual void SetHistogram(TH1F *h)
virtual Double_t GetErrorYlow(Int_t bin) const
Double_t fMinimum
Minimum value for plotting along y.
Definition TGraph.h:51
void PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
void SetTitle(const char *title="") override
Set the title of the TNamed.
virtual Double_t * GetEXlow() const
Definition TGraph.h:143
virtual void SetMaximum(Double_t maximum=-1111)
void RecursiveRemove(TObject *obj) override
Recursively remove this object from a list.
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) const
TGraph(Int_t n, const Double_t *x, const Double_t *y)
virtual void Apply(TF1 *f)
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Computes distance from point (px,py) to the object.
virtual void UpdateArrays(const std::vector< Int_t > &sorting_indices, Int_t numSortedPoints, Int_t low)
virtual void LeastSquareFit(Int_t m, Double_t *a, Double_t xmin=0, Double_t xmax=0)
virtual Double_t GetPointX(Int_t i) const
void PaintGrapHist(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
virtual void InitExpo(Double_t xmin=0, Double_t xmax=0)
virtual void MovePoints(Double_t dx, Double_t dy, Bool_t logx=kFALSE, Bool_t logy=kFALSE)
TGraph(Int_t n, const Int_t *x, const Int_t *y)
void SetNameTitle(const char *name="", const char *title="") override
Set all the TNamed parameters (name and title).
virtual void InitPolynom(Double_t xmin=0, Double_t xmax=0)
TObject * FindObject(const TObject *obj) const override
Must be redefined in derived classes.
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 CopyAndRelease(Double_t **newarrays, Int_t ibegin, Int_t iend, Int_t obegin)
Double_t fMaximum
Maximum value for plotting along y.
Definition TGraph.h:52
TGraph(const TH1 *h)
virtual void SetHighlight(Bool_t set=kTRUE)
virtual Double_t GetErrorYhigh(Int_t bin) const
TGraph(Int_t n, const Float_t *x, const Float_t *y)
TGraph & operator=(const TGraph &)
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
A doubly linked list.
Definition TList.h:38
TNamed()
Definition TNamed.h:38
Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
TObject()
TObject constructor.
Definition TObject.h:259
Base class for spline implementation containing the Draw/Paint methods.
Definition TSpline.h:31
Basic string class.
Definition TString.h:138
STL class.
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
TF1 * f1
Definition legend1.C:11
TMarker m
Definition textangle.C:8