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