Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveTrackProjected.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TEveTrackProjected.h"
13 #include "TEveTrackPropagator.h"
14 #include "TEveProjectionManager.h"
15 #include "TEveTrans.h"
16 
17 /** \class TEveTrackProjected
18 \ingroup TEve
19 Projected copy of a TEveTrack.
20 */
21 
22 ClassImp(TEveTrackProjected);
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// Default constructor.
26 
27 TEveTrackProjected::TEveTrackProjected() :
28  TEveTrack (),
29  fOrigPnts (0)
30 {
31 }
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// This is virtual method from base-class TEveProjected.
35 
36 void TEveTrackProjected::SetProjection(TEveProjectionManager* mng, TEveProjectable* model)
37 {
38  TEveProjected::SetProjection(mng, model);
39  CopyVizParams(dynamic_cast<TEveElement*>(model));
40 
41  TEveTrack* otrack = dynamic_cast<TEveTrack*>(fProjectable);
42  SetTrackParams(*otrack);
43  SetLockPoints(otrack->GetLockPoints());
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Set depth (z-coordinate) of the projected points.
48 
49 void TEveTrackProjected::SetDepthLocal(Float_t d)
50 {
51  SetDepthCommon(d, this, fBBox);
52 
53  Int_t n = Size();
54  Float_t *p = GetP() + 2;
55  for (Int_t i = 0; i < n; ++i, p+=3)
56  {
57  *p = fDepth;
58  }
59 
60  for (vPathMark_i pm = fPathMarks.begin(); pm != fPathMarks.end(); ++pm)
61  {
62  pm->fV.fZ = fDepth;
63  }
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Virtual method from base-class TEveProjected.
68 
69 void TEveTrackProjected::UpdateProjection()
70 {
71  MakeTrack(kFALSE); // TEveProjectionManager makes recursive calls
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Find index of the last point that lies within the same
76 /// segment of projected space.
77 /// For example, rho-z projection separates upper and lower hemisphere
78 /// and tracks break into two lines when crossing the y=0 plane.
79 
80 Int_t TEveTrackProjected::GetBreakPointIdx(Int_t start)
81 {
82  TEveProjection *projection = fManager->GetProjection();
83 
84  Int_t val = fLastPoint;
85 
86  if (projection->HasSeveralSubSpaces())
87  {
88  TEveVector v1, v2;
89  if (Size() > 1)
90  {
91  Int_t i = start;
92  while(i < fLastPoint)
93  {
94  GetPoint(i, v1.fX, v1.fY, v1.fZ);
95  GetPoint(i+1, v2.fX, v2.fY, v2.fZ);
96  if(projection->AcceptSegment(v1, v2, fPropagator->GetDelta()) == kFALSE)
97  {
98  val = i;
99  break;
100  }
101  i++;
102  }
103  }
104  }
105  return val;
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Calculate the points of the track for drawing.
110 /// Call base-class, project, find break-points and insert points
111 /// required for full representation.
112 
113 void TEveTrackProjected::MakeTrack(Bool_t recurse)
114 {
115  TEveTrack *otrack = dynamic_cast<TEveTrack*>(fProjectable);
116  TEveTrans *trans = otrack->PtrMainTrans(kFALSE);
117  TEveProjection *projection = fManager->GetProjection();
118 
119  fBreakPoints.clear();
120 
121  fPathMarks.clear();
122  SetPathMarks(*otrack);
123  if (GetLockPoints() || otrack->Size() > 0)
124  {
125  ClonePoints(*otrack);
126  fLastPMIdx = otrack->GetLastPMIdx();
127  }
128  else
129  {
130  TEveTrack::MakeTrack(recurse);
131  }
132  if (Size() == 0) return; // All points can be outside of MaxR / MaxZ limits.
133 
134  // Break segments additionally if required by the projection.
135  ReduceSegmentLengths(projection->GetMaxTrackStep());
136 
137  // Project points, store originals (needed for break-points).
138  Float_t *p = GetP();
139  fOrigPnts = new TEveVector[Size()];
140  for (Int_t i = 0; i < Size(); ++i, p+=3)
141  {
142  if (trans) trans->MultiplyIP(p);
143  fOrigPnts[i].Set(p);
144  projection->ProjectPointfv(p, fDepth);
145  }
146 
147  Float_t x, y, z;
148  Int_t bL = 0, bR = GetBreakPointIdx(0);
149  std::vector<TEveVector> vvec;
150  while (kTRUE)
151  {
152  for (Int_t i=bL; i<=bR; i++)
153  {
154  GetPoint(i, x, y, z);
155  vvec.push_back(TEveVector(x, y, z));
156  }
157  if (bR == fLastPoint)
158  break;
159 
160  TEveVector vL = fOrigPnts[bR];
161  TEveVector vR = fOrigPnts[bR + 1];
162  projection->BisectBreakPoint(vL, vR, kTRUE, fDepth);
163  vvec.push_back(vL);
164  fBreakPoints.push_back((Int_t)vvec.size());
165  vvec.push_back(vR);
166 
167  bL = bR + 1;
168  bR = GetBreakPointIdx(bL);
169  }
170  fBreakPoints.push_back((Int_t)vvec.size()); // Mark the track-end for drawing.
171 
172  // Decide if points need to be fixed.
173  // This (and the fixing itself) should really be done in TEveProjection but
174  // for now we do it here as RhoZ is the only one that needs it.
175  Bool_t fix_y = kFALSE;
176  Float_t sign_y = 0;
177  if (projection->HasSeveralSubSpaces())
178  {
179  switch (fPropagator->GetProjTrackBreaking())
180  {
181  case TEveTrackPropagator::kPTB_UseFirstPointPos:
182  {
183  fix_y = kTRUE;
184  sign_y = vvec.front().fY;
185  break;
186  }
187  case TEveTrackPropagator::kPTB_UseLastPointPos:
188  {
189  fix_y = kTRUE;
190  sign_y = vvec.back().fY;
191  break;
192  }
193  }
194  }
195 
196  Reset((Int_t)vvec.size());
197  for (std::vector<TEveVector>::iterator i=vvec.begin(); i!=vvec.end(); ++i)
198  {
199  if (fix_y)
200  SetNextPoint((*i).fX, TMath::Sign((*i).fY, sign_y), (*i).fZ);
201  else
202  SetNextPoint((*i).fX, (*i).fY, (*i).fZ);
203  }
204  delete [] fOrigPnts; fOrigPnts = 0;
205 
206  // Project path-marks
207  for (vPathMark_i pm = fPathMarks.begin(); pm != fPathMarks.end(); ++pm)
208  {
209  projection->ProjectPointdv(trans, pm->fV.Arr(), pm->fV.Arr(), fDepth);
210  }
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Print line segments info.
215 
216 void TEveTrackProjected::PrintLineSegments()
217 {
218  printf("%s LineSegments:\n", GetName());
219  Int_t start = 0;
220  Int_t segment = 0;
221  TEveVector sVec;
222  TEveVector bPnt;
223  for (std::vector<Int_t>::iterator bpi = fBreakPoints.begin();
224  bpi != fBreakPoints.end(); ++bpi)
225  {
226  Int_t size = *bpi - start;
227 
228  GetPoint(start, sVec.fX, sVec.fY, sVec.fZ);
229  GetPoint((*bpi)-1, bPnt.fX, bPnt.fY, bPnt.fZ);
230  printf("seg %d size %d start %d ::(%f, %f, %f) (%f, %f, %f)\n",
231  segment, size, start, sVec.fX, sVec.fY, sVec.fZ,
232  bPnt.fX, bPnt.fY, bPnt.fZ);
233  start += size;
234  segment ++;
235  }
236 }
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 /// Virtual method from from base-class TEveTrack.
240 
241 void TEveTrackProjected::SecSelected(TEveTrack* /*track*/)
242 {
243  TEveTrack* t = dynamic_cast<TEveTrack*>(fProjectable);
244  if (t)
245  t->SecSelected(t);
246 }
247 
248 
249 /** \class TEveTrackListProjected
250 \ingroup TEve
251 Specialization of TEveTrackList for holding TEveTrackProjected objects.
252 */
253 
254 ClassImp(TEveTrackListProjected);
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Default constructor.
258 
259 TEveTrackListProjected::TEveTrackListProjected() :
260  TEveTrackList (),
261  TEveProjected ()
262 {
263 }
264 
265 ////////////////////////////////////////////////////////////////////////////////
266 /// This is virtual method from base-class TEveProjected.
267 
268 void TEveTrackListProjected::SetProjection(TEveProjectionManager* proj, TEveProjectable* model)
269 {
270  TEveProjected::SetProjection(proj, model);
271  CopyVizParams(dynamic_cast<TEveElement*>(model));
272 
273  TEveTrackList& tl = * dynamic_cast<TEveTrackList*>(model);
274  SetPropagator(tl.GetPropagator());
275 }
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// This is not needed for functionality as SetDepth(Float_t d)
279 /// is overriden -- but SetDepthLocal() is abstract.
280 /// Just emits a warning if called.
281 
282 void TEveTrackListProjected::SetDepthLocal(Float_t /*d*/)
283 {
284  Warning("SetDepthLocal", "This function only exists to fulfill an abstract interface.");
285 }
286 
287 ////////////////////////////////////////////////////////////////////////////////
288 /// Set depth of all children inheriting from TEveTrackProjected.
289 
290 void TEveTrackListProjected::SetDepth(Float_t d)
291 {
292  SetDepth(d, this);
293 }
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Set depth of all children of el inheriting from TEveTrackProjected.
297 
298 void TEveTrackListProjected::SetDepth(Float_t d, TEveElement* el)
299 {
300  TEveTrackProjected* ptrack;
301  for (List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
302  {
303  ptrack = dynamic_cast<TEveTrackProjected*>(*i);
304  if (ptrack)
305  ptrack->SetDepth(d);
306  if (fRecurse)
307  SetDepth(d, *i);
308  }
309 }