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 TrackBaseRef Vertex::originalTrack(const Track & refTrack) const
72 {
73  if (refittedTracks_.empty())
74  throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
75  std::vector<Track>::const_iterator it =
76  find_if(refittedTracks_.begin(), refittedTracks_.end(), TrackEqual(refTrack));
77  if (it==refittedTracks_.end())
78  throw cms::Exception("Vertex") << "Refitted track not found in list\n";
79  size_t pos = it - refittedTracks_.begin();
80  return tracks_[pos];
81 }
82 
83 Track Vertex::refittedTrack(const TrackBaseRef & track) const
84 {
85  if (refittedTracks_.empty())
86  throw cms::Exception("Vertex") << "No refitted tracks stored in vertex\n";
88  if (it==tracks_end()) throw cms::Exception("Vertex") << "Track not found in list\n";
89  size_t pos = it - tracks_begin();
90  return refittedTracks_[pos];
91 }
92 
93 Track Vertex::refittedTrack(const TrackRef & track) const
94 {
95  return refittedTrack(TrackBaseRef(track));
96 }
97 
98 math::XYZTLorentzVectorD Vertex::p4(float mass,float minWeight) const
99 {
100 
102  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > vec;
103 
104  if(hasRefittedTracks()) {
105  for(std::vector<Track>::const_iterator iter = refittedTracks_.begin();
106  iter != refittedTracks_.end(); ++iter) {
107  if (trackWeight(originalTrack(*iter)) >=minWeight) {
108  vec.SetPx(iter->px());
109  vec.SetPy(iter->py());
110  vec.SetPz(iter->pz());
111  vec.SetM(mass);
112  sum += vec;
113  }
114  }
115  }
116  else
117  {
118  for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin();
119  iter != tracks_end(); iter++) {
120  if (trackWeight(*iter) >=minWeight) {
121  vec.SetPx((*iter)->px());
122  vec.SetPy((*iter)->py());
123  vec.SetPz((*iter)->pz());
124  vec.SetM(mass);
125  sum += vec;
126  }
127  }
128  }
129  return sum;
130 }
131 
132 unsigned int Vertex::nTracks(float minWeight) const
133 {
134  int n=0;
135  if(hasRefittedTracks()) {
136  for(std::vector<Track>::const_iterator iter = refittedTracks_.begin(); iter != refittedTracks_.end(); ++iter)
137  if (trackWeight(originalTrack(*iter)) >=minWeight)
138  n++;
139  }
140  else
141  {
142  for(std::vector<reco::TrackBaseRef>::const_iterator iter = tracks_begin(); iter != tracks_end(); iter++)
143  if (trackWeight(*iter) >=minWeight)
144  n++;
145  }
146  return n;
147 }
148 
int i
Definition: DBlmapReader.cc:9
std::vector< TrackBaseRef > tracks_
reference to tracks
Definition: Vertex.h:168
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:71
Track refittedTrack(const TrackBaseRef &track) const
std::vector< Track > refittedTracks_
The vector of refitted tracks.
Definition: Vertex.h:170
bool hasRefittedTracks() const
Checks whether refitted tracks are stored.
Definition: Vertex.h:127
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
int j
Definition: DBlmapReader.cc:9
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:73
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:132
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:98
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:166
index idx(index i, index j) const
position index
Definition: Vertex.h:177
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:173
std::vector< uint8_t > weights_
Definition: Vertex.h:171