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 #ifdef CMS_NOCXX11
72 float Vertex::trackWeight ( const TrackBaseRef & track ) const
73 {
75  if (it==tracks_end()) return 0.0;
76  size_t pos = it - tracks_begin();
77  return weights_[pos]/255.;
78 }
79 
80 float Vertex::trackWeight ( const TrackRef & track ) const
81 {
82  return trackWeight(TrackBaseRef(track));
83 }
84 #endif
85 
86 TrackBaseRef Vertex::originalTrack(const Track & refTrack) const
87 {
88  if (refittedTracks_.empty())
89  throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
90  std::vector<Track>::const_iterator it =
91  find_if(refittedTracks_.begin(), refittedTracks_.end(), TrackEqual(refTrack));
92  if (it==refittedTracks_.end())
93  throw cms::Exception("Vertex") << "Refitted track not found in list\n";
94  size_t pos = it - refittedTracks_.begin();
95  return tracks_[pos];
96 }
97 
98 Track Vertex::refittedTrack(const TrackBaseRef & track) const
99 {
100  if (refittedTracks_.empty())
101  throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
102  trackRef_iterator it = find(tracks_begin(), tracks_end(), track);
103  if (it==tracks_end()) throw cms::Exception("Vertex") << "Track not found in list\n";
104  size_t pos = it - tracks_begin();
105  return refittedTracks_[pos];
106 }
107 
109 {
110  return refittedTrack(TrackBaseRef(track));
111 }
112 
113 math::XYZTLorentzVectorD Vertex::p4(float mass,float minWeight) const
114 {
115 
117  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > vec;
118 
119  if(hasRefittedTracks()) {
120  for(std::vector<Track>::const_iterator iter = refittedTracks_.begin();
121  iter != refittedTracks_.end(); ++iter) {
122  if (trackWeight(originalTrack(*iter)) >=minWeight) {
123  vec.SetPx(iter->px());
124  vec.SetPy(iter->py());
125  vec.SetPz(iter->pz());
126  vec.SetM(mass);
127  sum += vec;
128  }
129  }
130  }
131  else
132  {
133  for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin();
134  iter != tracks_end(); iter++) {
135  if (trackWeight(*iter) >=minWeight) {
136  vec.SetPx((*iter)->px());
137  vec.SetPy((*iter)->py());
138  vec.SetPz((*iter)->pz());
139  vec.SetM(mass);
140  sum += vec;
141  }
142  }
143  }
144  return sum;
145 }
146 
147 unsigned int Vertex::nTracks(float minWeight) const
148 {
149  int n=0;
150  if(hasRefittedTracks()) {
151  for(std::vector<Track>::const_iterator iter = refittedTracks_.begin(); iter != refittedTracks_.end(); ++iter)
152  if (trackWeight(originalTrack(*iter)) >=minWeight)
153  n++;
154  }
155  else
156  {
157  for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin(); iter != tracks_end(); iter++)
158  if (trackWeight(*iter) >=minWeight)
159  n++;
160  }
161  return n;
162 }
163 
int i
Definition: DBlmapReader.cc:9
std::vector< TrackBaseRef > tracks_
reference to tracks
Definition: Vertex.h:175
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
const double w
Definition: UKUtility.cc:23
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
TrackBaseRef originalTrack(const Track &refTrack) const
Definition: Vertex.cc:86
Track refittedTrack(const TrackBaseRef &track) const
std::vector< Track > refittedTracks_
The vector of refitted tracks.
Definition: Vertex.h:177
bool hasRefittedTracks() const
Checks whether refitted tracks are stored.
Definition: Vertex.h:134
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:32
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:147
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:113
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:37
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:173
index idx(index i, index j) const
position index
Definition: Vertex.h:184
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:180
std::vector< uint8_t > weights_
Definition: Vertex.h:178