CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/VertexReco/interface/Vertex.h

Go to the documentation of this file.
00001 #ifndef VertexReco_Vertex_h
00002 #define VertexReco_Vertex_h
00003 
00021 #include <Rtypes.h>
00022 #include "DataFormats/Math/interface/Error.h"
00023 #include "DataFormats/Math/interface/Point3D.h"
00024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00025 #include "DataFormats/TrackReco/interface/Track.h"
00026 #include "DataFormats/Common/interface/RefToBase.h" 
00027 #include <Math/GenVector/PxPyPzE4D.h>                                                                                                   
00028 #include <Math/GenVector/PxPyPzM4D.h> 
00029 #include "DataFormats/Math/interface/LorentzVector.h"                                                                                   
00030 
00031 namespace reco {
00032 
00033   class Track;
00034 
00035   class Vertex {
00036   public:
00038     typedef std::vector<TrackBaseRef >::const_iterator trackRef_iterator;
00040     typedef math::XYZPoint Point;
00042     enum { dimension = 3 };
00044     typedef math::Error<dimension>::type Error;
00046     typedef math::Error<dimension>::type CovarianceMatrix;
00048     enum { size = dimension * ( dimension + 1 ) / 2 };
00050     typedef unsigned int index;
00054     Vertex():  chi2_( 0.0 ), ndof_( 0 ), position_(0.,0.,0. ) { validity_ = false; for(int i = 0; i < size; ++ i ) covariance_[i]=0.;
00055 }
00057     Vertex( const Point &, const Error &);
00059     Vertex( const Point &, const Error &, double chi2, double ndof, size_t size );
00061     bool isValid() const {return validity_;}
00065     bool isFake() const {return (chi2_==0 && ndof_==0 && tracks_.empty());}
00067     void add( const TrackBaseRef & r, float w=1.0 );
00069     void add( const TrackBaseRef & r, const Track & refTrack, float w=1.0 );
00070     void removeTracks();
00072     float trackWeight ( const TrackBaseRef & r ) const;
00074     float trackWeight ( const TrackRef & r ) const;
00076     trackRef_iterator tracks_begin() const;
00078     trackRef_iterator tracks_end() const;
00080     size_t tracksSize() const;
00082     double chi2() const { return chi2_; }
00089     double ndof() const { return ndof_; }
00091     double normalizedChi2() const { return ndof_ != 0 ? chi2_ / ndof_ : chi2_ * 1e6; }
00093     const Point & position() const { return position_; }
00095     double x() const { return position_.X(); }
00097     double y() const { return position_.Y(); }
00099     double z() const { return position_.Z(); }
00101     double xError() const { return sqrt( covariance(0, 0) ); }
00103     double yError() const { return sqrt( covariance(1, 1) ); }
00105     double zError() const { return sqrt( covariance(2, 2) ); }
00107     // Note that:
00108     //   double error( int i, int j ) const 
00109     // is OBSOLETE, use covariance(i, j)
00110     double covariance( int i, int j ) const { 
00111       return covariance_[ idx( i, j ) ]; 
00112     }
00114     CovarianceMatrix covariance() const { Error m; fill( m ); return m; }
00116     Error error() const { Error m; fill( m ); return m; }
00118     void fill( CovarianceMatrix & v ) const;
00119 
00121     bool hasRefittedTracks() const {return !refittedTracks_.empty();}
00122     
00125     TrackBaseRef originalTrack(const Track & refTrack) const;
00126 
00129     Track refittedTrack(const TrackBaseRef & track) const;
00130 
00133     Track refittedTrack(const TrackRef & track) const;
00134 
00136     const std::vector<Track> & refittedTracks() const { return refittedTracks_;}
00137 
00139     math::XYZTLorentzVectorD p4(float mass=0.13957018,float minWeight=0.5) const; 
00140 
00142     unsigned int nTracks(float minWeight=0.5) const; 
00143 
00144   private:
00145     class TrackEqual {
00146       public:
00147         TrackEqual( const Track & t) : track_( t ) { }
00148         bool operator()( const Track & t ) const { return t.pt()==track_.pt();}
00149       private:
00150         const Track & track_;
00151     };
00153     float chi2_;
00155     float ndof_;
00157     Point position_;
00159     float covariance_[ size ];
00161     std::vector<TrackBaseRef > tracks_;
00163     std::vector<Track> refittedTracks_;
00164     std::vector<uint8_t> weights_;
00166     bool validity_;
00167 
00168 
00170     index idx( index i, index j ) const {
00171       int a = ( i <= j ? i : j ), b = ( i <= j ? j : i );
00172       return b * ( b + 1 ) / 2 + a;
00173     }
00174   };
00175   
00176 }
00177 
00178 #endif