Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphPolar.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Sebastian Boser, Mathieu Demaret 02/02/06
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/** \class TGraphPolar
13\ingroup BasicGraphics
14
15To draw a polar graph.
16
17TGraphPolar creates a polar graph (including error bars). A TGraphPolar is
18a TGraphErrors represented in polar coordinates.
19It uses the class TGraphPolargram to draw the polar axis.
20
21Example:
22
23Begin_Macro(source)
24{
25 TCanvas * CPol = new TCanvas("CPol","TGraphPolar Example",500,500);
26
27 Double_t theta[8];
28 Double_t radius[8];
29 Double_t etheta[8];
30 Double_t eradius[8];
31
32 for (int i=0; i<8; i++) {
33 theta[i] = (i+1)*(TMath::Pi()/4.);
34 radius[i] = (i+1)*0.05;
35 etheta[i] = TMath::Pi()/8.;
36 eradius[i] = 0.05;
37 }
38
39 TGraphPolar * grP1 = new TGraphPolar(8, theta, radius, etheta, eradius);
40 grP1->SetTitle("TGraphPolar Example");
41
42 grP1->SetMarkerStyle(20);
43 grP1->SetMarkerSize(2.);
44 grP1->SetMarkerColor(4);
45 grP1->SetLineColor(2);
46 grP1->SetLineWidth(3);
47 grP1->Draw("PE");
48
49 // Update, otherwise GetPolargram returns 0
50 CPol->Update();
51 grP1->GetPolargram()->SetToRadian();
52
53 return CPol;
54}
55End_Macro
56*/
57
58#include "TGraphPolar.h"
59#include "TGraphPolargram.h"
60
61
62////////////////////////////////////////////////////////////////////////////////
63/// TGraphPolar default constructor.
64
66 fOptionAxis(kFALSE),fPolargram(nullptr),fXpol(nullptr),fYpol(nullptr)
67{
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// TGraphPolar constructor.
72///
73/// \param[in] n number of points.
74/// \param[in] theta angular values.
75/// \param[in] r radial values.
76/// \param[in] etheta errors on angular values.
77/// \param[in] er errors on radial values.
78
80 const Double_t *etheta, const Double_t* er)
81 : TGraphErrors(n,theta,r,etheta,er),
82 fOptionAxis(kFALSE),fPolargram(nullptr),fXpol(nullptr),fYpol(nullptr)
83{
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// TGraphPolar destructor.
89
91{
92 delete [] fXpol;
93 delete [] fYpol;
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Draw TGraphPolar.
98
100{
101 AppendPad(options);
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Return points in polar coordinates.
106
108{
109 if (!fXpol) fXpol = new Double_t[fNpoints];
110 return fXpol;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Return points in polar coordinates.
115
117{
118 if (!fYpol) fYpol = new Double_t[fNpoints];
119 return fYpol;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Set maximum Polar.
124
129
130////////////////////////////////////////////////////////////////////////////////
131/// Set maximum radial at the intersection of the positive X axis part and
132/// the circle.
133
138
139////////////////////////////////////////////////////////////////////////////////
140/// Set minimum Polar.
141
146
147////////////////////////////////////////////////////////////////////////////////
148/// Set minimum radial in the center of the circle.
149
154
155////////////////////////////////////////////////////////////////////////////////
156/// Create polargram object for given draw options
157
159{
161
162 if (theNpoints < 1)
163 return nullptr;
164
165 Double_t *theX = GetX();
166 Double_t *theY = GetY();
167 Double_t *theEX = GetEX();
168 Double_t *theEY = GetEY();
169
170 // Get range, initialize with first/last value
172
173 for (Int_t ipt = 0; ipt < theNpoints; ipt++) {
174 // Check for errors if available
175 if (theEX) {
176 if (theX[ipt] - theEX[ipt] < rwtmin)
177 rwtmin = theX[ipt] - theEX[ipt];
178 if (theX[ipt] + theEX[ipt] > rwtmax)
179 rwtmax = theX[ipt] + theEX[ipt];
180 } else {
181 if (theX[ipt] < rwtmin)
182 rwtmin = theX[ipt];
183 if (theX[ipt] > rwtmax)
184 rwtmax = theX[ipt];
185 }
186 if (theEY) {
187 if (theY[ipt] - theEY[ipt] < rwrmin)
188 rwrmin = theY[ipt] - theEY[ipt];
189 if (theY[ipt] + theEY[ipt] > rwrmax)
190 rwrmax = theY[ipt] + theEY[ipt];
191 } else {
192 if (theY[ipt] < rwrmin)
193 rwrmin = theY[ipt];
194 if (theY[ipt] > rwrmax)
195 rwrmax = theY[ipt];
196 }
197 }
198
199 // Add radial and Polar margins.
200 if (rwrmin == rwrmax)
201 rwrmax += 1.;
202 if (rwtmin == rwtmax)
203 rwtmax += 1.;
204
206
207 rwrmax += 0.1 * dr;
208 rwrmin -= 0.1 * dr;
209
210 // Assume equally spaced points for full 2*Pi.
211 rwtmax += dt / theNpoints;
212
213 return new TGraphPolargram("Polargram", rwrmin, rwrmax, rwtmin, rwtmax, opt);
214}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
A TGraphErrors is a TGraph with error bars.
Double_t * GetEX() const override
Double_t * GetEY() const override
void SetMinRadial(Double_t minimum=0)
Set minimum radial in the center of the circle.
Double_t * fXpol
[fNpoints] points in polar coordinates
Definition TGraphPolar.h:30
void SetMaxPolar(Double_t maximum=6.28318530717958623)
Set maximum Polar.
Double_t * GetYpol()
Return points in polar coordinates.
TGraphPolargram * fPolargram
The polar coordinates system.
Definition TGraphPolar.h:29
void SetMaxRadial(Double_t maximum=1)
Set maximum radial at the intersection of the positive X axis part and the circle.
TGraphPolar()
TGraphPolar default constructor.
void Draw(Option_t *options="") override
Draw TGraphPolar.
~TGraphPolar() override
TGraphPolar destructor.
Double_t * GetXpol()
Return points in polar coordinates.
TGraphPolargram * CreatePolargram(const char *opt)
Create polargram object for given draw options.
void SetMinPolar(Double_t minimum=0)
Set minimum Polar.
Double_t * fYpol
[fNpoints] points in polar coordinates
Definition TGraphPolar.h:31
To draw polar axis.
void SetRangeRadial(Double_t rmin, Double_t rmax)
Set the radial range.
void ChangeRangePolar(Double_t tmin, Double_t tmax)
Set the Polar range.
Int_t fNpoints
Number of points <= fMaxSize.
Definition TGraph.h:46
Double_t * GetY() const
Definition TGraph.h:139
Int_t GetN() const
Definition TGraph.h:131
Double_t * GetX() const
Definition TGraph.h:138
virtual void SetEditable(Bool_t editable=kTRUE)
if editable=kFALSE, the graph cannot be modified with the mouse by default a TGraph is editable
Definition TGraph.cxx:2249
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
const Int_t n
Definition legend1.C:16