BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
BesPolygon2D.cxx
Go to the documentation of this file.
1//
2// BesPolygon2D.cxx
3//
4// $Author: longpx $
5// 2005/7/16
6// Modified from zevis 2D shape
7//
8
9#include "BesVisLib/BesView.h"
11#include <iostream>
12
13#include <math.h>
14#include <TMath.h>
15#ifndef ROOT_TPad
16#include <TPad.h>
17#endif
18
19#ifndef ROOT_TString
20#include <TString.h>
21#endif
22
23#ifndef ROOT_TView
24#include <TView.h>
25#endif
26
27#ifndef ROOT_TGeometry
28#include <TGeometry.h>
29#endif
30
31#ifndef ROOT_TPaveText
32#include <TPaveText.h>
33#endif
34
35using namespace std;
36
37#ifndef __CINT__
39#endif
40
41//_____________________________________________________
42// BesPolygon2D
43// 2-dimensional polygon
44//
45//
46
47int BesPolygon2D::num = 0;
49 //
50 // BesPolygon2D default constructor
51 //cout << "####################" << endl;
52 //cout << "BesPolygon2D ctor called " << ++num << endl;
53 //cout << "####################" << endl;
54
55 fInfoBox = 0;
56 fN = 0;
57 fP = NULL;
58 fPBackUp = NULL;
59 fRotatable = false;
60 f_xx = NULL;
61 f_yy = NULL;
62
63}
64
65//_____________________________________________________
66
67BesPolygon2D::BesPolygon2D(const char* name, const char* title,
68 Int_t N, Double_t *P) :
69 TNamed(name, title), TAttLine(), TAttFill() {
70 //
71 // BesPolygon2D normal constructor
72 //cout << "####################" << endl;
73 //cout << "BesPolygon2D ctor called " << ++num << endl;
74 //cout << "####################" << endl;
75
76 fN = N;
77 fP = new Double_t[fN*3];
78 fPBackUp = new Double_t[fN*3];
79 f_xx = NULL;
80 f_yy = NULL;
81
82 fInfoBox = 0;
83 if (P!=NULL){
84 SetPoints(P);
85 }
86
87 for ( Int_t i = 0; i < fN*3; i++ ) {
88 fPBackUp[i] = fP[i];
89 }
90
91 for (Int_t j = 0; j < 3; j++) {
92 fCenter[j] = 0.0;
93 for ( Int_t i = 0; i < fN; i++) {
94 fCenter[j] += fP[3*i+j];
95 }
96 fCenter[j] /= fN;
97 }
98
99 for ( Int_t i = 0; i < fN; i++ ) {
100 }
101
102 fRotatable = false;
103}
104
105//_____________________________________________________
106
108 //
109 // BesPolygon2D default destructor
110 //cout << "####################" << endl;
111 //cout << "BesPolygon2D dtor called " << --num << endl;
112 //cout << "####################" << endl;
113
114 //Long Peixun's update: remove "if"
115 delete [] fP;
116 delete [] fPBackUp;
117}
118
119//_____________________________________________________
120
121void BesPolygon2D::Draw(Option_t *option) {
122 //
123 // BesPolygon2D draw function
124 TString opt = option;
125 opt.ToUpper();
126
127 AppendPad(option);
128}
129
130//_____________________________________________________
131
132void BesPolygon2D::Paint(Option_t *option) {
133 //
134 // BesPolygon2D paint function
135 TString opt = option;
136 opt.ToUpper();
137
138 // Transform to normalised desktop coordinates
139 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
140 if (view == 0) cout << "no view found" << endl;
141 Double_t viewPhi = view->GetLongitude();
142 if (IsRotatable()) RotatePhi(viewPhi-180.0);
143
144 if (f_xx) {
145 delete [] f_xx;
146 f_xx = NULL;
147 }
148 if (f_yy) {
149 delete [] f_yy;
150 f_yy = NULL;
151 }
152
153 f_xx = new Double_t[fN+1];
154 f_yy = new Double_t[fN+1];
155 Double_t Pndc[3];
156
157 for ( Int_t i = 0; i < fN; i++ ) {
158 view->WCtoNDC(&fP[i*3], Pndc);
159 f_xx[i] = Pndc[0];
160 f_yy[i] = Pndc[1];
161 }
162
163 // Close surface
164 f_xx[fN] = f_xx[0];
165 f_yy[fN] = f_yy[0];
166
167 TAttLine::Modify(); //Change line attributes only if necessary
168 TAttFill::Modify(); //Change fill attributes only if necessary
169
170 gPad->PaintFillArea(fN, f_xx, f_yy);
171 gPad->PaintPolyLine(fN+1, f_xx, f_yy);
172 if (IsRotatable()) Restore();
173}
174
175//_____________________________________________________
176
177Int_t BesPolygon2D::DistancetoPrimitive(Int_t px, Int_t py) {
178 //
179 // Compute the closest distance of approach from point px,py to the
180 // center of this polygon
181 // The distance is computed in pixels units.
182
183 const Int_t inaxis = 7;
184 Int_t dist = 9999;
185
186 if (this->IsRotatable()) return dist;
187
188 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
189 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
190 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
191 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
192
193 // return if point is not in the user area
194 if (px < puxmin - inaxis) return dist;
195 if (py > puymin + inaxis) return dist;
196 if (px > puxmax + inaxis) return dist;
197 if (py < puymax - inaxis) return dist;
198
199 // judge the mouse point and center are always on the same side of any line of ploygon
200 // Transform to normalised desktop coordinates
201
202 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
203 if (!view) return dist;
204
205 Bool_t inPolygon = true;
206 Int_t x1, y1, x2, y2, cx, cy;
207 Double_t Pndc[3], k, b, pb, cb;
208
209 view->WCtoNDC(&fCenter[0], Pndc);
210 cx = gPad->XtoAbsPixel(Pndc[0]);
211 cy = gPad->YtoAbsPixel(Pndc[1]);
212
213 //cout << "px " << px << " py " << py << endl;
214 //cout << "center " << cx << " " << cy << endl;
215
216 for (Int_t i = 0; i < fN; i++) {
217 view->WCtoNDC(&fP[3*i], Pndc);
218 x1 = gPad->XtoAbsPixel(Pndc[0]);
219 y1 = gPad->YtoAbsPixel(Pndc[1]);
220
221 if (i != fN-1) {
222 view->WCtoNDC(&fP[3*(i+1)], Pndc);
223 }
224 else
225 view->WCtoNDC(&fP[0], Pndc);
226
227 x2 = gPad->XtoAbsPixel(Pndc[0]);
228 y2 = gPad->YtoAbsPixel(Pndc[1]);
229
230 //cout << "x1 " << x1 << " y1 " << y1 << endl;
231 //cout << "x2 " << x2 << " y2 " << y2 << endl;
232 if (x1 == x2) {
233 if ((px-x1)*(cx-x1) <= 0) {
234 inPolygon = false;
235 break;
236 }
237 }
238 else {
239 k = Double_t(y2-y1)/(x2-x1);
240 b = y1-k*x1;
241 pb = py-k*px;
242 cb = cy-k*cx;
243 if ((pb-b)*(cb-b) <= 0) {
244 inPolygon = false;
245 break;
246 }
247 }
248 }
249
250 if (inPolygon == true) {
251 //gPad->SetSelected(this);
252 //gPad->SetCursor(kHand);
253 return 0;
254 }
255 else return 9999;
256
257 //cout << GetName() << dist << endl;
258 //if (dist < 100) dist = 0;
259}
260
261//_____________________________________________________
262
263void BesPolygon2D::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
264 //cout << "I am in " << GetName() << endl;
265
266 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
267 if (view) view->ExecuteEvent(event, px, py);
268}
269
270//_____________________________________________________
271
273 //
274 // Set tooltip textbox with some information
275 TView *view = dynamic_cast<TView*>(gPad->GetView());
276 Double_t Pndc[3];
277 if (view) view->WCtoNDC(&fP[0], Pndc);
278
279 if (fInfoBox){
280 delete fInfoBox;
281 fInfoBox = 0;
282 }
283 fInfoBox = new TPaveText(Pndc[0], Pndc[1],
284 Pndc[0]+0.4, Pndc[1]+0.1);
285 fInfoBox->SetBorderSize(1);
286 fInfoBox->SetFillColor(191);
287 fInfoBox->AddText(GetTitle());
288 fInfoBox->AddText(GetObjectInfo(0,0));
289 fInfoBox->Draw();
290}
291
292//_____________________________________________________
293
294char *BesPolygon2D::GetObjectInfo(Int_t px, Int_t py) const {
295
296 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
297 if (view) return view->GetObjectInfo(px, py);
298 else return TObject::GetObjectInfo(px, py);
299}
300
301//_____________________________________________________
302
303void BesPolygon2D::SetZRSign(Int_t sign) {
304 //
305 // set sign of points for ZR view
306
307 for ( Int_t i = 0; i < fN; i++ ) {
308 // clear sign
309 fP[(i*3)+1] = TMath::Sign(1.,Double_t(fP[(i*3)+1])) * fP[(i*3)+1];
310
311 // set sign
312 fP[(i*3)+1] = TMath::Sign(1,sign) * fP[(i*3)+1];
313 }
314
315}
316
317//_____________________________________________________
318
319void BesPolygon2D::Resize(Double_t ScaleFactor) {
320 //
321 // Resize the polygon by ScaleFactor
322
323 // Compute geometric center of the polygon
324 Double_t C[3];
325 GetCenter(C);
326
327 // Rescale distances from the center
328 for ( Int_t i = 0; i < 3; i++ ) {
329 for ( Int_t j = 0; j < fN; j++ ) {
330 fP[3*j+i] = C[i] + ScaleFactor*(fP[3*j+i]-C[i]);
331 }
332 }
333}
334
335//_____________________________________________________
336
337void BesPolygon2D::GetCenter(Double_t *Center) const {
338 //
339 // Compute geometric center of this polygon
340 for ( Int_t i = 0; i < 3; i++ ) {
341 Center[i] = 0;
342 for ( Int_t j = 0; j < fN; j++ ) Center[i] += fP[3*j+i];
343 Center[i] /= fN;
344 }
345}
346
347//_____________________________________________________
348
349void BesPolygon2D::RotatePhi(Double_t phi) {
350
351 //cout << "phi " << phi << endl;
352 for (Int_t i = 0; i < fN; i++) {
353 TVector3 vec(fP[i*3], fP[i*3+1], fP[i*3+2]);
354 Double_t r = vec.Pt();
355 Double_t newPhi = vec.Phi() + phi*TMath::DegToRad();
356 fP[i*3] = r * cos(newPhi);
357 fP[i*3+1] = r * sin(newPhi);
358 }
359}
360
361//_____________________________________________________
362
364
365 for (Int_t i = 0; i < fN*3; i++) {
366 fP[i] = fPBackUp[i];
367 }
368}
369
370//_____________________________________________________
371
372void BesPolygon2D::SetSize(Double_t size) {
373
374 if (size > 0.95) size = 0.98; // too big could not see border
375 if (size < 0.15) size = 0.2; // too small could not be seen
376
377 for (Int_t i = 0; i < 3; i++) {
378 for (Int_t j = 0; j < fN; j++) {
379 fP[3*j+i] = size * fP[3*j+i] + (1.0-size) * fCenter[i];
380 }
381 }
382}
383
384//_____________________________________________________
385//Long Peixun's update: Stretch polygon along (sx, sy, sz)
386void BesPolygon2D::Stretch(Double_t sx, Double_t sy, Double_t sz, Double_t factor)
387{
388 // Compute geometric center of the polygon
389 Double_t C[3], V[3];
390 GetCenter(C);
391 Double_t s = TMath::Sqrt(sx * sx + sy * sy + sz * sz);
392 V[0] = sx / s;
393 V[1] = sy / s;
394 V[2] = sz / s;
395
396 // Rescale distances from the center
397 for (Int_t i = 0; i < fN; ++i)
398 {
399 Double_t dot = (fP[3*i] - C[0]) * V[0] + (fP[3*i+1] - C[1]) * V[1] + (fP[3*i+2] - C[2]) * V[2];
400 for (Int_t j = 0; j < 3; ++j)
401 {
402 fP[3*i+j] += dot * (factor - 1) * V[j];
403 }
404 }
405}
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
double P(RecMdcKalTrack *trk)
XmlRpcServer s
Definition: HelloServer.cpp:11
***************************************************************************************Pseudo Class RRes *****************************************************************************************Parameters and physical constants **Maarten sept ************************************************************************DOUBLE PRECISION xsmu **************************************************************************PARTICLE DATA all others are from PDG *Only resonances with known widths into electron pairs are sept ************************************************************************C Declarations C
Definition: RRes.h:29
ClassImp(TBossFullEvent) TBossFullEvent
#define NULL
virtual void SetZRSign(Int_t sign)
virtual void SetSize(Double_t size)
Double_t fCenter[3]
Definition: BesPolygon2D.h:36
virtual void Paint(Option_t *option="")
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
TPaveText * fInfoBox
Definition: BesPolygon2D.h:39
Double_t * fP
Definition: BesPolygon2D.h:34
virtual void SetInfoBox()
void SetPoints(Double_t *P)
Definition: BesPolygon2D.h:86
Double_t * fPBackUp
Definition: BesPolygon2D.h:35
virtual void Stretch(Double_t sx, Double_t sy, Double_t sz, Double_t factor)
virtual void Resize(Double_t ScaleFactor)
virtual void Restore()
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Bool_t fRotatable
Definition: BesPolygon2D.h:37
BesPolygon2D()
info box
virtual ~BesPolygon2D()
Bool_t IsRotatable()
Definition: BesPolygon2D.h:62
Double_t * f_xx
Definition: BesPolygon2D.h:31
Double_t * f_yy
Definition: BesPolygon2D.h:32
virtual void GetCenter(Double_t *Center) const
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual void RotatePhi(Double_t phi)
virtual void Draw(Option_t *option="")
Double_t GetLongitude()
Definition: BesTView.h:95
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
const double b
Definition: slope.cxx:9