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 
12 public:
14  ~MuonSelectorVertex() override{};
15  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
16 
17 private:
20  double maxDZ_;
21 };
22 
23 #include <vector>
24 #include <memory>
25 #include <cmath>
26 
28  : muonSource_(consumes<std::vector<pat::Muon> >(iConfig.getParameter<edm::InputTag>("muonSource"))),
29  vertexSource_(consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("vertexSource"))),
30  maxDZ_(iConfig.getParameter<double>("maxDZ")) {
31  produces<std::vector<pat::Muon> >();
32 }
33 
36  iEvent.getByToken(muonSource_, muons);
37 
39  iEvent.getByToken(vertexSource_, vertices);
40 
41  std::vector<pat::Muon>* selectedMuons(new std::vector<pat::Muon>);
42 
43  if (!vertices->empty()) {
44  for (unsigned iMuon = 0; iMuon < muons->size(); ++iMuon) {
45  if (std::fabs(muons->at(iMuon).vertex().z() - vertices->at(0).z()) < maxDZ_) {
46  selectedMuons->push_back(muons->at(iMuon));
47  }
48  }
49  }
50 
51  std::unique_ptr<std::vector<pat::Muon> > selectedMuonsPtr(selectedMuons);
52  iEvent.put(std::move(selectedMuonsPtr));
53 }
54 
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
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
~MuonSelectorVertex() override
tuple muons
Definition: patZpeak.py:39
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< std::vector< reco::Vertex > > vertexSource_
edm::EDGetTokenT< std::vector< pat::Muon > > muonSource_
MuonSelectorVertex(const edm::ParameterSet &iConfig)