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

Go to the documentation of this file.
00001 #include <TPad.h>
00002 #include <TVector3.h>
00003 #include <TGeoManager.h>
00004 #include "math.h"
00005 #include <TMath.h>
00006 
00007 #include <iostream>
00008 
00009 #include "BesVisLib/BesGeoTrack.h"
00010 #include "BesVisLib/BesView.h"
00011 #include "BesVisLib/BesMarker2D.h"
00012 #include "BesVisLib/Mdc2DWire.h"
00013 #include "BesVisLib/Muc2DStrip.h"
00014 #include "BesVisLib/BesCursor.h"
00015 
00016 using namespace std;
00017 
00018 #ifndef __CINT__
00019 ClassImp(BesGeoTrack)
00020 #endif
00021 //int BesGeoTrack::count = 0;
00022 BesGeoTrack::BesGeoTrack()
00023         : TGeoTrack()
00024 {
00025 //  std::cout << "co BesGeoTrack: " << ++count << std::endl;
00026     Init();
00027 }
00028 
00029 BesGeoTrack::BesGeoTrack(Int_t id, Int_t pdgcode, TVirtualGeoTrack *parent, TObject *particle)
00030         : TGeoTrack(id, pdgcode, parent, particle)
00031 {
00032 //  std::cout << "co BesGeoTrack: " << ++count << std::endl;
00033     Init();
00034 }
00035 
00036 BesGeoTrack::~BesGeoTrack()
00037 {
00038 //  std::cout << "de BesGeoTrack: " << --count << std::endl;
00039     if (fTip)        delete fTip;
00040     if (fPolyLine3D) delete fPolyLine3D;
00041     if (fMarker)     delete fMarker;
00042 }
00043 
00044 void BesGeoTrack::Init()
00045 {
00046     fTip = new BesPaveText(0, 0, 0.1, 0.1, "TL");
00047 
00048     fMarker = 0;
00049 
00050     //fHits.Clear("C");
00051 }
00052 
00053 void BesGeoTrack::CloseInfo()
00054 {
00055     if (fTip) {
00056         fTip->SetText(fInfoCon);
00057     }
00058     else
00059         cout << "BesGeoTrack::CloseInfo, not initialized" << endl;
00060 }
00061 
00062 void BesGeoTrack::AddPoint(Double_t x, Double_t y, Double_t z, Double_t t)
00063 {
00064     TGeoTrack::AddPoint(x,y,z,t);
00065 }
00066 
00067 void BesGeoTrack::SetMarker(Double_t x, Double_t y, Double_t z)
00068 {
00069     fMarker = new BesMarker2D("RecMarker", "RecMarker", x, y, z);
00070 
00071     if (fType == 1) { // tof
00072         fMarker->SetMarkerSizeMultiple(20);
00073         fMarker->SetMarkerStyle(5);
00074         fMarker->SetMarkerColor(kBlack);
00075     }
00076     else if (fType == 2) { // emc
00077         fMarker->SetMarkerSizeMultiple(20);
00078         fMarker->SetMarkerStyle(2);
00079         fMarker->SetMarkerColor(kBlack);
00080     }
00081 }
00082 
00083 Int_t BesGeoTrack::DistancetoPrimitive(Int_t px, Int_t py)
00084 {
00085     Int_t dist = 9999;
00086     Int_t cx, cy;
00087     Double_t edge = 4.0; // edge width of track
00088     Double_t markSizeRatio = 4.0;  // 4.0 is approximate size.
00089 
00090     if (fType == 1 || fType == 2) { // tof or emc
00091         if (!fMarker) return dist;
00092         fMarker->GetCenterPixel(cx, cy);
00093         if (fType == 1) { // tof
00094             Double_t r = sqrt( Double_t((px-cx)*(px-cx) + (py-cy)*(py-cy)) );
00095             Double_t markerR = markSizeRatio*fMarker->GetMarkerSize();
00096             if (markerR > 50) markerR = 50;  
00097             // if the size of a marker with type of circle is too large > 50 pixel, it could not be enlarged.
00098             if ( fabs(r-markerR) < edge ) dist = 0;
00099         }
00100         else if (fType == 2) { // emc
00101             Double_t dx = abs(px-cx), dy = abs(py-cy);
00102             if ( fabs(dx) < edge && fabs(dy) < markSizeRatio*fMarker->GetMarkerSize() ||
00103                     fabs(dy) < edge && fabs(dx) < markSizeRatio*fMarker->GetMarkerSize() )
00104                 dist = 0;
00105         }
00106 
00107         return dist;
00108     }
00109     else return TGeoTrack::DistancetoPrimitive(px, py);
00110 }
00111 
00112 void BesGeoTrack::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00113 {
00114     BesView *view = (BesView*)gPad->GetView();
00115 
00116     if (gBesCursor->GetType() == kBesHand) {
00117         if (view) view->ExecuteEvent(event, px, py);
00118     }
00119     else if (gBesCursor->GetType() == kBesPick){
00120 
00121         if (gPad) gPad->SetCursor(kPointer);
00122 
00123         Int_t width, color;
00124         Int_t normalWidth = 1, hlWidth = 2;
00125 
00126         switch (event) {
00127         case kMouseEnter:
00128             if (fType == 0) {
00129                 if (view->GetVisMdcHitsGlobal()) {
00130                     for (Int_t i = 0; i < fHits.GetEntries(); i++) {
00131                         Mdc2DWire *aHit = (Mdc2DWire*)fHits.At(i);
00132                         if (aHit != 0) {
00133                             if (view->GetVisMdcHits()) {
00134                                 aHit->SetHighlighted(true);
00135                             }
00136                         }
00137                     }
00138                 }
00139             }
00140             else if (fType == 1) {
00141                 if (view->GetVisTofHitsGlobal()) {
00142                     for (Int_t i = 0; i < fHits.GetEntries(); i++) {
00143                         Tof2DScin *aHit = (Tof2DScin*)fHits.At(i);
00144                         if (aHit != 0) {
00145                             if ( aHit->GetPart() == 0 && view->GetVisTofHitsEast() ||
00146                                     aHit->GetPart() == 1 && view->GetVisTofHitsBarrel() ||
00147                                     aHit->GetPart() == 2 && view->GetVisTofHitsWest() ) {
00148                                 aHit->SetHighlighted(true);
00149                             }
00150                         }
00151                     }
00152                 }
00153             }
00154             else if (fType == 2) {
00155                 if (view->GetVisEmcHitsGlobal()) {
00156                     for (Int_t i = 0; i < fHits.GetEntries(); i++) {
00157                         Emc2DCrystal *aHit = (Emc2DCrystal*)fHits.At(i);
00158                         if (aHit != 0) {
00159                             if ( aHit->GetPart() == 0 && view->GetVisEmcHitsEast() ||
00160                                     aHit->GetPart() == 1 && view->GetVisEmcHitsBarrel() ||
00161                                     aHit->GetPart() == 2 && view->GetVisEmcHitsWest() ) {
00162                                 aHit->SetHighlighted(true);
00163                             }
00164                         }
00165                     }
00166                 }
00167             }
00168             else if (fType == 3) {
00169                 if (view->GetVisMucHitsGlobal()) {
00170                     for (Int_t i = 0; i < fHits.GetEntries(); i++) {
00171                         Muc2DStrip *aHit = (Muc2DStrip*)fHits.At(i);
00172                         if (aHit != 0) {
00173                             if (view->GetVisMucHitsGlobal()) {
00174                                 aHit->SetHighlighted(true);
00175                             }
00176                         }
00177                     }
00178                 }
00179             }
00180 
00181 
00182             if (fType == 0) {
00183                 width = this->GetLineWidth();
00184                 color = this->GetLineColor();
00185                 this->SetLineWidth(hlWidth);
00186                 this->SetLineColor(kRed);
00187             }
00188             else if (fType == 1) {
00189                 fMarker->SetMarkerColor(kMagenta);
00190             }
00191             else if (fType == 2) {
00192                 fMarker->SetMarkerColor(kMagenta);
00193             }
00194             else if (fType == 3) {
00195                 width = this->GetLineWidth();
00196                 color = this->GetLineColor();
00197                 this->SetLineWidth(hlWidth);
00198                 this->SetLineColor(kRed);
00199             }
00200             else if (fType == 4) {
00201                 this->SetLineWidth(hlWidth);
00202                 this->SetLineColor(kBlue);
00203             }
00204 
00205             fTip->SetPos(px, py);
00206             view->UpdateView(0);
00207 
00208             //yzhang 2011-11-15 TEMP
00209             //drawHeader(fTip->GetText);
00210             if (gBesCursor->GetShowInfo()) fTip->Draw("TL,SAME"); // "BR,ARC,SAME"
00211             gPad->Modified();
00212             gPad->Update();
00213             break;
00214 
00215         case kMouseLeave:
00216             if (fType == 0) {
00217                 for (Int_t i = 0; i < (Int_t)fHits.GetEntries(); i++) {
00218                     Mdc2DWire *aHit = (Mdc2DWire*)fHits.At(i);
00219                     if (aHit != 0 && aHit->IsHighlighted()) {
00220                         aHit->SetHighlighted(false);
00221                     }
00222                 }
00223             }
00224             else if (fType == 1) {
00225                 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
00226                     Tof2DScin *aHit = (Tof2DScin*)fHits.At(i);
00227                     if (aHit != 0 && aHit->IsHighlighted()) {
00228                         aHit->SetHighlighted(false);
00229                     }
00230                 }
00231             }
00232             else if (fType == 2) {
00233                 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
00234                     Emc2DCrystal *aHit = (Emc2DCrystal*)fHits.At(i);
00235                     if (aHit != 0 && aHit->IsHighlighted()) {
00236                         aHit->SetHighlighted(false);
00237                     }
00238                 }
00239             }
00240             else if (fType == 3) {
00241                 for (Int_t i = 0; i < (Int_t)fHits.GetEntries(); i++) {
00242                     Muc2DStrip *aHit = (Muc2DStrip*)fHits.At(i);
00243                     if (aHit != 0 && aHit->IsHighlighted()) {
00244                         aHit->SetHighlighted(false);
00245                     }
00246                 }
00247             }
00248 
00249 
00250             if (fType == 0) {
00251                 this->SetLineWidth(normalWidth);
00252                 this->SetLineColor(kBlack);
00253             }
00254             else if (fType == 1) {
00255                 fMarker->SetMarkerColor(kBlack);
00256             }
00257             else if (fType == 2) {
00258                 fMarker->SetMarkerColor(kBlack);
00259             }
00260             else if (fType == 3) {
00261                 this->SetLineWidth(normalWidth);
00262                 this->SetLineColor(kBlack);
00263             }
00264             else if (fType == 4) {
00265                 this->SetLineWidth(normalWidth);
00266                 this->SetLineColor(kBlack);
00267             }
00268 
00269             view->UpdateView(0);
00270             gPad->Modified();
00271             gPad->Update();
00272             break;
00273         }
00274 
00275         TGeoTrack::ExecuteEvent(event, px, py);
00276     }
00277 }
00278 
00279 void BesGeoTrack::Draw(Option_t *option)
00280 {
00281     // Draw Polyline3D for OpenGL and X3d
00282     BesView *view = (BesView*)gPad->GetView();
00283     if (view && view->GetViewType() & k3DView) {
00284         Double_t x,y,z,t;
00285         fPolyLine3D = new TPolyLine3D(GetNpoints());
00286         for (Int_t i = 0; i < GetNpoints(); i++) {
00287             GetPoint(i,x,y,z,t);
00288             fPolyLine3D->SetPoint(i,x,y,z);
00289         }
00290         fPolyLine3D->SetBit(kCanDelete);
00291 
00292         fPolyLine3D->SetLineWidth(5);
00293         fPolyLine3D->SetLineColor(kRed);
00294         fPolyLine3D->Draw(option);
00295     }
00296 
00297     if (!gPad) gGeoManager->GetMasterVolume()->Draw();
00298     char *opt1 = Compress(option); // we will have to delete this ?
00299     TString opt(opt1);
00300     Bool_t is_default = kTRUE;
00301     Bool_t is_onelevel = kFALSE;
00302     Bool_t is_all = kFALSE;
00303     Bool_t is_type = kFALSE;
00304     if (opt.Contains("/D")) {
00305         is_onelevel = kTRUE;
00306         is_default = kFALSE;
00307     }
00308     if (opt.Contains("/*")) {
00309         is_all = kTRUE;
00310         is_default = kFALSE;
00311     }
00312     if (opt.Contains("/N")) {
00313         is_type = kTRUE;
00314         Int_t ist = opt.Index("/N")+2;
00315         Int_t ilast = opt.Index("/",ist);
00316         if (ilast<0) ilast=opt.Length();
00317         TString type = opt(ist, ilast-ist);
00318         gGeoManager->SetParticleName(type.Data());
00319     }
00320     SetBits(is_default, is_onelevel, is_all, is_type);
00321     AppendPad("SAME");
00322 
00323     delete [] opt1;
00324     return;
00325 }
00326 
00327 void BesGeoTrack::Paint(Option_t *option)
00328 {
00329     BesView *view = (BesView*)gPad->GetView();
00330     Double_t viewPhi = view->GetLongitude();
00331     TVector3 viewVec(cos(viewPhi*TMath::DegToRad()), sin(viewPhi*TMath::DegToRad()), 0);
00332     Double_t x, y, z, t;
00333     Double_t x1=0.0, y1=0.0, z1=0.0;
00334     Double_t dot, dotMin = 1e+20, dotTolerance = 0.01;
00335     for (Int_t i = 1; i < GetNpoints(); i++) {
00336         GetPoint(i, x, y, z, t);
00337         TVector3 vec(x,y,0);
00338         if (vec.Mag() > 5.0) {
00339             vec.SetMag(1.0);
00340             dot = fabs(vec.Dot(viewVec));
00341             if ( dot < dotTolerance && dot < dotMin ) {
00342                 x1 = x;
00343                 y1 = y;
00344                 z1 = z;
00345                 dotMin = dot;
00346             }
00347         }
00348     }
00349 
00350     if (dotMin < 1e+20) {
00351         BesMarker2D sectionPhi("trackPhi", "trackPhi", x1, y1, z1);
00352         sectionPhi.SetMarkerStyle(28);
00353         sectionPhi.SetMarkerColor(1);
00354         sectionPhi.SetMarkerSize(2);
00355         sectionPhi.Paint();  
00356         //sectionPhi paint the marker in origin point of MdcTrack!!!
00357     }
00358 
00359     if (fMarker) fMarker->Paint(option);
00360     TGeoTrack::Paint(option);
00361 }
00362 
00363 //_____________________________________________________
00364 
00365 char *BesGeoTrack::GetObjectInfo(Int_t px, Int_t py) const {
00366 
00367     BesView *view = (BesView*)gPad->GetView();
00368     if (view) return view->GetObjectInfo(px, py);
00369     else return TObject::GetObjectInfo(px, py);
00370 }
00371 
00372 void BesGeoTrack::SetCharge(Int_t charge)
00373 {
00374     fCharge = charge;
00375     if (fCharge > 0)      this->SetLineColor(kBlack); // +
00376     else if (fCharge < 0) this->SetLineColor(kBlack); // -
00377     else                   this->SetLineColor(kGreen); // 0
00378 }
00379 

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