CMS 3D CMS Logo

FWPFTrackUtils.cc
Go to the documentation of this file.
2 
5 
6 //______________________________________________________________________________
9 {
10  if( !instanceFlag ) // Instance doesn't exist yet
11  {
13  instanceFlag = true;
14  }
15 
16  return pInstance; // Pointer to sole instance
17 }
18 
19 //______________________________________________________________________________
20 void
22 {
23  m_magField = new FWMagField();
24 
25  // Common propagator, helix stepper
26  m_trackPropagator = new TEveTrackPropagator();
27  m_trackPropagator->SetMagFieldObj( m_magField, false );
28  m_trackPropagator->SetMaxR( FWPFGeom::caloR3() );
29  m_trackPropagator->SetMaxZ( FWPFGeom::caloZ2() );
30  m_trackPropagator->SetDelta( 0.01 );
31  m_trackPropagator->SetProjTrackBreaking( TEveTrackPropagator::kPTB_UseLastPointPos );
32  m_trackPropagator->SetRnrPTBMarkers( kTRUE );
33  m_trackPropagator->IncDenyDestroy();
34 
35  // Tracker propagator
36  m_trackerTrackPropagator = new TEveTrackPropagator();
37  m_trackerTrackPropagator->SetStepper( TEveTrackPropagator::kRungeKutta );
38  m_trackerTrackPropagator->SetMagFieldObj( m_magField, false );
39  m_trackerTrackPropagator->SetDelta( 0.01 );
42  m_trackerTrackPropagator->SetProjTrackBreaking( TEveTrackPropagator::kPTB_UseLastPointPos );
43  m_trackerTrackPropagator->SetRnrPTBMarkers( kTRUE );
44  m_trackerTrackPropagator->IncDenyDestroy();
45 }
46 
47 //______________________________________________________________________________
49 {
50  m_singleton = FWPFTrackSingleton::Instance();
51 }
52 
53 
54 //______________________________________________________________________________
55 TEveTrack *
57 {
58  TEveTrackPropagator *propagator = ( !iData.extra().isAvailable() ) ?
59  m_singleton->getTrackerTrackPropagator() : m_singleton->getTrackPropagator();
60 
61  TEveRecTrack t;
62  t.fBeta = 1;
63  t.fP = TEveVector( iData.px(), iData.py(), iData.pz() );
64  t.fV = TEveVector( iData.vertex().x(), iData.vertex().y(), iData.vertex().z() );
65  t.fSign = iData.charge();
66  TEveTrack *trk = new TEveTrack( &t, propagator );
67  trk->MakeTrack();
68 
69  return trk;
70 }
71 
72 //______________________________________________________________________________
73 TEveStraightLineSet *
75 {
76  using namespace FWPFGeom;
77 
78  // Declarations
79  int wraps[3] = { -1, -1, -1 };
80  bool ECAL = false;
81  TEveTrack *trk = getTrack( iData );
82  std::vector<TEveVector> trackPoints( trk->GetN() - 1 );
83  const Float_t *points = trk->GetP();
84  TEveStraightLineSet *legoTrack = new TEveStraightLineSet();
85 
86  if( m_singleton->getField()->getSource() == FWMagField::kNone )
87  {
88  if( fabs( iData.eta() ) < 2.0 && iData.pt() > 0.5 && iData.pt() < 30 )
89  {
90  double estimate = fw::estimate_field( iData, true );
91  if( estimate >= 0 ) m_singleton->getField()->guessField( estimate );
92  }
93  }
94 
95  // Convert to Eta/Phi and store in vector
96  for( Int_t i = 1; i < trk->GetN(); ++i )
97  {
98  int j = i * 3;
99  TEveVector temp = TEveVector( points[j], points[j+1], points[j+2] );
100  TEveVector vec = TEveVector( temp.Eta(), temp.Phi(), 0.001 );
101 
102  trackPoints[i-1] = vec;
103  }
104 
105  // Add first point to ps if necessary
106  for( Int_t i = 1; i < trk->GetN(); ++i )
107  {
108  int j = i * 3;
109  TEveVector v1 = TEveVector( points[j], points[j+1], points[j+2] );
110 
111  if( !ECAL )
112  {
113  if( FWPFMaths::checkIntersect( v1, caloR1() ) )
114  {
115  TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
116  TEveVector xyPoint = FWPFMaths::lineCircleIntersect( v1, v2, caloR1() );
117  TEveVector zPoint;
118  if( v1.fZ < 0 )
119  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
120  else
121  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
122 
123  TEveVector vec = FWPFMaths::lineLineIntersect( v1, v2, xyPoint, zPoint );
124  legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 0 );
125 
126  wraps[0] = i; // There is now a chance that the track will also reach the HCAL radius
127  ECAL = true;
128  }
129  else if( fabs( v1.fZ ) >= caloZ1() )
130  {
131  TEveVector p1, p2;
132  TEveVector vec, v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
133  float z, y = FWPFMaths::linearInterpolation( v2, v1, caloZ1() );
134 
135  if( v2.fZ > 0 )
136  z = caloZ1();
137  else
138  z = caloZ1() * -1;
139 
140  p1 = TEveVector( v2.fX + 50, y, z );
141  p2 = TEveVector( v2.fX - 50, y, z );
142  vec = FWPFMaths::lineLineIntersect( v1, v2, p1, p2 );
143 
144  legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 0 );
145  wraps[0] = i;
146  ECAL = true;
147  }
148  }
149  else if( FWPFMaths::checkIntersect( v1, caloR2() ) )
150  {
151  TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
152  TEveVector xyPoint = FWPFMaths::lineCircleIntersect( v1, v2, caloR2() );
153  TEveVector zPoint;
154  if( v1.fZ < 0 )
155  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
156  else
157  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
158 
159  TEveVector vec = FWPFMaths::lineLineIntersect( v1, v2, xyPoint, zPoint );
160  legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 1 );
161 
162  wraps[1] = i; // There is now a chance that the track will also reach the HCAL radius
163  break;
164  }
165  }
166 
167  if( wraps[0] != -1 ) //if( ECAL )
168  {
169  int i = ( trk->GetN() - 1 ) * 3;
170  int j = trk->GetN() - 2; // This is equal to the last index in trackPoints vector
171  TEveVector vec = TEveVector( points[i], points[i+1], points[i+2] );
172 
173  if( FWPFMaths::checkIntersect( vec, caloR3() - 1 ) )
174  {
175  legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 2 );
176  wraps[2] = j;
177  }
178  else if( fabs( vec.fZ ) >= caloZ2() )
179  {
180  legoTrack->AddMarker( vec.Eta(), vec.Phi(), 0.001, 2 );
181  wraps[2] = j;
182  }
183  }
184 
185  /* Handle phi wrapping */
186  for( int i = 0; i < static_cast<int>( trackPoints.size() - 1 ); ++i )
187  {
188  if( ( trackPoints[i+1].fY - trackPoints[i].fY ) > 1 )
189  {
190  trackPoints[i+1].fY -= TMath::TwoPi();
191  if( i == wraps[0] )
192  {
193  TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
194  mi.next(); // First point
195  TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
196  m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
197  }
198  else if( i == wraps[1] )
199  {
200  TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
201  mi.next(); mi.next(); // Second point
202  TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
203  m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
204  }
205  }
206 
207  if( ( trackPoints[i].fY - trackPoints[i+1].fY ) > 1 )
208  {
209  trackPoints[i+1].fY += TMath::TwoPi();
210  if( i == wraps[0] )
211  {
212  TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
213  mi.next(); // First point
214  TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
215  m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
216  }
217  else if( i == wraps[1] )
218  {
219  TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
220  mi.next(); mi.next(); // Second point
221  TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
222  m.fV[0] = trackPoints[i+1].fX; m.fV[1] = trackPoints[i+1].fY; m.fV[2] = 0.001;
223  }
224  }
225  }
226 
227  int end = static_cast<int>( trackPoints.size() - 1 );
228  if( wraps[2] == end )
229  {
230  TEveChunkManager::iterator mi( legoTrack->GetMarkerPlex() );
231  mi.next(); mi.next(); mi.next(); // Third point
232  TEveStraightLineSet::Marker_t &m = * ( TEveStraightLineSet::Marker_t* ) mi();
233  m.fV[0] = trackPoints[end].fX; m.fV[1] = trackPoints[end].fY; m.fV[2] = 0.001;
234  }
235 
236  // Set points on TEveLineSet object ready for displaying
237  for( unsigned int i = 0;i < trackPoints.size() - 1; ++i )
238  legoTrack->AddLine( trackPoints[i], trackPoints[i+1] );
239 
240  legoTrack->SetDepthTest( false );
241  legoTrack->SetMarkerStyle( 4 );
242  legoTrack->SetMarkerSize( 1 );
243  legoTrack->SetRnrMarkers( true );
244 
245  delete trk; // Release memory that is no longer required
246 
247  return legoTrack;
248 }
249 
250 //______________________________________________________________________________
251 TEveTrack *
253 {
254  if( m_singleton->getField()->getSource() == FWMagField::kNone )
255  {
256  if( fabs( iData.eta() ) < 2.0 && iData.pt() > 0.5 && iData.pt() < 30 )
257  {
258  double estimate = fw::estimate_field( iData, true );
259  if( estimate >= 0 ) m_singleton->getField()->guessField( estimate );
260  }
261  }
262 
263  TEveTrack *trk = getTrack( iData );
264 
265  return trk;
266 }
267 
268 
269 //______________________________________________________________________________
270 TEvePointSet *
271 FWPFTrackUtils::getCollisionMarkers( const TEveTrack *trk )
272 {
273  using namespace FWPFGeom;
274 
275  bool ECAL = false;
276  const Float_t *points = trk->GetP();
277  TEvePointSet *ps = new TEvePointSet();
278 
279  for( Int_t i = 1; i < trk->GetN(); ++i )
280  {
281  int j = i * 3;
282  TEveVector v1 = TEveVector( points[j], points[j+1], points[j+2] );
283 
284  if( !ECAL )
285  {
286  if( FWPFMaths::checkIntersect( v1, caloR1() ) )
287  {
288  TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
289  TEveVector xyPoint = FWPFMaths::lineCircleIntersect( v1, v2, caloR1() );
290  TEveVector zPoint;
291  if( v1.fZ < 0 )
292  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
293  else
294  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
295 
296  TEveVector vec = FWPFMaths::lineLineIntersect( v1, v2, xyPoint, zPoint );
297  ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
298 
299  ECAL = true;
300  }
301  else if( fabs( v1.fZ ) >= caloZ1() )
302  {
303  TEveVector p1, p2;
304  TEveVector vec, v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
305  float z, y = FWPFMaths::linearInterpolation( v2, v1, caloZ1() );
306 
307  if( v2.fZ > 0 )
308  z = caloZ1();
309  else
310  z = caloZ1() * -1;
311 
312  p1 = TEveVector( v2.fX + 50, y, z );
313  p2 = TEveVector( v2.fX - 50, y, z );
314  vec = FWPFMaths::lineLineIntersect( v1, v2, p1, p2 );
315 
316  ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
317  ECAL = true;
318  }
319  }
320  else if ( FWPFMaths::checkIntersect( v1, caloR2() ) )
321  {
322  TEveVector v2 = TEveVector( points[j-3], points[j-2], points[j-1] );
323  TEveVector xyPoint = FWPFMaths::lineCircleIntersect( v1, v2, caloR2() );
324  TEveVector zPoint;
325  if( v1.fZ < 0 )
326  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ - 50.f );
327  else
328  zPoint = TEveVector( xyPoint.fX, xyPoint.fY, v1.fZ + 50.f );
329 
330  TEveVector vec = FWPFMaths::lineLineIntersect( v1, v2, xyPoint, zPoint );
331  ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
332  break; // ECAL and HCAL collisions found so stop looping
333  }
334  }
335 
336  // HCAL collisions (outer radius and endcap)
337  int i = ( trk->GetN() - 1 ) * 3;
338  TEveVector vec = TEveVector( points[i], points[i+1], points[i+2] );
339 
340  if( FWPFMaths::checkIntersect( vec, caloR3() - 1 ) )
341  ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
342  else if( fabs( vec.fZ ) >= caloZ2() )
343  ps->SetNextPoint( vec.fX, vec.fY, vec.fZ );
344 
345  return ps;
346 }
const double TwoPi
bool isAvailable() const
Definition: Ref.h:577
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:189
TEvePointSet * getCollisionMarkers(const TEveTrack *)
TEveTrack * setupTrack(const reco::Track &)
#define NULL
Definition: scimark2.h:8
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:627
float linearInterpolation(const TEveVector &p1, const TEveVector &p2, float r)
Definition: FWPFMaths.cc:91
float caloZ2()
Definition: FWPFGeom.h:27
double estimate_field(const reco::Track &track, bool highQuality=false)
bool checkIntersect(const TEveVector &vec, float r)
Definition: FWPFMaths.cc:103
TEveTrackPropagator * m_trackerTrackPropagator
float caloR1()
Definition: FWPFGeom.h:21
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:687
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
double pt() const
track transverse momentum
Definition: TrackBase.h:621
static FWPFTrackSingleton * pInstance
float caloR2()
Definition: FWPFGeom.h:25
#define end
Definition: vmac.h:37
double p2[4]
Definition: TauolaWrapper.h:90
TEveStraightLineSet * setupLegoTrack(const reco::Track &)
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:639
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
static FWPFTrackSingleton * Instance()
static bool instanceFlag
TEveTrack * getTrack(const reco::Track &)
float caloZ1()
Definition: FWPFGeom.h:22
double p1[4]
Definition: TauolaWrapper.h:89
TEveVector lineCircleIntersect(const TEveVector &v1, const TEveVector &v2, float r)
Definition: FWPFMaths.cc:38
TEveTrackPropagator * m_trackPropagator
int charge() const
track electric charge
Definition: TrackBase.h:567
TEveVector lineLineIntersect(const TEveVector &v1, const TEveVector &v2, const TEveVector &v3, const TEveVector &v4)
Definition: FWPFMaths.cc:73
float caloR3()
Definition: FWPFGeom.h:26
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:633
FWMagField * m_magField