CMS 3D CMS Logo

PVSorterBySumP.cc
Go to the documentation of this file.
1 // Includes
10 
11 #include <memory>
12 #include <vector>
13 #include <sstream>
14 
15 
17 // class definition
20 public:
21 
22  explicit bestPVselector(edm::ParameterSet const& iConfig);
23  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
24 
25 private:
27 };
28 
29 
31 // construction
33 
34 //______________________________________________________________________________
36  : src_{consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("src"))}
37 {
38  produces<std::vector<reco::Vertex>>();
39 }
40 
42 // implementation of member functions
44 
45 //______________________________________________________________________________
47 {
49  iEvent.getByToken(src_,vertices);
50 
51  auto theBestPV = std::make_unique<std::vector<reco::Vertex>>();
52 
53  if (!vertices->empty()) {
54  auto sumSquarePt = [](auto const& pv) { return pv.p4().pt()*pv.p4().pt(); };
55  auto bestPV = std::max_element(std::cbegin(*vertices), std::cend(*vertices),
56  [sumSquarePt](auto const& v1, auto const& v2) {
57  return sumSquarePt(v1) < sumSquarePt(v2);
58  });
59  theBestPV->push_back(*bestPV);
60  }
61  iEvent.put(std::move(theBestPV));
62 }
63 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bestPVselector(edm::ParameterSet const &iConfig)
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< reco::Vertex > > src_
def pv(vc)
Definition: MetAnalyzer.py:7
def move(src, dest)
Definition: eostools.py:511