Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-05 23:51:39

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