Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

EventDisplay/GfxTrack.cxx

Go to the documentation of this file.
00001 #include "GfxTrack.h"
00002 #include "GfxTrackList.h"
00003 #include "GfxTrackListCfg.h"
00004 #include "ViewState.h"
00005 #include <RecoBase/CandStripHandle.h>
00006 #include <RecoBase/CandTrackHandle.h>
00007 #include <RecoBase/CandFitTrackHandle.h>
00008 #include <UgliGeometry/UgliGeomHandle.h>
00009 #include <UgliGeometry/UgliStripHandle.h>
00010 
00011 #include <CandDigit/CandDigitHandle.h>
00012 #include <Plex/PlexSEIdAltL.h>
00013 #include <TEllipse.h>
00014 #include <TBox.h>
00015 #include <TPad.h>
00016 #include <TMarker.h>
00017 #include <TList.h>
00018 #include <TPolyLine.h>
00019 
00020 #include <map>
00021 using namespace std;
00022 
00023 ClassImp(GfxTrack)
00024 
00025 GfxTrack::GfxTrack(const CandTrackHandle& cth, GfxTrackList& parent)
00026     : fTrack(cth)
00027     , fParent(parent)
00028     , fImp(0)
00029 {
00030 //    cerr << "Creating GfxTrack with " << cth.GetNDaughters() << " strips\n";
00031 }
00032 
00033 GfxTrack::GfxTrack(const GfxTrack& rhs)
00034     : TObject()
00035       ,fTrack(rhs.fTrack), fParent(rhs.fParent), fImp(0)
00036 {
00037 }
00038 
00039 
00040 GfxTrack::~GfxTrack()
00041 {
00042    this->Clear(); 
00043 }
00044 
00045 void GfxTrack::Clear(Option_t*)
00046 {
00047   if (fImp) delete fImp; fImp=0;
00048 }
00049 
00050 void GfxTrack::Configure()
00051 {
00052     if (fImp) { delete fImp; fImp = 0; }
00053 
00054 
00055     switch (fParent.GetViewState()->GetSpatialMetric()) {
00056     case ViewState::metric_is_continuous:
00057         if (! this->BuildRealImp()) return;
00058         break;
00059     case ViewState::metric_is_discreet: default:
00060         if (! this->BuildDiscreteImp()) return;
00061         break;
00062     }
00063 
00064 }
00065 
00066 int GfxTrack::GetCandTrackData(float *u, float *v, 
00067                                float *x, float *y, float *z, 
00068                                float *q, float *t,
00069                                int *strip_number, int *plane_number)
00070 
00071 {
00072 
00073   CandStripHandleItr orderedstripItr(fTrack.GetDaughterIterator());
00074   CandStripHandleKeyFunc *stripKf = orderedstripItr.CreateKeyFunc();
00075   stripKf->SetFun(CandStripHandle::KeyFromPlane);
00076   orderedstripItr.GetSet()->AdoptSortKeyFunc(stripKf);
00077   stripKf = 0;
00078 
00079   //    TIter titr(fTrack.GetDaughterIterator());
00080   PlaneView::PlaneView_t view = fParent.GetPlaneView();
00081   GraphicsView::GraphicsView_t gview = fParent.GetGraphicsView();
00082   
00083   int ind=0;
00084   while (CandStripHandle *csh = dynamic_cast<CandStripHandle*>(orderedstripItr())) {  
00085 
00086       if (csh->GetPlaneView() == view ||
00087           gview == GraphicsView::kUV || gview == GraphicsView::kXY) 
00088         {
00089                 
00090           int plane = csh->GetPlane();
00091           if (plane_number) {
00092             plane_number[ind] = plane;
00093           }
00094           if (strip_number) {
00095             strip_number[ind] = csh->GetStrip();
00096           }
00097           if (u){
00098             u[ind] = fTrack.GetU(plane);
00099           }
00100           if (v) {
00101             v[ind] = fTrack.GetV(plane);
00102           }
00103           if (x) {
00104             x[ind] = 0.70710678*(fTrack.GetU(plane)-fTrack.GetV(plane));
00105           }
00106           if (y) {
00107             y[ind] = 0.70710678*(fTrack.GetU(plane)+fTrack.GetV(plane));
00108           }
00109           if (z) {
00110             z[ind] = fTrack.GetZ(plane);
00111           }
00112           if (t) {
00113             t[ind] = fTrack.GetT(plane);
00114           }
00115           if (q) {
00116             q[ind] = csh->GetCharge();
00117           }     
00118           ++ind;
00119         }
00120     }
00121     return ind;
00122 }
00123 
00124 bool GfxTrack::BuildRealImp()
00125 {
00126     float *x=0, *y=0;
00127     int *plane_number;
00128     int npoints=0;
00129     double cx,cy,dx,dy;
00130 
00131     int vtxColor=12;
00132     int trkColor=50;
00133     int trkStripColor=48;
00134     fColor=trkColor;
00135     if(fParent.GetEVD()->GetCandEvent()){
00136       Bool_t found=false;
00137       CandEventHandle * ev = fParent.GetEVD()->GetCandEvent();
00138       Int_t nTracks = ev->GetLastTrack()+1;
00139       for (Int_t it=0;it<nTracks;it++){
00140         const CandFitTrackHandle * evtrk = dynamic_cast<const CandFitTrackHandle *>(ev->GetTrack(it));  
00141         const CandTrackHandle * evtrkbase = dynamic_cast<const CandTrackHandle *>(ev->GetTrack(it));
00142         CandTrackHandle * findtrack=evtrk->GetFinderTrack();
00143         if(findtrack->IsCloneOf(fTrack))found=true;
00144         if(evtrkbase->IsCloneOf(fTrack))found=true;
00145       }
00146       if(!found){
00147         vtxColor=fParent.GetEVD()->GetGhostColor();
00148         trkColor=fParent.GetEVD()->GetGhostColor();
00149         trkStripColor=fParent.GetEVD()->GetGhostColor();
00150         fColor=fParent.GetEVD()->GetGhostColor();
00151       }
00152     }
00153     else if(fParent.GetEVD()->GetCandSlice()){
00154       CandSliceHandle slc1 =  *(fParent.GetEVD()->GetCandSlice());
00155       CandSliceHandle slc2;
00156       if(fTrack.GetCandSlice())slc2=*(fTrack.GetCandSlice());
00157       if(slc1!=slc2 && !slc1.IsCloneOf(slc2)){
00158         vtxColor=fParent.GetEVD()->GetGhostColor();
00159         trkColor=fParent.GetEVD()->GetGhostColor();
00160         trkStripColor=fParent.GetEVD()->GetGhostColor();
00161         fColor=fParent.GetEVD()->GetGhostColor();
00162       }
00163     }
00164 
00165     int n = fTrack.GetNDaughters();
00166     x = new float[n];
00167     y = new float[n];
00168     plane_number = new int[n];
00169 
00170     TList* track = new TList;
00171     track->SetOwner();
00172     double vx, vy;
00173     if (fParent.GetGraphicsView() == GraphicsView::kUZ) {
00174         npoints = this->GetCandTrackData(y,0,0,0,x,0,0,0,0);
00175         vx = fTrack.GetVtxZ();
00176         vy = fTrack.GetVtxU();
00177 
00178         TMarker * Vx = new TMarker(vx,vy,29);
00179         Vx->SetMarkerSize(1.);
00180         Vx->SetMarkerColor(vtxColor);
00181         TPolyLine * Trk = new TPolyLine(npoints,x,y);                   
00182         Trk->SetLineColor(trkColor);
00183         Trk->SetLineWidth(1);
00184         track->Add(Vx); 
00185         track->Add(Trk);
00186    }
00187     else if(fParent.GetGraphicsView() == GraphicsView::kVZ) 
00188       {                      // kV
00189         npoints = this->GetCandTrackData(0,y,0,0,x,0,0,0,0);
00190         vx = fTrack.GetVtxZ();
00191         vy = fTrack.GetVtxV();
00192         TMarker * Vx = new TMarker(vx,vy,29);
00193         Vx->SetMarkerSize(1.);
00194         Vx->SetMarkerColor(vtxColor);
00195         TPolyLine * Trk = new TPolyLine(npoints,x,y);                   
00196         Trk->SetLineColor(trkColor);
00197         Trk->SetLineWidth(1);
00198         track->Add(Vx); 
00199         track->Add(Trk);
00200     }
00201     else if(fParent.GetGraphicsView() == GraphicsView::kXY) 
00202       {                     
00203         npoints = this->GetCandTrackData(0,0,x,y,0,0,0,0,plane_number);
00204         vx =  0.70710678*(fTrack.GetVtxU()-fTrack.GetVtxV());
00205         vy =  0.70710678*(fTrack.GetVtxU()+fTrack.GetVtxV());
00206         TMarker * Vx = new TMarker(vx,vy,29);
00207         Vx->SetMarkerSize(1.);
00208         Vx->SetMarkerColor(vtxColor);
00209         track->Add(Vx); 
00210     }
00211     else if(fParent.GetGraphicsView() == GraphicsView::kUV) 
00212       {                     
00213         npoints = this->GetCandTrackData(y,x,0,0,0,0,0,0,plane_number);
00214         vx = fTrack.GetVtxV();
00215         vy = fTrack.GetVtxU();
00216         TMarker * Vx = new TMarker(vx,vy,29);
00217         Vx->SetMarkerSize(1.);
00218         Vx->SetMarkerColor(vtxColor);
00219         track->Add(Vx); 
00220     }
00221  
00222     TIter titr(fTrack.GetDaughterIterator());
00223     PlaneView::PlaneView_t view = fParent.GetPlaneView();
00224     GraphicsView::GraphicsView_t gview = fParent.GetGraphicsView();
00225     while (CandStripHandle* csh = dynamic_cast<CandStripHandle*>(titr())) 
00226       {
00227         if (csh->GetPlaneView() == view)
00228           {
00229             if(gview !=GraphicsView::kXY && gview !=GraphicsView::kUV)
00230               { 
00231                 
00232                 TIter digitItr(csh->GetDaughterIterator());
00233                 while (CandDigitHandle *cdh = dynamic_cast<CandDigitHandle*>(digitItr())) {
00234                   
00235                   UgliGeomHandle ugh(*cdh->GetVldContext());
00236                   UgliStripHandle ush;
00237                   
00238                   ush = ugh.GetStripHandle(cdh->GetPlexSEIdAltL().GetBestItem().GetSEId());
00239                   
00240                   if (!ush.IsValid()) return false;
00241                   
00242                   cx = ush.GlobalPos(0).Z();
00243                   cy = ush.GetTPos();
00244                   dx = 2.0*ush.GetHalfThickness();
00245                   dy = 2.0*ush.GetHalfWidth();
00246                   TEllipse* box = new TEllipse(cx,cy,dx,dy);
00247                   box->SetFillColor(trkStripColor);
00248                   box->SetLineColor(trkStripColor);
00249                   track->Add(box);
00250                   
00251                 }
00252               }
00253             else
00254               {
00255                 for(int i=0;i<npoints;i++){
00256        
00257                   cx = x[i];
00258                   cy = y[i];
00259                   dx = 0.02;
00260                   dy = 0.02;
00261                   TEllipse* box = new TEllipse(cx,cy,dx,dy);
00262                   box->SetFillColor(trkStripColor);
00263                   box->SetLineColor(trkStripColor);
00264                   track->Add(box);
00265                 }
00266                 
00267               }
00268           }
00269       }
00270 
00271     fImp = track;
00272 
00273     delete [] x;
00274     delete [] y;
00275     delete [] plane_number;
00276 
00277     return true;
00278 }
00279 
00280 bool GfxTrack::BuildDiscreteImp()
00281 {
00282   double cx,cy,dx,dy;
00283   int      n = fTrack.GetNDaughters();
00284 
00285     // using new [] here causes bizzare segv in unrelated parts of the
00286     // code, so lets get all FORTRAN about it.
00287     const int maxstrips = 10000;
00288     int strip[maxstrips], plane[maxstrips];
00289     float q[maxstrips];
00290     float x[maxstrips],y[maxstrips];
00291 
00292     int vtxColor=12;
00293     int trkColor=50;
00294     int trkStripColor=48;
00295     fColor=trkColor;
00296     if(fParent.GetEVD()->GetCandEvent()){
00297       Bool_t found=false;
00298       CandEventHandle * ev = fParent.GetEVD()->GetCandEvent();
00299       Int_t nTracks = ev->GetLastTrack()+1;
00300       for (Int_t it=0;it<nTracks;it++){
00301         const CandFitTrackHandle * evtrk = dynamic_cast<const CandFitTrackHandle*>(ev->GetTrack(it));
00302         if(evtrk->GetFinderTrack()->IsCloneOf(fTrack))found=true;
00303       }
00304       if(!found){
00305         vtxColor=fParent.GetEVD()->GetGhostColor();
00306         trkColor=fParent.GetEVD()->GetGhostColor();
00307         trkStripColor=fParent.GetEVD()->GetGhostColor();
00308         fColor=fParent.GetEVD()->GetGhostColor();
00309       }
00310     }  
00311     else if(fParent.GetEVD()->GetCandSlice()){
00312       CandSliceHandle slc1 =  *(fParent.GetEVD()->GetCandSlice());
00313       CandSliceHandle slc2;
00314       if(fTrack.GetCandSlice())slc2=*(fTrack.GetCandSlice());
00315       if(slc1!=slc2 && !slc2.IsCloneOf(slc2)){
00316         vtxColor=fParent.GetEVD()->GetGhostColor();
00317         trkColor=fParent.GetEVD()->GetGhostColor();
00318         trkStripColor=fParent.GetEVD()->GetGhostColor();
00319         fColor=fParent.GetEVD()->GetGhostColor();
00320       }
00321     }
00322 
00323 
00324     TList* track = new TList;
00325     track->SetOwner();
00326 
00327     int ind;
00328 
00329     if(fParent.GetGraphicsView() != GraphicsView::kXY && 
00330        fParent.GetGraphicsView() != GraphicsView::kUV)
00331       {
00332         n = this->GetCandTrackData(0,0,0,0,0,q,0,strip,plane);
00333         if (n > maxstrips) n = maxstrips;
00334         
00335         map<int,float> mean_strip, norm_strip;
00336         for (ind = 0; ind < n; ++ind) {
00337           if (mean_strip.find(plane[ind]) == mean_strip.end()) {
00338             mean_strip[plane[ind]] = 0;
00339             norm_strip[plane[ind]] = 0;
00340           }
00341           mean_strip[plane[ind]] += strip[ind]*q[ind];
00342           norm_strip[plane[ind]] += q[ind];
00343         }
00344         int vtx_plane = fTrack.GetVtxPlane();
00345         int vtx_ind = -1;
00346         
00347         map<int,float>::iterator it, done = mean_strip.end();
00348         for (ind=0, it = mean_strip.begin(); it != done && n < maxstrips; ++it, ++ind) {
00349           int plane = it->first;
00350           float qstrip = it->second;
00351           float norm = norm_strip[plane];
00352           x[ind] = plane;
00353           y[ind] = qstrip/norm;
00354           if (plane == vtx_plane) {
00355             vtx_ind = ind;
00356             //            cerr << Form("vertex: %d: plane=%.0f strip=%.1f\n",ind,x[ind],y[ind]);
00357           }
00358         }
00359         if(vtx_ind>-1 && vtx_ind<=ind){
00360           TMarker * Vx = new TMarker(x[vtx_ind],y[vtx_ind],29);
00361           Vx->SetMarkerSize(2);
00362           Vx->SetMarkerColor(vtxColor);
00363           track->Add(Vx);
00364         }       
00365         TPolyLine * Trk = new TPolyLine(ind,x,y);                       
00366         Trk->SetLineColor(trkColor);
00367         track->Add(Trk);
00368       }
00369 
00370     else if(fParent.GetGraphicsView() == GraphicsView::kXY) 
00371       {                     
00372         ind = this->GetCandTrackData(0,0,x,y,0,0,0,0,plane);
00373         float vx =  0.70710678*(fTrack.GetVtxU()-fTrack.GetVtxV());
00374         float vy =  0.70710678*(fTrack.GetVtxU()+fTrack.GetVtxV());
00375         TMarker * Vx = new TMarker(vx,vy,29);
00376         Vx->SetMarkerSize(2);
00377         Vx->SetMarkerColor(vtxColor);
00378         track->Add(Vx);
00379     }
00380     else if(fParent.GetGraphicsView() == GraphicsView::kUV) 
00381       {                     
00382         ind = this->GetCandTrackData(y,x,0,0,0,0,0,0,plane);
00383         float vx = fTrack.GetVtxV();
00384         float vy = fTrack.GetVtxU();
00385         TMarker * Vx = new TMarker(vx,vy,29);
00386         Vx->SetMarkerSize(2);
00387         Vx->SetMarkerColor(vtxColor);
00388         track->Add(Vx);
00389 
00390     }
00391 
00392  
00393     TIter titr(fTrack.GetDaughterIterator());
00394     PlaneView::PlaneView_t view = fParent.GetPlaneView();
00395     GraphicsView::GraphicsView_t gview = fParent.GetGraphicsView();
00396     ind=0;
00397     while (CandStripHandle* csh = dynamic_cast<CandStripHandle*>(titr())) 
00398       {
00399         if (csh->GetPlaneView() == view)
00400           {
00401             if(gview !=GraphicsView::kXY && gview !=GraphicsView::kUV)
00402               { 
00403                 
00404                 TIter digitItr(csh->GetDaughterIterator());
00405                 while (CandDigitHandle *cdh = dynamic_cast<CandDigitHandle*>(digitItr())) {
00406                   
00407 
00408                   cx = cdh->GetPlexSEIdAltL().GetBestItem().GetSEId().GetPlane();
00409                   cy = cdh->GetPlexSEIdAltL().GetBestItem().GetSEId().GetStrip();
00410                   dx = 1.0;
00411                   dy = 1.0;
00412                   TEllipse* box = new TEllipse(cx,cy,dx,dy);             
00413                   box->SetFillColor(trkStripColor);
00414                   box->SetLineColor(trkStripColor);
00415                   track->Add(box);
00416                   
00417                 }
00418               }
00419             else
00420               {
00421 
00422                 for(int i=0;i<ind;i++){
00423        
00424                   cx = x[i];
00425                   cy = y[i];
00426                   dx = 1.0;
00427                   dy = 1.0;
00428                   TEllipse* box = new TEllipse(cx,cy,dx,dy);
00429                   box->SetFillColor(trkStripColor);
00430                   box->SetLineColor(trkStripColor);
00431                   track->Add(box);
00432                 }
00433                 
00434               }
00435           }
00436       }
00437 
00438 
00439     fImp = track;
00440 
00441     return true;
00442 }
00443 
00444 void GfxTrack::ExecuteEvent(int event, int px, int py)
00445 {
00446     fParent.ExecuteEvent(event,px,py,this);
00447 }
00448 void GfxTrack::Paint(Option_t* option)
00449 {
00450     if (!fImp) return;
00451     if(!fParent.GetEVD()->GetDrawAll() && ((fColor==fParent.GetEVD()->GetGhostColor() && !fParent.GetEVD()->GetDrawGhosts()) || (fColor!=fParent.GetEVD()->GetGhostColor() && fParent.GetEVD()->GetDrawGhosts())))return;
00452     fImp->Paint(option);
00453 }
00454 int GfxTrack::DistancetoPrimitive(int px, int py)
00455 {
00456     int dist = 0xdead;
00457     if (fImp) {
00458         TList* l = dynamic_cast<TList*>(fImp);
00459         if (!l) 
00460             dist = fImp->DistancetoPrimitive(px,py);
00461         else {
00462             TIter next(l);
00463             TObject* obj;
00464             while ((obj=next())) {
00465                 int d = obj->DistancetoPrimitive(px,py);
00466                 if (d < dist) dist = d;
00467             }
00468         }
00469     }
00470     return dist;
00471 }
00472 

Generated on Mon Feb 15 11:06:46 2010 for loon by  doxygen 1.3.9.1