CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonSelectorVertex.cc
Go to the documentation of this file.
1 //
2 //
3 
7 
10 
11 #include <vector>
12 #include <memory>
13 #include <cmath>
14 
16 public:
18  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
19 
20 private:
23  const double maxDZ_;
24 };
25 
27  : muonSource_(consumes<std::vector<pat::Muon>>(iConfig.getParameter<edm::InputTag>("muonSource"))),
28  vertexSource_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertexSource"))),
29  maxDZ_(iConfig.getParameter<double>("maxDZ")) {
30  produces<std::vector<pat::Muon>>();
31 }
32 
34  const auto& muons = iEvent.get(muonSource_);
35  const auto& vertices = iEvent.get(vertexSource_);
36 
37  auto selectedMuons = std::make_unique<std::vector<pat::Muon>>();
38 
39  if (!vertices.empty()) {
40  for (const auto& muon : muons) {
41  if (std::abs(muon.vertex().z() - vertices.at(0).z()) < maxDZ_) {
42  selectedMuons->push_back(muon);
43  }
44  }
45  }
46 
47  iEvent.put(std::move(selectedMuons));
48 }
49 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< std::vector< pat::Muon > > muonSource_
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
tuple muons
Definition: patZpeak.py:41
const edm::EDGetTokenT< std::vector< reco::Vertex > > vertexSource_
MuonSelectorVertex(const edm::ParameterSet &iConfig)