/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventDisplay/BesVisLib/BesVisLib-00-04-04/src/BesView.cxx

Go to the documentation of this file.
00001 //
00002 // BesView.cxx
00003 //
00004 
00005 #include <TROOT.h>
00006 #include <TCanvas.h>
00007 #include <TPad.h>
00008 #include <TPaveLabel.h>
00009 #include <iostream>
00010 #include "math.h"
00011 #include "TMath.h"
00012 
00013 #include "BesVisLib/BesView.h"
00014 #include "BesVisLib/BesGeometry.h"
00015 #include "BesVisLib/BesEvent.h"
00016 #include "BesVisLib/BesCursor.h"
00017 
00018 using namespace std;
00019 
00020 #ifndef __CINT__
00021 ClassImp(BesView)
00022 #endif
00023 
00024 //_____________________________________________________
00025 // BesView
00026 // View class designed for the BesVis display
00027 //
00028 BesView::BesView() : BesTView(1) {
00029     //
00030     // BesView normal constructor
00031     if ( gDebug ) cout << "BesView normal ctor called" << endl;
00032 
00033     // init Label
00034     fLabel = new TPaveLabel(0.02,0.17,0.02,0.09,"3D View");
00035     fLabel->SetFillColor(42);
00036 
00037     // init status of 3D view
00038     fStatus3D = new BesStatus();
00039     fStatus3D->Default(k3DView);
00040 
00041     // init status of XY view
00042     fStatusXY = new BesStatus();
00043     fStatusXY->Default(kXYView);
00044 
00045     // init status of ZR view
00046     fStatusZR = new BesStatus();
00047     fStatusZR->Default(kZRView);
00048 
00049     // init status of current view
00050     fStatusCurrent = new BesStatus();
00051 
00052     // Init
00053     fViewType = k3DView;
00054     fStatusCurrent->Transfer(fStatus3D,1);
00055     if ( !gBesGeometry ) {
00056         cout << "BesGeometry does not exist! " << endl;
00057         return;
00058     }
00059 
00060     m_BesR = gBesGeometry->GetBesR();
00061     m_BesZ = gBesGeometry->GetBesZ();
00062     DefaultRange();
00063     fExtentDefault = GetExtent();
00064 
00065     fZoomFactor = 1.2;
00066     fMarkerSize = 0.1;
00067 }
00068 
00069 //_____________________________________________________
00070 
00071 BesView::~BesView() {
00072     //
00073     // BesView default destructor
00074     if ( gDebug ) cout << "BesView default dtor called" << endl;
00075 
00076     delete fLabel;
00077 
00078     delete fStatus3D;
00079     delete fStatusXY;
00080     delete fStatusZR;
00081     delete fStatusCurrent;
00082 
00083 }
00084 
00085 //_____________________________________________________
00086 
00087 void BesView::DefaultRange()
00088 {
00089     SetRange(-1.0*m_BesR, -1.0*m_BesR, -0.5*m_BesZ, m_BesR, m_BesR, 0.5*m_BesZ);
00090 }
00091 
00092 //_____________________________________________________
00093 
00094 void BesView::SetViewType(EBESViewType ViewType, Bool_t resetview) {
00095     //
00096     // Set type of view
00097 
00098     // check the state of the component before change and copy current status to respective status
00099     if ( fViewType & k3DView ){
00100 
00101         fStatus3D->Transfer(fStatusCurrent,0);
00102 
00103     } else if ( fViewType & kXYView ) {
00104 
00105         fStatusXY->Transfer(fStatusCurrent,0);
00106 
00107     } else if ( fViewType & kZRView ) {
00108 
00109         fStatusZR->Transfer(fStatusCurrent,0);
00110 
00111     }
00112 
00113     fViewType = ViewType;
00114     ClearPad();
00115 
00116     // Set view direction properly
00117     Int_t iret;
00118     if ( fViewType & k3DView ) {
00119         //cout << "SetViewType 3D" << endl;
00120         //
00121         // 3D view
00122 
00123         // remember my previous state, set parallel first anyway, then choose perspective or not
00124         Int_t iPerspective = 0;
00125 
00126         if (IsPerspective()) iPerspective = 1;
00127 
00128         // copy 3D status to current status
00129         fStatusCurrent->Transfer(fStatus3D,1);
00130 
00131         // Geometry exist ?
00132         if ( !gBesGeometry ) return;
00133 
00134         // set view
00135         if ( resetview ) {
00136             //SetView(0, 90, 270, iret);
00137             this->Front();
00138             this->Center();
00139 
00140             DefaultRange();
00141             for (int i = 0; i < 2; i++) this->ZoomView(gPad, fZoomFactor);
00142 
00143             // reset marker size
00144             fMarkerSize = 0.1;
00145         }
00146 
00147         // Draw geometry
00148 
00149         cout << "is there any problem after update from root's version 4.03 to 4.04" << endl;
00150         gBesGeometry->Draw("3D,SAME");
00151         //this->SetParralel();       //comment out 2007.5.1 try to use ROOT-5.10.00
00152         this->SetParallel();
00153         //old version 4.0.3 have a spell mistake BesTView::SetParralel()=>SetParallel()
00154         //changed by tianhl at Mon Aug 20 2007
00155         if (iPerspective == 1) this->SetPerspective();
00156 
00157         // Draw tracks
00158         if ( gEvent ) gEvent->DrawTracks("");
00159         //else cout << "3D gEvent does not exist " << endl;
00160 
00161     } else if ( fViewType & kXYView ) {
00162         //cout << "SetViewType XY" << endl;
00163         //
00164         // XY view
00165         // =======
00166 
00167         // copy XY status to current status
00168         fStatusCurrent->Transfer(fStatusXY,1);
00169 
00170         // Geometry exist ?
00171         if ( !gBesGeometry ) return;
00172 
00173         // set view
00174         if ( resetview ) {
00175             SetView(0, 0, 270, iret);
00176             this->Center();
00177 
00178             DefaultRange();
00179             DefaultRange();
00180             for (int i = 0; i < 2; i++) this->ZoomView(gPad, fZoomFactor);
00181 
00182             // reset marker size
00183             fMarkerSize = 0.1;
00184 
00185         }
00186 
00187         /*
00188         // Draw event
00189         if ( gEvent ) gEvent->SetHits("XY");
00190         else cout << "XY : gEvent does not exist " << endl;
00191         */
00192 
00193         // Draw geometry
00194         gBesGeometry->Draw("XY,SAME");
00195 
00196         // Draw 2D hits and tracks
00197         if ( gEvent ) {
00198             gEvent->DrawHits("");
00199             gEvent->DrawTracks("");
00200         }
00201         //else cout << "XY : gEvent does not exist " << endl;
00202 
00203     } else if ( fViewType & kZRView ) {
00204         //cout << "SetViewType ZR" << endl;
00205         //
00206         // ZR view
00207         // =======
00208 
00209         // copy ZR status to current status
00210         fStatusCurrent->Transfer(fStatusZR,1);
00211 
00212         // Geometry exist ?
00213         if ( !gBesGeometry ) return;
00214 
00215         // set view
00216         if ( resetview ) {
00217             SetView(180,90,90,iret);
00218             this->Center();
00219 
00220             DefaultRange();
00221             DefaultRange();
00222             for (int i = 0; i < 2; i++) this->ZoomView(gPad, fZoomFactor);
00223 
00224             // reset marker size
00225             fMarkerSize = 0.1;
00226 
00227         }
00228 
00229         /*
00230         // Draw event
00231         if ( gEvent ) gEvent->SetHits("ZR");
00232         else cout << "ZR : gEvent does not exist " << endl;
00233         */
00234 
00235         // Draw geometry
00236         gBesGeometry->Draw("ZR,SAME");
00237 
00238         // Draw hits and tracks
00239         if ( gEvent ) {
00240             gEvent->DrawHits("");
00241             gEvent->DrawTracks("");
00242         }
00243         //else cout << "ZR : gEvent does not exist " << endl;
00244 
00245     }
00246 
00247     // Draw label
00248     DrawLabel();
00249 }
00250 
00251 void BesView::SetViewTypeBare(EBESViewType ViewType, Bool_t resetview) {
00252     /*
00253     //
00254     // Set type of view
00255 
00256     cout << "setviewtypeBare: start..." << endl;
00257     // check the state of the component before change and copy current status to respective status
00258     if ( fViewType & k3DView ){
00259 
00260       fStatus3D->Transfer(fStatusCurrent,0);
00261 
00262     } else if ( fViewType & kXYView ) {
00263 
00264       fStatusXY->Transfer(fStatusCurrent,0);
00265 
00266     } else if ( fViewType & kZRView ) {
00267 
00268 
00269       fStatusZR->Transfer(fStatusCurrent,0);
00270 
00271     }
00272 
00273     fViewType = ViewType;
00274     ClearPad();
00275 
00276     // Set view direction properly
00277     Int_t iret;
00278     cout << "fViewType=" << fViewType << endl;
00279     if ( fViewType & k3DView ) {
00280       //
00281       // 3D view
00282 
00283       // copy 3D status to current status
00284       fStatusCurrent->Transfer(fStatus3D,1);
00285       // Geometry exist ?
00286       if ( !gGeometry ) return;
00287 
00288       // set view
00289       if ( resetview ) {
00290         SetView(0, 90, 270, iret);
00291         SetRange(-600,-600,-400,600,600,800);
00292 
00293         // reset marker size
00294         fMarkerSize = 0.1;
00295 
00296       }
00297 
00298     } else if ( fViewType & kXYView ) {
00299       //
00300       // XY view
00301       // =======
00302 
00303       // copy XY status to current status
00304       fStatusCurrent->Transfer(fStatusXY,1);
00305 
00306       // Geometry exist ?
00307       if ( !gGeometry ) return;
00308 
00309       // set view
00310       if ( resetview ) {
00311         SetView(270, 0, 0, iret);
00312         // SetRange(-200,-200,-200,200,200,200);
00313         SetRange(-310,-310,-310,310,310,310);
00314         // reset marker size
00315         fMarkerSize = 0.1;
00316 
00317       }
00318 
00319     } else if ( fViewType & kZRView ) {
00320 
00321       //
00322       // ZR view
00323       // =======
00324 
00325       // copy ZR status to current status
00326       cout << "fViewType & kZRView: before transfer..." << endl;
00327       fStatusCurrent->Transfer(fStatusZR,1);
00328       cout << "fViewType & kZRView: after transfer..." << endl;
00329 
00330       // Geometry exist ?
00331       if ( !gGeometry ) return;
00332 
00333       // set view
00334       if ( resetview ) {
00335         SetView(90, 180, 0, iret);
00336         //      SetRange(-130,-200,-200,270,200,200);
00337         SetRange(-160,-400,-400,740,400,400);
00338         // reset marker size
00339         fMarkerSize = 0.1;
00340 
00341       }
00342 
00343     }
00344 
00345     // Draw label
00346     cout << "SetViewTypeBare: no drawlabel" << endl;
00347     //DrawLabel();
00348     */
00349 }
00350 
00351 //_____________________________________________________
00352 
00353 void BesView::ClearPad() {
00354     //
00355     // Clear current without deleting this view
00356     //
00357     // Probably this doesn't work for the postscript output
00358     // Look at TPad::Clear() for more details
00359     if ( gDebug ) cout << "BesView::ClearPad called" << endl;
00360     if ( gPad->GetListOfPrimitives() ) gPad->GetListOfPrimitives()->Clear();
00361 }
00362 
00363 //_____________________________________________________
00364 
00365 void BesView::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
00366     //
00367     // Execute mouse events
00368     if ( gDebug ) cout << "BesView::ExecuteEvent called" << endl;
00369 
00370     // Editor mode
00371     if (gROOT->GetEditorMode()) {
00372         gPad->ExecuteEvent(event,px,py);
00373         return;
00374     }
00375 
00376     if (gBesCursor->GetType() == kBesHand) {
00377 
00378         gPad->SetCursor(kMove);
00379         static Double_t xmin, ymin, xmax, ymax, x0, y0;
00380         Double_t dx, dy, x, y;
00381         switch (event) {
00382 
00383         case kButton1Down:
00384             // Remember position of pointer
00385             xmin = gPad->GetX1();
00386             ymin = gPad->GetY1();
00387             xmax = gPad->GetX2();
00388             ymax = gPad->GetY2();
00389             x0   = gPad->AbsPixeltoX(px);
00390             y0   = gPad->AbsPixeltoY(py);
00391             break;
00392 
00393         case kButton1Motion:
00394             gPad->SetCursor(kMove);
00395 
00396         case kButton1Up:
00397             // Set new pad range
00398             x  = gPad->AbsPixeltoX(px);
00399             y  = gPad->AbsPixeltoY(py);
00400             dx = -(x - x0);
00401             dy = -(y - y0);
00402             //((ZPad*)gPad)->SetNoAspect(kTRUE);
00403             gPad->Range(xmin+dx, ymin+dy, xmax+dx, ymax+dy);
00404             //((ZPad*)gPad)->SetNoAspect(kFALSE);
00405             gPad->Modified();
00406             break;
00407 
00408         default:
00409             gPad->SetCursor(kMove);
00410         }
00411     }
00412     else if (gBesCursor->GetType() == kBesPick){
00413 
00414         gPad->SetCursor(kPointer);
00415 
00416         if ( fViewType & k3DView ) {
00417             ExecuteRotateView(event, px, py);
00418         }
00419     }
00420 }
00421 
00422 //_____________________________________________________
00423 
00424 void BesView::Move(Int_t px, Int_t py) {
00425 
00426     /*
00427     Double_t p[3], pw[3];
00428     for (Int_t i = 0; i < 3; i++) {
00429       pw[i] = 0.5*(fRmin[i]+fRmax[i]);
00430     }
00431     cout << "pw " << pw[0] << " " << pw[1] << " " << pw[2] << endl;
00432     WCtoNDC(pw, p);
00433     cout << "p " << p[0] << " " << p[1] << " " << p[2] << endl;
00434 
00435     p[0] += (gPad->PixeltoX(0) - gPad->PixeltoX(px));
00436     p[1] += (gPad->PixeltoY(0) - gPad->PixeltoY(py));
00437     cout << "p " << p[0] << " " << p[1] << " " << p[2] << endl;
00438     NDCtoWC(p, pw);
00439     cout << "pw " << pw[0] << " " << pw[1] << " " << pw[2] << endl;
00440 
00441     MoveFocus(&pw[0], fRmax[0]-fRmin[0], fRmax[1]-fRmin[1], fRmax[2]-fRmin[2]);
00442     gPad->Modified();
00443     gPad->Update();
00444     */
00445 
00446     //
00447     // Move (px, py in pixel coordinates)
00448     Double_t x1, y1, x2, y2, dx, dy, x, y, x0, y0;
00449     x1 = gPad->GetX1();
00450     y1 = gPad->GetY1();
00451     x2 = gPad->GetX2();
00452     y2 = gPad->GetY2();
00453     x0 = gPad->PixeltoX(0);
00454     y0 = gPad->PixeltoY(0);
00455     x = gPad->PixeltoX(px);
00456     y = gPad->PixeltoY(py);
00457     dx = -(x - x0);
00458     dy = -(y - y0);
00459 
00460     gPad->Range(x1+dx, y1+dy, x2+dx, y2+dy);
00461     gPad->Modified();
00462 }
00463 
00464 //_____________________________________________________
00465 
00466 void BesView::Center() {
00467     //
00468     // Center view
00469     //if ( fViewType & k3DView ){
00470     //this->Centered();
00471     //} else {
00472     Double_t xrange, yrange;
00473     xrange = gPad->GetX2() - gPad->GetX1();
00474     yrange = gPad->GetY2() - gPad->GetY1();
00475     gPad->Range(-xrange/2, -yrange/2, xrange/2, yrange/2);
00476     gPad->Modified();
00477     //}
00478 }
00479 
00480 //_____________________________________________________
00481 
00482 void BesView::SetZoomRatio(Double_t ratio)
00483 {
00484     DefaultRange();
00485     ZoomView(gPad, ratio);
00486     
00487     //yzhang TEMP FIXME
00488     fStatusCurrent->fZoom = ratio;
00489     fStatusXY->fZoom  = ratio;
00490     fStatusZR->fZoom  = ratio;
00491 }
00492 
00493 //_____________________________________________________
00494 
00495 void BesView::ZoomIn() {
00496     //
00497     // Magnify
00498     fMarkerSize = fMarkerSize * fZoomFactor;
00499     ZoomView(gPad, fZoomFactor); // dont use ZoomView as it is not base on center
00500 
00501 
00502     fStatusCurrent->fZoom = this->GetZoomRatio();
00503     fStatusXY->fZoom  = this->GetZoomRatio();
00504     fStatusZR->fZoom  = this->GetZoomRatio();
00505     //Double_t scale[3], center[3];
00506     //Int_t irep;
00507     //FindScope(&scale[0], &center[0], irep);
00508     //cout << "scale  " << scale[0]  << "  " << scale[1]  << " " << scale[2]  << endl;
00509     //cout << "center " << center[0] << "  " << center[1] << " " << center[2] << endl;
00510 
00511     //Double_t extent = GetExtent();
00512     //cout << extent << endl;
00513     //cout << GetZoomRatio() << endl;
00514 
00515     /*
00516     Double_t x1, y1, x2, y2;
00517     x1 = gPad->GetX1();
00518     y1 = gPad->GetY1();
00519     x2 = gPad->GetX2();
00520     y2 = gPad->GetY2();
00521 
00522     Double_t dx = (gPad->GetX2() - gPad->GetX1())*(1-1/fZoomFactor);
00523     Double_t dy = (gPad->GetY2() - gPad->GetY1())*(1-1/fZoomFactor);
00524 
00525     gPad->Range(x1+dx/2, y1+dy/2, x2-dx/2, y2-dy/2);
00526     gPad->Modified();
00527     */
00528 }
00529 
00530 //_____________________________________________________
00531 
00532 void BesView::ZoomOut() {
00533     //
00534     // Demagnify
00535     fMarkerSize = fMarkerSize / fZoomFactor;
00536     UnzoomView(gPad, fZoomFactor); // dont use ZoomView as it is not base on center
00537 
00538     fStatusCurrent->fZoom = this->GetZoomRatio();
00539     fStatusXY->fZoom  = this->GetZoomRatio();
00540     fStatusZR->fZoom  = this->GetZoomRatio();
00541     //Double_t extent = GetExtent();
00542     //cout << extent << endl;
00543     //cout << GetZoomRatio() << endl;
00544 
00545     /*
00546     Double_t x1, y1, x2, y2;
00547     x1 = gPad->GetX1();
00548     y1 = gPad->GetY1();
00549     x2 = gPad->GetX2();
00550     y2 = gPad->GetY2();
00551 
00552     Double_t dx = (gPad->GetX2() - gPad->GetX1())*(fZoomFactor-1);
00553     Double_t dy = (gPad->GetY2() - gPad->GetY1())*(fZoomFactor-1);
00554 
00555     gPad->Range(x1-dx/2, y1-dy/2, x2+dx/2, y2+dy/2);
00556     gPad->Modified();
00557     */
00558 }
00559 
00560 //_____________________________________________________
00561 
00562 Int_t BesView::GetRSign(Float_t Phi) {
00563     //
00564     // Get sign of the R coordinate (ZR view)
00565     // for a given phi (in radians)
00566     Int_t Sign;
00567 
00568     // Convert to deg, because phi range is given in degrees
00569     Float_t Phi2 = (Phi - 2*TMath::Pi()*Int_t(Phi/(2*TMath::Pi())))
00570                    * 180./TMath::Pi();
00571     if ( Phi2 < 0 ) Phi2 += 360;
00572     if ( Phi2 >= fStatusCurrent->fPhiRangeMin && Phi2 < fStatusCurrent->fPhiRangeMax ) {
00573         Sign = 1;
00574     } else {
00575         Sign = -1;
00576     }
00577     return Sign;
00578 }
00579 
00580 //_____________________________________________________
00581 
00582 void BesView::SetPhiRange(Float_t PhiMin, Float_t PhiMax) {
00583     //
00584     // Set phi range for ZR view
00585     if ( gDebug ) cout << "BesView::SetPhiRange called" << endl;
00586 
00587     fStatusCurrent->fPhiRangeMin = PhiMin;
00588     fStatusCurrent->fPhiRangeMax = PhiMax;
00589 
00590     // Update view
00591     if ( !gBesGeometry ) return;
00592     //gEvent->AddBACPadTowerZR();
00593     UpdateView(0);
00594 }
00595 
00596 //_____________________________________________________
00597 
00598 void BesView::UpdateView(Bool_t resetview) {
00599     //
00600     // Update current view
00601     if ( !gBesGeometry ) return;
00602 
00603     // Redraw
00604     SetViewType(fViewType,resetview);
00605 }
00606 
00607 
00608 // void BesView::Plot_Et_Eta_Phi() {
00609 //   //
00610 //   // View Et_eta_phi histogram
00611 //   static TCanvas *c_hist = new TCanvas("c_eta_phi", "Eta Phi Histogram",
00612 //                                     400, 300);
00613 //   c_hist->cd();
00614 //   gEvent->GetHistEt_eta_phi()->Draw("Lego2");
00615 // }
00616 
00617 
00618 void BesView::DrawLabel() {
00619     //
00620     // Draw label for current view
00621 
00622     fLabel->SetX1(-0.9);
00623     fLabel->SetX2(-0.6);
00624     fLabel->SetY1(-0.9);
00625     fLabel->SetY2(-0.78);
00626 
00627     switch (fViewType) {
00628     case k3DView:
00629         fLabel->SetLabel("3D View");
00630         break;
00631     case kXYView:
00632         fLabel->SetLabel("XY View");
00633         break;
00634     case kZRView:
00635         fLabel->SetLabel("ZR View");
00636         break;
00637     }
00638     fLabel->Draw("BR,NDC,SAME");
00639 
00640 
00641     /*
00642     switch (fViewType) {
00643     case k3DView:
00644       fLabel->DrawPaveLabel(0.02,0.02,0.17,0.09, "3D View", "BR,NDC,SAME");
00645       break;
00646     case kXYView:
00647       //fLabel->SetLabel("XY View");
00648       fLabel->DrawPaveLabel(0.02,0.02,0.17,0.09, "XY View", "BR,NDC,SAME");
00649       break;
00650     case kZRView:
00651       fLabel->DrawPaveLabel(0.02,0.02,0.17,0.09, "ZR View", "BR,NDC,SAME");
00652       break;
00653     }
00654     */
00655 }
00656 
00657 //_____________________________________________________
00658 
00659 void BesView::WCtoNDC(const Float_t *pw, Float_t *pn) {
00660     //
00661     // Transform world coordinates to
00662     // normalised device coordinates.
00663     // This method was taken from BesTView
00664     // and extended by FishEye view
00665     BesTView::WCtoNDC(pw, pn);
00666     //cout << "fFishEye " << fFishEye << endl;
00667 
00668     if ( fStatusCurrent->fFishEye == kTRUE ) {
00669         Float_t r, s;
00670         if ( fViewType & kZRView ) {
00671             Float_t pvWC[3], pvNDC[3];
00672             pvWC[0] = +4;
00673             pvWC[1] = 0;
00674             pvWC[2] = 0;
00675             BesTView::WCtoNDC(pvWC, pvNDC);
00676             pn[0] = TMath::Sign(Double_t(TMath::Sqrt(TMath::Abs(pn[0] - pvNDC[0]))),
00677                                 Double_t(pn[0] - pvNDC[0])) + pvNDC[0];
00678             pn[1] = TMath::Sign(Double_t(TMath::Sqrt(TMath::Abs(pn[1] - pvNDC[1]))),
00679                                 Double_t(pn[1] - pvNDC[1])) + pvNDC[1];
00680         } else {
00681             r = TMath::Sqrt(TMath::Power(pn[0],2)
00682                             +TMath::Power(pn[1],2));
00683             s = TMath::Sqrt(r)/r;
00684             pn[0] *= s;
00685             pn[1] *= s;
00686         }
00687     }
00688 }
00689 
00690 //_____________________________________________________
00691 
00692 void BesView::WCtoNDC(const Double_t *pw, Double_t *pn) {
00693     //
00694     // Transform world coordinates to
00695     // normalised device coordinates.
00696     // This method was taken from BesTView
00697     // and extended by FishEye view
00698     BesTView::WCtoNDC(pw, pn);
00699 
00700     if ( fStatusCurrent->fFishEye == kTRUE ) {
00701         Double_t r, s;
00702         if ( fViewType & kZRView ) {
00703             Double_t pvWC[3], pvNDC[3];
00704             pvWC[0] = +4;
00705             pvWC[1] = 0;
00706             pvWC[2] = 0;
00707             BesTView::WCtoNDC(pvWC, pvNDC);
00708             pn[0] = TMath::Sign(TMath::Sqrt(TMath::Abs(pn[0] - pvNDC[0])),
00709                                 pn[0] - pvNDC[0]) + pvNDC[0];
00710             pn[1] = TMath::Sign(TMath::Sqrt(TMath::Abs(pn[1] - pvNDC[1])),
00711                                 pn[1] - pvNDC[1]) + pvNDC[1];
00712         } else {
00713 
00714             r = TMath::Sqrt(TMath::Power(pn[0],2)
00715                             +TMath::Power(pn[1],2));
00716             s = TMath::Sqrt(r)/r;
00717             pn[0] *= s;
00718             pn[1] *= s;
00719         }
00720     }
00721 }
00722 
00723 //_____________________________________________________
00724 
00725 void BesView::NDCtoWC(const Float_t* pn, Float_t* pw) {
00726     //
00727     // Transform back from NDCs
00728     Float_t p[3];
00729     p[0] = pn[0];
00730     p[1] = pn[1];
00731     p[2] = pn[2];
00732 
00733     if ( fStatusCurrent->fFishEye == kTRUE ) {
00734         Float_t r;
00735         if ( fViewType & kZRView ) {
00736             Float_t pvWC[3], pvNDC[3];
00737             pvWC[0] = +4;
00738             pvWC[1] = 0;
00739             pvWC[2] = 0;
00740             BesTView::WCtoNDC(pvWC, pvNDC);
00741             p[0] = TMath::Sign((pn[0] - pvNDC[0])*(pn[0] - pvNDC[0]),
00742                                pn[0] - pvNDC[0]) + pvNDC[0];
00743             p[1] = TMath::Sign((pn[1] - pvNDC[1])*(pn[1] - pvNDC[1]),
00744                                pn[1] - pvNDC[1]) + pvNDC[1];
00745         } else {
00746             r = TMath::Sqrt(TMath::Power(p[0],2)
00747                             +TMath::Power(p[1],2));
00748             p[0] *= r;
00749             p[1] *= r;
00750         }
00751     }
00752     BesTView::NDCtoWC(p, pw);
00753 }
00754 
00755 //_____________________________________________________
00756 
00757 void BesView::NDCtoWC(const Double_t* pn, Double_t* pw) {
00758     //
00759     // Transform back from NDCs
00760     Double_t p[3];
00761     p[0] = pn[0];
00762     p[1] = pn[1];
00763     p[2] = pn[2];
00764 
00765     if ( fStatusCurrent->fFishEye == kTRUE ) {
00766         Double_t r;
00767         if ( fViewType & kZRView ) {
00768             Double_t pvWC[3], pvNDC[3];
00769             pvWC[0] = +4;
00770             pvWC[1] = 0;
00771             pvWC[2] = 0;
00772             BesTView::WCtoNDC(pvWC, pvNDC);
00773             p[0] = TMath::Sign((pn[0] - pvNDC[0])*(pn[0] - pvNDC[0]),
00774                                pn[0] - pvNDC[0]) + pvNDC[0];
00775             p[1] = TMath::Sign((pn[1] - pvNDC[1])*(pn[1] - pvNDC[1]),
00776                                pn[1] - pvNDC[1]) + pvNDC[1];
00777         } else {
00778             r = TMath::Sqrt(TMath::Power(p[0],2)
00779                             +TMath::Power(p[1],2));
00780             p[0] *= r;
00781             p[1] *= r;
00782         }
00783     }
00784     BesTView::NDCtoWC(p, pw);
00785 }
00786 
00787 //_____________________________________________________
00788 
00789 void BesView::Side3D() {
00790     //
00791     // set side view for 3D
00792 
00793     this->SetViewType(k3DView,1);
00794     Int_t iret;
00795     this->SetView(0,90,270,iret);
00796 }
00797 
00798 //_____________________________________________________
00799 
00800 char *BesView::GetObjectInfo(Int_t px, Int_t py) const {
00801     //
00802     // Returns string containing info about the object at position (px,py).
00803     Double_t pw[3];
00804     Double_t Pndc[3] = { gPad->AbsPixeltoX(px), gPad->AbsPixeltoY(py), 0};
00805     ((BesView*)gPad->GetView())->NDCtoWC(Pndc, pw);
00806     //cout << gPad->GetName() << endl;
00807 
00808     //
00809     // Converts from pixel coordinates to world
00810     // coordinates of according view
00811 
00812     static char info[64];
00813     if ( fViewType & kZRView ) {
00814         sprintf(info, "z=%-.3fmm, r=%-.3fmm", pw[2], pw[1]);
00815         return info;
00816     } else {
00817         sprintf(info, "x=%-.3fmm, y=%-.3fmm", pw[0], pw[1]);
00818         return info;
00819     }
00820 }
00821 
00822 //_____________________________________________________
00823 
00824 void BesView::Reset() {
00825     //
00826     // reset view to default values
00827 
00828     // reset status instances of views
00829     fStatus3D->Default(k3DView);
00830     fStatusXY->Default(kXYView);
00831     fStatusZR->Default(kZRView);
00832     fZoomFactor = 1.2;
00833 
00834     // reset current status instance tp fViewType
00835     fStatusCurrent->Default(fViewType);
00836 
00837     // reset phirange
00838     //  this->SetPhiRange(0,180);
00839     this->UpdateView(1);
00840     gPad->Update();
00841 }

Generated on Tue Nov 29 23:12:04 2016 for BOSS_7.0.2 by  doxygen 1.4.7