Go to the documentation of this file.00001 #include "DataFormats/VertexReco/interface/Vertex.h"
00002 #include <Math/GenVector/PxPyPzE4D.h>
00003 #include <Math/GenVector/PxPyPzM4D.h>
00004
00005
00006 using namespace reco;
00007 using namespace std;
00008
00009 Vertex::Vertex( const Point & p , const Error & err, double chi2, double ndof, size_t size ) :
00010 chi2_( chi2 ), ndof_( ndof ), position_( p ) {
00011 tracks_.reserve( size );
00012 index idx = 0;
00013 for( index i = 0; i < dimension; ++ i )
00014 for( index j = 0; j <= i; ++ j )
00015 covariance_[ idx ++ ] = err( i, j );
00016 validity_ = true;
00017 }
00018
00019 Vertex::Vertex( const Point & p , const Error & err) :
00020 chi2_( 0.0 ), ndof_( 0 ), position_( p ) {
00021 index idx = 0;
00022 for( index i = 0; i < dimension; ++ i )
00023 for( index j = 0; j <= i; ++ j )
00024 covariance_[ idx ++ ] = err( i, j );
00025 validity_ = true;
00026 }
00027
00028 void Vertex::fill( Error & err ) const {
00029 index idx = 0;
00030 for( index i = 0; i < dimension; ++ i )
00031 for( index j = 0; j <= i; ++ j )
00032 err( i, j ) = covariance_[ idx ++ ];
00033 }
00034
00035 size_t Vertex::tracksSize() const
00036 {
00037 return weights_.size();
00038 }
00039
00040 Vertex::trackRef_iterator Vertex::tracks_begin() const
00041 {
00042 return tracks_.begin();
00043 }
00044
00045 Vertex::trackRef_iterator Vertex::tracks_end() const
00046 {
00047
00048 return tracks_.end();
00049
00050 }
00051
00052 void Vertex::add ( const TrackBaseRef & r, float w )
00053 {
00054 tracks_.push_back ( r );
00055 weights_.push_back(w*255);
00056 }
00057
00058 void Vertex::add ( const TrackBaseRef & r, const Track & refTrack, float w )
00059 {
00060 tracks_.push_back ( r );
00061 refittedTracks_.push_back ( refTrack );
00062 weights_.push_back(w*255);
00063 }
00064
00065 void Vertex::removeTracks()
00066 {
00067 weights_.clear();
00068 tracks_.clear();
00069 refittedTracks_.clear();
00070 }
00071
00072 float Vertex::trackWeight ( const TrackBaseRef & track ) const
00073 {
00074 trackRef_iterator it = find(tracks_begin(), tracks_end(), track);
00075 if (it==tracks_end()) return 0.0;
00076 size_t pos = it - tracks_begin();
00077 return weights_[pos]/255.;
00078 }
00079
00080 float Vertex::trackWeight ( const TrackRef & track ) const
00081 {
00082 return trackWeight(TrackBaseRef(track));
00083 }
00084
00085
00086 TrackBaseRef Vertex::originalTrack(const Track & refTrack) const
00087 {
00088 if (refittedTracks_.empty())
00089 throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
00090 std::vector<Track>::const_iterator it =
00091 find_if(refittedTracks_.begin(), refittedTracks_.end(), TrackEqual(refTrack));
00092 if (it==refittedTracks_.end())
00093 throw cms::Exception("Vertex") << "Refitted track not found in list\n";
00094 size_t pos = it - refittedTracks_.begin();
00095 return tracks_[pos];
00096 }
00097
00098 Track Vertex::refittedTrack(const TrackBaseRef & track) const
00099 {
00100 if (refittedTracks_.empty())
00101 throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
00102 trackRef_iterator it = find(tracks_begin(), tracks_end(), track);
00103 if (it==tracks_end()) throw cms::Exception("Vertex") << "Track not found in list\n";
00104 size_t pos = it - tracks_begin();
00105 return refittedTracks_[pos];
00106 }
00107
00108 Track Vertex::refittedTrack(const TrackRef & track) const
00109 {
00110 return refittedTrack(TrackBaseRef(track));
00111 }
00112
00113 math::XYZTLorentzVectorD Vertex::p4(float mass,float minWeight) const
00114 {
00115
00116 math::XYZTLorentzVectorD sum;
00117 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > vec;
00118
00119 if(hasRefittedTracks()) {
00120 for(std::vector<Track>::const_iterator iter = refittedTracks_.begin();
00121 iter != refittedTracks_.end(); ++iter) {
00122 if (trackWeight(originalTrack(*iter)) >=minWeight) {
00123 vec.SetPx(iter->px());
00124 vec.SetPy(iter->py());
00125 vec.SetPz(iter->pz());
00126 vec.SetM(mass);
00127 sum += vec;
00128 }
00129 }
00130 }
00131 else
00132 {
00133 for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin();
00134 iter != tracks_end(); iter++) {
00135 if (trackWeight(*iter) >=minWeight) {
00136 vec.SetPx((*iter)->px());
00137 vec.SetPy((*iter)->py());
00138 vec.SetPz((*iter)->pz());
00139 vec.SetM(mass);
00140 sum += vec;
00141 }
00142 }
00143 }
00144 return sum;
00145 }
00146
00147 unsigned int Vertex::nTracks(float minWeight) const
00148 {
00149 int n=0;
00150 if(hasRefittedTracks()) {
00151 for(std::vector<Track>::const_iterator iter = refittedTracks_.begin(); iter != refittedTracks_.end(); ++iter)
00152 if (trackWeight(originalTrack(*iter)) >=minWeight)
00153 n++;
00154 }
00155 else
00156 {
00157 for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin(); iter != tracks_end(); iter++)
00158 if (trackWeight(*iter) >=minWeight)
00159 n++;
00160 }
00161 return n;
00162 }
00163