CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
getBestVertex.h
Go to the documentation of this file.
3 #include <limits>
4 
5 namespace {
6 
7  using Point = math::XYZPoint;
8 
9 
10  Point getBestVertex(reco::Track const & trk, reco::VertexCollection const & vertices, const size_t minNtracks = 2) {
11 
12  Point p_dz(0,0,-99999);
13  float dzmin = std::numeric_limits<float>::max();
14  for(auto const & vertex : vertices) {
15  size_t tracks = vertex.tracksSize();
16  if (tracks < minNtracks) {
17  continue;
18  }
19  float dz = std::abs(trk.dz(vertex.position()));
20  if(dz < dzmin){
21  p_dz = vertex.position();
22  dzmin = dz;
23  }
24  }
25 
26  return p_dz;
27 
28  }
29 
30  Point getBestVertex_withError(reco::Track const & trk, reco::VertexCollection const & vertices, Point& error, const size_t minNtracks = 2) {
31 
32  Point p_dz(0,0,-99999);
33  float dzmin = std::numeric_limits<float>::max();
34  for(auto const & vertex : vertices) {
35  size_t tracks = vertex.tracksSize();
36  if (tracks < minNtracks) {
37  continue;
38  }
39  float dz = std::abs(trk.dz(vertex.position()));
40  if(dz < dzmin){
41  p_dz = vertex.position();
42  error.SetXYZ(vertex.xError(),vertex.yError(),vertex.zError());
43  dzmin = dz;
44  }
45  }
46 
47  return p_dz;
48 
49  }
50 
51  /*
52  Point getBestVertex(reco::Track const & trk,, VertexCollection const & vertices) {
53 
54  // Point p(0,0,-99999);
55  Point p_dz(0,0,-99999);
56  // float bestWeight = 0;
57  float dzmin = 10000;
58  for(auto const & vertex : vertices){
59  // auto w = vertex.trackWeight(track);
60  Point v_pos = vertex.position();
61  // if(w > bestWeight){
62  // p = v_pos;
63  // bestWeight = w;
64  //} else if (0 == bestWeight) {
65  float dz = std::abs(trK.dz(v_pos));
66  if(dz < dzmin){
67  p_dz = v_pos;
68  dzmin = dz;
69  }
70  //}
71  }
72 
73  return (bestWeight > 0) ? p : p_dz;
74 
75  }
76  */
77 }
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
math::XYZPoint Point
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:604
tuple tracks
Definition: testEve_cfg.py:39
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12