Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:45:20

0001 #ifndef CommonTools_ParticleFlow_MuonIDPFCandidateSelectorDefinition
0002 #define CommonTools_ParticleFlow_MuonIDPFCandidateSelectorDefinition
0003 
0004 /**
0005    \class    pf2pat::MuonIDPFCandidateSelectorDefinition MuonIDPFCandidateSelectorDefinition.h "CommonTools/ParticleFlow/interface/MuonIDPFCandidateSelectorDefinition.h"
0006    \brief    Selects PFCandidates basing on cuts provided with string cut parser
0007 
0008    \author   Giovanni Petrucciani
0009    \version  $Id: MuonIDPFCandidateSelectorDefinition.h,v 1.1 2011/01/28 20:56:44 srappocc Exp $
0010 */
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0016 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0017 #include "DataFormats/Common/interface/ValueMap.h"
0018 #include "DataFormats/PatCandidates/interface/Muon.h"
0019 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0020 #include "CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h"
0021 
0022 namespace pf2pat {
0023 
0024   struct MuonIDPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {
0025     MuonIDPFCandidateSelectorDefinition(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
0026         : muonCut_(cfg.getParameter<std::string>("cut")) {}
0027 
0028     void select(const HandleToCollection& hc, const edm::Event& e, const edm::EventSetup& s) {
0029       selected_.clear();
0030 
0031       unsigned key = 0;
0032       for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
0033         reco::MuonRef muR = pfc->muonRef();
0034 
0035         // skip ones without a ref to a reco::Muon: they won't be matched anyway
0036         if (muR.isNull())
0037           continue;
0038 
0039         // convert into a pat::Muon, so that the 'muonID' method is available
0040         pat::Muon patMu(*muR);
0041 
0042         // apply muon id
0043         if (muonCut_(patMu)) {
0044           selected_.push_back(reco::PFCandidate(*pfc));
0045           reco::PFCandidatePtr ptrToMother(hc, key);
0046           selected_.back().setSourceCandidatePtr(ptrToMother);
0047         }
0048       }
0049     }
0050 
0051   private:
0052     StringCutObjectSelector<pat::Muon> muonCut_;
0053   };
0054 }  // namespace pf2pat
0055 
0056 #endif