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

Go to the documentation of this file.
00001 #include <TString.h>
00002 #include <TColor.h>
00003 #include <iostream>
00004 
00005 #include "math.h"
00006 #include "TMath.h"
00007 #include "BesVisLib/Muc2DStrip.h"
00008 #include "BesVisLib/BesView.h"
00009 #include "BesVisLib/BesCursor.h"
00010 
00011 using namespace std;
00012 
00013 #ifndef __CINT__
00014 ClassImp(Muc2DStrip)
00015 #endif
00016 
00017 //_____________________________________________________
00018 
00019 Muc2DStrip::Muc2DStrip() {
00020 
00021 }
00022 
00023 //_____________________________________________________
00024 
00025 Muc2DStrip::Muc2DStrip(const char* name, const char* title, Int_t N, Double_t *P, Int_t part, Int_t seg, Int_t gap, Int_t strip)
00026 {
00027     SetName(name);
00028     SetTitle(title);
00029     fTip = 0;
00030     fHighlighted = false;
00031     fFired = false;
00032     fPart  = part;
00033     fSeg   = seg;
00034     fGap   = gap;
00035     fStrip = strip;
00036 
00037     // ------XY------
00038 
00039     Double_t Pxy[3*4];
00040     for (Int_t i = 0; i < 4; i++) {
00041         if (part == 1) {
00042             Int_t iXYSeq[8] = {1,0,4,5, 2,3,7,6}; // center of 1+2, 0+3, 4+7, 5+6
00043             for (Int_t j = 0; j < 3; j++) {
00044                 Pxy[3*i+j] = ( P[3*iXYSeq[i]+j] + P[3*(iXYSeq[i+4])+j] )/2.0;
00045             }
00046         }
00047         else {
00048             Int_t iXYSeq[8] = {0,1,2,3, 4,5,6,7}; // center of 0+4, 1+5, 2+6, 3+7
00049             for (Int_t j = 0; j < 3; j++) {
00050                 Pxy[3*i+j] = ( P[3*iXYSeq[i]+j] + P[3*(iXYSeq[i+4])+j] )/2.0;
00051             }
00052         }
00053     }
00054 
00055     fStripXY      = new BesPolygon2D(name, title, 4, &Pxy[0]);
00056 
00057     // ------ZR------
00058 
00059     Double_t Pzr[3*6];
00060     Int_t nzrPoints = 6;
00061     if (part == 1) {
00062         Int_t iZRSeq[6] = {4,5,1,2,6,7}; //{1,2,6,5, 0,3,7,4}; // center of 0+4, 1+5, 2+6, 3+7
00063         for (Int_t i = 0; i < nzrPoints; i++) {
00064             for (Int_t j = 0; j < 3; j++) {
00065                 Pzr[3*i+j] = P[3*iZRSeq[i]+j]; // ( P[3*iZRSeq[i]+j] + P[3*(iZRSeq[i+4])+j] )/2.0;
00066             }
00067         }
00068     }
00069     else {
00070         nzrPoints = 6;
00071         Int_t iZRSeq[6] = {1,2,3,7,6,5};
00072         for (Int_t i = 0; i < nzrPoints; i++) {
00073             for (Int_t j = 0; j < 3; j++) {
00074                 Pzr[3*i+j] = P[3*iZRSeq[i]+j];
00075             }
00076         }
00077     }
00078 
00079     fStripZR      = new BesPolygon2D(name, title, nzrPoints, &Pzr[0]);
00080 
00081     // Init
00082 
00083     SetStyle();
00084 
00085     fTip = new BesPaveText(0, 0, 0.1, 0.1);
00086     CloseInfo();
00087 }
00088 
00089 //_____________________________________________________
00090 
00091 Muc2DStrip::~Muc2DStrip() {
00092 
00093     if (fStripXY)  delete fStripXY;
00094     if (fStripZR)  delete fStripZR;
00095 }
00096 
00097 void Muc2DStrip::SetStyle()
00098 {
00099     lcStrip = 15;
00100     lwStrip = 1;
00101     lsStrip = 1;
00102     fcStrip = 1007; // lightBrown // 1005;  // lightBlue
00103     fsStrip = 1001;
00104 
00105     lcStripFired = 15; //kRed; //15
00106     lwStripFired = 1;
00107     lsStripFired = 1;
00108     fcStripFired = kRed;
00109     fsStripFired = 1001;
00110 
00111     lcStripHL = lcStrip;
00112     lwStripHL = 1;
00113     lsStripHL = 1;
00114     fcStripHL = kBlue;
00115     fsStripHL = 1001;
00116 
00117 }
00118 
00119 void Muc2DStrip::ClearInfo()
00120 {
00121     fInfoCon.clear();
00122     fTip->DeleteText();
00123 }
00124 
00125 void Muc2DStrip::CloseInfo()
00126 {
00127     if (fTip) {
00128         fTip->Clear();
00129 
00130         if (fInfoCon.size() == 0) fInfoCon.push_back(GetTitle());
00131         fTip->SetText(fInfoCon);
00132     }
00133     else
00134         cout << "Muc2DStrip::CloseInfo, not initialized" << endl;
00135 }
00136 
00137 //_____________________________________________________
00138 
00139 Int_t Muc2DStrip::DistancetoPrimitive(Int_t px, Int_t py) {
00140 
00141     BesView *view = (BesView*)gPad->GetView();
00142     if ( view->GetViewType() & kXYView && fStripXY &&
00143             ( view->GetVisMucStrips()  || (view->GetVisMucHitsGlobal() && this->IsFired()) )  ) {
00144         return fStripXY->DistancetoPrimitive(px, py);
00145     }
00146     else if ( view->GetViewType() & kZRView && fStripZR &&
00147               ( (view->GetVisMucStrips() && this->IsZRVisible()) ||
00148                 (view->GetVisMucHitsGlobal() && this->IsFired() && this->IsZRVisible()) )  ) {
00149         return fStripZR->DistancetoPrimitive(px, py);
00150     }
00151 
00152     return 9999;
00153 }
00154 
00155 //_____________________________________________________
00156 
00157 void Muc2DStrip::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
00158 
00159     //cout << GetName() << endl;
00160     BesView *view = (BesView*)gPad->GetView();
00161 
00162     if (gBesCursor->GetType() == kBesHand) {
00163         if (view) view->ExecuteEvent(event, px, py);
00164     }
00165     else if (gBesCursor->GetType() == kBesPick){
00166 
00167         if (gPad) gPad->SetCursor(kPointer);
00168 
00169         switch (event) {
00170 
00171         case kMouseEnter :
00172             this->SetHighlighted(true);
00173 
00174             Draw();
00175 
00176             fTip->SetPos(px, py);
00177             view->UpdateView(0);
00178 
00179             fTip->Draw("BR,SAME"); // "BR,ARC,SAME"
00180             gPad->Modified();
00181             gPad->Update();
00182 
00183             break;
00184 
00185         case kMouseLeave:
00186             if (this->IsHighlighted()) {
00187                 this->SetHighlighted(false);
00188                 //if (view->GetVisMucHitsGlobal())
00189                 Draw();
00190 
00191                 view->UpdateView(0);
00192                 gPad->Modified();
00193                 gPad->Update();
00194                 break;
00195             }
00196         }
00197 
00198         //if (view) view->ExecuteEvent(event, px, py);
00199     }
00200 }
00201 
00202 //_____________________________________________________
00203 
00204 void Muc2DStrip::Draw(Option_t *option) {
00205     //
00206     // Muc2DStrip draw function
00207     TString opt = option;
00208     opt.ToUpper();
00209 
00210     AppendPad(option);
00211 }
00212 
00213 //_____________________________________________________
00214 
00215 void Muc2DStrip::Paint(Option_t *option) {
00216 
00217     TString opt = option;
00218     opt.ToUpper();
00219 
00220     BesView *view = (BesView*)gPad->GetView();
00221     Double_t min[3], max[3];
00222     view->GetRange(&min[0], &max[0]);
00223     Double_t maxRange = 0.0;
00224     Double_t range[3];
00225     for (Int_t i = 0; i < 3; i++) {
00226         range[i] = fabs(max[i] - min[i]);
00227         if (range[i] > maxRange) maxRange = range[i];
00228     }
00229 
00230     if (view->GetViewType() & kXYView) {
00231 
00232         if (fStripXY) {
00233             fStripXY->SetLineColor(lcStrip);
00234             fStripXY->SetLineWidth(lwStrip);
00235             fStripXY->SetLineStyle(lsStrip);
00236             fStripXY->SetFillColor(fcStrip);
00237             fStripXY->SetFillStyle(fsStrip);
00238         }
00239 
00240         if (this->IsFired()) {
00241             if (fStripXY) {
00242                 fStripXY->SetLineColor(lcStripFired);
00243                 if (maxRange > m_kDrawLineRange && fPart == 1)
00244                     fStripXY->SetLineColor(fcStripFired); // too small makes it hard to see
00245                 fStripXY->SetLineWidth(lwStripFired);
00246                 fStripXY->SetLineStyle(lsStripFired);
00247                 fStripXY->SetFillColor(fcStripFired);
00248                 fStripXY->SetFillStyle(fsStripFired);
00249             }
00250         }
00251 
00252         if (this->IsHighlighted()) {
00253             if (fStripXY) {
00254                 fStripXY->SetLineColor(lcStripHL);
00255                 if (maxRange > m_kDrawLineRange && fPart == 1)
00256                     fStripXY->SetLineColor(fcStripHL); // too small makes it hard to see
00257                 fStripXY->SetLineWidth(lwStripHL);
00258                 fStripXY->SetLineStyle(lsStripHL);
00259                 fStripXY->SetFillColor(fcStripHL);
00260                 fStripXY->SetFillStyle(fsStripHL);
00261             }
00262         }
00263 
00264         if ( fStripXY && view->GetVisMucStrips() ) fStripXY->Paint();
00265         if (this->IsFired()) {
00266             if (view->GetVisMucHitsGlobal() &&
00267                     ( (fPart == 0 && view->GetVisMucHitsEast())   ||
00268                       (fPart == 1 && view->GetVisMucHitsBarrel()) ||
00269                       (fPart == 2 && view->GetVisMucHitsWest()) )) {
00270                 fStripXY->Paint();
00271             }
00272         }
00273     }
00274 
00275     if (view->GetViewType() & kZRView) {
00276 
00277         if (fStripZR) {
00278             fStripZR->SetLineColor(lcStrip);
00279             fStripZR->SetLineWidth(lwStrip);
00280             fStripZR->SetLineStyle(lsStrip);
00281             fStripZR->SetFillColor(fcStrip);
00282             fStripZR->SetFillStyle(fsStrip);
00283         }
00284 
00285         if (this->IsFired()) {
00286             if (fStripZR) {
00287                 fStripZR->SetLineColor(lcStripFired);
00288                 if (maxRange > m_kDrawLineRange)
00289                     fStripZR->SetLineColor(fcStripFired); // too small makes it hard to see
00290                 fStripZR->SetLineWidth(lwStripFired);
00291                 fStripZR->SetLineStyle(lsStripFired);
00292                 fStripZR->SetFillColor(fcStripFired);
00293                 fStripZR->SetFillStyle(fsStripFired);
00294             }
00295         }
00296 
00297         if (this->IsHighlighted()) {
00298             if (fStripZR) {
00299                 fStripZR->SetLineColor(lcStripHL);
00300                 if (maxRange > m_kDrawLineRange)
00301                     fStripZR->SetLineColor(fcStripHL); // too small makes it hard to see
00302                 fStripZR->SetLineWidth(lwStripHL);
00303                 fStripZR->SetLineStyle(lsStripHL);
00304                 fStripZR->SetFillColor(fcStripHL);
00305                 fStripZR->SetFillStyle(fsStripHL);
00306             }
00307         }
00308 
00309         if ( fStripZR && view->GetVisMucStrips() && IsZRVisible() ) fStripZR->Paint();
00310         if (this->IsFired() && IsZRVisible() ) {
00311             if (view->GetVisMucHitsGlobal() &&
00312                     ( (fPart == 0 && view->GetVisMucHitsEast())   ||
00313                       (fPart == 1 && view->GetVisMucHitsBarrel()) ||
00314                       (fPart == 2 && view->GetVisMucHitsWest()) )) {
00315                 fStripZR->Paint();
00316             }
00317         }
00318     }
00319 }
00320 
00321 //_____________________________________________________
00322 
00323 char *Muc2DStrip::GetObjectInfo(Int_t px, Int_t py) const {
00324 
00325     BesView *view = (BesView*)gPad->GetView();
00326     if (view) return view->GetObjectInfo(px, py);
00327     else return TObject::GetObjectInfo(px, py);
00328 }
00329 
00330 //_____________________________________________________
00331 
00332 Bool_t Muc2DStrip::IsZRVisible()
00333 {
00334     BesView *view = (BesView*)gPad->GetView();
00335     Double_t viewPhi = view->GetLongitude();
00336     viewPhi = Range360(viewPhi);
00337 
00338     if (fPart != 1) {
00339         if ( (Int_t)viewPhi % 90 == 0 ) return true;
00340         else return false;
00341     }
00342     else {
00343         Int_t viewSeg = Int_t(viewPhi/45.0+0.5);
00344         //cout << "viewSeg " << viewSeg << endl;
00345         Int_t upSeg   = viewSeg-2;
00346         Int_t downSeg = viewSeg+2;
00347         if (upSeg   < 0) upSeg   += 8;
00348         else if (upSeg   >= 8) upSeg   -= 8;
00349         if (downSeg < 0) downSeg += 8;
00350         else if (downSeg >= 8) downSeg -= 8;
00351         //if (fStrip == 0) cout << GetName() << " upSeg " << upSeg << " downSeg " << downSeg << endl;
00352 
00353         if ( (Int_t)viewPhi % 45 == 0 && (fSeg == upSeg || fSeg == downSeg) ) return true;
00354         else return false;
00355     }
00356 
00357     return false;
00358 }
00359 
00360 //_____________________________________________________
00361 
00362 Double_t Muc2DStrip::GetAngle(Double_t x, Double_t y)  //degree
00363 {
00364     Double_t angle = TMath::ACos( x/TMath::Sqrt(x*x+y*y) ) * TMath::RadToDeg();
00365     if ( y<0.0 ) angle *= -1;
00366     angle = Range360(angle);
00367 
00368     return angle;
00369 }
00370 
00371 //_____________________________________________________
00372 
00373 Double_t Muc2DStrip::Range360(Double_t input)
00374 {
00375     if (input >= 360.0) {
00376         do {
00377             input -= 360.0;
00378         }
00379         while (input >= 360.0);
00380     }
00381     else if (input < 0.0) {
00382         do {
00383             input += 360.0;
00384         }
00385         while (input < 0.0);
00386     }
00387 
00388     return input;
00389 }

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