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