Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:25

0001 #include "FWCore/Framework/interface/MakerMacros.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0008 #include "CommonTools/UtilAlgos/interface/EventSetupInitTrait.h"
0009 #include "CommonTools/UtilAlgos/interface/SingleObjectRefSelector.h"
0010 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
0011 
0012 using namespace edm;
0013 using namespace reco;
0014 using namespace std;
0015 
0016 namespace reco {
0017   namespace modules {
0018 
0019     class MCMatchCandRefSelector {
0020     public:
0021       explicit MCMatchCandRefSelector(const EDGetTokenT<GenParticleMatch>& srcToken) : srcToken_(srcToken) {}
0022       void newEvent(const Event& evt, const EventSetup&);
0023       bool operator()(const CandidateBaseRef&) const;
0024 
0025     private:
0026       EDGetTokenT<GenParticleMatch> srcToken_;
0027       const GenParticleMatch* match_ = nullptr;
0028     };
0029 
0030     void MCMatchCandRefSelector::newEvent(const Event& evt, const EventSetup&) {
0031       Handle<GenParticleMatch> match;
0032       evt.getByToken(srcToken_, match);
0033       match_ = match.product();
0034     }
0035 
0036     bool MCMatchCandRefSelector::operator()(const CandidateBaseRef& c) const {
0037       GenParticleRef m = (*match_)[c];
0038       return m.isNonnull();
0039     }
0040 
0041     template <>
0042     struct ParameterAdapter<MCMatchCandRefSelector> {
0043       static MCMatchCandRefSelector make(const ParameterSet& cfg, edm::ConsumesCollector& iC) {
0044         return MCMatchCandRefSelector(iC.consumes<GenParticleMatch>(cfg.getParameter<InputTag>("match")));
0045       }
0046     };
0047 
0048   }  // namespace modules
0049 }  // namespace reco
0050 
0051 EVENTSETUP_STD_INIT(MCMatchCandRefSelector);
0052 
0053 typedef SingleObjectRefSelector<Candidate, reco::modules::MCMatchCandRefSelector> MCMatchCandRefSelector;
0054 
0055 DEFINE_FWK_MODULE(MCMatchCandRefSelector);