BOSS 7.0.4
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 //
49 // Bes2DView normal constructor
50 if ( gDebug ) cout << "Bes2DView normal ctor called" << endl;
51
52 // init Label
53 fLabel = new TPaveLabel(0.02,0.17,0.02,0.09,"3D View");
54 fLabel->SetFillColor(42);
55
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//_____________________________________________________
98
100 //
101 // Clear current without deleting this view
102 //
103 // Probably this doesn't work for the postscript output
104 // Look at TPad::Clear() for more details
105 if ( gDebug ) cout << "Bes2DView::ClearPad called" << endl;
106 if ( gPad->GetListOfPrimitives() ) gPad->GetListOfPrimitives()->Clear();
107}
108
109//_____________________________________________________
110
111void Bes2DView::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
112 //
113 // Execute mouse events
114 if ( gDebug ) cout << "Bes2DView::ExecuteEvent called" << endl;
115 //cout << "f2DViewType " << f2DViewType << " k3DView " << k3DView << endl;
116
117 /*
118 if ( fViewType & k3DView ) {
119 ExecuteRotateView(event, px, py);
120 } else {
121 */
122
123 // Editor mode
124 if (gROOT->GetEditorMode()) {
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 case kButton1Down:
135 gPad->SetCursor(kMove);
136 // Remember position of pointer
137 xmin = gPad->GetX1();
138 ymin = gPad->GetY1();
139 xmax = gPad->GetX2();
140 ymax = gPad->GetY2();
141 x0 = gPad->AbsPixeltoX(px);
142 y0 = gPad->AbsPixeltoY(py);
143 break;
144
145 case kButton1Motion:
146 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:
161 gPad->SetCursor(kCross);
162 }
163}
164
165//_____________________________________________________
166
167void Bes2DView::Move(Int_t px, Int_t py) {
168 //
169 // Move (px, py in pixel coordinates)
170 Double_t x1, y1, x2, y2, dx, dy, x, y, x0, y0;
171 x1 = gPad->GetX1();
172 y1 = gPad->GetY1();
173 x2 = gPad->GetX2();
174 y2 = gPad->GetY2();
175 x0 = gPad->PixeltoX(0);
176 y0 = gPad->PixeltoY(0);
177 x = gPad->PixeltoX(px);
178 y = gPad->PixeltoY(py);
179 dx = -(x - x0);
180 dy = -(y - y0);
181 //((TPad*)gPad)->SetNoAspect(kTRUE);
182 gPad->Range(x1+dx, y1+dy, x2+dx, y2+dy);
183 //((TPad*)gPad)->SetNoAspect(kFALSE);
184 gPad->Modified();
185}
186
187//_____________________________________________________
188
190 //
191 // Center view
192 /*
193 if ( fViewType & k3DView ){
194 this->Centered();
195 } else {
196 */
197 Double_t xrange, yrange;
198 xrange = gPad->GetX2() - gPad->GetX1();
199 yrange = gPad->GetY2() - gPad->GetY1();
200 gPad->Range(-xrange/2, -yrange/2, xrange/2, yrange/2);
201 gPad->Modified();
202}
203
204//_____________________________________________________
205
207 //
208 // Magnify
209 fMarkerSize = fMarkerSize * fZoomFactor;
210 ZoomView(gPad, fZoomFactor);
211}
212
213//_____________________________________________________
214
216 //
217 // Demagnify
218 fMarkerSize = fMarkerSize / fZoomFactor;
219 UnzoomView(gPad, fZoomFactor);
220}
221
222//_____________________________________________________
223
224Int_t Bes2DView::GetRSign(Float_t Phi) {
225 //
226 // Get sign of the R coordinate (ZR view)
227 // for a given phi (in radians)
228 Int_t Sign;
229
230 // Convert to deg, because phi range is given in degrees
231 Float_t Phi2 = (Phi - 2*TMath::Pi()*Int_t(Phi/(2*TMath::Pi())))
232 * 180./TMath::Pi();
233 if ( Phi2 < 0 ) Phi2 += 360;
234 if ( Phi2 >= fStatusCurrent->fPhiRangeMin && Phi2 < fStatusCurrent->fPhiRangeMax ) {
235 Sign = 1;
236 } else {
237 Sign = -1;
238 }
239 return Sign;
240}
241
242
243//_____________________________________________________
244
245void Bes2DView::UpdateView(Bool_t resetview) {
246 //
247 // Update current view
248 if ( !gGeometry ) return;
249
250 // Redraw
251 //SetViewType(fViewType,resetview);
252}
253
254
255
256
258 //
259 // Draw label for current view
260
261 fLabel->SetX1NDC(0.05);
262 fLabel->SetX2NDC(0.20);
263 fLabel->SetY1NDC(0.05);
264 fLabel->SetY2NDC(0.12);
265
266 switch (f2DViewType) {
267 //case k3DView:
268 //fLabel->SetLabel("3D View");
269 //break;
270 case 0:
271 fLabel->SetLabel("XY View");
272 break;
273 case 1:
274 fLabel->SetLabel("ZR View");
275 break;
276 }
277 fLabel->Draw("BR,NDC,SAME");
278}
279
280//_____________________________________________________
281
282void Bes2DView::WCtoNDC(const Float_t *pw, Float_t *pn) {
283 //
284 // Transform world coordinates to
285 // normalised device coordinates.
286 // This method was taken from BesTView
287 // and extended by FishEye view
288 BesTView::WCtoNDC(pw, pn);
289 //cout << "fFishEye " << fFishEye << endl;
290
291 if ( fStatusCurrent->fFishEye == kTRUE ) {
292 Float_t r, s;
293 if ( f2DViewType == 1) {
294 Float_t pvWC[3], pvNDC[3];
295 pvWC[0] = +4;
296 pvWC[1] = 0;
297 pvWC[2] = 0;
298 BesTView::WCtoNDC(pvWC, pvNDC);
299 pn[0] = TMath::Sign(Double_t(TMath::Sqrt(TMath::Abs(pn[0] - pvNDC[0]))),
300 Double_t(pn[0] - pvNDC[0])) + pvNDC[0];
301 pn[1] = TMath::Sign(Double_t(TMath::Sqrt(TMath::Abs(pn[1] - pvNDC[1]))),
302 Double_t(pn[1] - pvNDC[1])) + pvNDC[1];
303 } else {
304 r = TMath::Sqrt(TMath::Power(pn[0],2)
305 +TMath::Power(pn[1],2));
306 s = TMath::Sqrt(r)/r;
307 pn[0] *= s;
308 pn[1] *= s;
309 }
310 }
311}
312
313//_____________________________________________________
314
315void Bes2DView::WCtoNDC(const Double_t *pw, Double_t *pn) {
316 //
317 // Transform world coordinates to
318 // normalised device coordinates.
319 // This method was taken from BesTView
320 // and extended by FishEye view
321 BesTView::WCtoNDC(pw, pn);
322
323 if ( fStatusCurrent->fFishEye == kTRUE ) {
324 Double_t r, s;
325 if ( f2DViewType == 1 ) {
326 Double_t pvWC[3], pvNDC[3];
327 pvWC[0] = +4;
328 pvWC[1] = 0;
329 pvWC[2] = 0;
330 BesTView::WCtoNDC(pvWC, pvNDC);
331 pn[0] = TMath::Sign(TMath::Sqrt(TMath::Abs(pn[0] - pvNDC[0])),
332 pn[0] - pvNDC[0]) + pvNDC[0];
333 pn[1] = TMath::Sign(TMath::Sqrt(TMath::Abs(pn[1] - pvNDC[1])),
334 pn[1] - pvNDC[1]) + pvNDC[1];
335 } else {
336
337 r = TMath::Sqrt(TMath::Power(pn[0],2)
338 +TMath::Power(pn[1],2));
339 s = TMath::Sqrt(r)/r;
340 pn[0] *= s;
341 pn[1] *= s;
342 }
343 }
344}
345
346//_____________________________________________________
347
348void Bes2DView::NDCtoWC(const Float_t* pn, Float_t* pw) {
349 //
350 // Transform back from NDCs
351 Float_t p[3];
352 if (f2DViewType == 0) { // XYView
353 p[0] = pn[0];
354 p[1] = pn[1];
355 p[2] = pn[2];
356 }
357 else { // ZRView
358 p[0] = pn[2];
359 p[1] = pn[1];
360 p[2] = pn[0];
361 }
362
363 if ( fStatusCurrent->fFishEye == kTRUE ) {
364 Float_t r;
365 if ( f2DViewType == 1 ) {
366 Float_t pvWC[3], pvNDC[3];
367 pvWC[0] = +4;
368 pvWC[1] = 0;
369 pvWC[2] = 0;
370 BesTView::WCtoNDC(pvWC, pvNDC);
371 p[0] = TMath::Sign((pn[0] - pvNDC[0])*(pn[0] - pvNDC[0]),
372 pn[0] - pvNDC[0]) + pvNDC[0];
373 p[1] = TMath::Sign((pn[1] - pvNDC[1])*(pn[1] - pvNDC[1]),
374 pn[1] - pvNDC[1]) + pvNDC[1];
375 } else {
376 r = TMath::Sqrt(TMath::Power(p[0],2)
377 +TMath::Power(p[1],2));
378 p[0] *= r;
379 p[1] *= r;
380 }
381 }
382 BesTView::NDCtoWC(p, pw);
383}
384
385//_____________________________________________________
386
387void Bes2DView::NDCtoWC(const Double_t* pn, Double_t* pw) {
388 //
389 // Transform back from NDCs
390 Double_t p[3];
391 if (f2DViewType == 0) { // XYView
392 p[0] = pn[0];
393 p[1] = pn[1];
394 p[2] = pn[2];
395 }
396 else { // ZRView
397 p[0] = pn[2];
398 p[1] = pn[1];
399 p[2] = pn[0];
400 }
401
402 if ( fStatusCurrent->fFishEye == kTRUE ) {
403 Double_t r;
404 if ( f2DViewType == 1 ) {
405 Double_t pvWC[3], pvNDC[3];
406 pvWC[0] = +4;
407 pvWC[1] = 0;
408 pvWC[2] = 0;
409 BesTView::WCtoNDC(pvWC, pvNDC);
410 p[0] = TMath::Sign((pn[0] - pvNDC[0])*(pn[0] - pvNDC[0]),
411 pn[0] - pvNDC[0]) + pvNDC[0];
412 p[1] = TMath::Sign((pn[1] - pvNDC[1])*(pn[1] - pvNDC[1]),
413 pn[1] - pvNDC[1]) + pvNDC[1];
414 } else {
415 r = TMath::Sqrt(TMath::Power(p[0],2)
416 +TMath::Power(p[1],2));
417 p[0] *= r;
418 p[1] *= r;
419 }
420 }
421 BesTView::NDCtoWC(p, pw);
422}
423
424//_____________________________________________________
425
426char *Bes2DView::GetObjectInfo(Int_t px, Int_t py) const {
427 //
428 // Returns string containing info about the object at position (px,py).
429 Double_t pw[3];
430 //((TPad*)gPad)->PixeltoWC(px, py, pw);
431
432 static char info[64];
433 if ( f2DViewType == 1 ) {
434 sprintf(info, "z=%-.3fcm, r=%-.3fcm", pw[0], pw[1]);
435 return info;
436 } else {
437 sprintf(info, "x=%-.3fcm, y=%-.3fcm", pw[0], pw[1]);
438 return info;
439 }
440}
441
442//_____________________________________________________
443
445 //
446 // reset view to default values
447
448 // reset status instances of views
449 //fStatus3D->Default(k3DView);
450 //fStatusXY->Default(kXYView);
451 //fStatusZR->Default(kZRView);
452 fZoomFactor = 1.5;
453
454 // reset current status instance tp fViewType
455 //fStatusCurrent->Default(fViewType);
456
457 // center the view
458 this->Center();
459 this->SetRange(-2635,-2635,-2875,2635,2635,2875);
460 //int iret;
461 //this->SetView(0,0,270,iret);
462 this->ZoomView(gPad, 1.5);
463
464 // reset phirange
465 // this->SetPhiRange(0,180);
466 //this->UpdateView();
467 gPad->Update();
468}
ClassImp(Bes2DView) Bes2DView
Definition: Bes2DView.cxx:40
double Phi(RecMdcKalTrack *trk)
Double_t x[10]
XmlRpcServer s
Definition: HelloServer.cpp:11
virtual void DrawLabel()
Definition: Bes2DView.cxx:257
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition: Bes2DView.cxx:426
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition: Bes2DView.cxx:282
virtual void ClearPad()
Definition: Bes2DView.cxx:99
virtual void NDCtoWC(const Float_t *pn, Float_t *pw)
Definition: Bes2DView.cxx:348
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: Bes2DView.cxx:111
virtual Int_t GetRSign(Float_t Phi)
Definition: Bes2DView.cxx:224
void UnZoom()
Definition: Bes2DView.cxx:215
void Zoom()
Definition: Bes2DView.cxx:206
void Center()
Definition: Bes2DView.cxx:189
virtual void UpdateView(Bool_t resetview=kFALSE)
Definition: Bes2DView.cxx:245
void Reset()
Definition: Bes2DView.cxx:444
void Move(Int_t px, Int_t py)
Definition: Bes2DView.cxx:167
virtual ~Bes2DView()
Definition: Bes2DView.cxx:83
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
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)