CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"))},
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 
63  iEvent.getByToken(v_recoGsfElectronToken_, gsfElectrons);
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 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
GsfElectronFromPVSelector(edm::ParameterSet const &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< reco::GsfElectron > > v_recoGsfElectronToken_
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< std::vector< reco::Vertex > > v_recoVertexToken_