CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonFromPVSelector.cc
Go to the documentation of this file.
6 
8 
11 
14 
15 #include <memory>
16 #include <numeric>
17 #include <vector>
18 
20 // class definition
23 public:
24  explicit MuonFromPVSelector(edm::ParameterSet const&);
25  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
26 
27 private:
28  double max_dxy_;
29  double max_dz_;
32 };
33 
35 // construction
37 
39  : max_dxy_{iConfig.getParameter<double>("max_dxy")},
40  max_dz_{iConfig.getParameter<double>("max_dz")},
41  v_recoVertexToken_{consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcVertex"))},
42  v_recoMuonToken_{consumes<std::vector<reco::Muon>>(iConfig.getParameter<edm::InputTag>("srcMuon"))} {
43  produces<std::vector<reco::Muon>>();
44 }
45 
47 // implementation of member functions
49 
51  auto goodMuons = std::make_unique<std::vector<reco::Muon>>();
52 
54  iEvent.getByToken(v_recoVertexToken_, vertices);
55 
57  iEvent.getByToken(v_recoMuonToken_, muons);
58 
59  if (!vertices->empty()) {
60  auto const& pv = vertices->front();
61  std::copy_if(std::cbegin(*muons), std::cend(*muons), std::back_inserter(*goodMuons), [&pv, this](auto const& muon) {
62  return muon.innerTrack().isNonnull() && std::abs(muon.innerTrack()->dxy(pv.position())) < max_dxy_ &&
63  std::abs(muon.innerTrack()->dz(pv.position())) < max_dz_;
64  });
65  }
66 
67  iEvent.put(std::move(goodMuons));
68 }
69 
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
edm::EDGetTokenT< std::vector< reco::Muon > > v_recoMuonToken_
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< std::vector< reco::Vertex > > v_recoVertexToken_
MuonFromPVSelector(edm::ParameterSet const &)
tuple muons
Definition: patZpeak.py:41