CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Vertex.cc
Go to the documentation of this file.
2 #include <Math/GenVector/PxPyPzE4D.h>
3 #include <Math/GenVector/PxPyPzM4D.h>
4 
5 using namespace reco;
6 using namespace std;
7 
8 Vertex::Vertex( const Point & p , const Error & err, double chi2, double ndof, size_t size ) :
9  chi2_( chi2 ), ndof_( ndof ), position_( p ) {
10  tracks_.reserve( size );
11  index idx = 0;
12  for( index i = 0; i < dimension; ++ i )
13  for( index j = 0; j <= i; ++ j )
14  covariance_[ idx ++ ] = err( i, j );
15  validity_ = true;
16 }
17 
18 Vertex::Vertex( const Point & p , const Error & err) :
19  chi2_( 0.0 ), ndof_( 0 ), position_( p ) {
20  index idx = 0;
21  for( index i = 0; i < dimension; ++ i )
22  for( index j = 0; j <= i; ++ j )
23  covariance_[ idx ++ ] = err( i, j );
24  validity_ = true;
25 }
26 
27 void Vertex::fill( Error & err ) const {
28  index idx = 0;
29  for( index i = 0; i < dimension; ++ i )
30  for( index j = 0; j <= i; ++ j )
31  err( i, j ) = covariance_[ idx ++ ];
32 }
33 
34 size_t Vertex::tracksSize() const
35 {
36  return weights_.size();
37 }
38 
40 {
41  return tracks_.begin();
42 }
43 
45 {
46 // if ( !(tracks_.size() ) ) createTracks();
47  return tracks_.end();
48  // return weights_.keys().end();
49 }
50 
51 void Vertex::add ( const TrackBaseRef & r, float w )
52 {
53  tracks_.push_back ( r );
54  weights_.push_back(w*255);
55 }
56 
57 void Vertex::add ( const TrackBaseRef & r, const Track & refTrack, float w )
58 {
59  tracks_.push_back ( r );
60  refittedTracks_.push_back ( refTrack );
61  weights_.push_back(w*255);
62 }
63 
65 {
66  weights_.clear();
67  tracks_.clear();
68  refittedTracks_.clear();
69 }
70 
71 float Vertex::trackWeight ( const TrackBaseRef & track ) const
72 {
74  if (it==tracks_end()) return 0.0;
75  size_t pos = it - tracks_begin();
76  return weights_[pos]/255.;
77 }
78 
79 float Vertex::trackWeight ( const TrackRef & track ) const
80 {
81  return trackWeight(TrackBaseRef(track));
82 }
83 
84 
85 TrackBaseRef Vertex::originalTrack(const Track & refTrack) const
86 {
87  if (refittedTracks_.empty())
88  throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
89  std::vector<Track>::const_iterator it =
90  find_if(refittedTracks_.begin(), refittedTracks_.end(), TrackEqual(refTrack));
91  if (it==refittedTracks_.end())
92  throw cms::Exception("Vertex") << "Refitted track not found in list\n";
93  size_t pos = it - refittedTracks_.begin();
94  return tracks_[pos];
95 }
96 
97 Track Vertex::refittedTrack(const TrackBaseRef & track) const
98 {
99  if (refittedTracks_.empty())
100  throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
101  trackRef_iterator it = find(tracks_begin(), tracks_end(), track);
102  if (it==tracks_end()) throw cms::Exception("Vertex") << "Track not found in list\n";
103  size_t pos = it - tracks_begin();
104  return refittedTracks_[pos];
105 }
106 
108 {
109  return refittedTrack(TrackBaseRef(track));
110 }
111 
112 math::XYZTLorentzVectorD Vertex::p4(float mass,float minWeight) const
113 {
114 
116  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > vec;
117 
118  if(hasRefittedTracks()) {
119  for(std::vector<Track>::const_iterator iter = refittedTracks_.begin();
120  iter != refittedTracks_.end(); ++iter) {
121  if (trackWeight(originalTrack(*iter)) >=minWeight) {
122  vec.SetPx(iter->px());
123  vec.SetPy(iter->py());
124  vec.SetPz(iter->pz());
125  vec.SetM(mass);
126  sum += vec;
127  }
128  }
129  }
130  else
131  {
132  for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin();
133  iter != tracks_end(); iter++) {
134  if (trackWeight(*iter) >=minWeight) {
135  vec.SetPx((*iter)->px());
136  vec.SetPy((*iter)->py());
137  vec.SetPz((*iter)->pz());
138  vec.SetM(mass);
139  sum += vec;
140  }
141  }
142  }
143  return sum;
144 }
145 
146 unsigned int Vertex::nTracks(float minWeight) const
147 {
148  int n=0;
149  if(hasRefittedTracks()) {
150  for(std::vector<Track>::const_iterator iter = refittedTracks_.begin(); iter != refittedTracks_.end(); ++iter)
151  if (trackWeight(originalTrack(*iter)) >=minWeight)
152  n++;
153  }
154  else
155  {
156  for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin(); iter != tracks_end(); iter++)
157  if (trackWeight(*iter) >=minWeight)
158  n++;
159  }
160  return n;
161 }
162 
int i
Definition: DBlmapReader.cc:9
std::vector< TrackBaseRef > tracks_
reference to tracks
Definition: Vertex.h:161
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
TrackBaseRef originalTrack(const Track &refTrack) const
Definition: Vertex.cc:85
Track refittedTrack(const TrackBaseRef &track) const
std::vector< Track > refittedTracks_
The vector of refitted tracks.
Definition: Vertex.h:163
bool hasRefittedTracks() const
Checks whether refitted tracks are stored.
Definition: Vertex.h:120
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
void fill(CovarianceMatrix &v) const
fill SMatrix
Definition: Vertex.cc:27
unsigned int index
index type
Definition: Vertex.h:49
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:22
float trackWeight(const TrackBaseRef &r) const
returns the weight with which a Track has contributed to the vertex-fit.
int j
Definition: DBlmapReader.cc:9
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
void add(const TrackBaseRef &r, float w=1.0)
add a reference to a Track
unsigned int nTracks(float minWeight=0.5) const
Returns the number of tracks in the vertex with weight above minWeight.
Definition: Vertex.cc:146
math::XYZTLorentzVectorD p4(float mass=0.13957018, float minWeight=0.5) const
Returns the four momentum of the sum of the tracks, assuming the given mass for the decay products...
Definition: Vertex.cc:112
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:37
T w() const
void removeTracks()
Definition: Vertex.cc:64
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39
float covariance_[size]
covariance matrix (3x3) as vector
Definition: Vertex.h:159
index idx(index i, index j) const
position index
Definition: Vertex.h:170
tuple size
Write out results.
size_t tracksSize() const
number of tracks
Definition: Vertex.cc:34
bool validity_
tells wether the vertex is really valid.
Definition: Vertex.h:166
std::vector< uint8_t > weights_
Definition: Vertex.h:164