CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ZllArbitrator.cc
Go to the documentation of this file.
6 
17 
19 
20 #include <algorithm>
21 #include <memory>
22 #include <vector>
23 
25 // class definition
28 public:
29  explicit ZllArbitrator(edm::ParameterSet const&);
30  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
31 
32 private:
34 };
35 
37 // construction/destruction
39 
41  : srcZCand_{consumes<std::vector<reco::CompositeCandidate>>(
42  iConfig.getParameter<edm::InputTag>("ZCandidateCollection"))} {
43  produces<std::vector<reco::CompositeCandidate>>();
44 }
45 
47 // implementation of member functions
49 
52  iEvent.getByToken(srcZCand_, zCandidates);
53 
54  auto bestZ = std::make_unique<std::vector<reco::CompositeCandidate>>();
55  if (!zCandidates->empty()) {
56  // If you're going to hard-code numbers, at least make them constexpr.
57  double constexpr ZmassPDG{91.18}; // GeV
58 
59  auto bestZCand = std::min_element(
60  std::cbegin(*zCandidates), std::cend(*zCandidates), [ZmassPDG](auto const& firstCand, auto const& secondCand) {
61  return std::abs(firstCand.mass() - ZmassPDG) < std::abs(secondCand.mass() - ZmassPDG);
62  });
63  bestZ->push_back(*bestZCand);
64  }
65 
66  iEvent.put(std::move(bestZ));
67 }
68 
70 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ZllArbitrator(edm::ParameterSet const &)
edm::EDGetTokenT< std::vector< reco::CompositeCandidate > > srcZCand_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303