CMS 3D CMS Logo

MuonSelectorVertex.cc
Go to the documentation of this file.
1 //
2 //
3 
7 
10 
12 public:
13  explicit MuonSelectorVertex(const edm::ParameterSet& iConfig);
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:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
selectedMuons
====================================== Muons
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: Muon.py:1
~MuonSelectorVertex() override
fixed size matrix
HLT enums.
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)
def move(src, dest)
Definition: eostools.py:511