00001 #ifndef TrackReco_TrackBase_h
00002 #define TrackReco_TrackBase_h
00003
00053 #include "DataFormats/Math/interface/Vector.h"
00054 #include "DataFormats/Math/interface/Error.h"
00055 #include "DataFormats/Math/interface/Vector3D.h"
00056 #include "DataFormats/Math/interface/Point3D.h"
00057 #include "DataFormats/Math/interface/Error.h"
00058 #include "DataFormats/TrackReco/interface/HitPattern.h"
00059 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00060
00061 namespace reco {
00062
00063 class TrackBase {
00064 public:
00066 enum { dimension = 5 };
00068 enum { covarianceSize = dimension * ( dimension + 1 ) / 2 };
00070 typedef math::Vector<dimension>::type ParameterVector;
00072 typedef math::Error<dimension>::type CovarianceMatrix;
00074 typedef math::XYZVector Vector;
00076 typedef math::XYZPoint Point;
00078 enum { i_qoverp = 0 , i_lambda, i_phi, i_dxy, i_dsz };
00080 typedef unsigned int index;
00082 enum TrackAlgorithm { undefAlgorithm=0, ctf=1, rs=2, cosmics=3, iter0=4,
00083 iter1=5, iter2=6, iter3=7, iter4=8, iter5=9, iter6=10, iter7=11, iter8=12, iter9=13,iter10=14,
00084 outInEcalSeededConv=15, inOutEcalSeededConv=16,
00085 nuclInter=17,
00086 standAloneMuon=18,globalMuon=19,cosmicStandAloneMuon=20,cosmicGlobalMuon=21,
00087 iter1LargeD0=22,iter2LargeD0=23,iter3LargeD0=24,iter4LargeD0=25,iter5LargeD0=26,
00088 bTagGhostTracks=27,
00089 beamhalo=28,
00090 gsf=29,
00091 algoSize=30 };
00092 static const std::string algoNames[];
00093
00095 enum TrackQuality { undefQuality=-1, loose=0, tight=1, highPurity=2, confirmed=3, goodIterative=4, looseSetWithPV=5, highPuritySetWithPV=6, qualitySize=7 };
00096 static const std::string qualityNames[];
00097
00099 TrackBase();
00101 TrackBase( double chi2, double ndof, const Point & referencePoint,
00102 const Vector & momentum, int charge, const CovarianceMatrix &,
00103 TrackAlgorithm=undefAlgorithm, TrackQuality quality=undefQuality);
00105 ~TrackBase();
00107 double chi2() const { return chi2_; }
00109 double ndof() const { return ndof_; }
00111 double normalizedChi2() const { return ndof_ != 0 ? chi2_ / ndof_ : chi2_ * 1e6; }
00113 int charge() const { return charge_; }
00115 double qoverp() const { return charge() / p(); }
00117 double theta() const { return momentum_.theta(); }
00119 double lambda() const { return M_PI/2 - momentum_.theta(); }
00121 double dxy() const { return ( - vx() * py() + vy() * px() ) / pt(); }
00123 double d0() const { return - dxy(); }
00125 double dsz() const { return vz()*pt()/p() - (vx()*px()+vy()*py())/pt() * pz()/p(); }
00127 double dz() const { return vz() - (vx()*px()+vy()*py())/pt() * (pz()/pt()); }
00129 double p() const { return momentum_.R(); }
00131 double pt() const { return sqrt( momentum_.Perp2() ); }
00133 double px() const { return momentum_.x(); }
00135 double py() const { return momentum_.y(); }
00137 double pz() const { return momentum_.z(); }
00139 double phi() const { return momentum_.Phi(); }
00141 double eta() const { return momentum_.Eta(); }
00143 double vx() const { return vertex_.x(); }
00145 double vy() const { return vertex_.y(); }
00147 double vz() const { return vertex_.z(); }
00148
00150 const Vector & momentum() const { return momentum_; }
00151
00153 const Point & referencePoint() const { return vertex_; }
00154
00156 const Point & vertex() const { return vertex_; }
00157
00159 double dxy(const Point& myBeamSpot) const {
00160 return ( - (vx()-myBeamSpot.x()) * py() + (vy()-myBeamSpot.y()) * px() ) / pt();
00161 }
00162
00164 double dxy(const BeamSpot& theBeamSpot) const {
00165 return dxy(theBeamSpot.position(vz()));
00166 }
00167
00169 double dsz(const Point& myBeamSpot) const {
00170 return (vz()-myBeamSpot.z())*pt()/p() - ((vx()-myBeamSpot.x())*px()+(vy()-myBeamSpot.y())*py())/pt() *pz()/p();
00171 }
00173 double dz(const Point& myBeamSpot) const {
00174 return (vz()-myBeamSpot.z()) - ((vx()-myBeamSpot.x())*px()+(vy()-myBeamSpot.y())*py())/pt() * pz()/pt();
00175 }
00176
00178 ParameterVector parameters() const {
00179 return ParameterVector(qoverp(),lambda(),phi(),dxy(),dsz());
00180 }
00182 CovarianceMatrix covariance() const { CovarianceMatrix m; fill( m ); return m; }
00183
00185 double parameter(int i) const { return parameters()[i]; }
00187 double covariance( int i, int j ) const { return covariance_[ covIndex( i, j ) ]; }
00189 double error( int i ) const { return sqrt( covariance_[ covIndex( i, i ) ] ); }
00190
00192 double qoverpError() const { return error( i_qoverp ); }
00194 double ptError() const {
00195 return (charge()!=0) ? sqrt(
00196 pt()*pt()*p()*p()/charge()/charge() * covariance(i_qoverp,i_qoverp)
00197 + 2*pt()*p()/charge()*pz() * covariance(i_qoverp,i_lambda)
00198 + pz()*pz() * covariance(i_lambda,i_lambda) ) : 1.e6;
00199 }
00201 double thetaError() const { return error( i_lambda ); }
00203 double lambdaError() const { return error( i_lambda ); }
00205 double etaError() const { return error( i_lambda ) * p()/pt(); }
00207 double phiError() const { return error( i_phi ); }
00209 double dxyError() const { return error( i_dxy ); }
00211 double d0Error() const { return error( i_dxy ); }
00213 double dszError() const { return error( i_dsz ); }
00215 double dzError() const { return error( i_dsz ) * p()/pt(); }
00216
00218 CovarianceMatrix & fill( CovarianceMatrix & v ) const;
00220 static index covIndex( index i, index j );
00221
00223 const HitPattern & hitPattern() const { return hitPattern_; }
00225 const HitPattern & trackerExpectedHitsInner() const { return trackerExpectedHitsInner_; }
00227 const HitPattern & trackerExpectedHitsOuter() const { return trackerExpectedHitsOuter_; }
00228
00229
00230
00232 unsigned short numberOfValidHits() const { return hitPattern_.numberOfValidHits(); }
00234 unsigned short numberOfLostHits() const { return hitPattern_.numberOfLostHits(); }
00236 double validFraction() const {
00237 int valid = hitPattern_.numberOfValidTrackerHits();
00238 int lost = hitPattern_.numberOfLostTrackerHits();
00239 int lostIn = trackerExpectedHitsInner_.numberOfLostTrackerHits();
00240 int lostOut = trackerExpectedHitsOuter_.numberOfLostTrackerHits();
00241 if ((valid+lost+lostIn+lostOut)==0) return -1;
00242 return valid/(1.0*(valid+lost+lostIn+lostOut));
00243 }
00245 template<typename C>
00246 void setHitPattern( const C & c ) { hitPattern_.set( c.begin(), c.end() ); }
00247 template<typename C>
00248 void setTrackerExpectedHitsInner( const C & c ) { trackerExpectedHitsInner_.set( c.begin(), c.end() ); }
00249 template<typename C>
00250 void setTrackerExpectedHitsOuter( const C & c ) { trackerExpectedHitsOuter_.set( c.begin(), c.end() ); }
00251
00252 template<typename I>
00253 void setHitPattern( const I & begin, const I & end ) { hitPattern_.set( begin, end ); }
00254 template<typename I>
00255 void setTrackerExpectedHitsInner( const I & begin, const I & end ) { trackerExpectedHitsInner_.set( begin, end ); }
00256 template<typename I>
00257 void setTrackerExpectedHitsOuter( const I & begin, const I & end ) { trackerExpectedHitsOuter_.set( begin, end ); }
00258
00260 void setHitPattern( const TrackingRecHit & hit, size_t i ) { hitPattern_.set( hit, i ); }
00261 void setTrackerExpectedHitsInner( const TrackingRecHit & hit, size_t i ) { trackerExpectedHitsInner_.set( hit, i ); }
00262 void setTrackerExpectedHitsOuter( const TrackingRecHit & hit, size_t i ) { trackerExpectedHitsOuter_.set( hit, i ); }
00263
00265 void setHitPattern( const HitPattern& hitP) {hitPattern_ = hitP;}
00266 void setTrackerExpectedHitsInner( const HitPattern& hitP ) {trackerExpectedHitsInner_ = hitP;}
00267 void setTrackerExpectedHitsOuter( const HitPattern& hitP ) {trackerExpectedHitsOuter_ = hitP;}
00268
00270
00272 void setAlgorithm(const TrackAlgorithm a, bool set=true) { if (set) algorithm_=a; else algorithm_=undefAlgorithm;}
00273 TrackAlgorithm algo() const ;
00274 std::string algoName() const;
00275 static std::string algoName(TrackAlgorithm);
00276 static TrackAlgorithm algoByName(const std::string &name);
00277
00279 bool quality(const TrackQuality ) const;
00280 void setQuality(const TrackQuality, bool set=true);
00281 static std::string qualityName(TrackQuality);
00282 static TrackQuality qualityByName(const std::string &name);
00283
00284
00285 int qualityMask() const { return quality_; }
00286 void setQualityMask(int qualMask) {quality_ = qualMask;}
00287 private:
00289 float chi2_;
00291 float ndof_;
00293 Point vertex_;
00295 Vector momentum_;
00297 char charge_;
00299 float covariance_[ covarianceSize ];
00301 HitPattern hitPattern_;
00303 HitPattern trackerExpectedHitsInner_;
00305 HitPattern trackerExpectedHitsOuter_;
00306
00308 uint8_t algorithm_;
00310 uint8_t quality_;
00311
00312 };
00313
00314 inline TrackBase::index TrackBase::covIndex( index i, index j ) {
00315 int a = ( i <= j ? i : j ), b = ( i <= j ? j : i );
00316 return b * ( b + 1 ) / 2 + a;
00317 }
00318
00319 inline TrackBase::TrackAlgorithm TrackBase::algo() const {
00320 return (TrackAlgorithm) algorithm_;
00321 }
00322
00323 inline std::string TrackBase::algoName() const{
00324
00325
00326
00327
00328 switch(algorithm_)
00329 {
00330 case undefAlgorithm: return "undefAlgorithm";
00331 case ctf: return "ctf";
00332 case rs: return "rs";
00333 case cosmics: return "cosmics";
00334 case beamhalo: return "beamhalo";
00335 case iter0: return "iter0";
00336 case iter1: return "iter1";
00337 case iter2: return "iter2";
00338 case iter3: return "iter3";
00339 case iter4: return "iter4";
00340 case iter5: return "iter5";
00341 case iter6: return "iter6";
00342 case iter7: return "iter7";
00343 case iter8: return "iter8";
00344 case iter9: return "iter9";
00345 case iter10: return "iter10";
00346 case outInEcalSeededConv: return "outInEcalSeededConv";
00347 case inOutEcalSeededConv: return "inOutEcalSeededConv";
00348 case nuclInter: return "nuclInter";
00349 case standAloneMuon: return "standAloneMuon";
00350 case globalMuon: return "globalMuon";
00351 case cosmicStandAloneMuon: return "cosmicStandAloneMuon";
00352 case cosmicGlobalMuon: return "cosmicGlobalMuon";
00353 case iter1LargeD0: return "iter1LargeD0";
00354 case iter2LargeD0: return "iter2LargeD0";
00355 case iter3LargeD0: return "iter3LargeD0";
00356 case iter4LargeD0: return "iter4LargeD0";
00357 case iter5LargeD0: return "iter5LargeD0";
00358 case bTagGhostTracks: return "bTagGhostTracks";
00359 case gsf: return "gsf";
00360 }
00361 return "undefAlgorithm";
00362 }
00363
00364 inline bool TrackBase::quality( const TrackBase::TrackQuality q) const{
00365 switch(q){
00366 case undefQuality: return (quality_==0);
00367 case goodIterative:
00368 {
00369 return ( ((quality_ & (1<<TrackBase::confirmed))>>TrackBase::confirmed) ||
00370 ((quality_ & (1<<TrackBase::highPurity))>>TrackBase::highPurity));
00371 }
00372 default:
00373 {
00374 return (quality_ & (1<<q))>>q;
00375 }
00376 }
00377 return false;
00378 }
00379
00380 inline void TrackBase::setQuality( const TrackBase::TrackQuality q, bool set){
00381 switch(q){
00382 case undefQuality: quality_=0;
00383 default:
00384 {
00385 if (set)
00386 quality_= quality_ | (1<<q) ;
00387 else
00388 quality_= quality_ & (~(1<<q));
00389 }
00390 }
00391 }
00392
00393 inline std::string TrackBase::qualityName(TrackQuality q) {
00394 if(int(q) < int(qualitySize) && int(q)>=0) return qualityNames[int(q)];
00395 return "undefQuality";
00396 }
00397
00398 inline std::string TrackBase::algoName(TrackAlgorithm a){
00399 if(int(a) < int(algoSize) && int(a)>0) return algoNames[int(a)];
00400 return "undefAlgorithm";
00401 }
00402
00403
00404
00405 }
00406
00407 #endif