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

Midad/MultiPage/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 
00008 #include <TMarker.h>
00009 #include <TList.h>
00010 #include <TPolyLine.h>
00011 
00012 #include <map>
00013 using namespace std;
00014 
00015 GfxTrack::GfxTrack(const CandTrackHandle& cth, GfxTrackList& parent)
00016     : fTrack(cth)
00017     , fParent(parent)
00018     , fImp(0)
00019 {
00020 //    cerr << "Creating GfxTrack with " << cth.GetNDaughters() << " strips\n";
00021 }
00022 
00023 GfxTrack::GfxTrack(const GfxTrack& rhs)
00024     : TObject()
00025     , fTrack(rhs.fTrack), fParent(rhs.fParent), fImp(0)
00026 {
00027 }
00028 
00029 
00030 GfxTrack::~GfxTrack()
00031 {
00032     if (fImp) { delete fImp; fImp = 0; }
00033 }
00034 
00035 void GfxTrack::Configure()
00036 {
00037     if (fImp) { delete fImp; fImp = 0; }
00038 
00039 
00040     switch (fParent.GetViewState()->GetSpatialMetric()) {
00041     case ViewState::metric_is_continuous:
00042         if (! this->BuildRealImp()) return;
00043         break;
00044     case ViewState::metric_is_discreet: default:
00045         if (! this->BuildDiscreteImp()) return;
00046         break;
00047     }
00048 
00049 }
00050 
00051 int GfxTrack::GetCandTrackData(float *u, float *v, float *z, 
00052                                float* q, float *t,
00053                                int *strip_number, int *plane_number)
00054 
00055 {
00056     TIter titr(fTrack.GetDaughterIterator());
00057     PlaneView::PlaneView_t view = fParent.GetPlaneView();
00058 
00059     int ind=0;
00060     while (CandStripHandle* csh = dynamic_cast<CandStripHandle*>(titr())) {
00061 //        cerr << "PlaneView: " << view << " =? " << csh->GetPlaneView() << endl;
00062         if (csh->GetPlaneView() != view) continue;
00063 
00064         int plane = csh->GetPlane();
00065         if (plane_number) plane_number[ind] = plane;
00066         if (strip_number) strip_number[ind] = csh->GetStrip();
00067         if (u) u[ind] = fTrack.GetU(plane);
00068         if (v) v[ind] = fTrack.GetV(plane);
00069         if (z) z[ind] = fTrack.GetZ(plane);
00070         if (t) t[ind] = fTrack.GetT(plane);
00071         if (q) q[ind] = csh->GetCharge();
00072 
00073 #if 0
00074         cerr << "index = " << ind
00075              << " view = " << view
00076              << " plane = " << plane
00077              << " strip = " << csh->GetStrip()
00078              << " u = " << fTrack.GetU(plane)
00079              << " v = " << fTrack.GetV(plane)
00080              << " z = " << fTrack.GetZ(plane)
00081              << " t = " << fTrack.GetT(plane)
00082              << " q = " << csh->GetCharge()
00083              << endl;
00084 #endif
00085 
00086         ++ind;
00087     }
00088     return ind;
00089 }
00090 
00091 bool GfxTrack::BuildRealImp()
00092 {
00093     float *x=0, *y=0;
00094     int *plane_number, npoints;
00095 
00096     int n = fTrack.GetNDaughters();
00097     x = new float[n];
00098     y = new float[n];
00099     plane_number = new int[n];
00100 
00101     
00102     double vx, vy;
00103     if (fParent.GetPlaneView() == PlaneView::kU) {
00104         npoints = this->GetCandTrackData(y,0,x,0,0,0,plane_number);
00105         vy = fTrack.GetVtxU();
00106     }
00107     else {                      // kV
00108         npoints = this->GetCandTrackData(0,y,x,0,0,0,plane_number);
00109         vy = fTrack.GetVtxV();
00110     }
00111     vx = fTrack.GetVtxZ();
00112 
00113     TList* track = new TList;
00114     track->SetOwner();
00115 
00116     track->Add(new TMarker(vx,vy,3)); // 3 = astrix-ish marker.
00117     track->Add(new TPolyLine(npoints,x,y));
00118     fImp = track;
00119 
00120     delete [] x;
00121     delete [] y;
00122     delete [] plane_number;
00123 
00124     return true;
00125 }
00126 
00127 bool GfxTrack::BuildDiscreteImp()
00128 {
00129     int      n = fTrack.GetNDaughters();
00130 
00131     // using new [] here causes bizzare segv in unrelated parts of the
00132     // code, so lets get all FORTRAN about it.
00133     const int maxstrips = 1000;
00134     int strip[maxstrips], plane[maxstrips];
00135     float q[maxstrips];
00136 
00137 
00138     n = this->GetCandTrackData(0,0,0,q,0,strip,plane);
00139     if (n > maxstrips) n = maxstrips;
00140     
00141     map<int,float> mean_strip, norm_strip;
00142     for (int ind = 0; ind < n; ++ind) {
00143         if (mean_strip.find(plane[ind]) == mean_strip.end()) {
00144             mean_strip[plane[ind]] = 0;
00145             norm_strip[plane[ind]] = 0;
00146         }
00147         mean_strip[plane[ind]] += strip[ind]*q[ind];
00148         norm_strip[plane[ind]] += q[ind];
00149     }
00150 
00151     int vtx_plane = fTrack.GetVtxPlane();
00152     int vtx_ind = -1, ind;
00153     float x[maxstrips], y[maxstrips];
00154 
00155     map<int,float>::iterator it, done = mean_strip.end();
00156     for (ind=0, it = mean_strip.begin(); it != done && n < maxstrips; ++it, ++ind) {
00157         int plane = it->first;
00158         float qstrip = it->second;
00159         float norm = norm_strip[plane];
00160         x[ind] = plane;
00161         y[ind] = qstrip/norm;
00162         if (plane == vtx_plane) {
00163             vtx_ind = ind;
00164 //            cerr << Form("vertex: %d: plane=%.0f strip=%.1f\n",ind,x[ind],y[ind]);
00165         }
00166     }
00167 
00168     TList* track = new TList;
00169     track->SetOwner();
00170 
00171     if (vtx_ind >= 0) track->Add(new TMarker(x[vtx_ind],y[vtx_ind],3));
00172 
00173     track->Add(new TPolyLine(ind,x,y));
00174     fImp = track;
00175 
00176     return true;
00177 }
00178 
00179 void GfxTrack::ExecuteEvent(int event, int px, int py)
00180 {
00181     fParent.ExecuteEventTrack(event,px,py,this);
00182 }
00183 void GfxTrack::Paint(Option_t* option)
00184 {
00185     if (!fImp) return;
00186 
00187     fImp->Paint(option);
00188 }
00189 int GfxTrack::DistancetoPrimitive(int px, int py)
00190 {
00191     int dist = 0xdead;
00192     if (fImp) {
00193         TList* l = dynamic_cast<TList*>(fImp);
00194         if (!l) 
00195             dist = fImp->DistancetoPrimitive(px,py);
00196         else {
00197             TIter next(l);
00198             TObject* obj;
00199             while ((obj=next())) {
00200                 int d = obj->DistancetoPrimitive(px,py);
00201                 if (d < dist) dist = d;
00202             }
00203         }
00204     }
00205     return dist;
00206 }
00207 

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