TEveTrackProjected.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveTrackProjected.cxx 33955 2010-06-17 11:33:13Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveTrackProjected.h"
00013 #include "TEveTrackPropagator.h"
00014 #include "TEveProjectionManager.h"
00015 #include "TEveTrans.h"
00016 
00017 //==============================================================================
00018 //==============================================================================
00019 // TEveTrackProjected
00020 //==============================================================================
00021 
00022 //______________________________________________________________________________
00023 //
00024 // Projected copy of a TEveTrack.
00025 
00026 ClassImp(TEveTrackProjected);
00027 
00028 //______________________________________________________________________________
00029 TEveTrackProjected::TEveTrackProjected() :
00030    TEveTrack (),
00031    fOrigPnts (0)
00032 {
00033    // Default constructor.
00034 }
00035 
00036 /******************************************************************************/
00037 
00038 //______________________________________________________________________________
00039 void TEveTrackProjected::SetProjection(TEveProjectionManager* mng, TEveProjectable* model)
00040 {
00041    // This is virtual method from base-class TEveProjected.
00042 
00043    TEveProjected::SetProjection(mng, model);
00044    CopyVizParams(dynamic_cast<TEveElement*>(model));
00045 
00046    TEveTrack* otrack = dynamic_cast<TEveTrack*>(fProjectable);
00047    SetTrackParams(*otrack);
00048    SetLockPoints(otrack->GetLockPoints());
00049 }
00050 
00051 /******************************************************************************/
00052 
00053 //______________________________________________________________________________
00054 void TEveTrackProjected::SetDepthLocal(Float_t d)
00055 {
00056    // Set depth (z-coordinate) of the projected points.
00057 
00058    SetDepthCommon(d, this, fBBox);
00059 
00060    Int_t    n = Size();
00061    Float_t *p = GetP() + 2;
00062    for (Int_t i = 0; i < n; ++i, p+=3)
00063    {
00064       *p = fDepth;
00065    }
00066 
00067    for (vPathMark_i pm = fPathMarks.begin(); pm != fPathMarks.end(); ++pm)
00068    {
00069       pm->fV.fZ = fDepth;
00070    }
00071 }
00072 
00073 //______________________________________________________________________________
00074 void TEveTrackProjected::UpdateProjection()
00075 {
00076    // Virtual method from base-class TEveProjected.
00077 
00078    MakeTrack(kFALSE); // TEveProjectionManager makes recursive calls
00079 }
00080 
00081 //______________________________________________________________________________
00082 void TEveTrackProjected::GetBreakPoint(Int_t idx, Bool_t back,
00083                                        Float_t& x, Float_t& y, Float_t& z)
00084 {
00085    // With bisection calculate break-point vertex.
00086 
00087    TEveProjection *projection = fManager->GetProjection();
00088 
00089    TEveVector vL = fOrigPnts[idx];
00090    TEveVector vR = fOrigPnts[idx+1];
00091    TEveVector vM, vLP, vMP;
00092    while ((vL-vR).Mag2() > 1e-10f)
00093    {
00094       vM.Mult(vL+vR, 0.5f);
00095       vLP.Set(vL); projection->ProjectPoint(vLP.fX, vLP.fY, vLP.fZ, 0);
00096       vMP.Set(vM); projection->ProjectPoint(vMP.fX, vMP.fY, vMP.fZ, 0);
00097       if (projection->AcceptSegment(vLP, vMP, 0.0f))
00098       {
00099          vL.Set(vM);
00100       }
00101       else
00102       {
00103          vR.Set(vM);
00104       }
00105    }
00106 
00107    if (back) {
00108       x = vL.fX; y = vL.fY; z = vL.fZ;
00109    } else {
00110       x = vR.fX; y = vR.fY; z = vR.fZ;
00111    }
00112    projection->ProjectPoint(x, y, z, fDepth);
00113 }
00114 
00115 //______________________________________________________________________________
00116 Int_t TEveTrackProjected::GetBreakPointIdx(Int_t start)
00117 {
00118    // Findex index of the last point that lies within the same
00119    // segment of projected space.
00120    // For example, rho-z projection separates upper and lower hemisphere
00121    // and tracks break into two lines when crossing the y=0 plane.
00122 
00123    TEveProjection *projection = fManager->GetProjection();
00124 
00125    Int_t val = fLastPoint;
00126 
00127    TEveVector v1, v2;
00128    if (Size() > 1)
00129    {
00130       Int_t i = start;
00131       while(i < fLastPoint)
00132       {
00133          GetPoint(i,   v1.fX, v1.fY, v1.fZ);
00134          GetPoint(i+1, v2.fX, v2.fY, v2.fZ);
00135          if(projection->AcceptSegment(v1, v2, fPropagator->GetDelta()) == kFALSE)
00136          {
00137             val = i;
00138             break;
00139          }
00140          i++;
00141       }
00142    }
00143    return val;
00144 }
00145 
00146 /******************************************************************************/
00147 
00148 //______________________________________________________________________________
00149 void TEveTrackProjected::MakeTrack(Bool_t recurse)
00150 {
00151    // Calculate the points of the track for drawing.
00152    // Call base-class, project, find break-points and insert points
00153    // required for full representation.
00154 
00155    TEveTrack      *otrack     = dynamic_cast<TEveTrack*>(fProjectable);
00156    TEveTrans      *trans      = otrack->PtrMainTrans(kFALSE);
00157    TEveProjection *projection = fManager->GetProjection();
00158 
00159    fBreakPoints.clear();
00160 
00161    fPathMarks.clear();
00162    SetPathMarks(*otrack);
00163    if (GetLockPoints() || otrack->Size() > 0)
00164    {
00165       ClonePoints(*otrack);
00166       fLastPMIdx = otrack->GetLastPMIdx();
00167    }
00168    else
00169    {
00170       TEveTrack::MakeTrack(recurse);
00171    }
00172    if (Size() == 0) return; // All points can be outside of MaxR / MaxZ limits.
00173 
00174    // Break segments additionally if required by the projection.
00175    ReduceSegmentLengths(projection->GetMaxTrackStep());
00176 
00177    // Project points, store originals (needed for break-points).
00178    Float_t *p = GetP();
00179    fOrigPnts  = new TEveVector[Size()];
00180    for (Int_t i = 0; i < Size(); ++i, p+=3)
00181    {
00182       if (trans) trans->MultiplyIP(p);
00183       fOrigPnts[i].Set(p);
00184       projection->ProjectPointfv(p, fDepth);
00185    }
00186 
00187    Float_t x, y, z;
00188    Int_t   bL = 0, bR = GetBreakPointIdx(0);
00189    std::vector<TEveVector> vvec;
00190    while (kTRUE)
00191    {
00192       for (Int_t i=bL; i<=bR; i++)
00193       {
00194          GetPoint(i, x, y, z);
00195          vvec.push_back(TEveVector(x, y, z));
00196       }
00197       if (bR == fLastPoint)
00198          break;
00199 
00200       GetBreakPoint(bR, kTRUE,  x, y, z); vvec.push_back(TEveVector(x, y, z));
00201       fBreakPoints.push_back((Int_t)vvec.size());
00202       GetBreakPoint(bR, kFALSE, x, y, z); vvec.push_back(TEveVector(x, y, z));
00203 
00204       bL = bR + 1;
00205       bR = GetBreakPointIdx(bL);
00206    }
00207    fBreakPoints.push_back((Int_t)vvec.size()); // Mark the track-end for drawing.
00208 
00209    // Decide if points need to be fixed.
00210    // This (and the fixing itself) should really be done in TEveProjection but
00211    // for now we do it here as RhoZ is the only one that needs it.
00212    Bool_t  fix_y  = kFALSE;
00213    Float_t sign_y = 0;
00214    if (projection->HasSeveralSubSpaces())
00215    {
00216       switch (fPropagator->GetProjTrackBreaking())
00217       {
00218          case TEveTrackPropagator::kPTB_UseFirstPointPos:
00219          {
00220             fix_y  = kTRUE;
00221             sign_y = vvec.front().fY;
00222             break;
00223          }
00224          case TEveTrackPropagator::kPTB_UseLastPointPos:
00225          {
00226             fix_y  = kTRUE;
00227             sign_y = vvec.back().fY;
00228             break;
00229          }
00230       }
00231    }
00232 
00233    Reset((Int_t)vvec.size());
00234    for (std::vector<TEveVector>::iterator i=vvec.begin(); i!=vvec.end(); ++i)
00235    {
00236       if (fix_y)
00237          SetNextPoint((*i).fX, TMath::Sign((*i).fY, sign_y), (*i).fZ);
00238       else
00239          SetNextPoint((*i).fX, (*i).fY, (*i).fZ);
00240    }
00241    delete [] fOrigPnts;
00242 
00243    // Project path-marks
00244    for (vPathMark_i pm = fPathMarks.begin(); pm != fPathMarks.end(); ++pm)
00245    {
00246       projection->ProjectVector(trans, pm->fV, fDepth);
00247    }
00248 }
00249 
00250 /******************************************************************************/
00251 
00252 //______________________________________________________________________________
00253 void TEveTrackProjected::PrintLineSegments()
00254 {
00255    // Print line segments info.
00256 
00257    printf("%s LineSegments:\n", GetName());
00258    Int_t start = 0;
00259    Int_t segment = 0;
00260    TEveVector sVec;
00261    TEveVector bPnt;
00262    for (std::vector<Int_t>::iterator bpi = fBreakPoints.begin();
00263         bpi != fBreakPoints.end(); ++bpi)
00264    {
00265       Int_t size = *bpi - start;
00266 
00267       GetPoint(start, sVec.fX, sVec.fY, sVec.fZ);
00268       GetPoint((*bpi)-1, bPnt.fX, bPnt.fY, bPnt.fZ);
00269       printf("seg %d size %d start %d ::(%f, %f, %f) (%f, %f, %f)\n",
00270              segment, size, start, sVec.fX, sVec.fY, sVec.fZ,
00271              bPnt.fX, bPnt.fY, bPnt.fZ);
00272       start   += size;
00273       segment ++;
00274    }
00275 }
00276 
00277 /******************************************************************************/
00278 
00279 //______________________________________________________________________________
00280 void TEveTrackProjected::SecSelected(TEveTrack* /*track*/)
00281 {
00282     // Virtual method from from base-class TEveTrack.
00283 
00284    TEveTrack* t = dynamic_cast<TEveTrack*>(fProjectable);
00285    if (t)
00286       t->SecSelected(t);
00287 }
00288 
00289 
00290 //==============================================================================
00291 //==============================================================================
00292 // TEveTrackListProjected
00293 //==============================================================================
00294 
00295 //______________________________________________________________________________
00296 //
00297 // Specialization of TEveTrackList for holding TEveTrackProjected objects.
00298 
00299 ClassImp(TEveTrackListProjected);
00300 
00301 //______________________________________________________________________________
00302 TEveTrackListProjected::TEveTrackListProjected() :
00303    TEveTrackList (),
00304    TEveProjected ()
00305 {
00306    // Default constructor.
00307 }
00308 
00309 /******************************************************************************/
00310 
00311 //______________________________________________________________________________
00312 void TEveTrackListProjected::SetProjection(TEveProjectionManager* proj, TEveProjectable* model)
00313 {
00314    // This is virtual method from base-class TEveProjected.
00315 
00316    TEveProjected::SetProjection(proj, model);
00317    CopyVizParams(dynamic_cast<TEveElement*>(model));
00318 
00319    TEveTrackList& tl = * dynamic_cast<TEveTrackList*>(model);
00320    SetPropagator(tl.GetPropagator());
00321 }
00322 
00323 //______________________________________________________________________________
00324 void TEveTrackListProjected::SetDepthLocal(Float_t /*d*/)
00325 {
00326    // This is not needed for functionality as SetDepth(Float_t d)
00327    // is overriden -- but SetDepthLocal() is abstract.
00328    // Just emits a warning if called.
00329 
00330    Warning("SetDepthLocal", "This function only exists to fulfill an abstract interface.");
00331 }
00332 
00333 //______________________________________________________________________________
00334 void TEveTrackListProjected::SetDepth(Float_t d)
00335 {
00336    // Set depth of all children inheriting from TEveTrackProjected.
00337 
00338    SetDepth(d, this);
00339 }
00340 
00341 //______________________________________________________________________________
00342 void TEveTrackListProjected::SetDepth(Float_t d, TEveElement* el)
00343 {
00344    // Set depth of all children of el inheriting from TEveTrackProjected.
00345 
00346    TEveTrackProjected* ptrack;
00347    for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
00348    {
00349       ptrack = dynamic_cast<TEveTrackProjected*>(*i);
00350       if (ptrack)
00351          ptrack->SetDepth(d);
00352       if (fRecurse)
00353          SetDepth(d, *i);
00354    }
00355 }

Generated on Tue Jul 5 14:16:14 2011 for ROOT_528-00b_version by  doxygen 1.5.1