CMS 3D CMS Logo

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:
17  explicit MuonSelectorVertex(const edm::ParameterSet& iConfig);
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 
48 }
49 
selectedMuons
====================================== Muons
const edm::EDGetTokenT< std::vector< pat::Muon > > muonSource_
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
Definition: Muon.py:1
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
fixed size matrix
HLT enums.
const edm::EDGetTokenT< std::vector< reco::Vertex > > vertexSource_
MuonSelectorVertex(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:511