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

GfxShower.cxx

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

Generated on Mon Nov 23 05:26:55 2009 for loon by  doxygen 1.3.9.1