Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:34

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