Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:13

0001 
0002 #include "L1Trigger/VertexFinder/interface/selection.h"
0003 
0004 #include <algorithm>
0005 #include <stdexcept>
0006 
0007 namespace l1tVertexFinder {
0008 
0009   const l1t::Vertex& getPrimaryVertex(const std::vector<l1t::Vertex>& aVertexCollection) {
0010     typedef std::vector<edm::Ptr<l1t::Vertex::Track_t>> Tracks_t;
0011 
0012     return getPrimaryVertex(aVertexCollection, [](const Tracks_t& tracks) -> float {
0013       float sumPt = 0.0;
0014       for (const auto& t : tracks)
0015         sumPt += t->momentum().transverse();
0016       return sumPt;
0017     });
0018   }
0019 
0020   const l1t::Vertex& getPrimaryVertex(
0021       const std::vector<l1t::Vertex>& aVertexCollection,
0022       const std::function<float(const std::vector<edm::Ptr<l1t::Vertex::Track_t>>&)>& aFunction) {
0023     if (aVertexCollection.empty())
0024       throw std::invalid_argument("Cannot find primary vertex from empty vertex collection");
0025     return *std::max_element(aVertexCollection.begin(),
0026                              aVertexCollection.end(),
0027                              [aFunction](const l1t::Vertex& v1, const l1t::Vertex& v2) -> bool {
0028                                return (aFunction(v1.tracks()) < aFunction(v2.tracks()));
0029                              });
0030   }
0031 
0032 }  // end namespace l1tVertexFinder