/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventDisplay/BesVisLib/BesVisLib-00-04-04/src/Tof2DScin.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/Tof2DScin.h"
00008 #include "BesVisLib/BesView.h"
00009 #include "BesVisLib/BesCursor.h"
00010 
00011 using namespace std;
00012 
00013 #ifndef __CINT__
00014 ClassImp(Tof2DScin)
00015 #endif
00016 
00017 //_____________________________________________________
00018 
00019 Tof2DScin::Tof2DScin() {
00020 
00021 }
00022 
00023 //_____________________________________________________
00024 
00025 Tof2DScin::Tof2DScin(const char* name, const char* title, Int_t N, Double_t *P, Int_t part)
00026 {
00027     SetName(name);
00028     SetTitle(title);
00029     fTip = 0;
00030     fHighlighted = false;
00031     fFired = false;
00032     fPart = part;
00033 
00034     fTime      = 0.0;
00035     fCharge    = 0.0;
00036 
00037     fZRSectionTolerance[1] = 0.071; // half of gap between two scin
00038     fZRSectionTolerance[2] = fZRSectionTolerance[0] = 0.1647;
00039 
00040     // ------XY------
00041 
00042     Double_t Pxy[3*4]; // N=8
00043     for (Int_t i = 0; i < 3*4; i++) {
00044         Pxy[i] = (P[i] + P[i+3*4])/2.0;
00045         //if (GetName() == TString("EastEcScin0")) cout << Pxy[i] << endl;
00046     }
00047 
00048     fScinXY      = new BesPolygon2D(name, title, 4, &Pxy[0]);
00049     fScinXYFired = new BesPolygon2D(name, title, 4, &Pxy[0]);
00050 
00051     // ------ZR------
00052 
00053     Double_t Pzr[3*4];
00054     Int_t iSeq[8] = {0,3,1,2,5,6,4,7}; // center of 0+3, 1+2, 5+6, 4+7
00055     for (Int_t i = 0; i < 4; i++) {
00056         for (Int_t j = 0; j < 3; j++) {
00057             Pzr[3*i+j] = (P[3*iSeq[2*i]+j] + P[3*iSeq[2*i+1]+j])/2.0;
00058         }
00059         //if (GetName() == TString("EastEcScin0")) cout << Pxy[i] << endl;
00060     }
00061 
00062 
00063     fScinZR      = new BesPolygon2D(TString(name)+TString("zr"), title, 4, &Pzr[0]);
00064     fScinZRFired = new BesPolygon2D(TString(name)+TString("zr"), title, 4, &Pzr[0]);
00065 
00066     fPhiMin = GetAngle( P[3*3], P[3*3+1] );
00067     fPhiMax = GetAngle( P[3*0], P[3*0+1] );
00068     if (GetPart() == 2) {
00069         Double_t phiTemp = fPhiMin;
00070         fPhiMin = fPhiMax;
00071         fPhiMax = phiTemp;
00072     }
00073     //cout << GetName() << " min "<< fPhiMin << " max " << fPhiMax << endl;
00074 
00075     SetStyle();
00076 
00077     fTip = new BesPaveText(0, 0, 0.1, 0.1);
00078     CloseInfo();
00079 }
00080 
00081 //_____________________________________________________
00082 
00083 Tof2DScin::~Tof2DScin() {
00084 
00085     if (fScinXY)  delete fScinXY;
00086     if (fScinZR)  delete fScinZR;
00087     if (fScinXYFired)  delete fScinXYFired;
00088     if (fScinZRFired)  delete fScinZRFired;
00089 }
00090 
00091 void Tof2DScin::SetStyle()
00092 {
00093     lcScin = 15;
00094     lwScin = 1;
00095     fcScin = 1003;  // lightYellow
00096     fsScin = 1001;
00097 
00098     lcScinFired = kRed;
00099     lwScinFired = 1;
00100     fcScinFired = kRed;
00101     fsScinFired = 1001;
00102 
00103     lcScinHL = lcScin;
00104     lwScinHL = 1;
00105     fcScinHL = kBlue;
00106     fsScinHL = 1001;
00107 
00108     lcScinFiredHL = kRed;
00109     lwScinFiredHL = 2;
00110     fcScinFiredHL = kBlue;
00111     fsScinFiredHL = 4000;
00112 }
00113 
00114 
00115 void Tof2DScin::ClearInfo()
00116 {
00117     fInfoCon.clear();
00118     fTip->DeleteText();
00119 }
00120 
00121 void Tof2DScin::CloseInfo()
00122 {
00123     if (fTip) {
00124         fTip->Clear();
00125 
00126         if (fInfoCon.size() == 0) fInfoCon.push_back(GetTitle());
00127         fTip->SetText(fInfoCon);
00128     }
00129     else
00130         cout << "Tof2DScin::CloseInfo, not initialized" << endl;
00131 }
00132 
00133 //_____________________________________________________
00134 
00135 Int_t Tof2DScin::DistancetoPrimitive(Int_t px, Int_t py) {
00136 
00137     BesView *view = (BesView*)gPad->GetView();
00138     if (view->GetViewType() & kXYView && fScinXY) {
00139         return fScinXY->DistancetoPrimitive(px, py);
00140     }
00141     else if (view->GetViewType() & kZRView && fScinZR) {
00142         if (HasZRSection())
00143             return fScinZR->DistancetoPrimitive(px, py);
00144     }
00145 
00146     return 9999;
00147 }
00148 
00149 //_____________________________________________________
00150 
00151 void Tof2DScin::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
00152 
00153     //cout << GetName() << endl;
00154 
00155     BesView *view = (BesView*)gPad->GetView();
00156 
00157     if (gBesCursor->GetType() == kBesHand) {
00158         if (view) view->ExecuteEvent(event, px, py);
00159     }
00160     else if (gBesCursor->GetType() == kBesPick){
00161 
00162         if (gPad) gPad->SetCursor(kPointer);
00163 
00164         switch (event) {
00165 
00166         case kMouseEnter :
00167             this->SetHighlighted(true);
00168 
00169             //if (this->IsFired() || view->GetVisTofHitsGlobal()) {
00170             Draw();
00171 
00172             fTip->SetPos(px, py);
00173             view->UpdateView(0);
00174 
00175             fTip->Draw("BR,SAME"); // "BR,ARC,SAME"
00176             gPad->Modified();
00177             gPad->Update();
00178             break;
00179 
00180         case kMouseLeave:
00181             if (this->IsHighlighted()) {
00182                 this->SetHighlighted(false);
00183                 //if (view->GetVisTofHitsGlobal())
00184                 Draw();
00185 
00186                 view->UpdateView(0);
00187                 gPad->Modified();
00188                 gPad->Update();
00189                 break;
00190             }
00191         }
00192     }
00193 }
00194 
00195 //_____________________________________________________
00196 
00197 void Tof2DScin::Draw(Option_t *option) {
00198     //
00199     // Tof2DScin draw function
00200     TString opt = option;
00201     opt.ToUpper();
00202 
00203     AppendPad(option);
00204 }
00205 
00206 //_____________________________________________________
00207 
00208 void Tof2DScin::Paint(Option_t *option) {
00209 
00210     TString opt = option;
00211     opt.ToUpper();
00212 
00213     BesView *view = (BesView*)gPad->GetView();
00214     if (view->GetViewType() & kXYView) {
00215 
00216         if (this->IsFired()) {
00217             if (fScinXYFired) {
00218                 fScinXYFired->SetLineColor(lcScinFired);
00219                 fScinXYFired->SetLineWidth(lwScinFired);
00220                 fScinXYFired->SetFillColor(fcScinFired);
00221                 fScinXYFired->SetFillStyle(fsScinFired);
00222             }
00223         }
00224 
00225         if (fScinXY) {
00226             fScinXY->SetLineColor(lcScin);
00227             fScinXY->SetLineWidth(lwScin);
00228             fScinXY->SetFillColor(fcScin);
00229             fScinXY->SetFillStyle(fsScin);
00230         }
00231 
00232         if (this->IsHighlighted()) {
00233             if (fScinXY) {
00234                 fScinXY->SetLineColor(lcScinHL);
00235                 fScinXY->SetLineWidth(lwScinHL);
00236                 fScinXY->SetFillColor(fcScinHL);
00237                 fScinXY->SetFillStyle(fsScinHL);
00238             }
00239             if (fScinXYFired) {
00240                 fScinXYFired->SetLineColor(lcScinFiredHL);
00241                 fScinXYFired->SetLineWidth(lwScinFiredHL);
00242                 fScinXYFired->SetFillColor(fcScinFiredHL);
00243                 fScinXYFired->SetFillStyle(fsScinFiredHL);
00244             }
00245         }
00246 
00247         if (fScinXY) fScinXY->Paint();
00248         if (this->IsFired()) {
00249             if (view->GetVisTofHitsGlobal() &&
00250                     ( (fPart == 0 && view->GetVisTofHitsEast())   ||
00251                       (fPart == 1 && view->GetVisTofHitsBarrel()) ||
00252                       (fPart == 2 && view->GetVisTofHitsWest()) )) {
00253                 if (fScinXYFired) {
00254                     //cout << "Tof fired Scin size " << fCharge/fChargeMax << endl;
00255                     fScinXYFired->Restore(); // restore default size
00256                     fScinXYFired->SetSize(fCharge/fChargeMax);
00257                     fScinXYFired->Paint();
00258                 }
00259             }
00260         }
00261     }
00262 
00263     if (view->GetViewType() & kZRView) {
00264         if (HasZRSection()) {
00265             if (this->IsFired()) {
00266                 if (fScinZRFired) {
00267                     fScinZRFired->SetLineColor(lcScinFired);
00268                     fScinZRFired->SetLineWidth(lwScinFired);
00269                     fScinZRFired->SetFillColor(fcScinFired);
00270                     fScinZRFired->SetFillStyle(fsScinFired);
00271                 }
00272             }
00273 
00274             if (fScinZR) {
00275                 fScinZR->SetLineColor(lcScin);
00276                 fScinZR->SetLineWidth(lwScin);
00277                 fScinZR->SetFillColor(fcScin);
00278                 fScinZR->SetFillStyle(fsScin);
00279             }
00280 
00281             if (this->IsHighlighted()) {
00282                 if (fScinZR) {
00283                     fScinZR->SetLineColor(lcScinHL);
00284                     fScinZR->SetLineWidth(lwScinHL);
00285                     fScinZR->SetFillColor(fcScinHL);
00286                     fScinZR->SetFillStyle(fsScinHL);
00287                 }
00288                 if (fScinZRFired) {
00289                     fScinZRFired->SetLineColor(lcScinFiredHL);
00290                     fScinZRFired->SetLineWidth(lwScinFiredHL);
00291                     fScinZRFired->SetFillColor(fcScinFiredHL);
00292                     fScinZRFired->SetFillStyle(fsScinFiredHL);
00293                 }
00294             }
00295 
00296             if (fScinZR) fScinZR->Paint();
00297             if (this->IsFired()) {
00298                 if (view->GetVisTofHitsGlobal() &&
00299                         ( (fPart == 0 && view->GetVisTofHitsEast())   ||
00300                           (fPart == 1 && view->GetVisTofHitsBarrel()) ||
00301                           (fPart == 2 && view->GetVisTofHitsWest()) )) {
00302                     if (fScinZRFired) {
00303                         //cout << "Tof fired Scin size " << fCharge/fChargeMax << endl;
00304                         fScinZRFired->Restore(); // restore default size
00305                         fScinZRFired->SetSize(fCharge/fChargeMax);
00306                         fScinZRFired->Paint();
00307                     }
00308                 }
00309             }
00310         }
00311     }
00312 
00313 }
00314 
00315 //_____________________________________________________
00316 
00317 char *Tof2DScin::GetObjectInfo(Int_t px, Int_t py) const {
00318 
00319     BesView *view = (BesView*)gPad->GetView();
00320     if (view) return view->GetObjectInfo(px, py);
00321     else return TObject::GetObjectInfo(px, py);
00322 }
00323 
00324 //_____________________________________________________
00325 
00326 bool Tof2DScin::HasZRSection()
00327 {
00328     bool flag = false;
00329     BesView *view = (BesView*)gPad->GetView();
00330     Double_t viewPhi = view->GetLongitude();
00331     viewPhi = Range360(viewPhi);
00332     //if (GetName() == TString("Layer0Wire0")) cout << "view " << viewPhi << endl;
00333 
00334     Double_t zrPhi = viewPhi-90.0;
00335     zrPhi = Range360(zrPhi);
00336     //if (GetName() == TString("Layer0Wire0")) cout << zrPhi << endl;
00337 
00338     for (Int_t i = 0; i < 2; i++) {
00339         if (i==1) {
00340             zrPhi += 180.0;
00341             zrPhi = Range360(zrPhi);
00342         }
00343 
00344         if (zrPhi >= fPhiMin-fZRSectionTolerance[GetPart()] &&
00345                 zrPhi <= fPhiMax+fZRSectionTolerance[GetPart()]) {
00346             flag = true;
00347             break;
00348         }
00349         else if (fPhiMin > fPhiMax) { // cross 0 degree
00350             if (zrPhi >= fPhiMin-fZRSectionTolerance[GetPart()] ||
00351                     zrPhi <= fPhiMax+fZRSectionTolerance[GetPart()]) {
00352                 flag = true;
00353                 break;
00354             }
00355         }
00356     }
00357 
00358     return flag;
00359 }
00360 
00361 //_____________________________________________________
00362 
00363 Double_t Tof2DScin::GetAngle(Double_t x, Double_t y)  //degree
00364 {
00365     Double_t angle = TMath::ACos( x/TMath::Sqrt(x*x+y*y) ) * TMath::RadToDeg();
00366     if ( y<0.0 ) angle *= -1;
00367     angle = Range360(angle);
00368 
00369     return angle;
00370 }
00371 
00372 //_____________________________________________________
00373 
00374 Double_t Tof2DScin::Range360(Double_t input)
00375 {
00376     if (input >= 360.0) {
00377         do {
00378             input -= 360.0;
00379         }
00380         while (input >= 360.0);
00381     }
00382     else if (input < 0.0) {
00383         do {
00384             input += 360.0;
00385         }
00386         while (input < 0.0);
00387     }
00388 
00389     return input;
00390 }

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