LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TrackImpl.cc
Go to the documentation of this file.
1 #include "IMPL/TrackImpl.h"
2 #include "IMPL/TrackStateImpl.h"
3 
4 #include <cmath>
5 #include <sstream>
6 
7 using namespace EVENT ;
8 
9 namespace IMPL {
10 
11  const TrackStateImpl TrackImpl::_dummy ;
12 
13  TrackImpl::TrackImpl() :
14  _type(0),
15  _chi2(0),
16  _ndf(0),
17  _dEdx(0),
18  _dEdxError(0),
19  _radiusOfInnermostHit(0) {
20  }
21 
22  // copy constructor
24  {
25 
26  *this = o ; // call operator =
27 
28  }
29 
31  {
32  _type = o._type ;
33  _chi2 = o._chi2 ;
34  _ndf = o._ndf ;
35  _dEdx = o._dEdx ;
38 
40 
42 
44 
46  for( unsigned int i=0; i< o._trackStates.size() ; i++ ){
48  }
49 
50  return *this ;
51  }
52 
53 
55 
56  // delete track states in here ?
57  for( unsigned int i=0; i<_trackStates.size() ; i++ ){
58 
59  // std::cout << " *************** TrackImpl::~TrackImpl() @ " << this
60  // << " - _trackStates.size() : " << _trackStates.size()
61  // << " - delete object at : " << _trackStates[i]
62  // << std::endl ;
63 
64  delete _trackStates[i] ;
65  }
66 
67  // for( IndexMap::const_iterator iter = _indexMap.begin() ; iter != _indexMap.end() ; iter++ ){
68  // delete iter->second ;
69  // }
70 
71  }
72 
73  // const std::string & TrackImpl::getType() const { return _type ; }
74 
75  int TrackImpl::getType() const { return _type.to_ulong() ; }
76 
77  // bool TrackImpl::testType(int bitIndex) const {
78  // return _type.test( bitIndex ) ;
79  // }
80 
81  //float TrackImpl::getD0() const { return _d0 ;}
82  //float TrackImpl::getPhi() const { return _phi ; }
83  //float TrackImpl::getOmega() const { return _omega ; }
84  //float TrackImpl::getZ0() const { return _z0 ;}
85  //float TrackImpl::getTanLambda() const { return _tanLambda ;}
86  //const FloatVec& TrackImpl::getCovMatrix() const { return _covMatrix ; }
87  //const float* TrackImpl::getReferencePoint() const { return _reference ; }
88 
89  float TrackImpl::getD0() const { return ( _trackStates.size()>0 ? _trackStates[0]->getD0() : 0 ) ; }
90  float TrackImpl::getPhi() const { return ( _trackStates.size()>0 ? _trackStates[0]->getPhi() : 0 ) ; }
91  float TrackImpl::getOmega() const { return ( _trackStates.size()>0 ? _trackStates[0]->getOmega() : 0 ) ; }
92  float TrackImpl::getZ0() const { return ( _trackStates.size()>0 ? _trackStates[0]->getZ0() : 0 ) ; }
93  float TrackImpl::getTanLambda() const { return ( _trackStates.size()>0 ? _trackStates[0]->getTanLambda() : 0 ) ; }
95  // static const TrackStateImpl dummy ;
96  return ( _trackStates.size()>0 ? _trackStates[0]->getCovMatrix() : _dummy.getCovMatrix() ) ;
97  }
98  const float* TrackImpl::getReferencePoint() const {
99  // static const TrackStateImpl dummy ;
100  return ( _trackStates.size()>0 ? _trackStates[0]->getReferencePoint() : _dummy.getReferencePoint() ) ;
101  }
102 
103 
104  //bool TrackImpl::isReferencePointPCA() const {
105  // // return _isReferencePointPCA ;
106  // return _type.test( BIT_ISREFERENCEPOINTDCA ) ;
107  //}
108 
109  float TrackImpl::getChi2() const { return _chi2 ;}
110  int TrackImpl::getNdf() const { return _ndf ;}
111  float TrackImpl::getdEdx() const { return _dEdx ; }
112  float TrackImpl::getdEdxError() const { return _dEdxError ; }
113 
114 
116  return _radiusOfInnermostHit ;
117  }
118 
120  return _subdetectorHitNumbers ;
121  }
123  return _hits ;
124  }
125 
126  const TrackVec & TrackImpl::getTracks() const {
127  return _tracks ;
128  }
129 
131  return _trackStates ;
132  }
133 
134  const TrackState* TrackImpl::getClosestTrackState( float x, float y, float z ) const {
135  TrackState* closest = _trackStates[0] ;
136  const float * refP = _trackStates[0]->getReferencePoint() ;
137  float shortest_distance_square = pow( ( x - refP[0] ) , 2 ) + pow( ( y - refP[1] ) , 2 ) + pow( ( z - refP[2] ) , 2 ) ;
138  float current_distance_square = 0 ;
139 
140  for( unsigned int i=1 ; i < _trackStates.size() ; i++ ){
141  refP = _trackStates[i]->getReferencePoint() ;
142  current_distance_square = pow( ( x - refP[0] ) , 2 ) + pow( ( y - refP[1] ) , 2 ) + pow( ( z - refP[2] ) , 2 ) ;
143  if( current_distance_square < shortest_distance_square ){
144  closest = _trackStates[i] ;
145  shortest_distance_square = current_distance_square ;
146  }
147  }
148  return closest ;
149  }
150 
151  const TrackState* TrackImpl::getTrackState( int location ) const {
152 
153  // if( location < 0 || location > TrackState::LastLocation ){
154  // throw( Exception( " trying to use getTrackState with an undefined Location" )) ;
155  // }
156 
157  for( unsigned int i=0 ; i < _trackStates.size() ; i++ ){
158  if( _trackStates[i]->getLocation() == location ){
159  return _trackStates[i] ;
160  }
161  }
162  return NULL ;
163  }
164 
165  void TrackImpl::setTypeBit( int index, bool val){
166  checkAccess("TrackImpl::setTypeBit") ;
167  _type.set( index, val ) ;
168  }
169 
170  // void TrackImpl::setType( const std::string& type ){
171  void TrackImpl::setType( int type ){
172  checkAccess("TrackImpl::setType") ;
173 
174  // int highWord = ( _type.to_ulong() & 0xFFFF0000 ) ;
175  // int lowWord = ( 0x0000FFFF & type ) ;
176  // _type = highWord | lowWord ;
177 
178  _type = type ;
179  }
180 
181  void TrackImpl::setD0( float d0 ){
182  //checkAccess("TrackImpl::setD0") ;
183  //_d0 = d0 ;
184 
185  if( _trackStates.size() == 0 ){
186  // create a first TrackState for backwards compatibility
187  TrackState* ts = new TrackStateImpl() ;
188  _trackStates.push_back( ts ) ;
189  }
190 
191  if( _trackStates.size() != 1 ){
192  throw( Exception( " trying to use setD0 within Track object containing more than one TrackState." )) ;
193  }
194 
195  ((TrackStateImpl*)_trackStates[0])->setD0( d0 ) ;
196  }
197  void TrackImpl::setPhi( float phi ){
198  //checkAccess("TrackImpl::setPhi") ;
199  //_phi = phi ;
200 
201  if( _trackStates.size() == 0 ){
202  // create a first TrackState for backwards compatibility
203  TrackState* ts = new TrackStateImpl() ;
204  _trackStates.push_back( ts ) ;
205  }
206 
207  if( _trackStates.size() != 1 ){
208  throw( Exception( " trying to use setPhi within Track object containing more than one TrackState." )) ;
209  }
210 
211  ((TrackStateImpl*)_trackStates[0])->setPhi( phi ) ;
212  }
213  void TrackImpl::setOmega( float omega ) {
214  //checkAccess("TrackImpl::setOmega") ;
215  //_omega = omega ;
216 
217  if( _trackStates.size() == 0 ){
218  // create a first TrackState for backwards compatibility
219  TrackState* ts = new TrackStateImpl() ;
220  _trackStates.push_back( ts ) ;
221  }
222 
223  if( _trackStates.size() != 1 ){
224  throw( Exception( " trying to use setOmega within Track object containing more than one TrackState." )) ;
225  }
226 
227  ((TrackStateImpl*)_trackStates[0])->setOmega( omega ) ;
228  }
229  void TrackImpl::setZ0( float z0 ){
230  //checkAccess("TrackImpl::setZ0") ;
231  //_z0 = z0 ;
232 
233  if( _trackStates.size() == 0 ){
234  // create a first TrackState for backwards compatibility
235  TrackState* ts = new TrackStateImpl() ;
236  _trackStates.push_back( ts ) ;
237  }
238 
239  if( _trackStates.size() != 1 ){
240  throw( Exception( " trying to use setZ0 within Track object containing more than one TrackState." )) ;
241  }
242 
243  ((TrackStateImpl*)_trackStates[0])->setZ0( z0 ) ;
244  }
245  void TrackImpl::setTanLambda( float tanLambda ){
246  //checkAccess("TrackImpl::setTanLambda") ;
247  //_tanLambda = tanLambda ;
248 
249  if( _trackStates.size() == 0 ){
250  // create a first TrackState for backwards compatibility
251  TrackState* ts = new TrackStateImpl() ;
252  _trackStates.push_back( ts ) ;
253  }
254 
255  if( _trackStates.size() != 1 ){
256  throw( Exception( " trying to use setTanLambda within Track object containing more than one TrackState." )) ;
257  }
258 
259  ((TrackStateImpl*)_trackStates[0])->setTanLambda( tanLambda ) ;
260  }
261 
262  void TrackImpl::setCovMatrix( const float* cov ){
263  //checkAccess("TrackImpl::setCovMatrix") ;
264  //for(int i=0;i<TRKNCOVMATRIX;i++) {
265  // _covMatrix[i] = cov[i] ;
266  //}
267 
268  if( _trackStates.size() == 0 ){
269  // create a first TrackState for backwards compatibility
270  TrackState* ts = new TrackStateImpl() ;
271  _trackStates.push_back( ts ) ;
272  }
273 
274  if( _trackStates.size() != 1 ){
275  throw( Exception( " trying to use setCovMatrix within Track object containing more than one TrackState." )) ;
276  }
277 
278  ((TrackStateImpl*)_trackStates[0])->setCovMatrix( cov ) ;
279  }
280  void TrackImpl::setCovMatrix( const FloatVec& cov ){
281  //checkAccess("TrackImpl::setCovMatrix") ;
282  //for(int i=0;i<TRKNCOVMATRIX;i++) {
283  // _covMatrix[i] = cov[i] ;
284  //}
285 
286  if( _trackStates.size() == 0 ){
287  // create a first TrackState for backwards compatibility
288  TrackState* ts = new TrackStateImpl() ;
289  _trackStates.push_back( ts ) ;
290  }
291 
292  if( _trackStates.size() != 1 ){
293  throw( Exception( " trying to use setCovMatrix within Track object containing more than one TrackState." )) ;
294  }
295 
296  ((TrackStateImpl*)_trackStates[0])->setCovMatrix( cov ) ;
297  }
298 
299  void TrackImpl::setReferencePoint( const float* rPnt){
300  //checkAccess("TrackImpl::setReferencePoint") ;
301  //for(int i=0;i<3;i++) {
302  // _reference[i] = rPnt[i] ;
303  //}
304 
305  if( _trackStates.size() == 0 ){
306  // create a first TrackState for backwards compatibility
307  TrackState* ts = new TrackStateImpl() ;
308  _trackStates.push_back( ts ) ;
309  }
310 
311  if( _trackStates.size() != 1 ){
312  throw( Exception( " trying to use setReferencePoint within Track object containing more than one TrackState." )) ;
313  }
314 
315  ((TrackStateImpl*)_trackStates[0])->setReferencePoint( rPnt ) ;
316  }
317 
318  //void TrackImpl::setIsReferencePointPCA( bool val){
319  // checkAccess("TrackImpl::setIsReferencePointPCA") ;
320  // // _isReferencePointPCA = val ;
321  // _type.set( BIT_ISREFERENCEPOINTDCA , val ) ;
322  //}
323 
324  void TrackImpl::setChi2( float chi2 ){
325  checkAccess("TrackImpl::setChi2") ;
326  _chi2 = chi2 ;
327  }
328  void TrackImpl::setNdf( int ndf ){
329  checkAccess("TrackImpl::setNdf") ;
330  _ndf = ndf ;
331  }
332  void TrackImpl::setdEdx( float dEdx ){
333  checkAccess("TrackImpl::setdEdx") ;
334  _dEdx = dEdx ;
335  }
336  void TrackImpl::setdEdxError( float dEdxError ){
337  checkAccess("TrackImpl::setdEdxError") ;
338  _dEdxError = dEdxError ;
339  }
340 
342  _hits.push_back( hit ) ;
343  }
344 
346  checkAccess("TrackImpl::addTrack") ;
347  _tracks.push_back( trk ) ;
348  }
349 
351  checkAccess("TrackImpl::addTrackState") ;
352  if( trkstate->getLocation() != TrackState::AtOther &&
353  getTrackState( trkstate->getLocation() ) != NULL )
354  {
356  ss << "another TrackState already exists with Location set to: " << trkstate->getLocation() ;
357  throw( Exception( ss.str() )) ;
358  }
359  _trackStates.push_back( trkstate ) ;
360  }
361 
363  checkAccess("TrackImpl::trackStates") ;
364  return _trackStates ;
365  }
366 
368  checkAccess("TrackImpl::subdetectorHitNumbers") ;
369  return _subdetectorHitNumbers ;
370  }
371 
373  checkAccess("TrackImpl::setRadiusOfInnermostHit") ;
375  }
376 
377 } // namespace IMPL
378 
379 
virtual float getRadiusOfInnermostHit() const
The radius of the innermost hit that has been used in the track fit.
Definition: TrackImpl.cc:115
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
virtual void setTypeBit(int index, bool val=true)
Definition: TrackImpl.cc:165
float _dEdxError
Definition: TrackImpl.h:204
virtual void setZ0(float z0)
Definition: TrackImpl.cc:229
virtual void addHit(EVENT::TrackerHit *hit)
Definition: TrackImpl.cc:341
A generic tracker hit to be used by pattern recognition.
Definition: TrackerHit.h:26
virtual EVENT::TrackStateVec & trackStates()
Definition: TrackImpl.cc:362
T copy(T...args)
virtual void setNdf(int ndf)
Definition: TrackImpl.cc:328
virtual const EVENT::TrackState * getTrackState(int location) const
Returns track state for the given location - or NULL if not found.
Definition: TrackImpl.cc:151
virtual const EVENT::FloatVec & getCovMatrix() const
Covariance matrix of the track parameters.
Definition: TrackImpl.cc:94
virtual const EVENT::TrackVec & getTracks() const
The tracks (as Track objects) that have been combined to this track.
Definition: TrackImpl.cc:126
virtual void setOmega(float omega)
Definition: TrackImpl.cc:213
virtual void setReferencePoint(const float *rPnt)
Definition: TrackImpl.cc:299
virtual EVENT::IntVec & subdetectorHitNumbers()
Allows modification of the subdetectorHitNumbers, e.g.
Definition: TrackImpl.cc:367
Implementation of the LCIO track class.
Definition: TrackImpl.h:30
T to_ulong(T...args)
The LCIO TrackState class.
Definition: TrackState.h:26
virtual int getType() const
Flagword that defines the type of track.
Definition: TrackImpl.cc:75
T end(T...args)
Implementation of the LCIO TrackState class.
virtual float getOmega() const
Omega is the signed curvature of the track in [1/mm].
Definition: TrackImpl.cc:91
virtual int getNdf() const
Number of degrees of freedom of the track fit.
Definition: TrackImpl.cc:110
virtual void setD0(float d0)
Definition: TrackImpl.cc:181
virtual float getdEdx() const
dEdx of the track.
Definition: TrackImpl.cc:111
virtual const EVENT::IntVec & getSubdetectorHitNumbers() const
A vector that holds the number of hits in particular subdetectors.
Definition: TrackImpl.cc:119
TrackImpl()
Default constructor, initializes values to 0.
Definition: TrackImpl.cc:13
virtual int getLocation() const =0
The location of the track state.
static const TrackStateImpl _dummy
Definition: TrackImpl.h:213
virtual void addTrack(EVENT::Track *trk)
Definition: TrackImpl.cc:345
T push_back(T...args)
virtual void setRadiusOfInnermostHit(float r)
Definition: TrackImpl.cc:372
virtual float getChi2() const
True if the reference point is the point of closest approach.
Definition: TrackImpl.cc:109
EVENT::IntVec _subdetectorHitNumbers
Definition: TrackImpl.h:206
EVENT::TrackStateVec _trackStates
Definition: TrackImpl.h:211
virtual float getZ0() const
Impact paramter of the track in (r-z).
Definition: TrackImpl.cc:92
const TrackImpl & operator=(const TrackImpl &o)
Definition: TrackImpl.cc:30
virtual void setTanLambda(float tanLambda)
Definition: TrackImpl.cc:245
The LCIO track class.
Definition: Track.h:33
virtual void addTrackState(EVENT::TrackState *trkstate)
Definition: TrackImpl.cc:350
T str(T...args)
EVENT::TrackerHitVec _hits
Definition: TrackImpl.h:209
virtual const float * getReferencePoint() const
Reference point of the track parameters, e.g.
virtual const EVENT::TrackerHitVec & getTrackerHits() const
Optionaly ( check/set flag(LCIO::TRBIT_HITS)==1) return the hits that have been used to create this t...
Definition: TrackImpl.cc:122
virtual void setChi2(float chi2)
Definition: TrackImpl.cc:324
virtual const EVENT::FloatVec & getCovMatrix() const
Covariance matrix of the track parameters.
T size(T...args)
virtual void setType(int type)
Definition: TrackImpl.cc:171
T set(T...args)
EVENT::TrackVec _tracks
Definition: TrackImpl.h:208
virtual ~TrackImpl()
Destructor.
Definition: TrackImpl.cc:54
T begin(T...args)
virtual void setdEdxError(float dEdxError)
Definition: TrackImpl.cc:336
T back_inserter(T...args)
float _radiusOfInnermostHit
Definition: TrackImpl.h:205
virtual float getTanLambda() const
Lambda is the dip angle of the track in r-z at the reference point.
Definition: TrackImpl.cc:93
virtual void setPhi(float phi)
Definition: TrackImpl.cc:197
virtual const EVENT::TrackState * getClosestTrackState(float x, float y, float z) const
Returns track state closest to the given point.
Definition: TrackImpl.cc:134
virtual void setdEdx(float dEdx)
Definition: TrackImpl.cc:332
virtual const EVENT::TrackStateVec & getTrackStates() const
Returns track states associtated with this track.
Definition: TrackImpl.cc:130
virtual float getD0() const
Impact paramter of the track in (r-phi).
Definition: TrackImpl.cc:89
virtual float getdEdxError() const
Error of dEdx.
Definition: TrackImpl.cc:112
virtual void setCovMatrix(const float *cov)
Definition: TrackImpl.cc:262
std::bitset< 32 > _type
Definition: TrackImpl.h:198
T reserve(T...args)
virtual float getPhi() const
Phi of the track at reference point.
Definition: TrackImpl.cc:90
virtual const float * getReferencePoint() const
Reference point of the track parameters.
Definition: TrackImpl.cc:98