00001 #include "FWCore/Framework/interface/EDAnalyzer.h" 00002 #include "FWCore/ParameterSet/interface/InputTag.h" 00003 #include "FWCore/Framework/interface/Event.h" 00004 #include "DataFormats/Common/interface/Handle.h" 00005 #include "DataFormats/Candidate/interface/Candidate.h" 00006 #include "DataFormats/HepMCCandidate/interface/GenParticle.h" 00007 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" 00008 #include <iostream> 00009 using namespace edm; 00010 using namespace std; 00011 using namespace reco; 00012 00013 class DebugZMCTruth : public edm::EDAnalyzer { 00014 public: 00015 DebugZMCTruth(const edm::ParameterSet& pset); 00016 private: 00017 virtual void analyze(const Event& event, const EventSetup& setup); 00018 InputTag src_, genParticles_, match_; 00019 }; 00020 00021 DebugZMCTruth::DebugZMCTruth(const ParameterSet& cfg) : 00022 src_(cfg.getParameter<InputTag>("src")), 00023 genParticles_(cfg.getParameter<InputTag>("genParticles")), 00024 match_(cfg.getParameter<InputTag>("mcMatch")) { 00025 } 00026 00027 00028 void DebugZMCTruth::analyze(const Event& event, const EventSetup& setup) { 00029 Handle<GenParticleCollection> genParticles; 00030 event.getByLabel(genParticles_, genParticles); 00031 Handle<CandidateView> src; 00032 event.getByLabel(src_, src); 00033 cout << ">>> event has " << src->size() << " reconstructed particles in {" << src_ << "}" <<endl; 00034 Handle<GenParticleMatch> match; 00035 event.getByLabel(match_, match); 00036 cout << ">>> Z matches: "; 00037 for(size_t i = 0; i < src->size(); ++i) { 00038 CandidateBaseRef ref = src->refAt(i); 00039 GenParticleRef mc = (*match)[ref]; 00040 cout << (mc.isNull() ? "(no)" : "(yes)"); 00041 } 00042 cout << endl; 00043 } 00044 00045 #include "FWCore/Framework/interface/MakerMacros.h" 00046 00047 DEFINE_FWK_MODULE(DebugZMCTruth); 00048