BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Bes2DView.cxx
Go to the documentation of this file.
1//
2// Bes2DView.cxx
3//
4// $Author: maqm $
5// $Date: 2011/03/09 07:22:53 $
6// $Revision: 1.7 $
7//
8
9#include "BesVisLib/Bes2DView.h"
10#include <iostream>
11
12#ifndef ROOT_TGeometry
13# include <TGeometry.h>
14#endif
15
16#ifndef ROOT_TPad
17# include <TPad.h>
18#endif
19
20// #ifndef ROOT_TVirtualPS
21// #include <TVirtualPS.h>
22// #endif
23
24#ifndef ROOT_TPaveLabel
25# include <TPaveLabel.h>
26#endif
27
28#ifndef ROOT_TROOT
29# include <TROOT.h>
30#endif
31
32#ifndef ROOT_TMath
33# include <TMath.h>
34#endif
35#include <TCanvas.h>
36
37using namespace std;
38
39#ifndef __CINT__
41#endif
42
43 //_____________________________________________________
44 // Bes2DView
45 // View class designed for the Bes event display
46 //
48 : BesTView( 1 ) {
49 //
50 // Bes2DView normal constructor
51 if ( gDebug ) cout << "Bes2DView normal ctor called" << endl;
52
53 // init Label
54 fLabel = new TPaveLabel( 0.02, 0.17, 0.02, 0.09, "3D View" );
55 fLabel->SetFillColor( 42 );
56
57 // init status of 3D view
58 fStatus3D = new BesStatus();
59 fStatus3D->Default( k3DView );
60
61 // init status of XY view
62 fStatusXY = new BesStatus();
63 fStatusXY->Default( kXYView );
64
65 // init status of ZR view
66 fStatusZR = new BesStatus();
67 fStatusZR->Default( kZRView );
68
69 // init status of current view
70 fStatusCurrent = new BesStatus();
71
72 // Init
73 f2DViewType = 0; // XY:0, ZR:1;
74 fStatusCurrent->Transfer( fStatus3D, 1 );
75 SetRange( -200, -200, -200, 200, 200, 200 );
76 fZoomFactor = 1.5;
77
78 fMarkerSize = 0.1;
79}
80
81//_____________________________________________________
82
84 //
85 // Bes2DView default destructor
86 if ( gDebug ) cout << "Bes2DView default dtor called" << endl;
87
88 delete fLabel;
89
90 delete fStatus3D;
91 delete fStatusXY;
92 delete fStatusZR;
93 delete fStatusCurrent;
94}
95
96//_____________________________________________________
97
99 //
100 // Clear current without deleting this view
101 //
102 // Probably this doesn't work for the postscript output
103 // Look at TPad::Clear() for more details
104 if ( gDebug ) cout << "Bes2DView::ClearPad called" << endl;
105 if ( gPad->GetListOfPrimitives() ) gPad->GetListOfPrimitives()->Clear();
106}
107
108//_____________________________________________________
109
110void Bes2DView::ExecuteEvent( Int_t event, Int_t px, Int_t py ) {
111 //
112 // Execute mouse events
113 if ( gDebug ) cout << "Bes2DView::ExecuteEvent called" << endl;
114 // cout << "f2DViewType " << f2DViewType << " k3DView " << k3DView << endl;
115
116 /*
117 if ( fViewType & k3DView ) {
118 ExecuteRotateView(event, px, py);
119 } else {
120 */
121
122 // Editor mode
123 if ( gROOT->GetEditorMode() )
124 {
125 cout << "ROOT" << endl;
126 gPad->ExecuteEvent( event, px, py );
127 return;
128 }
129
130 static Double_t xmin, ymin, xmax, ymax, x0, y0;
131 Double_t dx, dy, x, y;
132 switch ( event )
133 {
134
135 case kButton1Down:
136 gPad->SetCursor( kMove );
137 // Remember position of pointer
138 xmin = gPad->GetX1();
139 ymin = gPad->GetY1();
140 xmax = gPad->GetX2();
141 ymax = gPad->GetY2();
142 x0 = gPad->AbsPixeltoX( px );
143 y0 = gPad->AbsPixeltoY( py );
144 break;
145
146 case kButton1Motion: gPad->SetCursor( kMove );
147
148 case kButton1Up:
149 // Set new pad range
150 x = gPad->AbsPixeltoX( px );
151 y = gPad->AbsPixeltoY( py );
152 dx = -( x - x0 );
153 dy = -( y - y0 );
154 //((TPad*)gPad)->SetNoAspect(kTRUE);
155 gPad->Range( xmin + dx, ymin + dy, xmax + dx, ymax + dy );
156 //((TPad*)gPad)->SetNoAspect(kFALSE);
157 gPad->Modified();
158 break;
159
160 default: gPad->SetCursor( kCross );
161 }
162}
163
164//_____________________________________________________
165
166void Bes2DView::Move( Int_t px, Int_t py ) {
167 //
168 // Move (px, py in pixel coordinates)
169 Double_t x1, y1, x2, y2, dx, dy, x, y, x0, y0;
170 x1 = gPad->GetX1();
171 y1 = gPad->GetY1();
172 x2 = gPad->GetX2();
173 y2 = gPad->GetY2();
174 x0 = gPad->PixeltoX( 0 );
175 y0 = gPad->PixeltoY( 0 );
176 x = gPad->PixeltoX( px );
177 y = gPad->PixeltoY( py );
178 dx = -( x - x0 );
179 dy = -( y - y0 );
180 //((TPad*)gPad)->SetNoAspect(kTRUE);
181 gPad->Range( x1 + dx, y1 + dy, x2 + dx, y2 + dy );
182 //((TPad*)gPad)->SetNoAspect(kFALSE);
183 gPad->Modified();
184}
185
186//_____________________________________________________
187
189 //
190 // Center view
191 /*
192 if ( fViewType & k3DView ){
193 this->Centered();
194 } else {
195 */
196 Double_t xrange, yrange;
197 xrange = gPad->GetX2() - gPad->GetX1();
198 yrange = gPad->GetY2() - gPad->GetY1();
199 gPad->Range( -xrange / 2, -yrange / 2, xrange / 2, yrange / 2 );
200 gPad->Modified();
201}
202
203//_____________________________________________________
204
206 //
207 // Magnify
208 fMarkerSize = fMarkerSize * fZoomFactor;
209 ZoomView( gPad, fZoomFactor );
210}
211
212//_____________________________________________________
213
215 //
216 // Demagnify
217 fMarkerSize = fMarkerSize / fZoomFactor;
218 UnzoomView( gPad, fZoomFactor );
219}
220
221//_____________________________________________________
222
223Int_t Bes2DView::GetRSign( Float_t Phi ) {
224 //
225 // Get sign of the R coordinate (ZR view)
226 // for a given phi (in radians)
227 Int_t Sign;
228
229 // Convert to deg, because phi range is given in degrees
230 Float_t Phi2 =
231 ( Phi - 2 * TMath::Pi() * Int_t( Phi / ( 2 * TMath::Pi() ) ) ) * 180. / TMath::Pi();
232 if ( Phi2 < 0 ) Phi2 += 360;
233 if ( Phi2 >= fStatusCurrent->fPhiRangeMin && Phi2 < fStatusCurrent->fPhiRangeMax )
234 { Sign = 1; }
235 else { Sign = -1; }
236 return Sign;
237}
238
239//_____________________________________________________
240
241void Bes2DView::UpdateView( Bool_t resetview ) {
242 //
243 // Update current view
244 if ( !gGeometry ) return;
245
246 // Redraw
247 // SetViewType(fViewType,resetview);
248}
249
251 //
252 // Draw label for current view
253
254 fLabel->SetX1NDC( 0.05 );
255 fLabel->SetX2NDC( 0.20 );
256 fLabel->SetY1NDC( 0.05 );
257 fLabel->SetY2NDC( 0.12 );
258
259 switch ( f2DViewType )
260 {
261 // case k3DView:
262 // fLabel->SetLabel("3D View");
263 // break;
264 case 0: fLabel->SetLabel( "XY View" ); break;
265 case 1: fLabel->SetLabel( "ZR View" ); break;
266 }
267 fLabel->Draw( "BR,NDC,SAME" );
268}
269
270//_____________________________________________________
271
272void Bes2DView::WCtoNDC( const Float_t* pw, Float_t* pn ) {
273 //
274 // Transform world coordinates to
275 // normalised device coordinates.
276 // This method was taken from BesTView
277 // and extended by FishEye view
278 BesTView::WCtoNDC( pw, pn );
279 // cout << "fFishEye " << fFishEye << endl;
280
281 if ( fStatusCurrent->fFishEye == kTRUE )
282 {
283 Float_t r, s;
284 if ( f2DViewType == 1 )
285 {
286 Float_t pvWC[3], pvNDC[3];
287 pvWC[0] = +4;
288 pvWC[1] = 0;
289 pvWC[2] = 0;
290 BesTView::WCtoNDC( pvWC, pvNDC );
291 pn[0] = TMath::Sign( Double_t( TMath::Sqrt( TMath::Abs( pn[0] - pvNDC[0] ) ) ),
292 Double_t( pn[0] - pvNDC[0] ) ) +
293 pvNDC[0];
294 pn[1] = TMath::Sign( Double_t( TMath::Sqrt( TMath::Abs( pn[1] - pvNDC[1] ) ) ),
295 Double_t( pn[1] - pvNDC[1] ) ) +
296 pvNDC[1];
297 }
298 else
299 {
300 r = TMath::Sqrt( TMath::Power( pn[0], 2 ) + TMath::Power( pn[1], 2 ) );
301 s = TMath::Sqrt( r ) / r;
302 pn[0] *= s;
303 pn[1] *= s;
304 }
305 }
306}
307
308//_____________________________________________________
309
310void Bes2DView::WCtoNDC( const Double_t* pw, Double_t* pn ) {
311 //
312 // Transform world coordinates to
313 // normalised device coordinates.
314 // This method was taken from BesTView
315 // and extended by FishEye view
316 BesTView::WCtoNDC( pw, pn );
317
318 if ( fStatusCurrent->fFishEye == kTRUE )
319 {
320 Double_t r, s;
321 if ( f2DViewType == 1 )
322 {
323 Double_t pvWC[3], pvNDC[3];
324 pvWC[0] = +4;
325 pvWC[1] = 0;
326 pvWC[2] = 0;
327 BesTView::WCtoNDC( pvWC, pvNDC );
328 pn[0] = TMath::Sign( TMath::Sqrt( TMath::Abs( pn[0] - pvNDC[0] ) ), pn[0] - pvNDC[0] ) +
329 pvNDC[0];
330 pn[1] = TMath::Sign( TMath::Sqrt( TMath::Abs( pn[1] - pvNDC[1] ) ), pn[1] - pvNDC[1] ) +
331 pvNDC[1];
332 }
333 else
334 {
335
336 r = TMath::Sqrt( TMath::Power( pn[0], 2 ) + TMath::Power( pn[1], 2 ) );
337 s = TMath::Sqrt( r ) / r;
338 pn[0] *= s;
339 pn[1] *= s;
340 }
341 }
342}
343
344//_____________________________________________________
345
346void Bes2DView::NDCtoWC( const Float_t* pn, Float_t* pw ) {
347 //
348 // Transform back from NDCs
349 Float_t p[3];
350 if ( f2DViewType == 0 )
351 { // XYView
352 p[0] = pn[0];
353 p[1] = pn[1];
354 p[2] = pn[2];
355 }
356 else
357 { // ZRView
358 p[0] = pn[2];
359 p[1] = pn[1];
360 p[2] = pn[0];
361 }
362
363 if ( fStatusCurrent->fFishEye == kTRUE )
364 {
365 Float_t r;
366 if ( f2DViewType == 1 )
367 {
368 Float_t pvWC[3], pvNDC[3];
369 pvWC[0] = +4;
370 pvWC[1] = 0;
371 pvWC[2] = 0;
372 BesTView::WCtoNDC( pvWC, pvNDC );
373 p[0] = TMath::Sign( ( pn[0] - pvNDC[0] ) * ( pn[0] - pvNDC[0] ), pn[0] - pvNDC[0] ) +
374 pvNDC[0];
375 p[1] = TMath::Sign( ( pn[1] - pvNDC[1] ) * ( pn[1] - pvNDC[1] ), pn[1] - pvNDC[1] ) +
376 pvNDC[1];
377 }
378 else
379 {
380 r = TMath::Sqrt( TMath::Power( p[0], 2 ) + TMath::Power( p[1], 2 ) );
381 p[0] *= r;
382 p[1] *= r;
383 }
384 }
385 BesTView::NDCtoWC( p, pw );
386}
387
388//_____________________________________________________
389
390void Bes2DView::NDCtoWC( const Double_t* pn, Double_t* pw ) {
391 //
392 // Transform back from NDCs
393 Double_t p[3];
394 if ( f2DViewType == 0 )
395 { // XYView
396 p[0] = pn[0];
397 p[1] = pn[1];
398 p[2] = pn[2];
399 }
400 else
401 { // ZRView
402 p[0] = pn[2];
403 p[1] = pn[1];
404 p[2] = pn[0];
405 }
406
407 if ( fStatusCurrent->fFishEye == kTRUE )
408 {
409 Double_t r;
410 if ( f2DViewType == 1 )
411 {
412 Double_t pvWC[3], pvNDC[3];
413 pvWC[0] = +4;
414 pvWC[1] = 0;
415 pvWC[2] = 0;
416 BesTView::WCtoNDC( pvWC, pvNDC );
417 p[0] = TMath::Sign( ( pn[0] - pvNDC[0] ) * ( pn[0] - pvNDC[0] ), pn[0] - pvNDC[0] ) +
418 pvNDC[0];
419 p[1] = TMath::Sign( ( pn[1] - pvNDC[1] ) * ( pn[1] - pvNDC[1] ), pn[1] - pvNDC[1] ) +
420 pvNDC[1];
421 }
422 else
423 {
424 r = TMath::Sqrt( TMath::Power( p[0], 2 ) + TMath::Power( p[1], 2 ) );
425 p[0] *= r;
426 p[1] *= r;
427 }
428 }
429 BesTView::NDCtoWC( p, pw );
430}
431
432//_____________________________________________________
433
434char* Bes2DView::GetObjectInfo( Int_t px, Int_t py ) const {
435 //
436 // Returns string containing info about the object at position (px,py).
437 Double_t pw[3] = { 0., 0., 0. };
438 //((TPad*)gPad)->PixeltoWC(px, py, pw);
439
440 static char info[64];
441 if ( f2DViewType == 1 )
442 {
443 sprintf( info, "z=%-.3fcm, r=%-.3fcm", pw[0], pw[1] );
444 return info;
445 }
446 else
447 {
448 sprintf( info, "x=%-.3fcm, y=%-.3fcm", pw[0], pw[1] );
449 return info;
450 }
451}
452
453//_____________________________________________________
454
456 //
457 // reset view to default values
458
459 // reset status instances of views
460 // fStatus3D->Default(k3DView);
461 // fStatusXY->Default(kXYView);
462 // fStatusZR->Default(kZRView);
463 fZoomFactor = 1.5;
464
465 // reset current status instance tp fViewType
466 // fStatusCurrent->Default(fViewType);
467
468 // center the view
469 this->Center();
470 this->SetRange( -2635, -2635, -2875, 2635, 2635, 2875 );
471 // int iret;
472 // this->SetView(0,0,270,iret);
473 this->ZoomView( gPad, 1.5 );
474
475 // reset phirange
476 // this->SetPhiRange(0,180);
477 // this->UpdateView();
478 gPad->Update();
479}
ClassImp(Bes2DView) Bes2DView
Definition Bes2DView.cxx:40
double Phi(RecMdcKalTrack *trk)
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
XmlRpcServer s
virtual void DrawLabel()
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
virtual void ClearPad()
Definition Bes2DView.cxx:98
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual Int_t GetRSign(Float_t Phi)
void UnZoom()
void Zoom()
void Center()
virtual void UpdateView(Bool_t resetview=kFALSE)
void Reset()
void Move(Int_t px, Int_t py)
virtual ~Bes2DView()
Definition Bes2DView.cxx:83
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
virtual void UnzoomView(TVirtualPad *pad=0, Double_t unZoomFactor=1.25)
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)
virtual void ZoomView(TVirtualPad *pad=0, Double_t zoomFactor=1.25)
virtual void SetRange(const Double_t *min, const Double_t *max)