BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
BesPolygon2D.cxx
Go to the documentation of this file.
1//
2// BesPolygon2D.cxx
3//
4// $Author: maqm $
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 if ( fP) delete [] fP;
115 if ( fPBackUp) delete [] fPBackUp;
116}
117
118//_____________________________________________________
119
120void BesPolygon2D::Draw(Option_t *option) {
121 //
122 // BesPolygon2D draw function
123 TString opt = option;
124 opt.ToUpper();
125
126 AppendPad(option);
127}
128
129//_____________________________________________________
130
131void BesPolygon2D::Paint(Option_t *option) {
132 //
133 // BesPolygon2D paint function
134 TString opt = option;
135 opt.ToUpper();
136
137 // Transform to normalised desktop coordinates
138 BesView *view = (BesView*)gPad->GetView();
139 if (view == 0) cout << "no view found" << endl;
140 Double_t viewPhi = view->GetLongitude();
141 if (IsRotatable()) RotatePhi(viewPhi-180.0);
142
143 if (f_xx) {
144 delete [] f_xx;
145 f_xx = NULL;
146 }
147 if (f_yy) {
148 delete [] f_yy;
149 f_yy = NULL;
150 }
151
152 f_xx = new Double_t[fN+1];
153 f_yy = new Double_t[fN+1];
154 Double_t Pndc[3];
155
156 for ( Int_t i = 0; i < fN; i++ ) {
157 view->WCtoNDC(&fP[i*3], Pndc);
158 f_xx[i] = Pndc[0];
159 f_yy[i] = Pndc[1];
160 }
161
162 // Close surface
163 f_xx[fN] = f_xx[0];
164 f_yy[fN] = f_yy[0];
165
166 TAttLine::Modify(); //Change line attributes only if necessary
167 TAttFill::Modify(); //Change fill attributes only if necessary
168
169 gPad->PaintFillArea(fN, f_xx, f_yy);
170 gPad->PaintPolyLine(fN+1, f_xx, f_yy);
171 if (IsRotatable()) Restore();
172}
173
174//_____________________________________________________
175
176Int_t BesPolygon2D::DistancetoPrimitive(Int_t px, Int_t py) {
177 //
178 // Compute the closest distance of approach from point px,py to the
179 // center of this polygon
180 // The distance is computed in pixels units.
181
182 const Int_t inaxis = 7;
183 Int_t dist = 9999;
184
185 if (this->IsRotatable()) return dist;
186
187 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
188 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
189 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
190 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
191
192 // return if point is not in the user area
193 if (px < puxmin - inaxis) return dist;
194 if (py > puymin + inaxis) return dist;
195 if (px > puxmax + inaxis) return dist;
196 if (py < puymax - inaxis) return dist;
197
198 // judge the mouse point and center are always on the same side of any line of ploygon
199 // Transform to normalised desktop coordinates
200
201 BesView *view = (BesView*)gPad->GetView();
202 if (!view) return dist;
203
204 Bool_t inPolygon = true;
205 Int_t x1, y1, x2, y2, cx, cy;
206 Double_t Pndc[3], k, b, pb, cb;
207
208 view->WCtoNDC(&fCenter[0], Pndc);
209 cx = gPad->XtoAbsPixel(Pndc[0]);
210 cy = gPad->YtoAbsPixel(Pndc[1]);
211
212 //cout << "px " << px << " py " << py << endl;
213 //cout << "center " << cx << " " << cy << endl;
214
215 for (Int_t i = 0; i < fN; i++) {
216 view->WCtoNDC(&fP[3*i], Pndc);
217 x1 = gPad->XtoAbsPixel(Pndc[0]);
218 y1 = gPad->YtoAbsPixel(Pndc[1]);
219
220 if (i != fN-1) {
221 view->WCtoNDC(&fP[3*(i+1)], Pndc);
222 }
223 else
224 view->WCtoNDC(&fP[0], Pndc);
225
226 x2 = gPad->XtoAbsPixel(Pndc[0]);
227 y2 = gPad->YtoAbsPixel(Pndc[1]);
228
229 //cout << "x1 " << x1 << " y1 " << y1 << endl;
230 //cout << "x2 " << x2 << " y2 " << y2 << endl;
231 if (x1 == x2) {
232 if ((px-x1)*(cx-x1) <= 0) {
233 inPolygon = false;
234 break;
235 }
236 }
237 else {
238 k = Double_t(y2-y1)/(x2-x1);
239 b = y1-k*x1;
240 pb = py-k*px;
241 cb = cy-k*cx;
242 if ((pb-b)*(cb-b) <= 0) {
243 inPolygon = false;
244 break;
245 }
246 }
247 }
248
249 if (inPolygon == true) {
250 //gPad->SetSelected(this);
251 //gPad->SetCursor(kHand);
252 return 0;
253 }
254 else return 9999;
255
256 //cout << GetName() << dist << endl;
257 //if (dist < 100) dist = 0;
258}
259
260//_____________________________________________________
261
262void BesPolygon2D::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
263 //cout << "I am in " << GetName() << endl;
264
265 BesView *view = (BesView*)gPad->GetView();
266 if (view) view->ExecuteEvent(event, px, py);
267}
268
269//_____________________________________________________
270
272 //
273 // Set tooltip textbox with some information
274 TView *view = (TView*)gPad->GetView();
275 Double_t Pndc[3];
276 view->WCtoNDC(&fP[0], Pndc);
277
278 if (fInfoBox){
279 delete fInfoBox;
280 fInfoBox = 0;
281 }
282 fInfoBox = new TPaveText(Pndc[0], Pndc[1],
283 Pndc[0]+0.4, Pndc[1]+0.1);
284 fInfoBox->SetBorderSize(1);
285 fInfoBox->SetFillColor(191);
286 fInfoBox->AddText(GetTitle());
287 fInfoBox->AddText(GetObjectInfo(0,0));
288 fInfoBox->Draw();
289}
290
291//_____________________________________________________
292
293char *BesPolygon2D::GetObjectInfo(Int_t px, Int_t py) const {
294
295 BesView *view = (BesView*)gPad->GetView();
296 if (view) return view->GetObjectInfo(px, py);
297 else return TObject::GetObjectInfo(px, py);
298}
299
300//_____________________________________________________
301
302void BesPolygon2D::SetZRSign(Int_t sign) {
303 //
304 // set sign of points for ZR view
305
306 for ( Int_t i = 0; i < fN; i++ ) {
307 // clear sign
308 fP[(i*3)+1] = TMath::Sign(1.,Double_t(fP[(i*3)+1])) * fP[(i*3)+1];
309
310 // set sign
311 fP[(i*3)+1] = TMath::Sign(1,sign) * fP[(i*3)+1];
312 }
313
314}
315
316//_____________________________________________________
317
318void BesPolygon2D::Resize(Double_t ScaleFactor) {
319 //
320 // Resize the polygon by ScaleFactor
321
322 // Compute geometric center of the polygon
323 Double_t C[3];
324 GetCenter(C);
325
326 // Rescale distances from the center
327 for ( Int_t i = 0; i < 3; i++ ) {
328 for ( Int_t j = 0; j < fN; j++ ) {
329 fP[3*j+i] = C[i] + ScaleFactor*(fP[3*j+i]-C[i]);
330 }
331 }
332}
333
334//_____________________________________________________
335
336void BesPolygon2D::GetCenter(Double_t *Center) const {
337 //
338 // Compute geometric center of this polygon
339 for ( Int_t i = 0; i < 3; i++ ) {
340 Center[i] = 0;
341 for ( Int_t j = 0; j < fN; j++ ) Center[i] += fP[3*j+i];
342 Center[i] /= fN;
343 }
344}
345
346//_____________________________________________________
347
348void BesPolygon2D::RotatePhi(Double_t phi) {
349
350 //cout << "phi " << phi << endl;
351 for (Int_t i = 0; i < fN; i++) {
352 TVector3 vec(fP[i*3], fP[i*3+1], fP[i*3+2]);
353 Double_t r = vec.Pt();
354 Double_t newPhi = vec.Phi() + phi*TMath::DegToRad();
355 fP[i*3] = r * cos(newPhi);
356 fP[i*3+1] = r * sin(newPhi);
357 }
358}
359
360//_____________________________________________________
361
363
364 for (Int_t i = 0; i < fN*3; i++) {
365 fP[i] = fPBackUp[i];
366 }
367}
368
369//_____________________________________________________
370
371void BesPolygon2D::SetSize(Double_t size) {
372
373 if (size > 0.95) size = 0.98; // too big could not see border
374 if (size < 0.15) size = 0.2; // too small could not be seen
375
376 for (Int_t i = 0; i < 3; i++) {
377 for (Int_t j = 0; j < fN; j++) {
378 fP[3*j+i] = size * fP[3*j+i] + (1.0-size) * fCenter[i];
379 }
380 }
381}
382
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
double P(RecMdcKalTrack *trk)
***************************************************************************************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
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:84
Double_t * fPBackUp
Definition: BesPolygon2D.h:35
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:60
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:659
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition: BesView.cxx:800
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: BesView.cxx:365
dble_vec_t vec[12]
Definition: ranlxd.c:372