Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:26:37

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/Common/interface/ValueMap.h"
0007 #include "RecoParticleFlow/PFProducer/test/PFIsoReader.h"
0008 
0009 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0010 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0011 
0012 PFIsoReader::PFIsoReader(const edm::ParameterSet& iConfig) {
0013   inputTagGsfElectrons_ = iConfig.getParameter<edm::InputTag>("Electrons");
0014   inputTagPhotons_ = iConfig.getParameter<edm::InputTag>("Photons");
0015   inputTagPFCandidates_ = iConfig.getParameter<edm::InputTag>("PFCandidates");
0016 
0017   useValueMaps_ = iConfig.getParameter<bool>("useEGPFValueMaps");
0018   inputTagValueMapPhotons_ = iConfig.getParameter<edm::InputTag>("PhotonValueMap");
0019   inputTagValueMapElectrons_ = iConfig.getParameter<edm::InputTag>("ElectronValueMap");
0020   inputTagValueMapMerged_ = iConfig.getParameter<edm::InputTag>("MergedValueMap");
0021 
0022   inputTagElectronIsoDeposits_ = iConfig.getParameter<std::vector<edm::InputTag> >("ElectronIsoDeposits");
0023   inputTagPhotonIsoDeposits_ = iConfig.getParameter<std::vector<edm::InputTag> >("PhotonIsoDeposits");
0024 }
0025 
0026 PFIsoReader::~PFIsoReader() { ; }
0027 
0028 void PFIsoReader::beginRun(edm::Run const&, edm::EventSetup const&) { ; }
0029 
0030 void PFIsoReader::analyze(const edm::Event& iEvent, const edm::EventSetup& c) {
0031   edm::Handle<reco::PFCandidateCollection> pfCandidatesH;
0032   bool found = iEvent.getByLabel(inputTagPFCandidates_, pfCandidatesH);
0033   if (!found) {
0034     std::ostringstream err;
0035     err << " cannot get PFCandidates: " << inputTagPFCandidates_ << std::endl;
0036     edm::LogError("PFIsoReader") << err.str();
0037     throw cms::Exception("MissingProduct", err.str());
0038   }
0039 
0040   edm::Handle<reco::GsfElectronCollection> gsfElectronH;
0041   found = iEvent.getByLabel(inputTagGsfElectrons_, gsfElectronH);
0042   if (!found) {
0043     std::ostringstream err;
0044     err << " cannot get GsfElectrons: " << inputTagGsfElectrons_ << std::endl;
0045     edm::LogError("PFIsoReader") << err.str();
0046     throw cms::Exception("MissingProduct", err.str());
0047   }
0048 
0049   edm::Handle<reco::PhotonCollection> photonH;
0050   found = iEvent.getByLabel(inputTagPhotons_, photonH);
0051   if (!found) {
0052     std::ostringstream err;
0053     err << " cannot get Photonss: " << inputTagPhotons_ << std::endl;
0054     edm::LogError("PFIsoReader") << err.str();
0055     throw cms::Exception("MissingProduct", err.str());
0056   }
0057 
0058   // Get the value maps
0059 
0060   edm::Handle<edm::ValueMap<reco::PFCandidatePtr> > electronValMapH;
0061   found = iEvent.getByLabel(inputTagValueMapElectrons_, electronValMapH);
0062   const edm::ValueMap<reco::PFCandidatePtr>& myElectronValMap(*electronValMapH);
0063 
0064   std::cout << " Read Electron Value Map " << myElectronValMap.size() << std::endl;
0065 
0066   //  edm::Handle<edm::ValueMap<reco::PFCandidatePtr> > photonValMapH;
0067   //  found = iEvent.getByLabel(inputTagValueMapPhotons_,photonValMapH);
0068   //   const edm::ValueMap<reco::PFCandidatePtr> & myPhotonValMap(*photonValMapH);
0069 
0070   edm::Handle<edm::ValueMap<reco::PFCandidatePtr> > mergedValMapH;
0071   found = iEvent.getByLabel(inputTagValueMapMerged_, mergedValMapH);
0072   const edm::ValueMap<reco::PFCandidatePtr>& myMergedValMap(*mergedValMapH);
0073 
0074   // get the iso deposits
0075   IsoDepositMaps electronIsoDep(inputTagElectronIsoDeposits_.size());
0076   IsoDepositMaps photonIsoDep(inputTagPhotonIsoDeposits_.size());
0077 
0078   for (size_t j = 0; j < inputTagElectronIsoDeposits_.size(); ++j) {
0079     iEvent.getByLabel(inputTagElectronIsoDeposits_[j], electronIsoDep[j]);
0080   }
0081   for (size_t j = 0; j < inputTagPhotonIsoDeposits_.size(); ++j) {
0082     iEvent.getByLabel(inputTagPhotonIsoDeposits_[j], photonIsoDep[j]);
0083   }
0084 
0085   // Photons - from reco
0086   unsigned nphot = photonH->size();
0087   std::cout << "Photon: " << nphot << std::endl;
0088   for (unsigned iphot = 0; iphot < nphot; ++iphot) {
0089     reco::PhotonRef myPhotRef(photonH, iphot);
0090     //    const reco::PFCandidatePtr & pfPhotPtr(myPhotonValMap[myPhotRef]);
0091     const reco::PFCandidatePtr& pfPhotPtr(myMergedValMap[myPhotRef]);
0092     printIsoDeposits(photonIsoDep, pfPhotPtr);
0093   }
0094 
0095   // Photons - from PF Candidates
0096   unsigned ncandidates = pfCandidatesH->size();
0097   std::cout << "Candidates: " << ncandidates << std::endl;
0098   for (unsigned icand = 0; icand < ncandidates; ++icand) {
0099     const reco::PFCandidate& cand((*pfCandidatesH)[icand]);
0100     //    std::cout << " Pdg " << cand.pdgId() << " mva " << cand.mva_nothing_gamma() << std::endl;
0101     if (!(cand.pdgId() == 22 && cand.mva_nothing_gamma() > 0))
0102       continue;
0103 
0104     reco::PFCandidatePtr myPFCandidatePtr(pfCandidatesH, icand);
0105     printIsoDeposits(photonIsoDep, myPFCandidatePtr);
0106   }
0107 
0108   // Electrons - from reco
0109   unsigned nele = gsfElectronH->size();
0110   std::cout << "Electron: " << nele << std::endl;
0111   for (unsigned iele = 0; iele < nele; ++iele) {
0112     reco::GsfElectronRef myElectronRef(gsfElectronH, iele);
0113 
0114     if (myElectronRef->mva_e_pi() < -1)
0115       continue;
0116     //const reco::PFCandidatePtr & pfElePtr(myElectronValMap[myElectronRef]);
0117     const reco::PFCandidatePtr pfElePtr(myElectronValMap[myElectronRef]);
0118     printIsoDeposits(electronIsoDep, pfElePtr);
0119   }
0120 
0121   // Electrons - from PFCandidate
0122   nele = gsfElectronH->size();
0123   std::cout << "Candidates: " << nele << std::endl;
0124   for (unsigned icand = 0; icand < ncandidates; ++icand) {
0125     const reco::PFCandidate& cand((*pfCandidatesH)[icand]);
0126 
0127     if (!(abs(cand.pdgId()) == 11))
0128       continue;
0129 
0130     reco::PFCandidatePtr myPFCandidatePtr(pfCandidatesH, icand);
0131     printIsoDeposits(electronIsoDep, myPFCandidatePtr);
0132   }
0133 }
0134 
0135 void PFIsoReader::printIsoDeposits(const IsoDepositMaps& isodepmap, const reco::PFCandidatePtr& ptr) const {
0136   std::cout << " Isodeposits for " << ptr.id() << " " << ptr.key() << std::endl;
0137   unsigned nIsoDepTypes = isodepmap.size();  // should be 3 (charged hadrons, photons, neutral hadrons)
0138   for (unsigned ideptype = 0; ideptype < nIsoDepTypes; ++ideptype) {
0139     const reco::IsoDeposit& isoDep((*isodepmap[ideptype])[ptr]);
0140     typedef reco::IsoDeposit::const_iterator IM;
0141     std::cout << " Iso deposits type " << ideptype << std::endl;
0142     for (IM im = isoDep.begin(); im != isoDep.end(); ++im) {
0143       std::cout << "dR " << im->dR() << " val " << im->value() << std::endl;
0144     }
0145   }
0146 }
0147 
0148 DEFINE_FWK_MODULE(PFIsoReader);