CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/DataFormats/TrackReco/interface/TrackBase.h

Go to the documentation of this file.
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,signed char nloops=0);
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 appendHitPattern( const TrackingRecHit & hit) { hitPattern_.appendHit( hit); }
00262     void setTrackerExpectedHitsInner( const TrackingRecHit & hit, size_t i ) { trackerExpectedHitsInner_.set( hit, i ); }
00263     void setTrackerExpectedHitsOuter( const TrackingRecHit & hit, size_t i ) { trackerExpectedHitsOuter_.set( hit, i ); }
00264 
00266     void setHitPattern( const HitPattern& hitP) {hitPattern_ = hitP;}
00267     void setTrackerExpectedHitsInner( const HitPattern& hitP ) {trackerExpectedHitsInner_ = hitP;}
00268     void setTrackerExpectedHitsOuter( const HitPattern& hitP ) {trackerExpectedHitsOuter_ = hitP;}
00269 
00271 
00273     void setAlgorithm(const TrackAlgorithm a, bool set=true) { if (set) algorithm_=a; else algorithm_=undefAlgorithm;}
00274     TrackAlgorithm algo() const ;
00275     std::string algoName() const;
00276     static std::string algoName(TrackAlgorithm);
00277     static TrackAlgorithm algoByName(const std::string &name);
00278 
00280     bool quality(const TrackQuality ) const;
00281     void setQuality(const TrackQuality, bool set=true); 
00282     static std::string qualityName(TrackQuality);
00283     static TrackQuality qualityByName(const std::string &name);
00284 
00285 
00286     int qualityMask() const { return quality_; }
00287     void setQualityMask(int qualMask) {quality_ = qualMask;}
00288 
00289    
00290     void setNLoops(signed char value) { nLoops_=value;}
00291 
00292     bool isLooper() const { return (nLoops_>0);}
00293     signed char nLoops() const {return nLoops_;}
00294    
00295   private:
00297     HitPattern hitPattern_;
00299     HitPattern trackerExpectedHitsInner_; 
00301     HitPattern trackerExpectedHitsOuter_;
00302 
00304     float covariance_[ covarianceSize ];
00306     float chi2_;
00308     Point vertex_;
00310     Vector momentum_;
00311 
00313     float ndof_;
00314 
00316     char charge_;
00318     uint8_t algorithm_;
00320     uint8_t quality_;
00321 
00323     signed char nLoops_; 
00324 
00325   };
00326 
00327   inline TrackBase::index TrackBase::covIndex( index i, index j )  {
00328     int a = ( i <= j ? i : j ), b = ( i <= j ? j : i );
00329     return b * ( b + 1 ) / 2 + a;
00330   }
00331 
00332   inline TrackBase::TrackAlgorithm TrackBase::algo() const {
00333     return (TrackAlgorithm) algorithm_;
00334   }
00335 
00336   inline std::string TrackBase::algoName() const{
00337     // I'd like to do:
00338     // return TrackBase::algoName(algorithm_);
00339     // but I cannot define a const static function. Why???
00340 
00341     switch(algorithm_)
00342       {
00343       case undefAlgorithm: return "undefAlgorithm";
00344       case ctf: return "ctf";
00345       case rs: return "rs";
00346       case cosmics: return "cosmics";
00347       case beamhalo: return "beamhalo";
00348       case iter0: return "iter0";
00349       case iter1: return "iter1";
00350       case iter2: return "iter2";
00351       case iter3: return "iter3";
00352       case iter4: return "iter4";
00353       case iter5: return "iter5";
00354       case iter6: return "iter6";
00355       case iter7: return "iter7";
00356       case iter8: return "iter8";
00357       case iter9: return "iter9";
00358       case iter10: return "iter10";
00359       case outInEcalSeededConv: return "outInEcalSeededConv";
00360       case inOutEcalSeededConv: return "inOutEcalSeededConv";
00361       case nuclInter: return "nuclInter";
00362       case standAloneMuon: return "standAloneMuon";
00363       case globalMuon: return "globalMuon";
00364       case cosmicStandAloneMuon: return "cosmicStandAloneMuon";
00365       case cosmicGlobalMuon: return "cosmicGlobalMuon";
00366       case iter1LargeD0: return "iter1LargeD0";
00367       case iter2LargeD0: return "iter2LargeD0";
00368       case iter3LargeD0: return "iter3LargeD0";
00369       case iter4LargeD0: return "iter4LargeD0";
00370       case iter5LargeD0: return "iter5LargeD0";
00371       case bTagGhostTracks: return "bTagGhostTracks";
00372       case gsf: return "gsf";
00373       }
00374     return "undefAlgorithm";
00375   }
00376       
00377   inline bool TrackBase::quality( const TrackBase::TrackQuality q) const{
00378     switch(q){
00379     case undefQuality: return (quality_==0);
00380     case goodIterative: 
00381       {
00382         return ( ((quality_ & (1<<TrackBase::confirmed))>>TrackBase::confirmed) ||
00383                  ((quality_ & (1<<TrackBase::highPurity))>>TrackBase::highPurity));
00384       }
00385      default:
00386       {
00387         return (quality_ & (1<<q))>>q;
00388       }
00389     }
00390     return false;
00391   }
00392 
00393   inline void TrackBase::setQuality( const TrackBase::TrackQuality q, bool set){
00394     switch(q){
00395     case undefQuality: quality_=0;
00396     default: 
00397       {
00398         if (set)//regular OR if setting value to true
00399           quality_= quality_ | (1<<q) ;
00400         else // doing "half-XOR" if unsetting value
00401           quality_= quality_ & (~(1<<q));
00402       }
00403     }
00404   }
00405 
00406   inline std::string TrackBase::qualityName(TrackQuality q) {
00407     if(int(q) < int(qualitySize) && int(q)>=0) return qualityNames[int(q)];
00408     return "undefQuality";
00409   }
00410 
00411   inline std::string TrackBase::algoName(TrackAlgorithm a){
00412     if(int(a) < int(algoSize) && int(a)>0) return algoNames[int(a)];
00413     return "undefAlgorithm";
00414   }
00415 
00416 
00417 
00418 }
00419 
00420 #endif