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

Go to the documentation of this file.
00001 #include <TString.h>
00002 #include <TColor.h>
00003 #include <iostream>
00004 #include "math.h"
00005 #include "TMath.h"
00006 #include "BesVisLib/Mdc2DWire.h"
00007 #include "BesVisLib/BesView.h"
00008 #include "BesVisLib/BesCursor.h"
00009 
00010 using namespace std;
00011 
00012 #ifndef __CINT__
00013 ClassImp(Mdc2DWire)
00014 #endif
00015 
00016 //_____________________________________________________
00017 
00018 Mdc2DWire::Mdc2DWire() {
00019 
00020 }
00021 
00022 //_____________________________________________________
00023 
00024 Mdc2DWire::Mdc2DWire(const char* name,
00025                      const char* title,
00026                      Double_t rmin,
00027                      Double_t rmax,
00028                      Double_t dz,
00029                      Double_t phi,
00030                      Double_t *center )
00031 {
00032 
00033     SetName(name);
00034     SetTitle(title);
00035     fTip = 0;
00036     fHighlighted = false;
00037     fFired = false;
00038     fColorfulWire = false;
00039     fWireType  = 1; // axial wire
00040     evTime = 0;
00041 
00042     Double_t r = 0.25*(rmax-rmin);
00043     fWireCircle = new BesCircle2D(name, title, 0.0, r, &center[0]);
00044 
00045     Double_t dx = fabs(r*cos(phi));
00046     Double_t dy = fabs(r*sin(phi));
00047     Double_t P[12] = { center[0] - dx, center[1] - dy, center[2] - dz,
00048                        center[0] + dx, center[1] + dy, center[2] - dz,
00049                        center[0] - dx, center[1] - dy, center[2] + dz,
00050                        center[0] + dx, center[1] + dy, center[2] + dz
00051                      };
00052 
00053     fWireCone = new BesPolygon2D(name, title, 4, P);
00054 
00055     Init();
00056 }
00057 
00058 //_____________________________________________________
00059 
00060 Mdc2DWire::Mdc2DWire(const char* name, const char* title, Int_t N, Double_t *P)
00061 {
00062     SetName(name);
00063     SetTitle(title);
00064     fTip = 0;
00065     fHighlighted = false;
00066     fFired = false;
00067     fColorfulWire = false;
00068     fWireType  = 2;  // stereo wire
00069 
00070     Double_t *tubeP = &P[3*N/2]; // east four points, P4~P7
00071     fTube = new BesPolygon2D(name, title, N/2, tubeP);
00072     fWireCircle = 0;
00073     fWireCone   = 0;
00074 
00075     for (Int_t i = 0; i < 3; i++) {
00076         fWestHole[i] = (P[i]    + P[3+i]  + P[6+i]  + P[9+i] )/4.0;  // (P0+P1+P2+P3)/4
00077         fEastHole[i] = (P[12+i] + P[15+i] + P[18+i] + P[21+i])/4.0;  // (P4+P5+P6+P7)/4
00078     }
00079     TVector3 westVec(fWestHole[0], fWestHole[1], fWestHole[2]);
00080     TVector3 eastVec(fEastHole[0], fEastHole[1], fEastHole[2]);
00081     fWestPhi = westVec.Phi() * TMath::RadToDeg();
00082     fEastPhi = eastVec.Phi() * TMath::RadToDeg();
00083     if (fWestPhi < 0.0) fWestPhi += 360.0;
00084     if (fEastPhi < 0.0) fEastPhi += 360.0;
00085 
00086     // ------XY------
00087     Double_t rMax = sqrt( (P[4*3]  -P[7*3])   * (P[4*3]-P[7*3])     +
00088                           (P[4*3+1]-P[7*3+1]) * (P[4*3+1]-P[7*3+1]) +
00089                           (P[4*3+2]-P[7*3+2]) * (P[4*3+2]-P[7*3+2]) ) / 2.0;
00090 
00091     Double_t rMinRatio = 0.0001; // min bubble radius = rMinRatio * rMax;
00092     Double_t rMaxRatio = 0.8;//0.6; // 0.4//yzhang
00093 
00094     Double_t newP[12];
00095     Double_t edge = rMaxRatio*0.0001; //*0.85
00096     for (Int_t i = 0; i < 3; i++) {
00097         newP[i]   = (0.5+edge*rMinRatio)*(P[i]+P[3+i])*0.5
00098                     + (0.5-edge*rMinRatio)*(P[6+i]+P[9+i])*0.5;   // near center of P0+P1
00099         newP[3+i] = (0.5-edge*rMinRatio)*(P[i]+P[3+i])*0.5
00100                     + (0.5+edge*rMinRatio)*(P[6+i]+P[9+i])*0.5;   // near center of P2+P3
00101         newP[6+i] = (0.5+edge*rMaxRatio)*(P[12+i]+P[15+i])*0.5
00102                     + (0.5-edge*rMaxRatio)*(P[18+i]+P[21+i])*0.5; // near center of P4+P5
00103         newP[9+i] = (0.5-edge*rMaxRatio)*(P[12+i]+P[15+i])*0.5
00104                     + (0.5+edge*rMaxRatio)*(P[18+i]+P[21+i])*0.5; // near center of P6+P7
00105     }
00106     fWireCone = new BesPolygon2D("WireCone", "WireCone", 4, &newP[0]);
00107 
00108     fWireCircle =
00109         new BesCircle2D("WireBubble", "WireBubble", 0.0, rMaxRatio*rMax, &fEastHole[0]);
00110 
00111     // ------ZR------
00112     fZRPosMarker2D =
00113         new BesMarker2D("MdcZRPos", "MdcZRPos", fEastHole[0], fEastHole[1], fEastHole[2]);
00114 
00115     Init();
00116 }
00117 
00118 //_____________________________________________________
00119 
00120 Mdc2DWire::~Mdc2DWire() {
00121 
00122     if (fTube)          delete fTube;
00123     if (fWireCircle)    delete fWireCircle;
00124     if (fWireCone)      delete fWireCone;
00125     if (fZRPosMarker2D) delete fZRPosMarker2D;
00126 
00127     if (fTip) delete fTip;
00128 }
00129 
00130 //_____________________________________________________
00131 
00132 void Mdc2DWire::Init() {
00133 
00134     SetStyle();
00135 
00136     fTip = new BesPaveText(0, 0, 0.1, 0.1);
00137     CloseInfo();
00138 }
00139 
00140 //_____________________________________________________
00141 
00142 void Mdc2DWire::SetStyle()
00143 {
00144     lcTube = kBlack; // grey;
00145     lwTube = 1;
00146     fcTube = kBlack; // grey 15;
00147     fsTube = 4000;
00148 
00149     lcWire = 15;
00150     if (fWireType == 1) lcWire = kGreen;
00151     if (fWireType == 2) lcWire = kBlue;
00152     lwCircle = 1;
00153     lwCone   = 1;
00154     fcCircle = kWhite;
00155     fcCone   = 0;
00156     fsCircle = 1001;
00157     fsCone   = 0;
00158 
00159     lcWireFired    = kRed;
00160     lwCircleFired  = 2;//yzhang 2;
00161     lwConeFired    = 2;
00162     fcCircleFired  = 1004; //kBlack;
00163     fcConeFired    = kBlack;
00164     fsCircleFired  = 1001;//solid
00165     fsConeFired    = 3001;
00166 
00167     lcWireHL   = kMagenta;//yzhang lcWire;
00168     lwCircleHL = 2;
00169     lwConeHL   = 2;
00170     fcCircleHL = kMagenta;//yzhang kBlack;
00171     fcConeHL   = kRed;
00172     fsCircleHL = 1001;
00173     fsConeHL   = 4000;
00174 
00175     sizeMarker   = 4;
00176     cMarker      = kBlue;
00177     cMarkerFired = kRed;    // color of fired marker
00178     cMarkerHL    = cMarker; // cMarkerFired;
00179     sMarker      = 24;
00180     sMarkerFired = 20;   // style of fired marker
00181     sMarkerHL    = 25;   // style of highlighted marker
00182 }
00183 
00184 void Mdc2DWire::ClearInfo()
00185 {
00186     fInfoCon.clear();
00187     fTip->DeleteText();
00188 }
00189 
00190 void Mdc2DWire::CloseInfo()
00191 {
00192     if (fTip) {
00193         fTip->Clear();
00194 
00195         if (fInfoCon.size() == 0) fInfoCon.push_back(GetTitle());
00196         fTip->SetText(fInfoCon);
00197     }
00198     else
00199         cout << "Mdc2DWire::CloseInfo, not initialized" << endl;
00200 }
00201 
00202 //_____________________________________________________
00203 
00204 Int_t Mdc2DWire::DistancetoPrimitive(Int_t px, Int_t py) {
00205     BesView *view = (BesView*)gPad->GetView();
00206     if (view->GetViewType() & kXYView) {
00207         return fWireCircle->DistancetoPrimitive(px, py);
00208     }
00209     else if (view->GetViewType() & kZRView) {
00210         if (fZRPosMarker2D) {
00211             fZRPosMarker2D->DistancetoPrimitive(px, py);
00212             return fZRPosMarker2D->DistancetoPrimitive(px, py);
00213         }
00214     }
00215 
00216     return 999;
00217 }
00218 
00219 //_____________________________________________________
00220 
00221 void Mdc2DWire::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
00222 
00223     BesView *view = (BesView*)gPad->GetView();
00224 
00225     if (gBesCursor->GetType() == kBesHand) {
00226         if (view) view->ExecuteEvent(event, px, py);
00227     }
00228     else if (gBesCursor->GetType() == kBesPick){
00229 
00230         if (gPad) gPad->SetCursor(kPointer);
00231 
00232         Int_t    origColor = 1;
00233 
00234         switch (event) {
00235 
00236         case kMouseEnter :
00237 
00238             if ( fWireCircle )    origColor = fWireCircle->GetFillColor();
00239             if ( fZRPosMarker2D ) origColor = fZRPosMarker2D->GetMarkerColor();
00240             this->SetHighlighted(true);
00241 
00242             if (this->IsFired() || view->GetVisMdcWires()) {
00243                 Draw("WIRE,SAME");
00244 
00245                 fTip->SetPos(px, py);
00246                 view->UpdateView(0);
00247 
00248                 fTip->Draw("BR,SAME"); // "BR,ARC,SAME"
00249                 gPad->Modified();
00250                 gPad->Update();
00251             }
00252             break;
00253 
00254         case kMouseLeave:
00255 
00256             if (this->IsHighlighted()) {
00257                 this->SetHighlighted(false);
00258                 if (view->GetVisMdcWires()) Draw("WIRE,SAME");
00259 
00260                 view->UpdateView(0);
00261                 gPad->Modified();
00262                 gPad->Update();
00263             }
00264             break;
00265         }
00266 
00267     }
00268 }
00269 
00270 //_____________________________________________________
00271 
00272 void Mdc2DWire::Draw(Option_t *option) {
00273     //
00274     // Mdc2DWire draw function
00275     TString opt = option;
00276     opt.ToUpper();
00277 
00278     AppendPad(option);
00279 }
00280 
00281 //_____________________________________________________
00282 
00283 void Mdc2DWire::Paint(Option_t *option) {
00284 
00285     TString opt = option;
00286     opt.ToUpper();
00287 
00288     BesView *view = (BesView*)gPad->GetView();
00289 
00290     //gStyle->SetPalette(1);
00291     if (view->GetViewType() & kXYView) {
00292 
00293         Double_t wcCenter[3], ncCenter[3];
00294         fWireCircle->GetCenter(&wcCenter[0]);
00295         view->WCtoNDC(wcCenter, &ncCenter[0]);
00296         Double_t x1, y1, x2, y2;
00297         Double_t d = 0.05;
00298         gPad->GetRange(x1, y1, x2, y2);
00299 
00300         // Only draw wire in pad range
00301         if (ncCenter[0] > x1-d && ncCenter[0] < x2+d &&
00302                 ncCenter[1] > y1-d && ncCenter[1] < y2+d) {
00303             if (opt.Contains("TUBE") && fTube ) {
00304                 fTube->SetLineColor(lcTube);
00305                 fTube->SetLineWidth(lwTube);
00306                 fTube->SetFillColor(fcTube);
00307                 fTube->SetFillStyle(fsTube);
00308 
00309                 fTube->Paint();
00310             }
00311 
00312             if (this->IsFired()) {
00313                 if (fWireCircle) {
00314                     fWireCircle->SetLineColor(lcWireFired);
00315                     fWireCircle->SetLineWidth(lwCircleFired);
00316                     fWireCircle->SetFillColor(fcCircleFired);
00317                     fWireCircle->SetFillStyle(fsCircleFired);
00318                 }
00319                 if (fWireCone) {
00320                     fWireCone->SetLineColor(lcWireFired);
00321                     fWireCone->SetLineWidth(lwConeFired);
00322                     fWireCone->SetFillColor(fcConeFired);
00323                     fWireCone->SetFillStyle(fsConeFired);
00324                 }
00325             }
00326             else {
00327                 if (fWireCone) {
00328                     fWireCone->SetLineColor(lcWire);
00329                     fWireCone->SetLineWidth(lwCone);
00330                     fWireCone->SetFillColor(fcCone);
00331                     fWireCone->SetFillStyle(fsCone);
00332                 }
00333                 if (fWireCircle) {
00334                     fWireCircle->SetLineColor(lcWire);
00335                     fWireCircle->SetLineWidth(lwCircle);
00336                     fWireCircle->SetFillColor(fcCircle);
00337                     fWireCircle->SetFillStyle(fsCircle);
00338                 }
00339             }
00340 
00341             if (this->IsHighlighted()) {
00342                 if (fWireCircle) {
00343                     fWireCircle->SetLineColor(lcWireHL);
00344                     fWireCircle->SetLineWidth(lwCircleHL);
00345                     fWireCircle->SetFillColor(fcCircleHL);
00346                     fWireCircle->SetFillStyle(fsCircleHL);
00347                 }
00348                 if (fWireCone) {
00349                     fWireCone->SetLineColor(lcWireHL);
00350                     fWireCone->SetLineWidth(lwConeHL);
00351                     fWireCone->SetFillColor(fcConeHL);
00352                     fWireCone->SetFillStyle(fsConeHL);
00353                 }
00354             }
00355             if (opt.Contains("WIRE")) {
00356                 if (!fColorfulWire)   fWireCone->Paint();//yzhang remove stereo wire line
00357                 if (fWireCircle) fWireCircle->Paint();
00358             }
00359         }
00360     }
00361 
00362     if (view->GetViewType() & kZRView) {
00363         if (HasZRSection()) {
00364             fZRPosMarker2D->SetWCX(fZRSectionPos[0]);
00365             fZRPosMarker2D->SetWCY(fZRSectionPos[1]);
00366             fZRPosMarker2D->SetWCZ(fZRSectionPos[2]);
00367             fZRPosMarker2D->SetMarkerColor(cMarker);
00368             fZRPosMarker2D->SetMarkerStyle(sMarker);
00369             fZRPosMarker2D->SetMarkerSizeMultiple(sizeMarker);
00370 
00371             if (this->IsFired()) {
00372                 if (fZRPosMarker2D) {
00373                     fZRPosMarker2D->SetMarkerColor(cMarkerFired);
00374                     fZRPosMarker2D->SetMarkerStyle(sMarkerFired);
00375                 }
00376             }
00377             else {
00378                 if (fZRPosMarker2D) {
00379                     fZRPosMarker2D->SetMarkerColor(cMarker);
00380                     fZRPosMarker2D->SetMarkerStyle(sMarker);
00381                 }
00382             }
00383 
00384             if (this->IsHighlighted()) {
00385                 if (fZRPosMarker2D) {
00386                     fZRPosMarker2D->SetMarkerColor(cMarkerHL);
00387                     fZRPosMarker2D->SetMarkerStyle(sMarkerHL);
00388                 }
00389             }
00390 
00391             if (opt.Contains("WIRE")) {
00392                 if (fZRPosMarker2D) fZRPosMarker2D->Paint();
00393             }
00394         }
00395     }
00396 }
00397 
00398 //_____________________________________________________
00399 
00400 char *Mdc2DWire::GetObjectInfo(Int_t px, Int_t py) const {
00401 
00402     BesView *view = (BesView*)gPad->GetView();
00403     if (view) return view->GetObjectInfo(px, py);
00404     else return TObject::GetObjectInfo(px, py);
00405 }
00406 
00407 //_____________________________________________________
00408 
00409 bool Mdc2DWire::HasZRSection()
00410 {
00411     if (fWireType != 2) return false;
00412 
00413     bool flag = false;
00414     BesView *view = (BesView*)gPad->GetView();
00415     Double_t viewPhi = view->GetLongitude();
00416     viewPhi = Range360(viewPhi);
00417     //if (GetName() == TString("Layer0Wire0")) cout << "view " << viewPhi << endl;
00418 
00419     Double_t zrPhi = viewPhi-90.0;
00420     zrPhi = Range360(zrPhi);
00421     //if (GetName() == TString("Layer0Wire0")) cout << zrPhi << endl;
00422 
00423     for (Int_t i = 0; i < 2; i++) {
00424         if (i==1) {
00425             zrPhi += 180.0;
00426             zrPhi = Range360(zrPhi);
00427         }
00428 
00429         if ( fabs(fEastPhi-fWestPhi) < 180.0 ) {  // no cross phi=0.0
00430             if ( (fEastPhi-zrPhi)*(fWestPhi-zrPhi) > 0.0 ) flag = false;
00431             else {
00432                 Double_t factor = fabs( (fEastPhi-zrPhi)/(fEastPhi-fWestPhi) );
00433                 for (Int_t i = 0; i < 3; i++) {
00434                     fZRSectionPos[i] =  factor*fWestHole[i] + (1.0-factor)*fEastHole[i];
00435                 }
00436                 flag = true;
00437                 break;
00438             }
00439         }
00440         else { // cross phi=0.0
00441             if ( (fEastPhi-zrPhi)*(fWestPhi-zrPhi) < 0.0 ) flag = false;
00442             else { // range 0~360 -> -180~180
00443                 Double_t tempEastPhi = fEastPhi;
00444                 if (tempEastPhi >= 180.0) tempEastPhi -= 360.0;
00445                 Double_t tempWestPhi = fWestPhi;
00446                 if (tempWestPhi >= 180.0) tempWestPhi -= 360.0;
00447                 Double_t tempZRPhi   = zrPhi;
00448                 if (tempZRPhi   >= 180.0) tempZRPhi   -= 360.0;
00449 
00450                 Double_t factor = fabs( (tempEastPhi-tempZRPhi)/(tempEastPhi-tempWestPhi) );
00451                 for (Int_t i = 0; i < 3; i++) {
00452                     fZRSectionPos[i] =  factor*fWestHole[i] + (1.0-factor)*fEastHole[i];
00453                 }
00454                 flag = true;
00455                 break;
00456             }
00457         }
00458     }
00459 
00460     return flag;
00461 }
00462 
00463 //_____________________________________________________
00464 
00465 Double_t Mdc2DWire::Range360(Double_t input)
00466 {
00467     if (input >= 360.0) {
00468         do {
00469             input -= 360.0;
00470         }
00471         while (input >= 360.0);
00472     }
00473     else if (input < 0.0) {
00474         do {
00475             input += 360.0;
00476         }
00477         while (input < 0.0);
00478     }
00479 
00480     return input;
00481 }
00482 
00483 //_____________________________________________________
00484 
00485 void Mdc2DWire::SetTime(Double_t time)
00486 { 
00487     mdcTime = time;
00488 }
00489 
00490 //_____________________________________________________
00491 
00492 void Mdc2DWire::SetCharge(Double_t charge)
00493 { 
00494     mdcCharge = charge;
00495 }
00496 
00497 //_____________________________________________________
00498 
00499 void Mdc2DWire::SetQOverflow(Bool_t qOvfl)
00500 { 
00501     qOverflow = qOvfl;
00502 }
00503 
00504 //_____________________________________________________
00505 
00506 void Mdc2DWire::SetEvTime(Double_t time)
00507 { 
00508     evTime = time;
00509 }
00510 
00511 //_____________________________________________________
00512 
00513 void Mdc2DWire::SetColorfulWire(Bool_t colorfulWire, Bool_t subEvTime)
00514 { 
00515     fColorfulWire = colorfulWire;
00516     if(fColorfulWire){
00517         //yzhang change LINE COLOR of fired mdc wires 
00518         //n color bin = 50, time of max bin is 2000 
00519         //time max value = 1943.8125 ~ 2000 ns 
00520         //no time info color is kGray 
00521         //time > 2000 && time <=10000, color is kBlack
00522         int tempColor;
00523         if(subEvTime){ 
00524             // raw time - event start time
00525             double tempMdcTime = mdcTime - evTime; 
00526             if(fabs(evTime)>0.0001) tempMdcTime += 230;
00527             if(tempMdcTime>10000) { 
00528                 tempColor = kGray;
00529             }else if(tempMdcTime>2000&&tempMdcTime<=10000){
00530                 tempColor = kRed;
00531             }else if(tempMdcTime<-10){
00532                 tempColor = kWhite;
00533             }else{
00534                 tempColor = 51 + (int) (tempMdcTime/40);
00535             }
00536         }else{
00537             //raw time
00538             if(mdcTime>10000) { 
00539                 tempColor= kGray;
00540             }else if(mdcTime>2000&&mdcTime<=10000){
00541                 tempColor = kRed;
00542             }else{
00543                 tempColor = 51 + (int) (mdcTime/40);
00544             }
00545         }
00546         lcWireFired = tempColor;
00547         //std::cout<< " mdcTime  "<<mdcTime <<" evTime "<< evTime << " t-t0 "<< mdcTime - evTime +230<< " lcWireFired " << lcWireFired <<std::endl;
00548 
00549         //yzhang change FILL COLOR of fired mdc wires
00550         //n color bin = 50,  charge of max bin is 2000
00551         //charge max value = 29783 ~ 30000
00552         //adc> 2000&&<=30000 color is kBlack
00553         //no adc color is kGray
00554         if(mdcCharge>30000){
00555             tempColor = kGray;
00556         }else if(mdcCharge>2000&&mdcCharge<=30000){
00557             tempColor = kRed;
00558         }else {
00559             tempColor = 51 + (int) (mdcCharge/40);
00560         }
00561         if(qOverflow) { tempColor = kBlack; }
00562         fcCircleFired  = tempColor;
00563         //std::cout<< " mdcCharge "<<mdcCharge<<" ovfl "<<qOverflow<<" fcCircleFired " << fcCircleFired<< std::endl;
00564     }else{
00565         lcWireFired = kRed;
00566         fcCircleFired  = 1004;
00567     } 
00568 }

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