CMS 3D CMS Logo

ElectronFromPVSelector.cc
Go to the documentation of this file.
1 // Includes
9 
11 
20 
21 #include <algorithm>
22 #include <cmath>
23 #include <memory>
24 #include <vector>
25 
27 // class definition
30 public:
32  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
33 
34 private:
35  double max_dxy_;
36  double max_dz_;
39 };
40 
42 // construction
44 
46  : max_dxy_{iConfig.getParameter<double>("max_dxy")},
47  max_dz_{iConfig.getParameter<double>("max_dz")},
48  v_recoVertexToken_{consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcVertex"))},
49  v_recoGsfElectronToken_{
50  consumes<std::vector<reco::GsfElectron>>(iConfig.getParameter<edm::InputTag>("srcElectron"))} {
51  produces<std::vector<reco::GsfElectron>>();
52 }
53 
55 // implementation of member functions
57 
60  iEvent.getByToken(v_recoVertexToken_, vertices);
61 
64 
65  auto goodGsfElectrons = std::make_unique<std::vector<reco::GsfElectron>>();
66 
67  if (!vertices->empty() && !gsfElectrons->empty()) {
68  auto const& pv = vertices->front();
69  std::copy_if(std::cbegin(*gsfElectrons),
70  std::cend(*gsfElectrons),
71  std::back_inserter(*goodGsfElectrons),
72  [this, &pv](auto const& GsfElectron) {
73  return std::abs(GsfElectron.gsfTrack()->dxy(pv.position())) < max_dxy_ &&
74  std::abs(GsfElectron.gsfTrack()->dz(pv.position())) < max_dz_;
75  });
76  }
77 
78  iEvent.put(std::move(goodGsfElectrons));
79 }
80 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
GsfElectronFromPVSelector(edm::ParameterSet const &)
edm::EDGetTokenT< std::vector< reco::GsfElectron > > v_recoGsfElectronToken_
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< std::vector< reco::Vertex > > v_recoVertexToken_