Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:51

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