CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackBase.h
Go to the documentation of this file.
1 #ifndef TrackReco_TrackBase_h
2 #define TrackReco_TrackBase_h
3 
60 
61 namespace reco {
62 
63  class TrackBase {
64  public:
66  enum { dimension = 5 };
68  enum { covarianceSize = dimension * ( dimension + 1 ) / 2 };
78  enum { i_qoverp = 0 , i_lambda, i_phi, i_dxy, i_dsz };
80  typedef unsigned int index;
83  iter1=5, iter2=6, iter3=7, iter4=8, iter5=9, iter6=10, iter7=11, iter8=12, iter9=13,iter10=14,
89  beamhalo=28,
90  gsf=29,
91  algoSize=30 };
92  static const std::string algoNames[];
93 
96  static const std::string qualityNames[];
97 
99  TrackBase();
101  TrackBase( double chi2, double ndof, const Point & referencePoint,
102  const Vector & momentum, int charge, const CovarianceMatrix &,
105  ~TrackBase();
107  double chi2() const { return chi2_; }
109  double ndof() const { return ndof_; }
111  double normalizedChi2() const { return ndof_ != 0 ? chi2_ / ndof_ : chi2_ * 1e6; }
113  int charge() const { return charge_; }
115  double qoverp() const { return charge() / p(); }
117  double theta() const { return momentum_.theta(); }
119  double lambda() const { return M_PI/2 - momentum_.theta(); }
121  double dxy() const { return ( - vx() * py() + vy() * px() ) / pt(); }
123  double d0() const { return - dxy(); }
125  double dsz() const { return vz()*pt()/p() - (vx()*px()+vy()*py())/pt() * pz()/p(); }
127  double dz() const { return vz() - (vx()*px()+vy()*py())/pt() * (pz()/pt()); }
129  double p() const { return momentum_.R(); }
131  double pt() const { return sqrt( momentum_.Perp2() ); }
133  double px() const { return momentum_.x(); }
135  double py() const { return momentum_.y(); }
137  double pz() const { return momentum_.z(); }
139  double phi() const { return momentum_.Phi(); }
141  double eta() const { return momentum_.Eta(); }
143  double vx() const { return vertex_.x(); }
145  double vy() const { return vertex_.y(); }
147  double vz() const { return vertex_.z(); }
148 
150  const Vector & momentum() const { return momentum_; }
151 
153  const Point & referencePoint() const { return vertex_; }
154 
156  const Point & vertex() const { return vertex_; }
157 
159  double dxy(const Point& myBeamSpot) const {
160  return ( - (vx()-myBeamSpot.x()) * py() + (vy()-myBeamSpot.y()) * px() ) / pt();
161  }
162 
164  double dxy(const BeamSpot& theBeamSpot) const {
165  return dxy(theBeamSpot.position(vz()));
166  }
167 
169  double dsz(const Point& myBeamSpot) const {
170  return (vz()-myBeamSpot.z())*pt()/p() - ((vx()-myBeamSpot.x())*px()+(vy()-myBeamSpot.y())*py())/pt() *pz()/p();
171  }
173  double dz(const Point& myBeamSpot) const {
174  return (vz()-myBeamSpot.z()) - ((vx()-myBeamSpot.x())*px()+(vy()-myBeamSpot.y())*py())/pt() * pz()/pt();
175  }
176 
178  ParameterVector parameters() const {
179  return ParameterVector(qoverp(),lambda(),phi(),dxy(),dsz());
180  }
182  CovarianceMatrix covariance() const { CovarianceMatrix m; fill( m ); return m; }
183 
185  double parameter(int i) const { return parameters()[i]; }
187  double covariance( int i, int j ) const { return covariance_[ covIndex( i, j ) ]; }
189  double error( int i ) const { return sqrt( covariance_[ covIndex( i, i ) ] ); }
190 
192  double qoverpError() const { return error( i_qoverp ); }
194  double ptError() const {
195  return (charge()!=0) ? sqrt(
196  pt()*pt()*p()*p()/charge()/charge() * covariance(i_qoverp,i_qoverp)
197  + 2*pt()*p()/charge()*pz() * covariance(i_qoverp,i_lambda)
198  + pz()*pz() * covariance(i_lambda,i_lambda) ) : 1.e6;
199  }
201  double thetaError() const { return error( i_lambda ); }
203  double lambdaError() const { return error( i_lambda ); }
205  double etaError() const { return error( i_lambda ) * p()/pt(); }
207  double phiError() const { return error( i_phi ); }
209  double dxyError() const { return error( i_dxy ); }
211  double d0Error() const { return error( i_dxy ); }
213  double dszError() const { return error( i_dsz ); }
215  double dzError() const { return error( i_dsz ) * p()/pt(); }
216 
218  CovarianceMatrix & fill( CovarianceMatrix & v ) const;
220  static index covIndex( index i, index j );
221 
223  const HitPattern & hitPattern() const { return hitPattern_; }
228 
229 
230 
232  unsigned short numberOfValidHits() const { return hitPattern_.numberOfValidHits(); }
234  unsigned short numberOfLostHits() const { return hitPattern_.numberOfLostHits(); }
236  double validFraction() const {
241  if ((valid+lost+lostIn+lostOut)==0) return -1;
242  return valid/(1.0*(valid+lost+lostIn+lostOut));
243  }
245  template<typename C>
246  void setHitPattern( const C & c ) { hitPattern_.set( c.begin(), c.end() ); }
247  template<typename C>
248  void setTrackerExpectedHitsInner( const C & c ) { trackerExpectedHitsInner_.set( c.begin(), c.end() ); }
249  template<typename C>
250  void setTrackerExpectedHitsOuter( const C & c ) { trackerExpectedHitsOuter_.set( c.begin(), c.end() ); }
251 
252  template<typename I>
253  void setHitPattern( const I & begin, const I & end ) { hitPattern_.set( begin, end ); }
254  template<typename I>
255  void setTrackerExpectedHitsInner( const I & begin, const I & end ) { trackerExpectedHitsInner_.set( begin, end ); }
256  template<typename I>
257  void setTrackerExpectedHitsOuter( const I & begin, const I & end ) { trackerExpectedHitsOuter_.set( begin, end ); }
258 
260  void setHitPattern( const TrackingRecHit & hit, size_t i ) { hitPattern_.set( hit, i ); }
264 
266  void setHitPattern( const HitPattern& hitP) {hitPattern_ = hitP;}
269 
271 
273  void setAlgorithm(const TrackAlgorithm a, bool set=true) { if (set) algorithm_=a; else algorithm_=undefAlgorithm;}
274  TrackAlgorithm algo() const ;
275  std::string algoName() const;
276  static std::string algoName(TrackAlgorithm);
277  static TrackAlgorithm algoByName(const std::string &name);
278 
280  bool quality(const TrackQuality ) const;
281  void setQuality(const TrackQuality, bool set=true);
282  static std::string qualityName(TrackQuality);
283  static TrackQuality qualityByName(const std::string &name);
284 
285 
286  int qualityMask() const { return quality_; }
287  void setQualityMask(int qualMask) {quality_ = qualMask;}
288 
289 
290  void setNLoops(signed char value) { nLoops_=value;}
291 
292  bool isLooper() const { return (nLoops_>0);}
293  signed char nLoops() const {return nLoops_;}
294 
295  private:
302 
306  float chi2_;
308  Point vertex_;
310  Vector momentum_;
311 
313  float ndof_;
314 
316  char charge_;
318  uint8_t algorithm_;
320  uint8_t quality_;
321 
323  signed char nLoops_;
324 
325  };
326 
328  int a = ( i <= j ? i : j ), b = ( i <= j ? j : i );
329  return b * ( b + 1 ) / 2 + a;
330  }
331 
333  return (TrackAlgorithm) algorithm_;
334  }
335 
336  inline std::string TrackBase::algoName() const{
337  // I'd like to do:
338  // return TrackBase::algoName(algorithm_);
339  // but I cannot define a const static function. Why???
340 
341  switch(algorithm_)
342  {
343  case undefAlgorithm: return "undefAlgorithm";
344  case ctf: return "ctf";
345  case rs: return "rs";
346  case cosmics: return "cosmics";
347  case beamhalo: return "beamhalo";
348  case iter0: return "iter0";
349  case iter1: return "iter1";
350  case iter2: return "iter2";
351  case iter3: return "iter3";
352  case iter4: return "iter4";
353  case iter5: return "iter5";
354  case iter6: return "iter6";
355  case iter7: return "iter7";
356  case iter8: return "iter8";
357  case iter9: return "iter9";
358  case iter10: return "iter10";
359  case outInEcalSeededConv: return "outInEcalSeededConv";
360  case inOutEcalSeededConv: return "inOutEcalSeededConv";
361  case nuclInter: return "nuclInter";
362  case standAloneMuon: return "standAloneMuon";
363  case globalMuon: return "globalMuon";
364  case cosmicStandAloneMuon: return "cosmicStandAloneMuon";
365  case cosmicGlobalMuon: return "cosmicGlobalMuon";
366  case iter1LargeD0: return "iter1LargeD0";
367  case iter2LargeD0: return "iter2LargeD0";
368  case iter3LargeD0: return "iter3LargeD0";
369  case iter4LargeD0: return "iter4LargeD0";
370  case iter5LargeD0: return "iter5LargeD0";
371  case bTagGhostTracks: return "bTagGhostTracks";
372  case gsf: return "gsf";
373  }
374  return "undefAlgorithm";
375  }
376 
377  inline bool TrackBase::quality( const TrackBase::TrackQuality q) const{
378  switch(q){
379  case undefQuality: return (quality_==0);
380  case goodIterative:
381  {
382  return ( ((quality_ & (1<<TrackBase::confirmed))>>TrackBase::confirmed) ||
384  }
385  default:
386  {
387  return (quality_ & (1<<q))>>q;
388  }
389  }
390  return false;
391  }
392 
394  switch(q){
395  case undefQuality: quality_=0;
396  default:
397  {
398  if (set)//regular OR if setting value to true
399  quality_= quality_ | (1<<q) ;
400  else // doing "half-XOR" if unsetting value
401  quality_= quality_ & (~(1<<q));
402  }
403  }
404  }
405 
406  inline std::string TrackBase::qualityName(TrackQuality q) {
407  if(int(q) < int(qualitySize) && int(q)>=0) return qualityNames[int(q)];
408  return "undefQuality";
409  }
410 
411  inline std::string TrackBase::algoName(TrackAlgorithm a){
412  if(int(a) < int(algoSize) && int(a)>0) return algoNames[int(a)];
413  return "undefAlgorithm";
414  }
415 
416 
417 
418 }
419 
420 #endif
double qoverp() const
q/p
Definition: TrackBase.h:115
double p() const
momentum vector magnitude
Definition: TrackBase.h:129
float chi2_
chi-squared
Definition: TrackBase.h:306
void setQualityMask(int qualMask)
Definition: TrackBase.h:287
int i
Definition: DBlmapReader.cc:9
double d0Error() const
error on d0
Definition: TrackBase.h:211
double dxy(const Point &myBeamSpot) const
dxy parameter with respect to a user-given beamSpot (WARNING: this quantity can only be interpreted a...
Definition: TrackBase.h:159
static std::string qualityName(TrackQuality)
Definition: TrackBase.h:406
unsigned int index
index type
Definition: TrackBase.h:80
bool isLooper() const
Definition: TrackBase.h:292
void setTrackerExpectedHitsInner(const C &c)
Definition: TrackBase.h:248
static index covIndex(index i, index j)
covariance matrix index in array
Definition: TrackBase.h:327
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:150
uint8_t quality_
track quality
Definition: TrackBase.h:320
double validFraction() const
fraction of valid hits on the track
Definition: TrackBase.h:236
double d0() const
dxy parameter in perigee convention (d0 = - dxy)
Definition: TrackBase.h:123
void setTrackerExpectedHitsOuter(const I &begin, const I &end)
Definition: TrackBase.h:257
void appendHit(const TrackingRecHit &hit)
Definition: HitPattern.cc:88
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:111
TrackBase()
default constructor
Definition: TrackBase.cc:20
double dxy(const BeamSpot &theBeamSpot) const
dxy parameter with respect to the beamSpot taking into account the beamspot slopes WARNING: this quan...
Definition: TrackBase.h:164
int numberOfLostTrackerHits() const
Definition: HitPattern.h:615
TrackQuality
track quality
Definition: TrackBase.h:95
double theta() const
polar angle
Definition: TrackBase.h:117
double dxyError() const
error on dxy
Definition: TrackBase.h:209
char charge_
electric charge
Definition: TrackBase.h:316
int numberOfValidHits() const
Definition: HitPattern.h:554
Point vertex_
innermost (reference) point on track
Definition: TrackBase.h:308
void setTrackerExpectedHitsInner(const I &begin, const I &end)
Definition: TrackBase.h:255
int numberOfLostHits() const
Definition: HitPattern.h:611
void setHitPattern(const TrackingRecHit &hit, size_t i)
set hit pattern for specified hit
Definition: TrackBase.h:260
void setHitPattern(const HitPattern &hitP)
set hitPattern from pre-defined hitPattern
Definition: TrackBase.h:266
double etaError() const
error on eta
Definition: TrackBase.h:205
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:139
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:234
HitPattern trackerExpectedHitsInner_
hit pattern used for expected crossed layers after the last trajectory&#39;s hit
Definition: TrackBase.h:299
ErrorD< N >::type type
Definition: Error.h:30
void set(const I &begin, const I &end)
Definition: HitPattern.h:139
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:70
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:133
const Point & referencePoint() const
Reference point on the track.
Definition: TrackBase.h:153
double dsz() const
dsz parameter (THIS IS NOT the SZ impact parameter to (0,0,0) if refPoint is far from (0...
Definition: TrackBase.h:125
signed char nLoops_
number of loops made during the building of the trajectory of a looper particle
Definition: TrackBase.h:323
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:182
TrackAlgorithm
track algorithm
Definition: TrackBase.h:82
TrackAlgorithm algo() const
Definition: TrackBase.h:332
void setTrackerExpectedHitsInner(const TrackingRecHit &hit, size_t i)
Definition: TrackBase.h:262
void setNLoops(signed char value)
Definition: TrackBase.h:290
void setHitPattern(const I &begin, const I &end)
Definition: TrackBase.h:253
double dszError() const
error on dsz
Definition: TrackBase.h:213
const HitPattern & trackerExpectedHitsOuter() const
Access the hit pattern counting (in the Tracker) the number of expected crossed layers after the last...
Definition: TrackBase.h:227
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
void setQuality(const TrackQuality, bool set=true)
Definition: TrackBase.h:393
static const std::string qualityNames[]
Definition: TrackBase.h:96
fixed size vector
Definition: Vector.h:23
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:107
ParameterVector parameters() const
Track parameters with one-to-one correspondence to the covariance matrix.
Definition: TrackBase.h:178
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:109
T sqrt(T t)
Definition: SSEVec.h:46
void setTrackerExpectedHitsOuter(const C &c)
Definition: TrackBase.h:250
double pt() const
track transverse momentum
Definition: TrackBase.h:131
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:194
double phiError() const
error on phi
Definition: TrackBase.h:207
void setTrackerExpectedHitsOuter(const TrackingRecHit &hit, size_t i)
Definition: TrackBase.h:263
int qualityMask() const
Definition: TrackBase.h:286
int j
Definition: DBlmapReader.cc:9
double lambda() const
Lambda angle.
Definition: TrackBase.h:119
const std::complex< double > I
Definition: I.h:8
double error(int i) const
error on specified element
Definition: TrackBase.h:189
const HitPattern & trackerExpectedHitsInner() const
Access the hit pattern counting (in the Tracker) the number of expected crossed layers before the fir...
Definition: TrackBase.h:225
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:232
#define end
Definition: vmac.h:38
math::XYZPoint Point
point in the space
Definition: TrackBase.h:76
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:223
void setTrackerExpectedHitsOuter(const HitPattern &hitP)
Definition: TrackBase.h:268
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:137
double parameter(int i) const
i-th parameter ( i = 0, ... 4 )
Definition: TrackBase.h:185
double qoverpError() const
error on signed transverse curvature
Definition: TrackBase.h:192
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:127
double dzError() const
error on dz
Definition: TrackBase.h:215
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:156
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:147
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:246
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
#define M_PI
Definition: BFit3D.cc:3
~TrackBase()
virtual destructor
Definition: TrackBase.cc:39
signed char nLoops() const
Definition: TrackBase.h:293
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
std::string algoName() const
Definition: TrackBase.h:336
This class analyses the reconstruction quality for a given track.
Definition: TrackQuality.h:26
double b
Definition: hdecay.h:120
float ndof_
number of degrees of freedom
Definition: TrackBase.h:313
static const std::string algoNames[]
Definition: TrackBase.h:92
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:377
double dsz(const Point &myBeamSpot) const
dsz parameter with respect to a user-given beamSpot (WARNING: this quantity can only be interpreted a...
Definition: TrackBase.h:169
int numberOfValidTrackerHits() const
Definition: HitPattern.h:558
double lambdaError() const
error on lambda
Definition: TrackBase.h:203
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:145
float covariance_[covarianceSize]
perigee 5x5 covariance matrix
Definition: TrackBase.h:304
#define begin
Definition: vmac.h:31
HitPattern hitPattern_
hit pattern
Definition: TrackBase.h:297
void setAlgorithm(const TrackAlgorithm a, bool set=true)
position index
Definition: TrackBase.h:273
double a
Definition: hdecay.h:121
double covariance(int i, int j) const
(i,j)-th element of covarianve matrix ( i, j = 0, ... 4 )
Definition: TrackBase.h:187
CovarianceMatrix & fill(CovarianceMatrix &v) const
fill SMatrix
Definition: TrackBase.cc:42
void appendHitPattern(const TrackingRecHit &hit)
Definition: TrackBase.h:261
HitPattern trackerExpectedHitsOuter_
hit pattern used for expected crossed layers before the first trajectory&#39;s hit
Definition: TrackBase.h:301
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:55
double dz(const Point &myBeamSpot) const
dz parameter with respect to a user-given beamSpot (WARNING: this quantity can only be interpreted as...
Definition: TrackBase.h:173
Vector momentum_
momentum vector at innermost point
Definition: TrackBase.h:310
int charge() const
track electric charge
Definition: TrackBase.h:113
const Point & position() const
position
Definition: BeamSpot.h:63
uint8_t algorithm_
track algorithm
Definition: TrackBase.h:318
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:121
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:74
void setTrackerExpectedHitsInner(const HitPattern &hitP)
Definition: TrackBase.h:267
mathSSE::Vec4< T > v
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:135
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:143
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:72
double thetaError() const
error on theta
Definition: TrackBase.h:201
void set(const std::string &name, int value)
set the flag, with a run-time name