BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
BesCircle2D.cxx
Go to the documentation of this file.
1//
2// BesCircle2D.cxx
3//
4// $Author: longpx $
5// 2005/7/16
6// Modified from zevis 2D shape
7//
8
9#include <TString.h>
10#include <TPad.h>
11#include <TMath.h>
12
14#include "BesVisLib/BesView.h"
15#include <iostream>
16
17using namespace std;
18
19#ifndef __CINT__
21#endif
22
23//_____________________________________________________
24// BesCircle2D
25// Circle in 2D
26//
27//
29 //
30 // BesCircle2D default constructor
31 if ( gDebug ) cout << "BesCircle2D ctor called" << endl;
32 fInnerRadius = 0;
33 fOuterRadius = 0;
34 fCenter = 0;
35 fNSegment = 40;
36 f_innerCircleX = NULL;
37 f_innerCircleY = NULL;
38 f_outerCircleX = NULL;
39 f_outerCircleY = NULL;
40 f_areaX = NULL;
41 f_areaY = NULL;
42}
43
44//_____________________________________________________
45
46BesCircle2D::BesCircle2D(const char* name, const char* title, Double_t innerRadius, Double_t outerRadius, Double_t *center) :
47 TNamed(name, title), TAttLine(), TAttFill() {
48 //
49 // BesCircle2D normal constructor
50 if ( gDebug ) cout << "BesCircle2D normal ctor called" << endl;
51
52 fCenter = new Double_t[3];
53 for ( Int_t i = 0; i < 3; i++ ) fCenter[i] = center[i];
54 //Long Peixun's update: Update fInnerRadius and fOuterRadius initialization for single variables
55 fInnerRadius = innerRadius;
56 fOuterRadius = outerRadius;
57 fNSegment = 40;
58 f_innerCircleX = NULL;
59 f_innerCircleY = NULL;
60 f_outerCircleX = NULL;
61 f_outerCircleY = NULL;
62 f_areaX = NULL;
63 f_areaY = NULL;
64}
65
66//_____________________________________________________
67
69 //
70 // BesCircle2D default destructor
71 if ( gDebug ) cout << "BesCircle2D default dtor called" << endl;
72
73 delete[] fCenter; //Long Peixun's update: delete -> delete[]
74}
75
76//_____________________________________________________
77
78Int_t BesCircle2D::DistancetoPrimitive(Int_t px, Int_t py) {
79
80 const Int_t inaxis = 7;
81 Int_t dist = 9999;
82
83 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
84 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
85 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
86 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
87
88 // return if point is not in the user area
89 if (px < puxmin - inaxis) return dist;
90 if (py > puymin + inaxis) return dist;
91 if (px > puxmax + inaxis) return dist;
92 if (py < puymax - inaxis) return dist;
93
94 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
95 if (!view) return dist;
96
97 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px));
98 Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py));
99 Double_t xndc[3];
100 //if (view->GetViewType() & kXYView)
101 xndc[0] = x;
102 xndc[1] = y;
103 xndc[2] = 0;
104 //cout << "NDC X:" << xndc[0] << " Y:" << xndc[1] << endl;
105
106 Double_t xwc[3];
107 view->NDCtoWC(xndc, xwc);
108 //cout << "WC X:" << xwc[0] << " Y:" << xwc[1] << endl;
109 //cout << "Center X:" << fCenter[0] << " Y:" << fCenter[1] << endl;
110
111 Double_t distw = 0.0;
112 for (Int_t i = 0; i < 2; i++) {
113 distw += (xwc[i]-fCenter[i]) * (xwc[i]-fCenter[i]);
114 }
115
116 //Long Peixun's update: for single variables
117 if (distw >= fInnerRadius * fInnerRadius &&
118 distw <= fOuterRadius * fOuterRadius)
119 return 0;
120 else
121 return dist;
122}
123
124//_____________________________________________________
125
126void BesCircle2D::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
127 //cout << "I am in " << GetName() << endl;
128
129 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
130 if (view) view->ExecuteEvent(event, px, py);
131}
132
133//_____________________________________________________
134
135void BesCircle2D::Draw(Option_t *option) {
136 //
137 // BesCircle2D draw function
138 TString opt = option;
139 opt.ToUpper();
140
141 AppendPad(option);
142}
143
144//_____________________________________________________
145
146void BesCircle2D::Paint(Option_t *option) {
147 // BesCircle2D paint function
148 TString opt = option;
149 opt.ToUpper();
150
151 // Transform to normalised desktop coordinates
152 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
153 if (view == 0) cout << "no view found" << endl;
154
155 // Draw Painted area between circles as PaintFilledArea
156 Int_t np = fNSegment; //40;
157
158 if (f_innerCircleX){
159 delete [] f_innerCircleX;
160 f_innerCircleX = NULL;
161 }
162 if (f_innerCircleY){
163 delete [] f_innerCircleY;
164 f_innerCircleY = NULL;
165 }
166 if (f_outerCircleX){
167 delete [] f_outerCircleX;
168 f_outerCircleX = NULL;
169 }
170 if (f_outerCircleY){
171 delete [] f_outerCircleY;
172 f_outerCircleY = NULL;
173 }
174 if (f_areaX) {
175 delete [] f_areaX;
176 f_areaX = NULL;
177 }
178 if (f_areaY) {
179 delete [] f_areaY;
180 f_areaY = NULL;
181 }
182
183 f_innerCircleX = new Double_t[np+1];
184 f_innerCircleY = new Double_t[np+1];
185 f_outerCircleX = new Double_t[np+1];
186 f_outerCircleY = new Double_t[np+1];
187 f_areaX = new Double_t[4*np];
188 f_areaY = new Double_t[4*np];
189
190 TAttLine::Modify(); //Change line attributes only if necessary
191 TAttFill::Modify(); //Change fill attributes only if necessary
192
193 Double_t angle;
194 Double_t dphi = 2*TMath::Pi()/(np);
195 Double_t pointWC[3],pointNDC[3];
196
197 for (Int_t i=0; i< np ; i++) {
198 angle = Double_t(i)*dphi;
199
200 // inner circle
201 //Long Peixun's update: fInnerRadius has been changed to single variable
202 pointWC[0] = fCenter[0] + fInnerRadius * TMath::Cos(angle);
203 pointWC[1] = fCenter[1] + fInnerRadius * TMath::Sin(angle);
204 pointWC[2] = fCenter[2];
205 view->WCtoNDC(pointWC,pointNDC);
206 f_innerCircleX[i] = pointNDC[0];
207 f_innerCircleY[i] = pointNDC[1];
208 f_areaX[4*i] = pointNDC[0];
209 f_areaY[4*i] = pointNDC[1];
210 if ( i == 0 ) {
211 f_areaX[4*np - 3] = pointNDC[0];
212 f_areaY[4*np - 3] = pointNDC[1];
213 } else {
214 f_areaX[4*i - 3] = pointNDC[0];
215 f_areaY[4*i - 3] = pointNDC[1];
216 }
217
218 // outer circle
219 //Long Peixun's update: fOuterRadius has been changed to single variable
220 pointWC[0] = fCenter[0] + fOuterRadius * TMath::Cos(angle);
221 pointWC[1] = fCenter[1] + fOuterRadius * TMath::Sin(angle);
222 pointWC[2] = fCenter[2];
223 view->WCtoNDC(pointWC,pointNDC);
224 f_outerCircleX[i] = pointNDC[0];
225 f_outerCircleY[i] = pointNDC[1];
226 f_areaX[4*i + 3] = pointNDC[0];
227 f_areaY[4*i + 3] = pointNDC[1];
228 if ( i == 0 ) {
229 f_areaX[4*np - 2] = pointNDC[0];
230 f_areaY[4*np - 2] = pointNDC[1];
231 } else {
232 f_areaX[4*i - 2] = pointNDC[0];
233 f_areaY[4*i - 2] = pointNDC[1];
234 }
235
236 }
237
238 // last point for circles
239 f_innerCircleX[np] = f_innerCircleX[0];
240 f_innerCircleY[np] = f_innerCircleY[0];
241 f_outerCircleX[np] = f_outerCircleX[0];
242 f_outerCircleY[np] = f_outerCircleY[0];
243
244 // paint filled areas
245 for (Int_t i = 0; i < np; i++ ) {
246 gPad->PaintFillArea(4,&f_areaX[4*i],&f_areaY[4*i]);
247 }
248
249 // paint circles
250 // yzhang
251 gPad->PaintPolyLine(np+1,f_innerCircleX,f_innerCircleY);
252 gPad->PaintPolyLine(np+1,f_outerCircleX,f_outerCircleY);
253
254}
255//_____________________________________________________
256
257char *BesCircle2D::GetObjectInfo(Int_t px, Int_t py) const {
258
259 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
260 if (view) return view->GetObjectInfo(px, py);
261 else return TObject::GetObjectInfo(px, py);
262}
263
264//_____________________________________________________
265
266void BesCircle2D::SetCenter(Double_t x, Double_t y, Double_t z)
267{
268 fCenter[0] = x;
269 fCenter[1] = y;
270 fCenter[2] = z;
271}
272
273//_____________________________________________________
274
275void BesCircle2D::GetCenter(Double_t *center)
276{
277 for (Int_t i = 0; i < 3; i++) center[i] = fCenter[i];
278}
ClassImp(BesCircle2D) BesCircle2D
Definition: BesCircle2D.cxx:20
titledef title[20]
virtual void Paint(Option_t *option="")
virtual void Draw(Option_t *option="")
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Definition: BesCircle2D.cxx:78
virtual void SetCenter(Double_t x, Double_t y, Double_t z)
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual ~BesCircle2D()
Definition: BesCircle2D.cxx:68
virtual void GetCenter(Double_t *center)
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition: BesView.cxx:728
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition: BesView.cxx:869
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: BesView.cxx:366
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)
Definition: BesView.cxx:794
double y[1000]
double x[1000]