00001 #ifndef PhysicsTools_PFCandProducer_MuonIDPFCandidateSelectorDefinition 00002 #define PhysicsTools_PFCandProducer_MuonIDPFCandidateSelectorDefinition 00003 00012 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" 00013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" 00014 #include "DataFormats/Common/interface/ValueMap.h" 00015 #include "DataFormats/PatCandidates/interface/Muon.h" 00016 #include "CommonTools/Utils/interface/StringCutObjectSelector.h" 00017 #include "PhysicsTools/PFCandProducer/interface/PFCandidateSelectorDefinition.h" 00018 00019 namespace pf2pat { 00020 00021 struct MuonIDPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition { 00022 00023 MuonIDPFCandidateSelectorDefinition ( const edm::ParameterSet & cfg ) : 00024 muonCut_( cfg.getParameter< std::string >( "cut" ) ) 00025 { 00026 } 00027 00028 void select( const HandleToCollection & hc, 00029 const edm::Event & e, 00030 const edm::EventSetup& s) { 00031 selected_.clear(); 00032 00033 unsigned key=0; 00034 for( collection::const_iterator pfc = hc->begin(); 00035 pfc != hc->end(); ++pfc, ++key) { 00036 00037 reco::MuonRef muR = pfc->muonRef(); 00038 00039 // skip ones without a ref to a reco::Muon: they won't be matched anyway 00040 if (muR.isNull()) continue; 00041 00042 // convert into a pat::Muon, so that the 'muonID' method is available 00043 pat::Muon patMu(*muR); 00044 00045 // apply muon id 00046 if (muonCut_(patMu)) { 00047 selected_.push_back( reco::PFCandidate(*pfc) ); 00048 reco::PFCandidatePtr ptrToMother( hc, key ); 00049 selected_.back().setSourceCandidatePtr( ptrToMother ); 00050 } 00051 } 00052 } 00053 00054 private: 00055 StringCutObjectSelector<pat::Muon> muonCut_; 00056 }; 00057 } 00058 00059 #endif