00001 // 00002 // $Id: MuonSelectorVertex.cc,v 1.1 2012/06/26 16:19:18 vadler Exp $ 00003 // 00004 00005 00006 #include "FWCore/Framework/interface/EDProducer.h" 00007 #include "FWCore/Framework/interface/Event.h" 00008 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00009 00010 00011 class MuonSelectorVertex : public edm::EDProducer { 00012 00013 public: 00014 00015 explicit MuonSelectorVertex( const edm::ParameterSet & iConfig ); 00016 ~ MuonSelectorVertex() {}; 00017 virtual void produce( edm::Event & iEvent, const edm::EventSetup & iSetup ); 00018 00019 private: 00020 00021 edm::InputTag muonSource_; 00022 edm::InputTag vertexSource_; 00023 double maxDZ_; 00024 00025 }; 00026 00027 00028 #include <vector> 00029 #include <memory> 00030 #include <cmath> 00031 00032 #include "DataFormats/PatCandidates/interface/Muon.h" 00033 #include "DataFormats/VertexReco/interface/Vertex.h" 00034 00035 00036 MuonSelectorVertex::MuonSelectorVertex( const edm::ParameterSet & iConfig ) 00037 : muonSource_( iConfig.getParameter< edm::InputTag >( "muonSource" ) ) 00038 , vertexSource_( iConfig.getParameter< edm::InputTag >( "vertexSource" ) ) 00039 , maxDZ_( iConfig.getParameter< double >( "maxDZ" ) ) 00040 { 00041 00042 produces< std::vector< pat::Muon > >(); 00043 00044 } 00045 00046 00047 void MuonSelectorVertex::produce( edm::Event & iEvent, const edm::EventSetup & iSetup ) 00048 { 00049 00050 edm::Handle< std::vector< pat::Muon > > muons; 00051 iEvent.getByLabel( muonSource_, muons ); 00052 00053 edm::Handle< std::vector< reco::Vertex > > vertices; 00054 iEvent.getByLabel( vertexSource_, vertices ); 00055 00056 std::vector< pat::Muon > * selectedMuons( new std::vector< pat::Muon > ); 00057 00058 if ( vertices->size() > 0 ) { 00059 00060 for ( unsigned iMuon = 0; iMuon < muons->size(); ++iMuon ) { 00061 if ( std::fabs( muons->at( iMuon ).vertex().z() - vertices->at( 0 ).z() ) < maxDZ_ ) { 00062 selectedMuons->push_back( muons->at( iMuon ) ); 00063 } 00064 } 00065 } 00066 00067 std::auto_ptr< std::vector< pat::Muon > > selectedMuonsPtr( selectedMuons ); 00068 iEvent.put( selectedMuonsPtr ); 00069 00070 } 00071 00072 00073 #include "FWCore/Framework/interface/MakerMacros.h" 00074 DEFINE_FWK_MODULE( MuonSelectorVertex );