CMS 3D CMS Logo

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
const std::vector< edm::Ptr< Track_t > > & tracks() const
Definition: Vertex.h:23
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
auto const & tracks
cannot be loose