CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
BesPolygon2D Class Reference

#include <BesPolygon2D.h>

+ Inheritance diagram for BesPolygon2D:

Public Member Functions

 BesPolygon2D ()
 info box
 
 BesPolygon2D (const char *name, const char *title, Int_t N, Double_t *P)
 
virtual ~BesPolygon2D ()
 
virtual void Draw (Option_t *option="")
 
virtual void Paint (Option_t *option="")
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 
virtual void SetZRSign (Int_t sign)
 
virtual void Resize (Double_t ScaleFactor)
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 
virtual void SetInfoBox ()
 
virtual void GetCenter (Double_t *Center) const
 
virtual void RotatePhi (Double_t phi)
 
virtual void Restore ()
 
virtual void SetSize (Double_t size)
 
virtual void Stretch (Double_t sx, Double_t sy, Double_t sz, Double_t factor)
 
Bool_t IsRotatable ()
 
void SetRotatable (Bool_t input)
 
void SetName (const char *name)
 
void SetTitle (const char *name)
 
void Delete (Option_t *option)
 
void DrawClass ()
 
void DrawClone (Option_t *option)
 
void SetDrawOption (Option_t *option)
 
void SetPoints (Double_t *P)
 

Protected Attributes

Double_t * f_xx
 
Double_t * f_yy
 
Int_t fN
 
Double_t * fP
 
Double_t * fPBackUp
 
Double_t fCenter [3]
 
Bool_t fRotatable
 
TPaveText * fInfoBox
 

Detailed Description

Definition at line 27 of file BesPolygon2D.h.

Constructor & Destructor Documentation

◆ BesPolygon2D() [1/2]

BesPolygon2D::BesPolygon2D ( )

info box

◆ BesPolygon2D() [2/2]

BesPolygon2D::BesPolygon2D ( const char * name,
const char * title,
Int_t N,
Double_t * P )

Definition at line 67 of file BesPolygon2D.cxx.

68 :
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}
double P(RecMdcKalTrack *trk)
Double_t fCenter[3]
TPaveText * fInfoBox
Double_t * fP
void SetPoints(Double_t *P)
Double_t * fPBackUp
Bool_t fRotatable
Double_t * f_xx
Double_t * f_yy

◆ ~BesPolygon2D()

BesPolygon2D::~BesPolygon2D ( )
virtual

Definition at line 107 of file BesPolygon2D.cxx.

107 {
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}

Member Function Documentation

◆ Delete()

void BesPolygon2D::Delete ( Option_t * option)
inline

Definition at line 74 of file BesPolygon2D.h.

74 {
75 TObject::Delete(option);
76 }

◆ DistancetoPrimitive()

Int_t BesPolygon2D::DistancetoPrimitive ( Int_t px,
Int_t py )
virtual

Definition at line 177 of file BesPolygon2D.cxx.

177 {
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}
Bool_t IsRotatable()
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition BesView.cxx:824

Referenced by Cgem2DVStrip::DistancetoPrimitive(), Cgem2DXStrip::DistancetoPrimitive(), Emc2DCrystal::DistancetoPrimitive(), Muc2DStrip::DistancetoPrimitive(), and Tof2DScin::DistancetoPrimitive().

◆ Draw()

void BesPolygon2D::Draw ( Option_t * option = "")
virtual

Definition at line 121 of file BesPolygon2D.cxx.

121 {
122 //
123 // BesPolygon2D draw function
124 TString opt = option;
125 opt.ToUpper();
126
127 AppendPad(option);
128}

Referenced by CgemROOTGeo::Draw(), MdcROOTGeo::Draw(), MucROOTGeo::Draw(), BesGeometry::Draw2DXY(), BesGeometry::Draw2DZR(), and CgemROOTGeo::DrawUF().

◆ DrawClass()

void BesPolygon2D::DrawClass ( )
inline

Definition at line 77 of file BesPolygon2D.h.

77 {
78 TObject::DrawClass();
79 }

◆ DrawClone()

void BesPolygon2D::DrawClone ( Option_t * option)
inline

Definition at line 80 of file BesPolygon2D.h.

80 {
81 TObject::DrawClone(option);
82 }

◆ ExecuteEvent()

void BesPolygon2D::ExecuteEvent ( Int_t event,
Int_t px,
Int_t py )
virtual

Definition at line 263 of file BesPolygon2D.cxx.

263 {
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}
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition BesView.cxx:451

◆ GetCenter()

void BesPolygon2D::GetCenter ( Double_t * Center) const
virtual

Definition at line 337 of file BesPolygon2D.cxx.

337 {
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}

Referenced by Cgem2DXStrip::Paint(), Resize(), and Stretch().

◆ GetObjectInfo()

char * BesPolygon2D::GetObjectInfo ( Int_t px,
Int_t py ) const
virtual

Definition at line 294 of file BesPolygon2D.cxx.

294 {
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}
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition BesView.cxx:965

Referenced by SetInfoBox().

◆ IsRotatable()

Bool_t BesPolygon2D::IsRotatable ( )
inline

Definition at line 62 of file BesPolygon2D.h.

62 {
63 return fRotatable;
64 }

Referenced by DistancetoPrimitive(), and Paint().

◆ Paint()

void BesPolygon2D::Paint ( Option_t * option = "")
virtual

Definition at line 132 of file BesPolygon2D.cxx.

132 {
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}
virtual void Restore()
virtual void RotatePhi(Double_t phi)
Double_t GetLongitude()
Definition BesTView.h:95

Referenced by Cgem2DVStrip::Paint(), Cgem2DXStrip::Paint(), Emc2DCrystal::Paint(), Mdc2DWire::Paint(), Muc2DStrip::Paint(), and Tof2DScin::Paint().

◆ Resize()

void BesPolygon2D::Resize ( Double_t ScaleFactor)
virtual

Definition at line 319 of file BesPolygon2D.cxx.

319 {
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}
***************************************************************************************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
virtual void GetCenter(Double_t *Center) const

◆ Restore()

void BesPolygon2D::Restore ( )
virtual

Definition at line 363 of file BesPolygon2D.cxx.

363 {
364
365 for (Int_t i = 0; i < fN*3; i++) {
366 fP[i] = fPBackUp[i];
367 }
368}

Referenced by Paint(), Cgem2DXStrip::Paint(), Emc2DCrystal::Paint(), and Tof2DScin::Paint().

◆ RotatePhi()

void BesPolygon2D::RotatePhi ( Double_t phi)
virtual

Definition at line 349 of file BesPolygon2D.cxx.

349 {
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}
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
dble_vec_t vec[12]
Definition ranlxd.c:372

Referenced by Paint().

◆ SetDrawOption()

void BesPolygon2D::SetDrawOption ( Option_t * option)
inline

Definition at line 83 of file BesPolygon2D.h.

83 {
84 TObject::SetDrawOption(option);
85 }

◆ SetInfoBox()

void BesPolygon2D::SetInfoBox ( )
virtual

Definition at line 272 of file BesPolygon2D.cxx.

272 {
273 //
274 // Set tooltip textbox with some information
275 TView *view = dynamic_cast<TView*>(gPad->GetView());
276 Double_t Pndc[3];
277 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}
virtual char * GetObjectInfo(Int_t px, Int_t py) const

◆ SetName()

void BesPolygon2D::SetName ( const char * name)
inline

Definition at line 68 of file BesPolygon2D.h.

68 {
69 TNamed::SetName(name);
70 }

◆ SetPoints()

void BesPolygon2D::SetPoints ( Double_t * P)
inline

Definition at line 86 of file BesPolygon2D.h.

86 {
87 for ( Int_t i = 0; i < fN*3; i++ ) fP[i] = P[i];
88 }

Referenced by BesPolygon2D().

◆ SetRotatable()

void BesPolygon2D::SetRotatable ( Bool_t input)
inline

◆ SetSize()

void BesPolygon2D::SetSize ( Double_t size)
virtual

Definition at line 372 of file BesPolygon2D.cxx.

372 {
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}

Referenced by Emc2DCrystal::Paint(), and Tof2DScin::Paint().

◆ SetTitle()

void BesPolygon2D::SetTitle ( const char * name)
inline

Definition at line 71 of file BesPolygon2D.h.

71 {
72 TNamed::SetTitle(name);
73 }

◆ SetZRSign()

void BesPolygon2D::SetZRSign ( Int_t sign)
virtual

Definition at line 303 of file BesPolygon2D.cxx.

303 {
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}

◆ Stretch()

void BesPolygon2D::Stretch ( Double_t sx,
Double_t sy,
Double_t sz,
Double_t factor )
virtual

Definition at line 386 of file BesPolygon2D.cxx.

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}
XmlRpcServer s

Referenced by Cgem2DXStrip::Paint().

Member Data Documentation

◆ f_xx

Double_t* BesPolygon2D::f_xx
protected

Definition at line 31 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), and Paint().

◆ f_yy

Double_t* BesPolygon2D::f_yy
protected

Definition at line 32 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), and Paint().

◆ fCenter

Double_t BesPolygon2D::fCenter[3]
protected

Definition at line 36 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), DistancetoPrimitive(), and SetSize().

◆ fInfoBox

TPaveText* BesPolygon2D::fInfoBox
protected

Definition at line 39 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), and SetInfoBox().

◆ fN

Int_t BesPolygon2D::fN
protected

◆ fP

Double_t* BesPolygon2D::fP
protected

◆ fPBackUp

Double_t* BesPolygon2D::fPBackUp
protected

Definition at line 35 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), Restore(), and ~BesPolygon2D().

◆ fRotatable

Bool_t BesPolygon2D::fRotatable
protected

Definition at line 37 of file BesPolygon2D.h.

Referenced by BesPolygon2D(), IsRotatable(), and SetRotatable().


The documentation for this class was generated from the following files: