Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:06

0001 #include "FWCore/Framework/interface/Event.h"
0002 
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Framework/interface/EDAnalyzer.h"
0007 
0008 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0009 #include "DataFormats/Common/interface/ValueMap.h"
0010 
0011 #include <iostream>
0012 
0013 class GEDValueMapAnalyzer : public edm::EDAnalyzer {
0014 public:
0015   GEDValueMapAnalyzer(const edm::ParameterSet&);
0016   ~GEDValueMapAnalyzer();
0017   virtual void beginRun(edm::Run const&, edm::EventSetup const&);
0018   virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& c);
0019 
0020 private:
0021   edm::InputTag inputTagValueMapElectrons_;
0022   edm::InputTag inputTagPFCandidates_;
0023 };
0024 
0025 GEDValueMapAnalyzer::GEDValueMapAnalyzer(const edm::ParameterSet& iConfig) {
0026   inputTagPFCandidates_ = iConfig.getParameter<edm::InputTag>("PFCandidates");
0027   inputTagValueMapElectrons_ = iConfig.getParameter<edm::InputTag>("ElectronValueMap");
0028 }
0029 
0030 GEDValueMapAnalyzer::~GEDValueMapAnalyzer() { ; }
0031 
0032 void GEDValueMapAnalyzer::beginRun(edm::Run const&, edm::EventSetup const&) { ; }
0033 
0034 void GEDValueMapAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& c) {
0035   edm::Handle<reco::PFCandidateCollection> pfCandidatesH;
0036   bool found = iEvent.getByLabel(inputTagPFCandidates_, pfCandidatesH);
0037   if (!found) {
0038     std::ostringstream err;
0039     err << " cannot get PFCandidates: " << inputTagPFCandidates_ << std::endl;
0040     edm::LogError("PFIsoReader") << err.str();
0041     throw cms::Exception("MissingProduct", err.str());
0042   }
0043 
0044   // Get the value maps
0045 
0046   edm::Handle<edm::ValueMap<reco::GsfElectronRef> > electronValMapH;
0047   found = iEvent.getByLabel(inputTagValueMapElectrons_, electronValMapH);
0048   const edm::ValueMap<reco::GsfElectronRef>& myElectronValMap(*electronValMapH);
0049 
0050   std::cout << " Read Electron Value Map " << myElectronValMap.size() << std::endl;
0051 
0052   unsigned ncandidates = pfCandidatesH->size();
0053   for (unsigned ic = 0; ic < ncandidates; ++ic) {
0054     // check if it has a GsfTrack
0055     const reco::PFCandidate& cand((*pfCandidatesH)[ic]);
0056     if (!cand.gsfTrackRef().isNonnull())
0057       continue;
0058 
0059     reco::PFCandidateRef pfRef(pfCandidatesH, ic);
0060     // get the GsfElectronRef from the ValueMap
0061     reco::GsfElectronRef gsfRef = myElectronValMap[pfRef];
0062 
0063     //basic check
0064     std::cout << " Comparing GsfTrackRef from GsfElectron and PFCandidate ";
0065     if (gsfRef->gsfTrack() == cand.gsfTrackRef())
0066       std::cout << " OK " << std::endl;
0067     else
0068       std::cout << " Problem different Ref" << std::endl;
0069   }
0070 }
0071 
0072 DEFINE_FWK_MODULE(GEDValueMapAnalyzer);