Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:58

0001 #ifndef CommonTools_ParticleFlow_PdgIdPFCandidateSelectorDefinition
0002 #define CommonTools_ParticleFlow_PdgIdPFCandidateSelectorDefinition
0003 
0004 #include "FWCore/Common/interface/EventBase.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0009 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0010 #include "CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h"
0011 
0012 namespace pf2pat {
0013 
0014   class PdgIdPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {
0015   public:
0016     PdgIdPFCandidateSelectorDefinition(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
0017         : pdgIds_(cfg.getParameter<std::vector<int> >("pdgId")) {}
0018 
0019     void select(const HandleToCollection& hc, const edm::EventBase& e, const edm::EventSetup& s) {
0020       selected_.clear();
0021 
0022       unsigned key = 0;
0023       for (collection::const_iterator pfc = hc->begin(); pfc != hc->end(); ++pfc, ++key) {
0024         for (unsigned iId = 0; iId < pdgIds_.size(); iId++) {
0025           if (pfc->pdgId() == pdgIds_[iId]) {
0026             selected_.push_back(reco::PFCandidate(*pfc));
0027             reco::PFCandidatePtr ptrToMother(hc, key);
0028             selected_.back().setSourceCandidatePtr(ptrToMother);
0029             break;
0030           }
0031         }
0032       }
0033     }
0034 
0035   private:
0036     std::vector<int> pdgIds_;
0037   };
0038 
0039 }  // namespace pf2pat
0040 
0041 #endif