CMS 3D CMS Logo

MuonFromPVSelector.cc
Go to the documentation of this file.
6 
8 
11 
14 
15 #include <memory>
16 #include <numeric>
17 #include <vector>
18 
19 
21 // class definition
24 public:
25 
26  explicit MuonFromPVSelector(edm::ParameterSet const&);
27  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
28 
29 private:
30 
31  double max_dxy_;
32  double max_dz_;
35 };
36 
37 
39 // construction
41 
43  : max_dxy_{iConfig.getParameter<double>("max_dxy")}
44  , max_dz_{iConfig.getParameter<double>("max_dz")}
45  , v_recoVertexToken_{consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcVertex"))}
46  , v_recoMuonToken_{consumes<std::vector<reco::Muon>>(iConfig.getParameter<edm::InputTag>("srcMuon"))}
47 {
48  produces<std::vector<reco::Muon>>();
49 }
50 
52 // implementation of member functions
54 
56 {
57  auto goodMuons = std::make_unique<std::vector<reco::Muon>>();
58 
60  iEvent.getByToken(v_recoVertexToken_, vertices);
61 
63  iEvent.getByToken(v_recoMuonToken_, muons);
64 
65  if (!vertices->empty()) {
66  auto const& pv = vertices->front();
67  std::copy_if(std::cbegin(*muons), std::cend(*muons), std::back_inserter(*goodMuons),
68  [&pv, this](auto const& muon){
69  return muon.innerTrack().isNonnull() &&
70  std::abs(muon.innerTrack()->dxy(pv.position())) < max_dxy_ &&
71  std::abs(muon.innerTrack()->dz(pv.position())) < max_dz_;
72  });
73  }
74 
75  iEvent.put(std::move(goodMuons));
76 }
77 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< std::vector< reco::Muon > > v_recoMuonToken_
int iEvent
Definition: GenABIO.cc:230
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< std::vector< reco::Vertex > > v_recoVertexToken_
MuonFromPVSelector(edm::ParameterSet const &)
def move(src, dest)
Definition: eostools.py:511