CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/PhysicsTools/HepMCCandAlgos/plugins/MCMatchCandRefSelector.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/MakerMacros.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/Utilities/interface/InputTag.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00007 #include "CommonTools/UtilAlgos/interface/EventSetupInitTrait.h"
00008 #include "CommonTools/UtilAlgos/interface/SingleObjectRefSelector.h"
00009 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00010 
00011 using namespace edm;
00012 using namespace reco;
00013 using namespace std;
00014 
00015 namespace reco {
00016   namespace modules {
00017     
00018     class MCMatchCandRefSelector {
00019     public:
00020       explicit MCMatchCandRefSelector(const InputTag& src) : 
00021         src_(src) { }
00022       void newEvent(const Event& evt, const EventSetup&); 
00023       bool operator()(const CandidateBaseRef &) const;
00024     private:
00025       InputTag src_;
00026       const GenParticleMatch * match_;
00027     };
00028     
00029     void MCMatchCandRefSelector::newEvent(const Event& evt, const EventSetup&) {
00030       Handle<GenParticleMatch> match;
00031       evt.getByLabel(src_, match);
00032       match_ = match.product();
00033     } 
00034     
00035     bool MCMatchCandRefSelector::operator()(const CandidateBaseRef & c) const {
00036       GenParticleRef m = (*match_)[c];
00037       return m.isNonnull();
00038     }
00039   
00040     template<>
00041     struct ParameterAdapter<MCMatchCandRefSelector> {
00042       static MCMatchCandRefSelector make(const ParameterSet & cfg) {
00043         return MCMatchCandRefSelector(cfg.getParameter<InputTag>("match"));
00044       }
00045     };
00046     
00047   }
00048 }
00049 
00050 EVENTSETUP_STD_INIT(MCMatchCandRefSelector);
00051 
00052 typedef SingleObjectRefSelector<Candidate, reco::modules::MCMatchCandRefSelector> MCMatchCandRefSelector;
00053 
00054 DEFINE_FWK_MODULE(MCMatchCandRefSelector);