BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesView.cxx
Go to the documentation of this file.
1//
2// BesView.cxx
3//
4
5#include "TMath.h"
6#include "math.h"
7#include <TCanvas.h>
8#include <TPad.h>
9#include <TPaveLabel.h>
10#include <TROOT.h>
11#include <iostream>
12
13#include "BesVisLib/BesCursor.h"
14#include "BesVisLib/BesEvent.h"
15#include "BesVisLib/BesGeometry.h"
16#include "BesVisLib/BesView.h"
17
18using namespace std;
19
20#ifndef __CINT__
22#endif
23
24 //_____________________________________________________
25 // BesView
26 // View class designed for the BesVis display
27 //
29 : BesTView( 1 ) {
30 //
31 // BesView normal constructor
32 if ( gDebug ) cout << "BesView normal ctor called" << endl;
33
34 // init Label
35 fLabel = new TPaveLabel( 0.02, 0.17, 0.02, 0.09, "3D View" );
36 fLabel->SetFillColor( 42 );
37
38 // init status of 3D view
39 fStatus3D = new BesStatus();
40 fStatus3D->Default( k3DView );
41
42 // init status of XY view
43 fStatusXY = new BesStatus();
44 fStatusXY->Default( kXYView );
45
46 // init status of ZR view
47 fStatusZR = new BesStatus();
48 fStatusZR->Default( kZRView );
49
50 // init status of current view
51 fStatusCurrent = new BesStatus();
52
53 // Init
54 fViewType = k3DView;
55 fStatusCurrent->Transfer( fStatus3D, 1 );
56 if ( !gBesGeometry )
57 {
58 cout << "BesGeometry does not exist! " << endl;
59 return;
60 }
61
62 m_BesR = gBesGeometry->GetBesR();
63 m_BesZ = gBesGeometry->GetBesZ();
64 DefaultRange();
65 fExtentDefault = GetExtent();
66
67 fZoomFactor = 1.2;
68 // fMarkerSize = 0.1; //Long Peixun's update: fMarkerSize has been initialized in
69 // DefaultRange() Long Peixun's update: Initialize ViewCenter
70 ViewCenter[0] = ViewCenter[1] = 0.0;
71}
72
73//_____________________________________________________
74
76 //
77 // BesView default destructor
78 if ( gDebug ) cout << "BesView default dtor called" << endl;
79
80 delete fLabel;
81
82 delete fStatus3D;
83 delete fStatusXY;
84 delete fStatusZR;
85 delete fStatusCurrent;
86}
87
88//_____________________________________________________
89
91 SetRange( -1.0 * m_BesR, -1.0 * m_BesR, -0.5 * m_BesZ, m_BesR, m_BesR, 0.5 * m_BesZ );
92 fMarkerSize = 0.1; // Long Peixun's update: Reset marker size here
93}
94
95//_____________________________________________________
96
97void BesView::SetViewType( EBESViewType ViewType, Bool_t resetview ) {
98 //
99 // Set type of view
100
101 // check the state of the component before change and copy current status to respective
102 // status
103 if ( fViewType & k3DView ) { fStatus3D->Transfer( fStatusCurrent, 0 ); }
104 else if ( fViewType & kXYView ) { fStatusXY->Transfer( fStatusCurrent, 0 ); }
105 else if ( fViewType & kZRView ) { fStatusZR->Transfer( fStatusCurrent, 0 ); }
106
107 fViewType = ViewType;
108 ClearPad();
109
110 // Set view direction properly
111 Int_t iret;
112 if ( fViewType & k3DView )
113 {
114 // cout << "SetViewType 3D" << endl;
115 //
116 // 3D view
117
118 // remember my previous state, set parallel first anyway, then choose perspective or not
119 Int_t iPerspective = 0;
120
121 if ( IsPerspective() ) iPerspective = 1;
122
123 // copy 3D status to current status
124 fStatusCurrent->Transfer( fStatus3D, 1 );
125
126 // Geometry exist ?
127 if ( !gBesGeometry ) return;
128
129 // set view
130 if ( resetview )
131 {
132 // SetView(0, 90, 270, iret);
133 this->Front();
134 this->Center();
135
136 DefaultRange();
137 // for (int i = 0; i < 2; i++) this->ZoomView(gPad, fZoomFactor);
138 // Long Peixun's update: Using SetZoomRatio instead of ZoomView
139 SetZoomRatio( fStatus3D->fZoom );
140
141 // Long Peixun's update: don't reset marker size
142 // fMarkerSize = 0.1;
143 }
144
145 // Draw geometry
146
147 // cout << "is there any problem after update from root's version 4.03 to 4.04" << endl;
148 // //Long Peixun remove
149 gBesGeometry->Draw( "3D,SAME" );
150 // this->SetParralel(); //comment out 2007.5.1 try to use ROOT-5.10.00
151 this->SetParallel();
152 // old version 4.0.3 have a spell mistake BesTView::SetParralel()=>SetParallel()
153 // changed by tianhl at Mon Aug 20 2007
154 if ( iPerspective == 1 ) this->SetPerspective();
155
156 // Draw tracks
157 if ( gEvent ) { gEvent->DrawTracks( "" ); }
158 // else cout << "3D gEvent does not exist " << endl;
159 }
160 else if ( fViewType & kXYView )
161 {
162 // cout << "SetViewType XY" << endl;
163 //
164 // XY view
165 // =======
166
167 // copy XY status to current status
168 fStatusCurrent->Transfer( fStatusXY, 1 );
169
170 // Geometry exist ?
171 if ( !gBesGeometry ) return;
172
173 // set view
174 if ( resetview )
175 {
176 SetView( 0, 0, 270, iret );
177 this->Center();
178
179 DefaultRange();
180 // DefaultRange(); //Long Peixun's update: Remove redundant DefaultRange()
181 // for (int i = 0; i < 2; i++) this->ZoomView(gPad, fZoomFactor);
182 // Long Peixun's update: Using SetZoomRatio instead of ZoomView
183 SetZoomRatio( fStatusXY->fZoom );
184
185 // Long Peixun's update: don't reset marker size
186 // fMarkerSize = 0.1;
187 }
188
189 /*
190 // Draw event
191 if ( gEvent ) gEvent->SetHits("XY");
192 else cout << "XY : gEvent does not exist " << endl;
193 */
194
195 // Draw geometry
196 gBesGeometry->Draw( "XY,SAME" );
197
198 // Draw 2D hits and tracks
199 if ( gEvent )
200 {
201 gEvent->DrawHits( "" );
202 gEvent->DrawTracks( "" );
203 }
204 // else cout << "XY : gEvent does not exist " << endl;
205 }
206 else if ( fViewType & kZRView )
207 {
208 // cout << "SetViewType ZR" << endl;
209 //
210 // ZR view
211 // =======
212
213 // copy ZR status to current status
214 fStatusCurrent->Transfer( fStatusZR, 1 );
215
216 // Geometry exist ?
217 if ( !gBesGeometry ) return;
218
219 // set view
220 if ( resetview )
221 {
222 SetView( 180, 90, 90, iret );
223 this->Center();
224
225 DefaultRange();
226 // DefaultRange(); //Long Peixun's update: Remove redundant DefaultRange()
227 // for (int i = 0; i < 2; i++) this->ZoomView(gPad, fZoomFactor);
228 // Long Peixun's update: Using SetZoomRatio instead of ZoomView
229 SetZoomRatio( fStatusZR->fZoom );
230
231 // Long Peixun's update: don't reset marker size
232 // fMarkerSize = 0.1;
233 }
234
235 /*
236 // Draw event
237 if ( gEvent ) gEvent->SetHits("ZR");
238 else cout << "ZR : gEvent does not exist " << endl;
239 */
240
241 // Draw geometry
242 gBesGeometry->Draw( "ZR,SAME" );
243
244 // Draw hits and tracks
245 if ( gEvent )
246 {
247 gEvent->DrawHits( "" );
248 gEvent->DrawTracks( "" );
249 }
250 // else cout << "ZR : gEvent does not exist " << endl;
251 }
252
253 // Draw label
254 DrawLabel();
255}
256
257void BesView::SetViewTypeBare( EBESViewType ViewType, Bool_t resetview ) {
258 /*
259 //
260 // Set type of view
261
262 cout << "setviewtypeBare: start..." << endl;
263 // check the state of the component before change and copy current status to respective
264 status if ( fViewType & k3DView ){
265
266 fStatus3D->Transfer(fStatusCurrent,0);
267
268 } else if ( fViewType & kXYView ) {
269
270 fStatusXY->Transfer(fStatusCurrent,0);
271
272 } else if ( fViewType & kZRView ) {
273
274
275 fStatusZR->Transfer(fStatusCurrent,0);
276
277 }
278
279 fViewType = ViewType;
280 ClearPad();
281
282 // Set view direction properly
283 Int_t iret;
284 cout << "fViewType=" << fViewType << endl;
285 if ( fViewType & k3DView ) {
286 //
287 // 3D view
288
289 // copy 3D status to current status
290 fStatusCurrent->Transfer(fStatus3D,1);
291 // Geometry exist ?
292 if ( !gGeometry ) return;
293
294 // set view
295 if ( resetview ) {
296 SetView(0, 90, 270, iret);
297 SetRange(-600,-600,-400,600,600,800);
298
299 // reset marker size
300 fMarkerSize = 0.1;
301
302 }
303
304 } else if ( fViewType & kXYView ) {
305 //
306 // XY view
307 // =======
308
309 // copy XY status to current status
310 fStatusCurrent->Transfer(fStatusXY,1);
311
312 // Geometry exist ?
313 if ( !gGeometry ) return;
314
315 // set view
316 if ( resetview ) {
317 SetView(270, 0, 0, iret);
318 // SetRange(-200,-200,-200,200,200,200);
319 SetRange(-310,-310,-310,310,310,310);
320 // reset marker size
321 fMarkerSize = 0.1;
322
323 }
324
325 } else if ( fViewType & kZRView ) {
326
327 //
328 // ZR view
329 // =======
330
331 // copy ZR status to current status
332 cout << "fViewType & kZRView: before transfer..." << endl;
333 fStatusCurrent->Transfer(fStatusZR,1);
334 cout << "fViewType & kZRView: after transfer..." << endl;
335
336 // Geometry exist ?
337 if ( !gGeometry ) return;
338
339 // set view
340 if ( resetview ) {
341 SetView(90, 180, 0, iret);
342 // SetRange(-130,-200,-200,270,200,200);
343 SetRange(-160,-400,-400,740,400,400);
344 // reset marker size
345 fMarkerSize = 0.1;
346
347 }
348
349 }
350
351 // Draw label
352 cout << "SetViewTypeBare: no drawlabel" << endl;
353 //DrawLabel();
354 */
355}
356
357//_____________________________________________________
358
360 //
361 // Clear current without deleting this view
362 //
363 // Probably this doesn't work for the postscript output
364 // Look at TPad::Clear() for more details
365 if ( gDebug ) cout << "BesView::ClearPad called" << endl;
366 if ( gPad->GetListOfPrimitives() ) gPad->GetListOfPrimitives()->Clear();
367}
368
369//_____________________________________________________
370
371void BesView::ExecuteEvent( Int_t event, Int_t px, Int_t py ) {
372 //
373 // Execute mouse events
374 if ( gDebug ) cout << "BesView::ExecuteEvent called" << endl;
375
376 // Editor mode
377 if ( gROOT->GetEditorMode() )
378 {
379 gPad->ExecuteEvent( event, px, py );
380 return;
381 }
382
383 if ( gBesCursor->GetType() == kBesHand )
384 {
385
386 gPad->SetCursor( kMove );
387 static Double_t xmin, ymin, xmax, ymax, x0, y0;
388 Double_t dx, dy, x, y;
389 switch ( event )
390 {
391
392 case kButton1Down:
393 // Remember position of pointer
394 xmin = gPad->GetX1();
395 ymin = gPad->GetY1();
396 xmax = gPad->GetX2();
397 ymax = gPad->GetY2();
398 x0 = gPad->AbsPixeltoX( px );
399 y0 = gPad->AbsPixeltoY( py );
400 break;
401
402 case kButton1Motion: gPad->SetCursor( kMove );
403
404 case kButton1Up:
405 // Set new pad range
406 x = gPad->AbsPixeltoX( px );
407 y = gPad->AbsPixeltoY( py );
408 dx = -( x - x0 );
409 dy = -( y - y0 );
410 //((ZPad*)gPad)->SetNoAspect(kTRUE);
411 gPad->Range( xmin + dx, ymin + dy, xmax + dx, ymax + dy );
412 //((ZPad*)gPad)->SetNoAspect(kFALSE);
413 gPad->Modified();
414 // Long Peixun's update: Set view center
415 ViewCenter[0] = ( xmin + xmax ) / 2 + dx;
416 ViewCenter[1] = ( ymin + ymax ) / 2 + dy;
417 break;
418
419 default: gPad->SetCursor( kMove );
420 }
421 }
422 else if ( gBesCursor->GetType() == kBesPick )
423 {
424
425 gPad->SetCursor( kPointer );
426
427 if ( fViewType & k3DView ) { ExecuteRotateView( event, px, py ); }
428 }
429}
430
431//_____________________________________________________
432
433void BesView::Move( Int_t px, Int_t py ) {
434
435 /*
436 Double_t p[3], pw[3];
437 for (Int_t i = 0; i < 3; i++) {
438 pw[i] = 0.5*(fRmin[i]+fRmax[i]);
439 }
440 cout << "pw " << pw[0] << " " << pw[1] << " " << pw[2] << endl;
441 WCtoNDC(pw, p);
442 cout << "p " << p[0] << " " << p[1] << " " << p[2] << endl;
443
444 p[0] += (gPad->PixeltoX(0) - gPad->PixeltoX(px));
445 p[1] += (gPad->PixeltoY(0) - gPad->PixeltoY(py));
446 cout << "p " << p[0] << " " << p[1] << " " << p[2] << endl;
447 NDCtoWC(p, pw);
448 cout << "pw " << pw[0] << " " << pw[1] << " " << pw[2] << endl;
449
450 MoveFocus(&pw[0], fRmax[0]-fRmin[0], fRmax[1]-fRmin[1], fRmax[2]-fRmin[2]);
451 gPad->Modified();
452 gPad->Update();
453 */
454 if ( !gPad ) return; // Long Peixun's update: check pad pointer before move
455
456 //
457 // Move (px, py in pixel coordinates)
458 Double_t x1, y1, x2, y2, dx, dy, x, y, x0, y0;
459 x1 = gPad->GetX1();
460 y1 = gPad->GetY1();
461 x2 = gPad->GetX2();
462 y2 = gPad->GetY2();
463 x0 = gPad->PixeltoX( 0 );
464 y0 = gPad->PixeltoY( 0 );
465 x = gPad->PixeltoX( px );
466 y = gPad->PixeltoY( py );
467 dx = -( x - x0 );
468 dy = -( y - y0 );
469
470 gPad->Range( x1 + dx, y1 + dy, x2 + dx, y2 + dy );
471 gPad->Modified();
472
473 // Long Peixun's update: Set view center
474 ViewCenter[0] = ( x1 + x2 ) / 2 + dx;
475 ViewCenter[1] = ( y1 + y2 ) / 2 + dy;
476}
477
478//_____________________________________________________
479
481 //
482 // Center view
483 // if ( fViewType & k3DView ){
484 // this->Centered();
485 //} else {
486 Double_t xrange, yrange;
487 xrange = gPad->GetX2() - gPad->GetX1();
488 yrange = gPad->GetY2() - gPad->GetY1();
489 gPad->Range( -xrange / 2, -yrange / 2, xrange / 2, yrange / 2 );
490 gPad->Modified();
491
492 // Long Peixun's update: Set view center
493 ViewCenter[0] = ViewCenter[1] = 0.0;
494 //}
495}
496
497//_____________________________________________________
498
499void BesView::SetZoomRatio( Double_t ratio ) {
500 // Long Peixun's update: Move pad and let Pad center be ViewCenter
501 Double_t dx = ( ratio / GetZoomRatio() - 1 ) * ViewCenter[0];
502 Double_t dy = ( ratio / GetZoomRatio() - 1 ) * ViewCenter[1];
503
504 DefaultRange();
505 fMarkerSize *= ratio; // Long Peixun's update: Should set marker size
506 ZoomView( gPad, ratio );
507
508 // Long Peixun's update: Move pad and let Pad center be ViewCenter
509 Double_t newx1 = gPad->GetX1() + dx;
510 Double_t newy1 = gPad->GetY1() + dy;
511 Double_t newx2 = gPad->GetX2() + dx;
512 Double_t newy2 = gPad->GetY2() + dy;
513 gPad->Range( newx1, newy1, newx2, newy2 );
514 gPad->Modified();
515 ViewCenter[0] = ( newx1 + newx2 ) / 2;
516 ViewCenter[1] = ( newy1 + newy2 ) / 2;
517
518 // yzhang TEMP FIXME
519 fStatusCurrent->fZoom = ratio;
520 fStatusXY->fZoom = ratio;
521 fStatusZR->fZoom = ratio;
522 fStatus3D->fZoom = ratio;
523}
524
525//_____________________________________________________
526
528 //
529 // Magnify
530 // Long Peixun's update: Move pad and let Pad center be ViewCenter
531 Double_t dx = ( fZoomFactor - 1 ) * ViewCenter[0];
532 Double_t dy = ( fZoomFactor - 1 ) * ViewCenter[1];
533
534 fMarkerSize = fMarkerSize * fZoomFactor;
535 ZoomView( gPad, fZoomFactor ); // dont use ZoomView as it is not base on center
536
537 fStatusCurrent->fZoom = GetZoomRatio();
538 fStatusXY->fZoom = GetZoomRatio();
539 fStatusZR->fZoom = GetZoomRatio();
540 fStatus3D->fZoom = GetZoomRatio();
541
542 // Long Peixun's update: Move pad and let Pad center be ViewCenter
543 Double_t newx1 = gPad->GetX1() + dx;
544 Double_t newy1 = gPad->GetY1() + dy;
545 Double_t newx2 = gPad->GetX2() + dx;
546 Double_t newy2 = gPad->GetY2() + dy;
547 gPad->Range( newx1, newy1, newx2, newy2 );
548 gPad->Modified();
549 ViewCenter[0] = ( newx1 + newx2 ) / 2;
550 ViewCenter[1] = ( newy1 + newy2 ) / 2;
551
552 // Double_t scale[3], center[3];
553 // Int_t irep;
554 // FindScope(&scale[0], &center[0], irep);
555 // cout << "scale " << scale[0] << " " << scale[1] << " " << scale[2] << endl;
556 // cout << "center " << center[0] << " " << center[1] << " " << center[2] << endl;
557
558 // Double_t extent = GetExtent();
559 // cout << extent << endl;
560 // cout << GetZoomRatio() << endl;
561
562 /*
563 Double_t x1, y1, x2, y2;
564 x1 = gPad->GetX1();
565 y1 = gPad->GetY1();
566 x2 = gPad->GetX2();
567 y2 = gPad->GetY2();
568
569 Double_t dx = (gPad->GetX2() - gPad->GetX1())*(1-1/fZoomFactor);
570 Double_t dy = (gPad->GetY2() - gPad->GetY1())*(1-1/fZoomFactor);
571
572 gPad->Range(x1+dx/2, y1+dy/2, x2-dx/2, y2-dy/2);
573 gPad->Modified();
574 */
575}
576
577//_____________________________________________________
578
580 //
581 // Demagnify
582 // Long Peixun's update: Move pad and let Pad center be ViewCenter
583 Double_t dx = ( 1 / fZoomFactor - 1 ) * ViewCenter[0];
584 Double_t dy = ( 1 / fZoomFactor - 1 ) * ViewCenter[1];
585
586 fMarkerSize = fMarkerSize / fZoomFactor;
587 UnzoomView( gPad, fZoomFactor ); // dont use ZoomView as it is not base on center
588
589 fStatusCurrent->fZoom = GetZoomRatio();
590 fStatusXY->fZoom = GetZoomRatio();
591 fStatusZR->fZoom = GetZoomRatio();
592 fStatus3D->fZoom = GetZoomRatio();
593
594 // Long Peixun's update: Move pad and let Pad center be ViewCenter
595 Double_t newx1 = gPad->GetX1() + dx;
596 Double_t newy1 = gPad->GetY1() + dy;
597 Double_t newx2 = gPad->GetX2() + dx;
598 Double_t newy2 = gPad->GetY2() + dy;
599 gPad->Range( newx1, newy1, newx2, newy2 );
600 gPad->Modified();
601 ViewCenter[0] = ( newx1 + newx2 ) / 2;
602 ViewCenter[1] = ( newy1 + newy2 ) / 2;
603
604 // Double_t extent = GetExtent();
605 // cout << extent << endl;
606 // cout << GetZoomRatio() << endl;
607
608 /*
609 Double_t x1, y1, x2, y2;
610 x1 = gPad->GetX1();
611 y1 = gPad->GetY1();
612 x2 = gPad->GetX2();
613 y2 = gPad->GetY2();
614
615 Double_t dx = (gPad->GetX2() - gPad->GetX1())*(fZoomFactor-1);
616 Double_t dy = (gPad->GetY2() - gPad->GetY1())*(fZoomFactor-1);
617
618 gPad->Range(x1-dx/2, y1-dy/2, x2+dx/2, y2+dy/2);
619 gPad->Modified();
620 */
621}
622
623//_____________________________________________________
624
625Int_t BesView::GetRSign( Float_t Phi ) {
626 //
627 // Get sign of the R coordinate (ZR view)
628 // for a given phi (in radians)
629 Int_t Sign;
630
631 // Convert to deg, because phi range is given in degrees
632 Float_t Phi2 =
633 ( Phi - 2 * TMath::Pi() * Int_t( Phi / ( 2 * TMath::Pi() ) ) ) * 180. / TMath::Pi();
634 if ( Phi2 < 0 ) Phi2 += 360;
635 if ( Phi2 >= fStatusCurrent->fPhiRangeMin && Phi2 < fStatusCurrent->fPhiRangeMax )
636 { Sign = 1; }
637 else { Sign = -1; }
638 return Sign;
639}
640
641//_____________________________________________________
642
643void BesView::SetPhiRange( Float_t PhiMin, Float_t PhiMax ) {
644 //
645 // Set phi range for ZR view
646 if ( gDebug ) cout << "BesView::SetPhiRange called" << endl;
647
648 fStatusCurrent->fPhiRangeMin = PhiMin;
649 fStatusCurrent->fPhiRangeMax = PhiMax;
650
651 // Update view
652 if ( !gBesGeometry ) return;
653 // gEvent->AddBACPadTowerZR();
654 UpdateView( 0 );
655}
656
657//_____________________________________________________
658
659void BesView::UpdateView( Bool_t resetview ) {
660 //
661 // Update current view
662 if ( !gBesGeometry ) return;
663
664 // Redraw
665 SetViewType( fViewType, resetview );
666}
667
668// void BesView::Plot_Et_Eta_Phi() {
669// //
670// // View Et_eta_phi histogram
671// static TCanvas *c_hist = new TCanvas("c_eta_phi", "Eta Phi Histogram",
672// 400, 300);
673// c_hist->cd();
674// gEvent->GetHistEt_eta_phi()->Draw("Lego2");
675// }
676
678 //
679 // Draw label for current view
680
681 fLabel->SetX1( -0.9 );
682 fLabel->SetX2( -0.6 );
683 fLabel->SetY1( -0.9 );
684 fLabel->SetY2( -0.78 );
685
686 switch ( fViewType )
687 {
688 case k3DView: fLabel->SetLabel( "3D View" ); break;
689 case kXYView: fLabel->SetLabel( "XY View" ); break;
690 case kZRView: fLabel->SetLabel( "ZR View" ); break;
691 // Long Peixun's update: CGEM Unfolded display for each layer
692 case kCgemUFView0: fLabel->SetLabel( "CGEM Layer0" ); break;
693 case kCgemUFView1: fLabel->SetLabel( "CGEM Layer1" ); break;
694 case kCgemUFView2: fLabel->SetLabel( "CGEM Layer2" ); break;
695 }
696 fLabel->Draw( "BR,NDC,SAME" );
697
698 /*
699 switch (fViewType) {
700 case k3DView:
701 fLabel->DrawPaveLabel(0.02,0.02,0.17,0.09, "3D View", "BR,NDC,SAME");
702 break;
703 case kXYView:
704 //fLabel->SetLabel("XY View");
705 fLabel->DrawPaveLabel(0.02,0.02,0.17,0.09, "XY View", "BR,NDC,SAME");
706 break;
707 case kZRView:
708 fLabel->DrawPaveLabel(0.02,0.02,0.17,0.09, "ZR View", "BR,NDC,SAME");
709 break;
710 }
711 */
712}
713
714//_____________________________________________________
715
716void BesView::WCtoNDC( const Float_t* pw, Float_t* pn ) {
717 //
718 // Transform world coordinates to
719 // normalised device coordinates.
720 // This method was taken from BesTView
721 // and extended by FishEye view
722 BesTView::WCtoNDC( pw, pn );
723 // cout << "fFishEye " << fFishEye << endl;
724
725 if ( fStatusCurrent->fFishEye == kTRUE )
726 {
727 Float_t r, s;
728 if ( fViewType & kZRView )
729 {
730 Float_t pvWC[3], pvNDC[3];
731 pvWC[0] = +4;
732 pvWC[1] = 0;
733 pvWC[2] = 0;
734 BesTView::WCtoNDC( pvWC, pvNDC );
735 pn[0] = TMath::Sign( Double_t( TMath::Sqrt( TMath::Abs( pn[0] - pvNDC[0] ) ) ),
736 Double_t( pn[0] - pvNDC[0] ) ) +
737 pvNDC[0];
738 pn[1] = TMath::Sign( Double_t( TMath::Sqrt( TMath::Abs( pn[1] - pvNDC[1] ) ) ),
739 Double_t( pn[1] - pvNDC[1] ) ) +
740 pvNDC[1];
741 }
742 else
743 {
744 r = TMath::Sqrt( TMath::Power( pn[0], 2 ) + TMath::Power( pn[1], 2 ) );
745 s = TMath::Sqrt( r ) / r;
746 pn[0] *= s;
747 pn[1] *= s;
748 }
749 }
750}
751
752//_____________________________________________________
753
754void BesView::WCtoNDC( const Double_t* pw, Double_t* pn ) {
755 //
756 // Transform world coordinates to
757 // normalised device coordinates.
758 // This method was taken from BesTView
759 // and extended by FishEye view
760 BesTView::WCtoNDC( pw, pn );
761
762 if ( fStatusCurrent->fFishEye == kTRUE )
763 {
764 Double_t r, s;
765 if ( fViewType & kZRView )
766 {
767 Double_t pvWC[3], pvNDC[3];
768 pvWC[0] = +4;
769 pvWC[1] = 0;
770 pvWC[2] = 0;
771 BesTView::WCtoNDC( pvWC, pvNDC );
772 pn[0] = TMath::Sign( TMath::Sqrt( TMath::Abs( pn[0] - pvNDC[0] ) ), pn[0] - pvNDC[0] ) +
773 pvNDC[0];
774 pn[1] = TMath::Sign( TMath::Sqrt( TMath::Abs( pn[1] - pvNDC[1] ) ), pn[1] - pvNDC[1] ) +
775 pvNDC[1];
776 }
777 else
778 {
779
780 r = TMath::Sqrt( TMath::Power( pn[0], 2 ) + TMath::Power( pn[1], 2 ) );
781 s = TMath::Sqrt( r ) / r;
782 pn[0] *= s;
783 pn[1] *= s;
784 }
785 }
786}
787
788//_____________________________________________________
789
790void BesView::NDCtoWC( const Float_t* pn, Float_t* pw ) {
791 //
792 // Transform back from NDCs
793 Float_t p[3];
794 p[0] = pn[0];
795 p[1] = pn[1];
796 p[2] = pn[2];
797
798 if ( fStatusCurrent->fFishEye == kTRUE )
799 {
800 Float_t r;
801 if ( fViewType & kZRView )
802 {
803 Float_t pvWC[3], pvNDC[3];
804 pvWC[0] = +4;
805 pvWC[1] = 0;
806 pvWC[2] = 0;
807 BesTView::WCtoNDC( pvWC, pvNDC );
808 p[0] = TMath::Sign( ( pn[0] - pvNDC[0] ) * ( pn[0] - pvNDC[0] ), pn[0] - pvNDC[0] ) +
809 pvNDC[0];
810 p[1] = TMath::Sign( ( pn[1] - pvNDC[1] ) * ( pn[1] - pvNDC[1] ), pn[1] - pvNDC[1] ) +
811 pvNDC[1];
812 }
813 else
814 {
815 r = TMath::Sqrt( TMath::Power( p[0], 2 ) + TMath::Power( p[1], 2 ) );
816 p[0] *= r;
817 p[1] *= r;
818 }
819 }
820 BesTView::NDCtoWC( p, pw );
821}
822
823//_____________________________________________________
824
825void BesView::NDCtoWC( const Double_t* pn, Double_t* pw ) {
826 //
827 // Transform back from NDCs
828 Double_t p[3];
829 p[0] = pn[0];
830 p[1] = pn[1];
831 p[2] = pn[2];
832
833 if ( fStatusCurrent->fFishEye == kTRUE )
834 {
835 Double_t r;
836 if ( fViewType & kZRView )
837 {
838 Double_t pvWC[3], pvNDC[3];
839 pvWC[0] = +4;
840 pvWC[1] = 0;
841 pvWC[2] = 0;
842 BesTView::WCtoNDC( pvWC, pvNDC );
843 p[0] = TMath::Sign( ( pn[0] - pvNDC[0] ) * ( pn[0] - pvNDC[0] ), pn[0] - pvNDC[0] ) +
844 pvNDC[0];
845 p[1] = TMath::Sign( ( pn[1] - pvNDC[1] ) * ( pn[1] - pvNDC[1] ), pn[1] - pvNDC[1] ) +
846 pvNDC[1];
847 }
848 else
849 {
850 r = TMath::Sqrt( TMath::Power( p[0], 2 ) + TMath::Power( p[1], 2 ) );
851 p[0] *= r;
852 p[1] *= r;
853 }
854 }
855 BesTView::NDCtoWC( p, pw );
856}
857
858//_____________________________________________________
859
861 //
862 // set side view for 3D
863
864 this->SetViewType( k3DView, 1 );
865 Int_t iret;
866 this->SetView( 0, 90, 270, iret );
867}
868
869//_____________________________________________________
870
871char* BesView::GetObjectInfo( Int_t px, Int_t py ) const {
872 //
873 // Returns string containing info about the object at position (px,py).
874 Double_t pw[3];
875 Double_t Pndc[3] = { gPad->AbsPixeltoX( px ), gPad->AbsPixeltoY( py ), 0 };
876 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
877 if ( view )
878 view->NDCtoWC( Pndc, pw ); // Long Peixun's update: check view pointer before call function
879 // cout << gPad->GetName() << endl;
880
881 //
882 // Converts from pixel coordinates to world
883 // coordinates of according view
884
885 static char info[64];
886 if ( fViewType & kZRView )
887 {
888 sprintf( info, "z=%-.3fmm, r=%-.3fmm", pw[2], pw[1] );
889 return info;
890 }
891 else
892 {
893 sprintf( info, "x=%-.3fmm, y=%-.3fmm", pw[0], pw[1] );
894 return info;
895 }
896}
897
898//_____________________________________________________
899
901 //
902 // reset view to default values
903
904 // reset status instances of views
905 fStatus3D->Default( k3DView );
906 fStatusXY->Default( kXYView );
907 fStatusZR->Default( kZRView );
908 fZoomFactor = 1.2;
909
910 // reset current status instance tp fViewType
911 fStatusCurrent->Default( fViewType );
912
913 // reset phirange
914 // this->SetPhiRange(0,180);
915 this->UpdateView( 1 );
916 gPad->Update();
917}
918
919//______________________________________________________
920// Long Peixun's update: refresh view's values
922 // Reset status instances of views
923 fStatus3D->Default( k3DView );
924 fStatusXY->Default( kXYView );
925 fStatusZR->Default( kZRView );
926
927 // Refresh status instances of views
928 switch ( fViewType )
929 {
930 case k3DView: fStatus3D->Transfer( fStatusCurrent, 1 ); break;
931 case kXYView: fStatusXY->Transfer( fStatusCurrent, 1 ); break;
932 case kZRView: fStatusZR->Transfer( fStatusCurrent, 1 ); break;
933 }
934
935 this->UpdateView( 1 );
936 gPad->Update();
937}
ClassImp(BesView) BesView
Definition BesView.cxx:21
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)
#define PhiMax
#define PhiMin
R__EXTERN BesGeometry * gBesGeometry
XmlRpcServer s
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)
virtual void SetParallel()
virtual void SetView(Double_t longitude, Double_t latitude, Double_t psi, Int_t &irep)
virtual void ExecuteRotateView(Int_t event, Int_t px, Int_t py)
Definition BesTView.cxx:741
virtual void SetPerspective()
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition BesView.cxx:716
void ZoomIn()
Definition BesView.cxx:527
virtual ~BesView()
Definition BesView.cxx:75
virtual Int_t GetRSign(Float_t Phi)
Definition BesView.cxx:625
void Move(Int_t px, Int_t py)
Definition BesView.cxx:433
virtual void UpdateView(Bool_t resetview=kFALSE)
Definition BesView.cxx:659
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition BesView.cxx:871
virtual void ClearPad()
Definition BesView.cxx:359
void Center()
Definition BesView.cxx:480
void SetPhiRange(Float_t PhiMin=0, Float_t PhiMax=180)
Definition BesView.cxx:643
virtual void SetViewTypeBare(EBESViewType ViewType, Bool_t resetview=kFALSE)
Definition BesView.cxx:257
void Side3D()
Definition BesView.cxx:860
void ZoomOut()
Definition BesView.cxx:579
virtual void SetViewType(EBESViewType ViewType, Bool_t resetview=kFALSE)
Definition BesView.cxx:97
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition BesView.cxx:371
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)
Definition BesView.cxx:790
void Refresh()
Definition BesView.cxx:921
virtual void DefaultRange()
Definition BesView.cxx:90
void SetZoomRatio(Double_t ratio)
Definition BesView.cxx:499
void Reset()
Definition BesView.cxx:900
virtual void DrawLabel()
Definition BesView.cxx:677