CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/ElectroWeakAnalysis/ZMuMu/plugins/DebugZMCTruth.cc

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