CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
selection.cc
Go to the documentation of this file.
1 
3 
4 #include <algorithm>
5 #include <stdexcept>
6 
7 namespace l1tVertexFinder {
8 
9  const l1t::Vertex& getPrimaryVertex(const std::vector<l1t::Vertex>& aVertexCollection) {
10  typedef std::vector<edm::Ptr<l1t::Vertex::Track_t>> Tracks_t;
11 
12  return getPrimaryVertex(aVertexCollection, [](const Tracks_t& tracks) -> float {
13  float sumPt = 0.0;
14  for (const auto& t : tracks)
15  sumPt += t->momentum().transverse();
16  return sumPt;
17  });
18  }
19 
21  const std::vector<l1t::Vertex>& aVertexCollection,
22  const std::function<float(const std::vector<edm::Ptr<l1t::Vertex::Track_t>>&)>& aFunction) {
23  if (aVertexCollection.empty())
24  throw std::invalid_argument("Cannot find primary vertex from empty vertex collection");
25  return *std::max_element(aVertexCollection.begin(),
26  aVertexCollection.end(),
27  [aFunction](const l1t::Vertex& v1, const l1t::Vertex& v2) -> bool {
28  return (aFunction(v1.tracks()) < aFunction(v2.tracks()));
29  });
30  }
31 
32 } // end namespace l1tVertexFinder
auto const & tracks
cannot be loose
const l1t::Vertex & getPrimaryVertex(const std::vector< l1t::Vertex > &aVertexCollection)
Returns primary vertex based on default criterion (max sum pT from all constituent tracks); throws if...
Definition: selection.cc:9
string function
Definition: callgraph.py:50
const std::vector< edm::Ptr< Track_t > > & tracks() const
Definition: Vertex.cc:16