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 <iostream> 00027 #include "DataFormats/Common/interface/RefToBase.h" 00028 00029 namespace reco { 00030 00031 class Track; 00032 00033 class Vertex { 00034 public: 00036 typedef std::vector<TrackBaseRef >::const_iterator trackRef_iterator; 00038 typedef math::XYZPoint Point; 00040 enum { dimension = 3 }; 00042 typedef math::Error<dimension>::type Error; 00044 typedef math::Error<dimension>::type CovarianceMatrix; 00046 enum { size = dimension * ( dimension + 1 ) / 2 }; 00048 typedef unsigned int index; 00052 Vertex() { validity_ = false;} 00054 Vertex( const Point &, const Error &); 00056 Vertex( const Point &, const Error &, double chi2, double ndof, size_t size ); 00058 bool isValid() const {return validity_;} 00062 bool isFake() const {return (chi2_==0 && ndof_==0 && tracks_.empty());} 00064 void add( const TrackBaseRef & r, float w=1.0 ); 00066 void add( const TrackBaseRef & r, const Track & refTrack, float w=1.0 ); 00067 void removeTracks(); 00069 float trackWeight ( const TrackBaseRef & r ) const; 00071 float trackWeight ( const TrackRef & r ) const; 00073 trackRef_iterator tracks_begin() const; 00075 trackRef_iterator tracks_end() const; 00077 size_t tracksSize() const; 00079 double chi2() const { return chi2_; } 00086 double ndof() const { return ndof_; } 00088 double normalizedChi2() const { return chi2_ / ndof_; } 00090 const Point & position() const { return position_; } 00092 double x() const { return position_.X(); } 00094 double y() const { return position_.Y(); } 00096 double z() const { return position_.Z(); } 00098 double xError() const { return sqrt( covariance(0, 0) ); } 00100 double yError() const { return sqrt( covariance(1, 1) ); } 00102 double zError() const { return sqrt( covariance(2, 2) ); } 00104 double error( int i, int j ) const { 00105 std::cout << "reco::Vertex::error(i, j) OBSOLETE, use covariance(i, j)" 00106 << std::endl; 00107 return covariance_[ idx( i, j ) ]; 00108 } 00109 double covariance( int i, int j ) const { 00110 return covariance_[ idx( i, j ) ]; 00111 } 00113 CovarianceMatrix covariance() const { Error m; fill( m ); return m; } 00115 Error error() const { Error m; fill( m ); return m; } 00117 void fill( CovarianceMatrix & v ) const; 00118 00120 bool hasRefittedTracks() const {return !refittedTracks_.empty();} 00121 00124 TrackBaseRef originalTrack(const Track & refTrack) const; 00125 00128 Track refittedTrack(const TrackBaseRef & track) const; 00129 00132 Track refittedTrack(const TrackRef & track) const; 00133 00135 const std::vector<Track> & refittedTracks() const { return refittedTracks_;} 00136 00137 private: 00138 class TrackEqual { 00139 public: 00140 TrackEqual( const Track & t) : track_( t ) { } 00141 bool operator()( const Track & t ) const { return t.pt()==track_.pt();} 00142 private: 00143 const Track & track_; 00144 }; 00146 Double32_t chi2_; 00148 Double32_t ndof_; 00150 Point position_; 00152 Double32_t covariance_[ size ]; 00154 std::vector<TrackBaseRef > tracks_; 00156 std::vector<Track> refittedTracks_; 00157 std::vector<float> weights_; 00159 bool validity_; 00160 00161 00163 index idx( index i, index j ) const { 00164 int a = ( i <= j ? i : j ), b = ( i <= j ? j : i ); 00165 return b * ( b + 1 ) / 2 + a; 00166 } 00167 }; 00168 00169 } 00170 00171 #endif