BOSS 8.0.0
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/BesPolygon2D.h"
10#include "BesVisLib/BesView.h"
11#include <iostream>
12
13#include <TMath.h>
14#include <math.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
47 int 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
66BesPolygon2D::BesPolygon2D( const char* name, const char* title, Int_t N, Double_t* P )
67 : TNamed( name, title ), TAttLine(), TAttFill() {
68 //
69 // BesPolygon2D normal constructor
70 // cout << "####################" << endl;
71 // cout << "BesPolygon2D ctor called " << ++num << endl;
72 // cout << "####################" << endl;
73
74 fN = N;
75 fP = new Double_t[fN * 3];
76 fPBackUp = new Double_t[fN * 3];
77 f_xx = NULL;
78 f_yy = NULL;
79
80 fInfoBox = 0;
81 if ( P != NULL ) { SetPoints( P ); }
82
83 for ( Int_t i = 0; i < fN * 3; i++ ) { fPBackUp[i] = fP[i]; }
84
85 for ( Int_t j = 0; j < 3; j++ )
86 {
87 fCenter[j] = 0.0;
88 for ( Int_t i = 0; i < fN; i++ ) { fCenter[j] += fP[3 * i + j]; }
89 fCenter[j] /= fN;
90 }
91
92 for ( Int_t i = 0; i < fN; i++ ) {}
93
94 fRotatable = false;
95}
96
97//_____________________________________________________
98
100 //
101 // BesPolygon2D default destructor
102 // cout << "####################" << endl;
103 // cout << "BesPolygon2D dtor called " << --num << endl;
104 // cout << "####################" << endl;
105
106 // Long Peixun's update: remove "if"
107 delete[] fP;
108 delete[] fPBackUp;
109}
110
111//_____________________________________________________
112
113void BesPolygon2D::Draw( Option_t* option ) {
114 //
115 // BesPolygon2D draw function
116 TString opt = option;
117 opt.ToUpper();
118
119 AppendPad( option );
120}
121
122//_____________________________________________________
123
124void BesPolygon2D::Paint( Option_t* option ) {
125 //
126 // BesPolygon2D paint function
127 TString opt = option;
128 opt.ToUpper();
129
130 // Transform to normalised desktop coordinates
131 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
132 if ( view == 0 ) cout << "no view found" << endl;
133 Double_t viewPhi = view->GetLongitude();
134 if ( IsRotatable() ) RotatePhi( viewPhi - 180.0 );
135
136 if ( f_xx )
137 {
138 delete[] f_xx;
139 f_xx = NULL;
140 }
141 if ( f_yy )
142 {
143 delete[] f_yy;
144 f_yy = NULL;
145 }
146
147 f_xx = new Double_t[fN + 1];
148 f_yy = new Double_t[fN + 1];
149 Double_t Pndc[3];
150
151 for ( Int_t i = 0; i < fN; i++ )
152 {
153 view->WCtoNDC( &fP[i * 3], Pndc );
154 f_xx[i] = Pndc[0];
155 f_yy[i] = Pndc[1];
156 }
157
158 // Close surface
159 f_xx[fN] = f_xx[0];
160 f_yy[fN] = f_yy[0];
161
162 TAttLine::Modify(); // Change line attributes only if necessary
163 TAttFill::Modify(); // Change fill attributes only if necessary
164
165 gPad->PaintFillArea( fN, f_xx, f_yy );
166 gPad->PaintPolyLine( fN + 1, f_xx, f_yy );
167 if ( IsRotatable() ) Restore();
168}
169
170//_____________________________________________________
171
172Int_t BesPolygon2D::DistancetoPrimitive( Int_t px, Int_t py ) {
173 //
174 // Compute the closest distance of approach from point px,py to the
175 // center of this polygon
176 // The distance is computed in pixels units.
177
178 const Int_t inaxis = 7;
179 Int_t dist = 9999;
180
181 if ( this->IsRotatable() ) return dist;
182
183 Int_t puxmin = gPad->XtoAbsPixel( gPad->GetUxmin() );
184 Int_t puymin = gPad->YtoAbsPixel( gPad->GetUymin() );
185 Int_t puxmax = gPad->XtoAbsPixel( gPad->GetUxmax() );
186 Int_t puymax = gPad->YtoAbsPixel( gPad->GetUymax() );
187
188 // return if point is not in the user area
189 if ( px < puxmin - inaxis ) return dist;
190 if ( py > puymin + inaxis ) return dist;
191 if ( px > puxmax + inaxis ) return dist;
192 if ( py < puymax - inaxis ) return dist;
193
194 // judge the mouse point and center are always on the same side of any line of ploygon
195 // Transform to normalised desktop coordinates
196
197 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
198 if ( !view ) return dist;
199
200 Bool_t inPolygon = true;
201 Int_t x1, y1, x2, y2, cx, cy;
202 Double_t Pndc[3], k, b, pb, cb;
203
204 view->WCtoNDC( &fCenter[0], Pndc );
205 cx = gPad->XtoAbsPixel( Pndc[0] );
206 cy = gPad->YtoAbsPixel( Pndc[1] );
207
208 // cout << "px " << px << " py " << py << endl;
209 // cout << "center " << cx << " " << cy << endl;
210
211 for ( Int_t i = 0; i < fN; i++ )
212 {
213 view->WCtoNDC( &fP[3 * i], Pndc );
214 x1 = gPad->XtoAbsPixel( Pndc[0] );
215 y1 = gPad->YtoAbsPixel( Pndc[1] );
216
217 if ( i != fN - 1 ) { view->WCtoNDC( &fP[3 * ( i + 1 )], Pndc ); }
218 else view->WCtoNDC( &fP[0], Pndc );
219
220 x2 = gPad->XtoAbsPixel( Pndc[0] );
221 y2 = gPad->YtoAbsPixel( Pndc[1] );
222
223 // cout << "x1 " << x1 << " y1 " << y1 << endl;
224 // cout << "x2 " << x2 << " y2 " << y2 << endl;
225 if ( x1 == x2 )
226 {
227 if ( ( px - x1 ) * ( cx - x1 ) <= 0 )
228 {
229 inPolygon = false;
230 break;
231 }
232 }
233 else
234 {
235 k = Double_t( y2 - y1 ) / ( x2 - x1 );
236 b = y1 - k * x1;
237 pb = py - k * px;
238 cb = cy - k * cx;
239 if ( ( pb - b ) * ( cb - b ) <= 0 )
240 {
241 inPolygon = false;
242 break;
243 }
244 }
245 }
246
247 if ( inPolygon == true )
248 {
249 // gPad->SetSelected(this);
250 // gPad->SetCursor(kHand);
251 return 0;
252 }
253 else return 9999;
254
255 // cout << GetName() << dist << endl;
256 // if (dist < 100) dist = 0;
257}
258
259//_____________________________________________________
260
261void BesPolygon2D::ExecuteEvent( Int_t event, Int_t px, Int_t py ) {
262 // cout << "I am in " << GetName() << endl;
263
264 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
265 if ( view ) view->ExecuteEvent( event, px, py );
266}
267
268//_____________________________________________________
269
271 //
272 // Set tooltip textbox with some information
273 TView* view = dynamic_cast<TView*>( gPad->GetView() );
274 Double_t Pndc[3];
275 if ( view ) view->WCtoNDC( &fP[0], Pndc );
276
277 if ( fInfoBox )
278 {
279 delete fInfoBox;
280 fInfoBox = 0;
281 }
282 fInfoBox = new TPaveText( Pndc[0], Pndc[1], Pndc[0] + 0.4, Pndc[1] + 0.1 );
283 fInfoBox->SetBorderSize( 1 );
284 fInfoBox->SetFillColor( 191 );
285 fInfoBox->AddText( GetTitle() );
286 fInfoBox->AddText( GetObjectInfo( 0, 0 ) );
287 fInfoBox->Draw();
288}
289
290//_____________________________________________________
291
292char* BesPolygon2D::GetObjectInfo( Int_t px, Int_t py ) const {
293
294 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
295 if ( view ) return view->GetObjectInfo( px, py );
296 else return TObject::GetObjectInfo( px, py );
297}
298
299//_____________________________________________________
300
301void BesPolygon2D::SetZRSign( Int_t sign ) {
302 //
303 // set sign of points for ZR view
304
305 for ( Int_t i = 0; i < fN; i++ )
306 {
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
317void BesPolygon2D::Resize( Double_t ScaleFactor ) {
318 //
319 // Resize the polygon by ScaleFactor
320
321 // Compute geometric center of the polygon
322 Double_t C[3];
323 GetCenter( C );
324
325 // Rescale distances from the center
326 for ( Int_t i = 0; i < 3; i++ )
327 {
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
335void BesPolygon2D::GetCenter( Double_t* Center ) const {
336 //
337 // Compute geometric center of this polygon
338 for ( Int_t i = 0; i < 3; i++ )
339 {
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 {
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++ ) { fP[i] = fPBackUp[i]; }
366}
367
368//_____________________________________________________
369
370void BesPolygon2D::SetSize( Double_t size ) {
371
372 if ( size > 0.95 ) size = 0.98; // too big could not see border
373 if ( size < 0.15 ) size = 0.2; // too small could not be seen
374
375 for ( Int_t i = 0; i < 3; i++ )
376 {
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//_____________________________________________________
383// Long Peixun's update: Stretch polygon along (sx, sy, sz)
384void BesPolygon2D::Stretch( Double_t sx, Double_t sy, Double_t sz, Double_t factor ) {
385 // Compute geometric center of the polygon
386 Double_t C[3], V[3];
387 GetCenter( C );
388 Double_t s = TMath::Sqrt( sx * sx + sy * sy + sz * sz );
389 V[0] = sx / s;
390 V[1] = sy / s;
391 V[2] = sz / s;
392
393 // Rescale distances from the center
394 for ( Int_t i = 0; i < fN; ++i )
395 {
396 Double_t dot = ( fP[3 * i] - C[0] ) * V[0] + ( fP[3 * i + 1] - C[1] ) * V[1] +
397 ( fP[3 * i + 2] - C[2] ) * V[2];
398 for ( Int_t j = 0; j < 3; ++j ) { fP[3 * i + j] += dot * ( factor - 1 ) * V[j]; }
399 }
400}
dble_vec_t vec[12]
double P(RecMdcKalTrack *trk)
titledef title[20]
XmlRpcServer s
***************************************************************************************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)
virtual void SetZRSign(Int_t sign)
virtual void SetSize(Double_t size)
virtual void Paint(Option_t *option="")
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
virtual void SetInfoBox()
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)
BesPolygon2D()
info box
virtual ~BesPolygon2D()
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="")
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition BesView.cxx:716
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition BesView.cxx:871
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition BesView.cxx:371