From c6cc8eb56b4f96ad3da843b5374ea379166c9904 Mon Sep 17 00:00:00 2001 From: Rafael Date: Wed, 25 Jan 2017 08:54:35 +0100 Subject: [PATCH] modification without touching the standard code --- .../python/gsFixedRefinedSuperClusters_cfi.py | 8 + .../src/EGRefinedSCFixer.cc | 340 +++++++++++------- .../plugins/GsfElectronCoreGSCrysFixer.cc | 104 +++--- .../plugins/GsfElectronGSCrysFixer.cc | 83 ++--- .../python/gsFixedGsfElectronCores_cfi.py | 8 +- .../python/gsFixedGsfElectrons_cfi.py | 11 +- .../EgammaEcalPFClusterIsolationRemapper.cc | 63 ++++ .../EgammaEcalPFClusterIsolationRemapper.h | 35 ++ .../EgammaHcalPFClusterIsolationRemapper.cc | 63 ++++ .../EgammaHcalPFClusterIsolationRemapper.h | 35 ++ .../pfClusterIsolationRemapForPAT_cff.py | 31 ++ .../python/pfClusterIsolationRemap_cfi.py | 32 ++ .../interface/ConversionGSCrysFixer.h | 62 ++++ .../interface/GEDPhotonCoreGSCrysFixer.h | 83 ++--- .../interface/GEDPhotonGSCrysFixer.h | 89 ++--- .../python/gsFixedConversions_cfi.py | 7 + .../python/gsFixedGEDPhotonCores_cfi.py | 8 + .../python/gsFixedGEDPhotons_cfi.py | 22 ++ .../python/gsFixedGedPhotonCores_cfi.py | 8 - .../python/gsFixedGedPhotons_cfi.py | 12 - .../src/ConversionGSCrysFixer.cc | 72 ++++ .../src/GEDPhotonCoreGSCrysFixer.cc | 132 ++++--- .../src/GEDPhotonGSCrysFixer.cc | 321 ++++++++++++----- .../EgammaPhotonProducers/src/SealModule.cc | 2 + .../EgammaTools/interface/GainSwitchTools.h | 65 +++- .../python/egammaGainSwitchFixForPAT_cff.py | 48 +++ .../python/egammaGainSwitchFixTools.py | 2 +- .../egammaGainSwitchFixToolsForPAT_cff.py | 35 ++ .../python/egammaGainSwitchFix_cff.py | 36 +- RecoEgamma/EgammaTools/src/GainSwitchTools.cc | 39 -- RecoEgamma/EgammaTools/test/gsFixTest_cfg.py | 16 +- RecoEgamma/EgammaTools/test/miniaod_PAT.py | 21 +- .../ElectronIDExternalProducerRemapper.cc | 52 +++ .../ElectronIDExternalProducerRemapper.h | 29 ++ .../PhotonIDExternalProducerRemapper.cc | 52 +++ .../PhotonIDExternalProducerRemapper.h | 29 ++ .../python/idExternalRemapForPAT_cff.py | 57 +++ .../python/idExternalRemap_cfi.py | 63 ++++ .../plugins/PFEGFootprintGSFixLinker.cc | 91 +++++ .../plugins/PFEGFootprintGSFixLinker.h | 66 ++++ .../PFProducer/plugins/PFGSFixLinker.cc | 131 +++++++ .../PFProducer/plugins/PFGSFixLinker.h | 62 ++++ .../python/pfEGFootprintGSFixLinker_cfi.py | 11 + .../python/pfGSFixLinkerForPAT_cff.py | 25 ++ .../PFProducer/python/pfGSFixLinker_cfi.py | 9 + 45 files changed, 2002 insertions(+), 568 deletions(-) create mode 100644 RecoEcal/EgammaClusterProducers/python/gsFixedRefinedSuperClusters_cfi.py create mode 100644 RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.cc create mode 100644 RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.h create mode 100644 RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.cc create mode 100644 RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.h create mode 100644 RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemapForPAT_cff.py create mode 100644 RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemap_cfi.py create mode 100644 RecoEgamma/EgammaPhotonProducers/interface/ConversionGSCrysFixer.h create mode 100644 RecoEgamma/EgammaPhotonProducers/python/gsFixedConversions_cfi.py create mode 100644 RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotonCores_cfi.py create mode 100644 RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotons_cfi.py delete mode 100644 RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotonCores_cfi.py delete mode 100644 RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotons_cfi.py create mode 100644 RecoEgamma/EgammaPhotonProducers/src/ConversionGSCrysFixer.cc create mode 100644 RecoEgamma/EgammaTools/python/egammaGainSwitchFixForPAT_cff.py create mode 100644 RecoEgamma/EgammaTools/python/egammaGainSwitchFixToolsForPAT_cff.py create mode 100644 RecoEgamma/ElectronIdentification/plugins/ElectronIDExternalProducerRemapper.cc create mode 100644 RecoEgamma/ElectronIdentification/plugins/ElectronIDExternalProducerRemapper.h create mode 100644 RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.cc create mode 100644 RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.h create mode 100644 RecoEgamma/ElectronIdentification/python/idExternalRemapForPAT_cff.py create mode 100644 RecoEgamma/ElectronIdentification/python/idExternalRemap_cfi.py create mode 100644 RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.cc create mode 100644 RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.h create mode 100644 RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.cc create mode 100644 RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.h create mode 100644 RecoParticleFlow/PFProducer/python/pfEGFootprintGSFixLinker_cfi.py create mode 100644 RecoParticleFlow/PFProducer/python/pfGSFixLinkerForPAT_cff.py create mode 100644 RecoParticleFlow/PFProducer/python/pfGSFixLinker_cfi.py diff --git a/RecoEcal/EgammaClusterProducers/python/gsFixedRefinedSuperClusters_cfi.py b/RecoEcal/EgammaClusterProducers/python/gsFixedRefinedSuperClusters_cfi.py new file mode 100644 index 0000000000000..24442b84e872c --- /dev/null +++ b/RecoEcal/EgammaClusterProducers/python/gsFixedRefinedSuperClusters_cfi.py @@ -0,0 +1,8 @@ +import FWCore.ParameterSet.Config as cms + +gsFixedRefinedSuperClusters = cms.EDProducer("EGRefinedSCFixer", + orgRefinedSC = cms.InputTag("particleFlowEGamma", '', cms.InputTag.skipCurrentProcess()), + orgSC = cms.InputTag("particleFlowSuperClusterECAL", '', cms.InputTag.skipCurrentProcess()), + fixedSC = cms.InputTag("particleFlowSuperClusterECALGSFixed"), + fixedPFClusters = cms.InputTag("particleFlowClusterECALGSFixed"), +) diff --git a/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc b/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc index 97316755260c9..a6271e83afdc1 100644 --- a/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc +++ b/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc @@ -7,10 +7,10 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" #include "DataFormats/EgammaReco/interface/SuperCluster.h" #include "DataFormats/EcalDetId/interface/EcalSubdetector.h" -#include "DataFormats/EcalDetId/interface/EBDetId.h" #include "RecoParticleFlow/PFClusterTools/interface/PFClusterWidthAlgo.h" #include "DataFormats/ParticleFlowReco/interface/PFCluster.h" @@ -23,6 +23,8 @@ //we only really need to do this for barrel super with a gain switch //but usual to remake without gain switch for debugging //however it is barrel only +//everything else is copied or relinked to produce the same set of outputs +//as particleFlowEGamma //how it works: // a refined supercluster will have subclusters added or removed w.r.t to its parent SC @@ -40,8 +42,6 @@ // issues: sub cluster ordering may not be correct (its sorted by decreasing energy) // issues: when it assigns a sub cluster to a refined SC, it doesnt remove it from others -// however it now checks for this and will through an exception if the sub cluster -// is present in two superclusters class EGRefinedSCFixer : public edm::stream::EDProducer<> { public: @@ -54,12 +54,6 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> { const reco::SuperCluster& orgSC, const reco::SuperCluster& fixedSC); - - void - putClustersIntoEvent(edm::Event& iEvent, - std::unique_ptr superClusters); - - static std::vector > getSubClustersMissing(const reco::SuperCluster& lhs, @@ -67,13 +61,13 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> { - static std::unordered_set + static std::unordered_set getListOfClusterSeedIdsForNewSC(const reco::SuperCluster& orgRefinedSC, const reco::SuperCluster& orgSC, const reco::SuperCluster& fixedSC); static std::vector > - getClustersFromSeedIds(const std::unordered_set& seedIds,const edm::Handle >& inClusters); + getClustersFromSeedIds(const std::unordered_set& seedIds,const edm::Handle >& inClusters); static reco::SuperCluster makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedSC, @@ -82,34 +76,69 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> { const edm::Handle >& fixedClusters); private: - edm::EDGetTokenT orgRefinedSCToken_; - edm::EDGetTokenT orgSCToken_; - edm::EDGetTokenT fixedSCToken_; - edm::EDGetTokenT > fixedPFClustersToken_; - const std::string ebeeClustersCollection_; - const std::string esClustersCollection_; - + typedef edm::View PFClusterView; + typedef edm::ValueMap SCRefMap; + typedef edm::ValueMap ConvRefMap; + + template + void getToken(edm::EDGetTokenT& token,const edm::ParameterSet& pset, const std::string& label, const std::string& instance = "") { + auto tag(pset.getParameter(label)); + if (!instance.empty()) + tag = edm::InputTag(tag.label(), instance, tag.process()); + + token = consumes(tag); + } + // outputs from PFEGammaProducer + edm::EDGetTokenT orgRefinedSCToken_; + edm::EDGetTokenT orgBCToken_; // original basic clusters (EB&EE) + edm::EDGetTokenT orgESToken_; // original basic clusters (ES) + edm::EDGetTokenT orgConvToken_; + // outputs from PFECALSuperClusterProducer + edm::EDGetTokenT orgSCToken_[2]; // EB & EE+ES + // outputs from gs-fixed PFECALSuperClusterProducer + edm::EDGetTokenT fixedSCToken_[2]; // EB & EE+ES + // output from gs-fixed particleFlowClusterECAL + edm::EDGetTokenT fixedPFClustersToken_; + + // output instance name of EB/EE BC collection + std::string ebeeClustersCollection_; + // output instance name of ES BC collection + std::string esClustersCollection_; }; -EGRefinedSCFixer::EGRefinedSCFixer(const edm::ParameterSet& iConfig ): +EGRefinedSCFixer::EGRefinedSCFixer(const edm::ParameterSet& iConfig) : ebeeClustersCollection_("EBEEClusters"), esClustersCollection_("ESClusters") { - orgRefinedSCToken_ = consumes(iConfig.getParameter("orgRefinedSC")); - orgSCToken_ = consumes(iConfig.getParameter("orgSC")); - fixedSCToken_ = consumes(iConfig.getParameter("fixedSC")); - fixedPFClustersToken_ = consumes >(iConfig.getParameter("fixedPFClusters")); - - produces(); + getToken(orgRefinedSCToken_, iConfig, "orgRefinedSC"); + getToken(orgBCToken_, iConfig, "orgRefinedSC", "EBEEClusters"); + getToken(orgESToken_, iConfig, "orgRefinedSC", "ESClusters"); + getToken(orgConvToken_, iConfig, "orgRefinedSC"); + getToken(orgSCToken_[0], iConfig, "orgSC", "particleFlowSuperClusterECALBarrel"); + getToken(orgSCToken_[1], iConfig, "orgSC", "particleFlowSuperClusterECALEndcapWithPreshower"); + getToken(fixedSCToken_[0], iConfig, "fixedSC", "particleFlowSuperClusterECALBarrel"); + getToken(fixedSCToken_[1], iConfig, "fixedSC", "particleFlowSuperClusterECALEndcapWithPreshower"); + getToken(fixedPFClustersToken_, iConfig, "fixedPFClusters"); + + produces(); produces(ebeeClustersCollection_); produces(esClustersCollection_); + produces(); + + // products not in PFEGammaProducer; provide mapping from new to old objects + produces(); + produces("parentSCsEB"); + produces("parentSCsEE"); } namespace { - template edm::Handle getHandle(const edm::Event& iEvent,const edm::EDGetTokenT& token){ + template + edm::Handle + getHandle(const edm::Event& iEvent, const edm::EDGetTokenT& token) + { edm::Handle handle; - iEvent.getByToken(token,handle); + iEvent.getByToken(token, handle); return handle; } } @@ -141,113 +170,157 @@ namespace{ } return out; } - }; - std::ostream& operator<<(std::ostream& out,const SCDeepPrinter& obj){return obj(out);} - -} +} void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) { - auto orgRefinedSCs = getHandle(iEvent,orgRefinedSCToken_); - auto orgSCs = getHandle(iEvent,orgSCToken_); - auto fixedSCs = getHandle(iEvent,fixedSCToken_); + auto orgRefinedSCs = getHandle(iEvent, orgRefinedSCToken_); + auto orgBCs = getHandle(iEvent, orgBCToken_); + auto orgESs = getHandle(iEvent, orgESToken_); + auto orgConvs = getHandle(iEvent, orgConvToken_); + auto orgEBSCs = getHandle(iEvent,orgSCToken_[0]); + auto orgEESCs = getHandle(iEvent,orgSCToken_[1]); + auto fixedEBSCs = getHandle(iEvent,fixedSCToken_[0]); + auto fixedEESCs = getHandle(iEvent,fixedSCToken_[1]); auto fixedPFClusters = getHandle(iEvent,fixedPFClustersToken_); - - - // std::cout <<"new event "<(); - - - for(const auto& fixedSC : *fixedSCs){ - - reco::SuperClusterRef orgSC = GainSwitchTools::matchSCBySeedCrys(fixedSC,orgSCs,2,2); - reco::SuperClusterRef orgRefinedSC = orgSC.isNonnull() ? GainSwitchTools::matchSCBySeedCrys(*orgSC,orgRefinedSCs) : orgSC; - - //so we have a matched orginal and refined SC, we can remake the refined SC out of the new clusters - if(orgSC.isNonnull() && orgRefinedSC.isNonnull()){ - reco::SuperCluster fixedRefinedSC = makeFixedRefinedBarrelSC(*orgRefinedSC,*orgSC,fixedSC,fixedPFClusters); - if(orgRefinedSC->clustersSize()!=orgSC->clustersSize() && false){ - std::cout<<" org refined "<(); + // direct translation of the original ES collection - there is nothing "fixed" about this + auto fixedESs = std::make_unique(); + auto fixedConvs = std::make_unique(); + + std::vector mappedRefinedSCs; + std::vector mappedSCsEB(fixedEBSCs->size()); + std::vector mappedSCsEE(fixedEESCs->size()); + + for (unsigned iO(0); iO != orgRefinedSCs->size(); ++iO) { + auto& orgRefinedSC(orgRefinedSCs->at(iO)); + mappedRefinedSCs.emplace_back(orgRefinedSCs, iO); + + // find the PFSuperCluster for this refined SC + if (orgRefinedSC.seed()->seed().subdetId() == EcalBarrel) { + auto orgEBSC(GainSwitchTools::matchSCBySeedCrys(orgRefinedSC, orgEBSCs)); + + // particleFlowEGamma can create superclusters directly out of PFClusters too + // -> there is not always a matching EB SC + if (orgEBSC.isNonnull()) { + auto fixedEBSC(GainSwitchTools::matchSCBySeedCrys(*orgEBSC, fixedEBSCs, 2, 2)); + + // here we may genuinely miss a mapping, if the seed position moves too much by re-reconstruction + if (fixedEBSC.isNonnull()) { + mappedSCsEB[fixedEBSC.key()] = orgEBSC; + + auto fixedRefinedSC(makeFixedRefinedBarrelSC(orgRefinedSC, *orgEBSC, *fixedEBSC, fixedPFClusters)); + fixedRefinedSCs->push_back(fixedRefinedSC); + + continue; + } + } + } + else { + auto orgEESC(GainSwitchTools::matchSCBySeedCrys(orgRefinedSC, orgEESCs)); + if (orgEESC.isNonnull()) { + // there is nothing "fixed" here - two clusters are identical + auto fixedEESC(GainSwitchTools::matchSCBySeedCrys(*orgEESC, fixedEESCs)); + // fixedEESC has to be nonnull + mappedSCsEE[fixedEESC.key()] = orgEESC; } - fixedRefinedSCs->push_back(fixedRefinedSC); - }else if(orgSC.isNull()){ - //didnt find the orginal supercluster, just pass this through as a refined sc - fixedRefinedSCs->push_back(fixedSC); } - } - putClustersIntoEvent(iEvent,std::move(fixedRefinedSCs)); -} + // if EE or no PFSuperCluster match + fixedRefinedSCs->push_back(orgRefinedSC); + } -void EGRefinedSCFixer::putClustersIntoEvent(edm::Event& iEvent,std::unique_ptr superClusters) -{ - //now we need to rewrite out the sub clusters as calo clusters - //we will follow https://github.com/cms-sw/cmssw/blob/CMSSW_8_0_X/RecoParticleFlow/PFProducer/plugins/PFEGammaProducer.cc#L444-L493 - auto caloClustersEBEE = std::make_unique(); - auto caloClustersES = std::make_unique(); - - std::map, unsigned int> pfClusterMapEBEE; //maps of pfclusters to caloclusters - std::map, unsigned int> pfClusterMapES; - - for(const auto& superClus : *superClusters){ - for(const auto& pfClus : superClus.clusters()){ - if(!pfClusterMapEBEE.count(pfClus)) { - caloClustersEBEE->push_back(*pfClus); - pfClusterMapEBEE[pfClus] = caloClustersEBEE->size() - 1; - } - else{ - throw cms::Exception("EGRefinedSCFixer::putClustersIntoEvent") - << "Found an EB/EE pfcluster matched to more than one supercluster!" - << std::dec << std::endl; + // Put the PF SC maps in Event + std::auto_ptr pEBSCRefMap(new SCRefMap); + SCRefMap::Filler ebSCMapFiller(*pEBSCRefMap); + ebSCMapFiller.insert(fixedEBSCs, mappedSCsEB.begin(), mappedSCsEB.end()); + ebSCMapFiller.fill(); + iEvent.put(pEBSCRefMap, "parentSCsEB"); + + std::auto_ptr pEESCRefMap(new SCRefMap); + SCRefMap::Filler eeSCMapFiller(*pEESCRefMap); + eeSCMapFiller.insert(fixedEESCs, mappedSCsEE.begin(), mappedSCsEE.end()); + eeSCMapFiller.fill(); + iEvent.put(pEESCRefMap, "parentSCsEE"); + + // Copy basic clusters + std::map pfClusterMapEBEE; //maps of pfclusters to caloclusters + std::map pfClusterMapES; + + for (auto& sc : *fixedRefinedSCs) { + // The cluster ref in fixed EB and the other superclusters point to different collections (former to gs-fixed, latter to original) + // but we are copying the basic clusters by value and remaking yet another collection here -> no need to distinguish + for (auto&& cItr(sc.clustersBegin()); cItr != sc.clustersEnd(); ++cItr) { + auto& ptr(*cItr); + if (pfClusterMapEBEE.count(ptr) == 0) { + pfClusterMapEBEE[ptr] = fixedBCs->size(); + fixedBCs->emplace_back(*ptr); } + else + throw cms::Exception("EGRefinedSCFixer::produce") + << "Found an EB/EE pfcluster matched to more than one supercluster!"; } - for(const auto& pfClus : superClus.preshowerClusters()){ - if(!pfClusterMapES.count(pfClus)) { - caloClustersES->push_back(*pfClus); - pfClusterMapES[pfClus] = caloClustersES->size() - 1; - } - else { - throw cms::Exception("EGRefinedSCFixer::putClustersIntoEvent") - << "Found an ES pfcluster matched to more than one supercluster!" - << std::dec << std::endl; + + for (auto&& cItr = sc.preshowerClustersBegin(); cItr!=sc.preshowerClustersEnd(); ++cItr) { + auto& ptr(*cItr); + if (pfClusterMapES.count(ptr) == 0) { + pfClusterMapES[ptr] = fixedESs->size(); + fixedESs->emplace_back(*ptr); } + else + throw cms::Exception("PFEgammaProducer::produce") + << "Found an ES pfcluster matched to more than one supercluster!"; } } - - const edm::OrphanHandle &caloClusHandleEBEE = iEvent.put(std::move(caloClustersEBEE),ebeeClustersCollection_); - const edm::OrphanHandle &caloClusHandleES = iEvent.put(std::move(caloClustersES),esClustersCollection_); - + + //put calocluster output collections in event and get orphan handles to create ptrs + auto caloClusHandleEBEE(iEvent.put(std::move(fixedBCs), ebeeClustersCollection_)); + auto caloClusHandleES(iEvent.put(std::move(fixedESs), esClustersCollection_)); + //relink superclusters to output caloclusters - for( auto& superClus : *superClusters ) { - edm::Ptr seedPtr(caloClusHandleEBEE,pfClusterMapEBEE[superClus.seed()]); - superClus.setSeed(seedPtr); + for (auto& sc : *fixedRefinedSCs) { + edm::Ptr seedptr(caloClusHandleEBEE, pfClusterMapEBEE[sc.seed()]); + sc.setSeed(seedptr); reco::CaloClusterPtrVector clusters; - for (auto& pfClus : superClus.clusters()) { - edm::Ptr clusPtr(caloClusHandleEBEE,pfClusterMapEBEE[pfClus]); - clusters.push_back(clusPtr); - } - superClus.setClusters(clusters); + for (auto&& cItr(sc.clustersBegin()); cItr!=sc.clustersEnd(); ++cItr) + clusters.push_back(reco::CaloClusterPtr(caloClusHandleEBEE, pfClusterMapEBEE[*cItr])); + sc.setClusters(clusters); - reco::CaloClusterPtrVector psClusters; - for (auto& pfClus : superClus.preshowerClusters()) { - edm::Ptr clusPtr(caloClusHandleES,pfClusterMapES[pfClus]); - psClusters.push_back(clusPtr); - } - superClus.setPreshowerClusters(psClusters); + reco::CaloClusterPtrVector psclusters; + for (auto&& cItr(sc.preshowerClustersBegin()); cItr!=sc.preshowerClustersEnd(); ++cItr) + psclusters.push_back(reco::CaloClusterPtr(caloClusHandleES, pfClusterMapES[*cItr])); + sc.setPreshowerClusters(psclusters); } - - iEvent.put(std::move(superClusters)); + auto scHandle(iEvent.put(std::move(fixedRefinedSCs))); + + // Put the new to old refined SC map + std::auto_ptr pRefinedSCRefMap(new SCRefMap); + SCRefMap::Filler refinedSCMapFiller(*pRefinedSCRefMap); + refinedSCMapFiller.insert(scHandle, mappedRefinedSCs.begin(), mappedRefinedSCs.end()); + refinedSCMapFiller.fill(); + iEvent.put(pRefinedSCRefMap); + + // copy and relink conversions + for (auto& conv : *orgConvs) { + // copy Ctor is not defined for reco::Conversion but there is a clone() method + // that uses a copy Ctor. I suppose this object can be trivially copied.. + fixedConvs->emplace_back(conv); + auto& newConv(fixedConvs->back()); + // conversion keeps a PtrVector, but according to PFEGammaProducer, single-leg conversions + // always have only one SC ptr. + reco::CaloClusterPtrVector scPtrVec; + // we create the new refined SC collection in the same order as the old one + scPtrVec.push_back(reco::CaloClusterPtr(scHandle, conv.caloCluster()[0].key())); + newConv.setMatchingSuperCluster(scPtrVec); + } + + iEvent.put(std::move(fixedConvs)); } @@ -265,7 +338,7 @@ EGRefinedSCFixer::getSubClustersMissing(const reco::SuperCluster& lhs, return missingSubClusters; } -std::unordered_set +std::unordered_set EGRefinedSCFixer::getListOfClusterSeedIdsForNewSC(const reco::SuperCluster& orgRefinedSC, const reco::SuperCluster& orgSC, const reco::SuperCluster& fixedSC) @@ -274,20 +347,21 @@ EGRefinedSCFixer::getListOfClusterSeedIdsForNewSC(const reco::SuperCluster& orgR auto clusAdded = getSubClustersMissing(orgRefinedSC,orgSC); auto clusRemoved = getSubClustersMissing(orgSC,orgRefinedSC); - std::unordered_set detIdsOfClustersForNewSC; + std::unordered_set detIdsOfClustersForNewSC; for(auto& clus : fixedSC.clusters()){ auto compFunc=[&clus](auto& rhs){return rhs->seed().rawId()==clus->seed().rawId();}; if(std::find_if(clusRemoved.begin(),clusRemoved.end(),compFunc)==clusRemoved.end()){ detIdsOfClustersForNewSC.insert(clus->seed().rawId()); } } - for(auto clus : clusAdded) detIdsOfClustersForNewSC.insert(clus->seed().rawId()); + for(auto clus : clusAdded) + detIdsOfClustersForNewSC.insert(clus->seed().rawId()); return detIdsOfClustersForNewSC; } std::vector > -EGRefinedSCFixer::getClustersFromSeedIds(const std::unordered_set& seedIds,const edm::Handle >& inClusters) +EGRefinedSCFixer::getClustersFromSeedIds(const std::unordered_set& seedIds,const edm::Handle >& inClusters) { std::vector > outClusters; for(size_t clusNr=0;clusNrsize();clusNr++){ @@ -309,9 +383,23 @@ EGRefinedSCFixer::makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedS const reco::SuperCluster& fixedSC, const edm::Handle >& fixedClusters) { - auto listOfSeedIds = getListOfClusterSeedIdsForNewSC(orgRefinedSC,orgSC,fixedSC); + + // make sure the seed cluster is in the listOfSeedIds + unsigned seedSeedId(fixedSC.seed()->seed().rawId()); + listOfSeedIds.insert(seedSeedId); + std::vector > clusters = getClustersFromSeedIds(listOfSeedIds,fixedClusters); + + // fixedSC.seed() is from a different BasicCluster collection + edm::Ptr seedCluster; + for (auto& ptr : clusters) { + if (ptr->seed().rawId() == seedSeedId) { + seedCluster = ptr; + break; + } + } + std::vector clustersBarePtrs; double posX(0),posY(0),posZ(0); @@ -334,20 +422,11 @@ EGRefinedSCFixer::makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedS posY /= scNrgy; posZ /= scNrgy; - //now we need to figure out the seed which we take as the same as the non-refined SC - //which we match on seed crystal ID - edm::Ptr seedPtr(fixedClusters.id()); - for(const auto& clusPtr : clusters){ - if(clusPtr->seed()==fixedSC.seed()->seed()){ - seedPtr=clusPtr; - break; - } - } - //intentionally passing in scCorrNrgy its not supposed to be scNrgy - reco::SuperCluster newSC(scCorrNrgy,math::XYZPoint(posX,posY,posZ)); + reco::SuperCluster newSC(scCorrNrgy,math::XYZPoint(posX,posY,posZ)); + newSC.setCorrectedEnergy(scCorrNrgy); - newSC.setSeed(seedPtr); //the seed is the same as the non-refined SC + newSC.setSeed(seedCluster); //the seed is the same as the non-refined SC newSC.setPreshowerEnergyPlane1(0.); newSC.setPreshowerEnergyPlane2(0.); newSC.setPreshowerEnergy(0.); @@ -367,7 +446,6 @@ EGRefinedSCFixer::makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedS newSC.rawEnergy(); return newSC; - } DEFINE_FWK_MODULE(EGRefinedSCFixer); diff --git a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronCoreGSCrysFixer.cc b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronCoreGSCrysFixer.cc index d5086ea65a432..5bb4192b11639 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronCoreGSCrysFixer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronCoreGSCrysFixer.cc @@ -23,9 +23,6 @@ #include "DataFormats/EcalRecHit/interface/EcalRecHit.h" #include "DataFormats/EcalDetId/interface/EcalSubdetector.h" -#include "Geometry/CaloTopology/interface/CaloTopology.h" -#include "Geometry/Records/interface/CaloTopologyRecord.h" - #include "RecoCaloTools/Navigation/interface/CaloNavigator.h" #include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" @@ -39,24 +36,27 @@ class GsfElectronCoreGSCrysFixer : public edm::stream::EDProducer<> { virtual ~GsfElectronCoreGSCrysFixer(){} void produce(edm::Event&, const edm::EventSetup& ) override; - void beginLuminosityBlock(edm::LuminosityBlock const&, - edm::EventSetup const&) override; - template - void getToken(edm::EDGetTokenT& token,const edm::ParameterSet& pset,const std::string& label){ - token=consumes(pset.getParameter(label)); + void getToken(edm::EDGetTokenT& token,const edm::ParameterSet& pset,const std::string& label, const std::string& instance = ""){ + auto tag(pset.getParameter(label)); + if (!instance.empty()) + tag = edm::InputTag(tag.label(), instance, tag.process()); + + token = consumes(tag); } private: + typedef edm::ValueMap SCRefMap; + edm::EDGetTokenT orgCoresToken_; - edm::EDGetTokenT ebRecHitsToken_; - edm::EDGetTokenT > oldRefinedSCToNewMapToken_; - edm::EDGetTokenT > oldSCToNewMapToken_; - const CaloTopology* topology_; - + edm::EDGetTokenT refinedSCsToken_; // new + edm::EDGetTokenT refinedSCMapToken_; // new->old + edm::EDGetTokenT ebSCsToken_; // new + edm::EDGetTokenT ebSCMapToken_; // new->old + edm::EDGetTokenT eeSCsToken_; // new + edm::EDGetTokenT eeSCMapToken_; // new->old }; - namespace { template edm::Handle getHandle(const edm::Event& iEvent,const edm::EDGetTokenT& token){ edm::Handle handle; @@ -69,59 +69,59 @@ namespace { GsfElectronCoreGSCrysFixer::GsfElectronCoreGSCrysFixer( const edm::ParameterSet & pset ) { getToken(orgCoresToken_,pset,"orgCores"); - getToken(ebRecHitsToken_,pset,"ebRecHits"); - getToken(oldRefinedSCToNewMapToken_,pset,"oldRefinedSCToNewMap"); - getToken(oldSCToNewMapToken_,pset,"oldSCToNewMap"); + getToken(refinedSCsToken_, pset, "refinedSCs"); + getToken(refinedSCMapToken_, pset, "refinedSCs"); + getToken(ebSCsToken_, pset, "scs", "particleFlowSuperClusterECALBarrel"); + getToken(ebSCMapToken_, pset, "refinedSCs", "parentSCsEB"); + getToken(eeSCsToken_, pset, "scs", "particleFlowSuperClusterECALEndcapWithPreshower"); + getToken(eeSCMapToken_, pset, "refinedSCs", "parentSCsEE"); produces(); - produces >("parentCores"); + produces(); // new core to old SC } -void GsfElectronCoreGSCrysFixer::produce( edm::Event & iEvent, const edm::EventSetup & iSetup ) +void GsfElectronCoreGSCrysFixer::produce(edm::Event & iEvent, const edm::EventSetup &) { auto outCores = std::make_unique(); auto eleCoresHandle = getHandle(iEvent,orgCoresToken_); - auto& ebRecHits = *getHandle(iEvent,ebRecHitsToken_); - auto& oldRefinedSCToNewMap = *getHandle(iEvent,oldRefinedSCToNewMapToken_); - auto& oldSCToNewMap = *getHandle(iEvent,oldSCToNewMapToken_); + auto refinedSCs(getHandle(iEvent, refinedSCsToken_)); + auto& refinedSCMap(*getHandle(iEvent, refinedSCMapToken_)); + auto ebSCs(getHandle(iEvent, ebSCsToken_)); + auto& ebSCMap(*getHandle(iEvent, ebSCMapToken_)); + auto eeSCs(getHandle(iEvent, eeSCsToken_)); + auto& eeSCMap(*getHandle(iEvent, eeSCMapToken_)); + + std::vector oldSCRefs; - std::vector parentCores; - - for(size_t coreNr=0;coreNrsize();coreNr++){ - reco::GsfElectronCoreRef coreRef(eleCoresHandle,coreNr); - const reco::GsfElectronCore& core = *coreRef; - - //passing in the old refined supercluster - if(GainSwitchTools::hasEBGainSwitchIn5x5(*core.superCluster(),&ebRecHits,topology_)){ - reco::GsfElectronCore newCore(core); - //these references may be null, lets see what happens! - //turns out the orginal ele may have null references, odd - if(core.superCluster().isNonnull()) newCore.setSuperCluster( oldRefinedSCToNewMap[core.superCluster()] ); - if(core.parentSuperCluster().isNonnull()) newCore.setParentSuperCluster( oldSCToNewMap[core.parentSuperCluster()] ); - - outCores->push_back(newCore); - parentCores.push_back(coreRef->superCluster()); + for (auto& inCore : *eleCoresHandle) { + outCores->emplace_back(inCore); + auto& outCore(outCores->back()); + + // NOTE: These mappings can result in NULL superclusters! + auto& oldRefinedSC(inCore.superCluster()); + outCore.setSuperCluster(GainSwitchTools::findNewRef(oldRefinedSC, refinedSCs, refinedSCMap)); + + oldSCRefs.push_back(oldRefinedSC); + + auto& parentSC(inCore.parentSuperCluster()); + if (parentSC.isNonnull()) { + if (parentSC->seed()->seed().subdetId() == EcalBarrel) + outCore.setParentSuperCluster(GainSwitchTools::findNewRef(parentSC, ebSCs, ebSCMap)); + else + outCore.setParentSuperCluster(GainSwitchTools::findNewRef(parentSC, eeSCs, eeSCMap)); } } - auto outCoresHandle = iEvent.put(std::move(outCores)); - - std::unique_ptr > parentCoresValMap(new edm::ValueMap()); - typename edm::ValueMap::Filler filler(*parentCoresValMap); - filler.insert(outCoresHandle, parentCores.begin(), parentCores.end()); - filler.fill(); - iEvent.put(std::move(parentCoresValMap),"parentCores"); -} + auto newCoresHandle(iEvent.put(std::move(outCores))); -void GsfElectronCoreGSCrysFixer::beginLuminosityBlock(edm::LuminosityBlock const& lb, - edm::EventSetup const& es) { - edm::ESHandle caloTopo ; - es.get().get(caloTopo); - topology_ = caloTopo.product(); + std::auto_ptr pRefMap(new SCRefMap); + SCRefMap::Filler refMapFiller(*pRefMap); + refMapFiller.insert(newCoresHandle, oldSCRefs.begin(), oldSCRefs.end()); + refMapFiller.fill(); + iEvent.put(pRefMap); } - DEFINE_FWK_MODULE(GsfElectronCoreGSCrysFixer); #endif diff --git a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc index e9389d975d39c..93705d5e4bce8 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc @@ -50,14 +50,21 @@ class GsfElectronGSCrysFixer : public edm::stream::EDProducer<> { template - void getToken(edm::EDGetTokenT& token,const edm::ParameterSet& pset,const std::string& label){ - token=consumes(pset.getParameter(label)); + void getToken(edm::EDGetTokenT& token,const edm::ParameterSet& pset,const std::string& label, const std::string& instance = ""){ + auto tag(pset.getParameter(label)); + if (!instance.empty()) + tag = edm::InputTag(tag.label(), instance, tag.process()); + + token = consumes(tag); } private: - edm::EDGetTokenT oldGsfElesToken_; + typedef edm::View GsfElectronView; + typedef edm::ValueMap SCRefMap; + + edm::EDGetTokenT oldGsfElesToken_; edm::EDGetTokenT newCoresToken_; + edm::EDGetTokenT newCoresToOldSCMapToken_; edm::EDGetTokenT ebRecHitsToken_; - edm::EDGetTokenT > newCoresToOldCoresMapToken_; const CaloTopology* topology_; const CaloGeometry* geometry_; @@ -73,15 +80,16 @@ namespace { } } + + typedef edm::ValueMap ElectronRefMap; -typedef edm::ValueMap BoolMap; GsfElectronGSCrysFixer::GsfElectronGSCrysFixer( const edm::ParameterSet & pset ) { - getToken(newCoresToken_,pset,"newCores"); getToken(oldGsfElesToken_,pset,"oldEles"); + getToken(newCoresToken_,pset,"newCores"); + getToken(newCoresToOldSCMapToken_, pset, "newCores"); getToken(ebRecHitsToken_,pset,"ebRecHits"); - getToken(newCoresToOldCoresMapToken_,pset,"newCoresToOldCoresMap"); //ripped wholesale from GEDGsfElectronFinalizer if( pset.existsAs("regressionConfig") ) { @@ -97,21 +105,20 @@ GsfElectronGSCrysFixer::GsfElectronGSCrysFixer( const edm::ParameterSet & pset ) } produces(); + // new -> old produces(); - produces(); - } namespace { - reco::GsfElectronCoreRef getNewCore(const reco::GsfElectronRef& oldEle, + reco::GsfElectronCoreRef getNewCore(reco::GsfElectron const& oldEle, edm::Handle& newCores, - edm::ValueMap newToOldCoresMap) + edm::ValueMap const& newToOldCoresMap) { for(size_t coreNr=0;coreNrsize();coreNr++){ reco::GsfElectronCoreRef coreRef(newCores,coreNr); auto oldRef = newToOldCoresMap[coreRef]; - if( oldRef.isNonnull() && oldRef==oldEle->superCluster()){ + if( oldRef.isNonnull() && oldRef==oldEle.superCluster()){ return coreRef; } } @@ -127,61 +134,47 @@ void GsfElectronGSCrysFixer::produce( edm::Event & iEvent, const edm::EventSetup gedRegression_->setEvent(iEvent); gedRegression_->setEventContent(iSetup); } - auto elesHandle = getHandle(iEvent,oldGsfElesToken_); auto& ebRecHits = *getHandle(iEvent,ebRecHitsToken_); - auto& newCoresToOldCoresMap = *getHandle(iEvent,newCoresToOldCoresMapToken_); auto newCoresHandle = getHandle(iEvent,newCoresToken_); + auto newCoresToOldSCMap = *getHandle(iEvent, newCoresToOldSCMapToken_); std::vector oldElectrons; - std::vector isUpdated; - - for(size_t eleNr=0;eleNrsize();eleNr++){ - reco::GsfElectronRef eleRef(elesHandle,eleNr); - oldElectrons.emplace_back(eleRef); - reco::GsfElectronCoreRef newCoreRef = getNewCore(eleRef,newCoresHandle,newCoresToOldCoresMap); - - if(newCoreRef.isNonnull()){ //okay we have to remake the electron + unsigned iE(0); + for (auto& oldEle : *elesHandle) { + auto&& refToBase(elesHandle->refAt(iE++)); + oldElectrons.emplace_back(refToBase.id(), &oldEle, refToBase.key()); + + reco::GsfElectronCoreRef newCoreRef = getNewCore(oldEle,newCoresHandle,newCoresToOldSCMap); + + outEles->emplace_back(oldEle,newCoreRef); + auto& newEle(outEles->back()); + + if (GainSwitchTools::hasEBGainSwitchIn5x5(*oldEle.superCluster(), &ebRecHits, topology_)) { - reco::GsfElectron newEle(*eleRef,newCoreRef); reco::GsfElectron::ShowerShape full5x5ShowerShape = GainSwitchTools::redoEcalShowerShape(newEle.full5x5_showerShape(),newEle.superCluster(),&ebRecHits,topology_,geometry_); reco::GsfElectron::ShowerShape showerShape = GainSwitchTools::redoEcalShowerShape(newEle.showerShape(),newEle.superCluster(),&ebRecHits,topology_,geometry_); + newEle.full5x5_setShowerShape(full5x5ShowerShape); + newEle.setShowerShape(showerShape); - float eNewSCOverEOldSC = newEle.superCluster()->energy()/eleRef->superCluster()->energy(); + float eNewSCOverEOldSC = newEle.superCluster()->energy()/oldEle.superCluster()->energy(); GainSwitchTools::correctHadem(showerShape,eNewSCOverEOldSC,GainSwitchTools::ShowerShapeType::Fractions); GainSwitchTools::correctHadem(full5x5ShowerShape,eNewSCOverEOldSC,GainSwitchTools::ShowerShapeType::Full5x5); - newEle.full5x5_setShowerShape(full5x5ShowerShape); - newEle.setShowerShape(showerShape); - - if( gedRegression_ ) { + if( gedRegression_ ) gedRegression_->modifyObject(newEle); - } - - // std::cout <<"made a new electron "<ecalEnergy()<push_back(newEle); - isUpdated.emplace_back(true); - }else{ - outEles->push_back(*eleRef); - isUpdated.emplace_back(false); } } auto&& newElectronsHandle(iEvent.put(std::move(outEles))); - std::unique_ptr pRefMap(new ElectronRefMap); + + std::auto_ptr pRefMap(new ElectronRefMap); ElectronRefMap::Filler refMapFiller(*pRefMap); refMapFiller.insert(newElectronsHandle, oldElectrons.begin(), oldElectrons.end()); refMapFiller.fill(); - iEvent.put(std::move(pRefMap)); - std::unique_ptr bRefMap(new BoolMap); - BoolMap::Filler boolMapFiller(*bRefMap); - boolMapFiller.insert(newElectronsHandle, isUpdated.begin(), isUpdated.end()); - boolMapFiller.fill(); - iEvent.put(std::move(bRefMap)); - + iEvent.put(pRefMap); } void GsfElectronGSCrysFixer::beginLuminosityBlock(edm::LuminosityBlock const& lb, diff --git a/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectronCores_cfi.py b/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectronCores_cfi.py index f02fe825bbafe..0bf8548605056 100644 --- a/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectronCores_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectronCores_cfi.py @@ -1,9 +1,7 @@ import FWCore.ParameterSet.Config as cms gsFixedGsfElectronCores = cms.EDProducer("GsfElectronCoreGSCrysFixer", - orgCores=cms.InputTag("gedGsfElectronCores",processName=cms.InputTag.skipCurrentProcess()), - ebRecHits=cms.InputTag("reducedEcalRecHitsEB",processName=cms.InputTag.skipCurrentProcess()), ##ffs, weights dont have the gains switches set properly for some reason, doesnt matter, all we need this for is the gain so we can use orginal multifit - # ebRecHits=cms.InputTag("ecalWeightsRecHits","EcalRecHitsEB"), ##ffs, weights dont have the gains switches set properly for some reason - oldRefinedSCToNewMap=cms.InputTag("gsBrokenToGSFixedSuperClustersMap","refinedSCs"), - oldSCToNewMap=cms.InputTag("gsBrokenToGSFixedSuperClustersMap","parentSCs"), + orgCores=cms.InputTag("gedGsfElectronCores", '', cms.InputTag.skipCurrentProcess()), + refinedSCs = cms.InputTag('gsFixedRefinedSuperClusters'), + scs = cms.InputTag('particleFlowSuperClusterECALGSFixed'), ) diff --git a/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectrons_cfi.py b/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectrons_cfi.py index 1ec1895a3b84e..3c3d73a3ea1f1 100644 --- a/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectrons_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/gsFixedGsfElectrons_cfi.py @@ -2,11 +2,8 @@ from RecoEgamma.EgammaTools.regressionModifier_cfi import regressionModifier gsFixedGsfElectrons = cms.EDProducer("GsfElectronGSCrysFixer", - newCores=cms.InputTag("gsFixedGsfElectronCores"), - oldEles=cms.InputTag("gedGsfElectrons",processName=cms.InputTag.skipCurrentProcess()), - ebRecHits=cms.InputTag("ecalMultiAndGSWeightRecHitEB"), - newCoresToOldCoresMap=cms.InputTag("gsFixedGsfElectronCores","parentCores"), - regressionConfig = regressionModifier.clone(rhoCollection=cms.InputTag("fixedGridRhoFastjetAllTmp")), - - + newCores=cms.InputTag("gsFixedGsfElectronCores"), + oldEles=cms.InputTag("gedGsfElectrons", '', cms.InputTag.skipCurrentProcess()), + ebRecHits=cms.InputTag("ecalMultiAndGSWeightRecHitEB"), + regressionConfig = regressionModifier.clone(rhoCollection=cms.InputTag("fixedGridRhoFastjetAllTmp")), ) diff --git a/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.cc b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.cc new file mode 100644 index 0000000000000..d17a36ec3322f --- /dev/null +++ b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.cc @@ -0,0 +1,63 @@ +#include "RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.h" + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/Common/interface/Handle.h" + +template +EgammaEcalPFClusterIsolationRemapper::EgammaEcalPFClusterIsolationRemapper(const edm::ParameterSet& config) : + emObjectProducer_ (consumes(config.getParameter("candidateProducer"))), + newToOldObjectMap_ (consumes(config.getParameter("newToOldObjectMap"))), + isolationMap_ (consumes(config.getParameter("isolationMap"))) +{ + produces>(); +} + +template +EgammaEcalPFClusterIsolationRemapper::~EgammaEcalPFClusterIsolationRemapper() +{ +} + +template +void EgammaEcalPFClusterIsolationRemapper::produce(edm::Event& iEvent, const edm::EventSetup&) +{ + edm::Handle emObjectHandle; + iEvent.getByToken(emObjectProducer_, emObjectHandle); + + edm::Handle objectMapHandle; + iEvent.getByToken(newToOldObjectMap_, objectMapHandle); + auto& objectMap(*objectMapHandle); + + edm::Handle isolationMapHandle; + iEvent.getByToken(isolationMap_, isolationMapHandle); + auto& isolationMap(*isolationMapHandle); + + std::vector retV(emObjectHandle->size(), 0.); + + for (unsigned iO(0); iO != emObjectHandle->size(); ++iO) { + CRef ref(emObjectHandle, iO); + auto oldRef(objectMap[ref]); + retV[iO] = isolationMap[oldRef]; + } + + std::auto_ptr isoMap(new FloatMap()); + FloatMap::Filler filler(*isoMap); + + filler.insert(emObjectHandle, retV.begin(), retV.end()); + filler.fill(); + + iEvent.put(isoMap); +} + +#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" + +typedef EgammaEcalPFClusterIsolationRemapper ElectronEcalPFClusterIsolationRemapper; +typedef EgammaEcalPFClusterIsolationRemapper PhotonEcalPFClusterIsolationRemapper; + +DEFINE_FWK_MODULE(ElectronEcalPFClusterIsolationRemapper); +DEFINE_FWK_MODULE(PhotonEcalPFClusterIsolationRemapper); diff --git a/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.h b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.h new file mode 100644 index 0000000000000..69a15e4a88a0b --- /dev/null +++ b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalPFClusterIsolationRemapper.h @@ -0,0 +1,35 @@ +#ifndef EgammaIsolationRemappers_EgammaEcalPFClusterIsolationRemapper_h +#define EgammaIsolationRemappers_EgammaEcalPFClusterIsolationRemapper_h + +//***************************************************************************** +// File: EgammaEcalPFClusterIsolationRemapper.h +// ---------------------------------------------------------------------------- +// OrigAuth: Yutaro Iiyama +// Institute: MIT +//***************************************************************************** + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/Common/interface/Ref.h" + +template +class EgammaEcalPFClusterIsolationRemapper : public edm::stream::EDProducer<> { + public: + EgammaEcalPFClusterIsolationRemapper(const edm::ParameterSet&); + ~EgammaEcalPFClusterIsolationRemapper(); + + void produce(edm::Event&, const edm::EventSetup&); + private: + typedef typename edm::refhelper::ValueTrait::value Value; + typedef edm::Ref::value> CRef; + typedef edm::ValueMap CRefMap; + typedef edm::ValueMap FloatMap; + + edm::EDGetTokenT emObjectProducer_; + edm::EDGetTokenT newToOldObjectMap_; + edm::EDGetTokenT isolationMap_; +}; + +#endif diff --git a/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.cc b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.cc new file mode 100644 index 0000000000000..f26c85a897e55 --- /dev/null +++ b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.cc @@ -0,0 +1,63 @@ +#include "RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.h" + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/Common/interface/Handle.h" + +template +EgammaHcalPFClusterIsolationRemapper::EgammaHcalPFClusterIsolationRemapper(const edm::ParameterSet& config) : + emObjectProducer_ (consumes(config.getParameter("candidateProducer"))), + newToOldObjectMap_ (consumes(config.getParameter("newToOldObjectMap"))), + isolationMap_ (consumes(config.getParameter("isolationMap"))) +{ + produces>(); +} + +template +EgammaHcalPFClusterIsolationRemapper::~EgammaHcalPFClusterIsolationRemapper() +{ +} + +template +void EgammaHcalPFClusterIsolationRemapper::produce(edm::Event& iEvent, const edm::EventSetup&) +{ + edm::Handle emObjectHandle; + iEvent.getByToken(emObjectProducer_, emObjectHandle); + + edm::Handle objectMapHandle; + iEvent.getByToken(newToOldObjectMap_, objectMapHandle); + auto& objectMap(*objectMapHandle); + + edm::Handle isolationMapHandle; + iEvent.getByToken(isolationMap_, isolationMapHandle); + auto& isolationMap(*isolationMapHandle); + + std::vector retV(emObjectHandle->size(), 0.); + + for (unsigned iO(0); iO != emObjectHandle->size(); ++iO) { + CRef ref(emObjectHandle, iO); + auto oldRef(objectMap[ref]); + retV[iO] = isolationMap[oldRef]; + } + + std::auto_ptr isoMap(new FloatMap()); + FloatMap::Filler filler(*isoMap); + + filler.insert(emObjectHandle, retV.begin(), retV.end()); + filler.fill(); + + iEvent.put(isoMap); +} + +#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" + +typedef EgammaHcalPFClusterIsolationRemapper ElectronHcalPFClusterIsolationRemapper; +typedef EgammaHcalPFClusterIsolationRemapper PhotonHcalPFClusterIsolationRemapper; + +DEFINE_FWK_MODULE(ElectronHcalPFClusterIsolationRemapper); +DEFINE_FWK_MODULE(PhotonHcalPFClusterIsolationRemapper); diff --git a/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.h b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.h new file mode 100644 index 0000000000000..319bbfbbaf51c --- /dev/null +++ b/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaHcalPFClusterIsolationRemapper.h @@ -0,0 +1,35 @@ +#ifndef EgammaIsolationRemappers_EgammaHcalPFClusterIsolationRemapper_h +#define EgammaIsolationRemappers_EgammaHcalPFClusterIsolationRemapper_h + +//***************************************************************************** +// File: EgammaHcalPFClusterIsolationRemapper.h +// ---------------------------------------------------------------------------- +// OrigAuth: Yutaro Iiyama +// Institute: MIT +//***************************************************************************** + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/Common/interface/Ref.h" + +template +class EgammaHcalPFClusterIsolationRemapper : public edm::stream::EDProducer<> { + public: + EgammaHcalPFClusterIsolationRemapper(const edm::ParameterSet&); + ~EgammaHcalPFClusterIsolationRemapper(); + + void produce(edm::Event&, const edm::EventSetup&); + private: + typedef typename edm::refhelper::ValueTrait::value Value; + typedef edm::Ref::value> CRef; + typedef edm::ValueMap CRefMap; + typedef edm::ValueMap FloatMap; + + edm::EDGetTokenT emObjectProducer_; + edm::EDGetTokenT newToOldObjectMap_; + edm::EDGetTokenT isolationMap_; +}; + +#endif diff --git a/RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemapForPAT_cff.py b/RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemapForPAT_cff.py new file mode 100644 index 0000000000000..1dd1773c87bf7 --- /dev/null +++ b/RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemapForPAT_cff.py @@ -0,0 +1,31 @@ +import FWCore.ParameterSet.Config as cms + +from RecoEgamma.EgammaIsolationAlgos.pfClusterIsolation_cfi import * +from RecoEgamma.EgammaIsolationAlgos.pfClusterIsolationRemap_cfi import * + +electronHcalPFClusterIsolationProducerGSFixed = electronHcalPFClusterIsolationRemapper.clone( + candidateProducer = 'gedGsfElectronsGSFixed', + newToOldObjectMap = 'gedGsfElectronsGSFixed' +) + +photonHcalPFClusterIsolationProducerGSFixed = photonHcalPFClusterIsolationRemapper.clone( + candidateProducer = 'gedPhotonsGSFixed', + newToOldObjectMap = 'gedPhotonsGSFixed' +) + +electronEcalPFClusterIsolationProducerGSFixed = electronEcalPFClusterIsolationRemapper.clone( + candidateProducer = 'gedGsfElectronsGSFixed', + newToOldObjectMap = 'gedGsfElectronsGSFixed' +) + +photonEcalPFClusterIsolationProducerGSFixed = photonEcalPFClusterIsolationRemapper.clone( + candidateProducer = 'gedPhotonsGSFixed', + newToOldObjectMap = 'gedPhotonsGSFixed' +) + +pfClusterIsolationSequence = cms.Sequence( + electronEcalPFClusterIsolationProducerGSFixed + + photonEcalPFClusterIsolationProducerGSFixed + + electronHcalPFClusterIsolationProducerGSFixed + + photonHcalPFClusterIsolationProducerGSFixed +) diff --git a/RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemap_cfi.py b/RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemap_cfi.py new file mode 100644 index 0000000000000..c856fa2661bd5 --- /dev/null +++ b/RecoEgamma/EgammaIsolationAlgos/python/pfClusterIsolationRemap_cfi.py @@ -0,0 +1,32 @@ +import FWCore.ParameterSet.Config as cms + +electronHcalPFClusterIsolationRemapper = cms.EDProducer('ElectronHcalPFClusterIsolationRemapper', + candidateProducer = cms.InputTag('gsFixedGsfElectrons'), + newToOldObjectMap = cms.InputTag('gsFixedGsfElectrons'), + isolationMap = cms.InputTag('electronHcalPFClusterIsolationProducer', '', cms.InputTag.skipCurrentProcess()) +) + +photonHcalPFClusterIsolationRemapper = cms.EDProducer('PhotonHcalPFClusterIsolationRemapper', + candidateProducer = cms.InputTag('gsFixedGEDPhotons'), + newToOldObjectMap = cms.InputTag('gsFixedGEDPhotons'), + isolationMap = cms.InputTag('photonHcalPFClusterIsolationProducer', '', cms.InputTag.skipCurrentProcess()) +) + +electronEcalPFClusterIsolationRemapper = cms.EDProducer('ElectronEcalPFClusterIsolationRemapper', + candidateProducer = cms.InputTag('gsFixedGsfElectrons'), + newToOldObjectMap = cms.InputTag('gsFixedGsfElectrons'), + isolationMap = cms.InputTag('electronEcalPFClusterIsolationProducer', '', cms.InputTag.skipCurrentProcess()) +) + +photonEcalPFClusterIsolationRemapper = cms.EDProducer('PhotonEcalPFClusterIsolationRemapper', + candidateProducer = cms.InputTag('gsFixedGEDPhotons'), + newToOldObjectMap = cms.InputTag('gsFixedGEDPhotons'), + isolationMap = cms.InputTag('photonEcalPFClusterIsolationProducer', '', cms.InputTag.skipCurrentProcess()) +) + +pfClusterIsolationRemapSequence = cms.Sequence( + electronHcalPFClusterIsolationRemapper + + photonHcalPFClusterIsolationRemapper + + electronEcalPFClusterIsolationRemapper + + photonEcalPFClusterIsolationRemapper +) diff --git a/RecoEgamma/EgammaPhotonProducers/interface/ConversionGSCrysFixer.h b/RecoEgamma/EgammaPhotonProducers/interface/ConversionGSCrysFixer.h new file mode 100644 index 0000000000000..bd499d1471d0c --- /dev/null +++ b/RecoEgamma/EgammaPhotonProducers/interface/ConversionGSCrysFixer.h @@ -0,0 +1,62 @@ +#ifndef RecoEgamma_EgammaPhotonProducers_ConversionGSCrysFixer_h +#define RecoEgamma_EgammaPhotonProducers_ConversionGSCrysFixer_h +/** \class ConversionGSCrysFixer + ** + ** + ** \author Yutaro Iiyama, MIT + ** + ***/ + +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/EgammaCandidates/interface/ConversionFwd.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" + +class ConversionGSCrysFixer : public edm::stream::EDProducer<> { + public: + + ConversionGSCrysFixer (const edm::ParameterSet&); + ~ConversionGSCrysFixer(); + + void produce(edm::Event&, const edm::EventSetup&) override; + + private: + typedef edm::ValueMap SCRefMap; + + template + void + getToken(edm::EDGetTokenT& token, edm::ParameterSet const& pset, std::string const& label, std::string const& instance = "") + { + auto tag(pset.getParameter(label)); + if (!instance.empty()) + tag = edm::InputTag(tag.label(), instance, tag.process()); + + token = consumes(tag); + } + template + edm::Handle + getHandle(edm::Event const& _event, edm::EDGetTokenT const& token, std::string const& name) + { + edm::Handle handle; + if (!_event.getByToken(token, handle)) + throw cms::Exception("ProductNotFound") << name; + + return handle; + } + + edm::EDGetTokenT inputConvsToken_; + // edm::EDGetTokenT inputSingleLegConvsToken_; + // edm::EDGetTokenT refinedSCsToken_; // new + // edm::EDGetTokenT refinedSCMapToken_; // new->old + edm::EDGetTokenT ebSCsToken_; // new + edm::EDGetTokenT ebSCMapToken_; // new->old + edm::EDGetTokenT eeSCsToken_; // new + edm::EDGetTokenT eeSCMapToken_; // new->old +}; + +#endif diff --git a/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonCoreGSCrysFixer.h b/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonCoreGSCrysFixer.h index 4eaad31ba2842..e261a66abc20e 100644 --- a/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonCoreGSCrysFixer.h +++ b/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonCoreGSCrysFixer.h @@ -3,56 +3,59 @@ #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/ESHandle.h" - - -#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" -#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Utilities/interface/Exception.h" -#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/Handle.h" #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/EgammaCandidates/interface/PhotonCoreFwd.h" -#include "DataFormats/EgammaCandidates/interface/PhotonCore.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHit.h" -#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" +#include "DataFormats/EgammaCandidates/interface/ConversionFwd.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" -#include "Geometry/CaloTopology/interface/CaloTopology.h" -#include "Geometry/Records/interface/CaloTopologyRecord.h" - -#include "RecoCaloTools/Navigation/interface/CaloNavigator.h" +class GEDPhotonCoreGSCrysFixer : public edm::stream::EDProducer<> { + public: -#include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" + GEDPhotonCoreGSCrysFixer (const edm::ParameterSet&); + ~GEDPhotonCoreGSCrysFixer(); -#include -#include + void produce(edm::Event&, const edm::EventSetup&) override; -class GEDPhotonCoreGSCrysFixer : public edm::stream::EDProducer<> { -public: - explicit GEDPhotonCoreGSCrysFixer(const edm::ParameterSet& ); - virtual ~GEDPhotonCoreGSCrysFixer(){} - - void produce(edm::Event&, const edm::EventSetup& ) override; - void beginLuminosityBlock(edm::LuminosityBlock const&, - edm::EventSetup const&) override; - + private: + typedef edm::ValueMap SCRefMap; + typedef edm::ValueMap ConvRefMap; template - void getToken(edm::EDGetTokenT& token,const edm::ParameterSet& pset,const std::string& label){ - token=consumes(pset.getParameter(label)); + void + getToken(edm::EDGetTokenT& token, edm::ParameterSet const& pset, std::string const& label, std::string const& instance = "") + { + auto tag(pset.getParameter(label)); + if (!instance.empty()) + tag = edm::InputTag(tag.label(), instance, tag.process()); + + token = consumes(tag); + } + template + edm::Handle + getHandle(edm::Event const& _event, edm::EDGetTokenT const& token, std::string const& name) + { + edm::Handle handle; + if (!_event.getByToken(token, handle)) + throw cms::Exception("ProductNotFound") << name; + + return handle; } -private: - edm::EDGetTokenT orgCoresToken_; - edm::EDGetTokenT ebRecHitsToken_; - edm::EDGetTokenT > oldRefinedSCToNewMapToken_; - edm::EDGetTokenT > oldSCToNewMapToken_; - const CaloTopology* topology_; - + + edm::EDGetTokenT inputCoresToken_; + edm::EDGetTokenT refinedSCsToken_; // new + edm::EDGetTokenT refinedSCMapToken_; // new->old + edm::EDGetTokenT ebSCsToken_; // new + edm::EDGetTokenT ebSCMapToken_; // new->old + edm::EDGetTokenT eeSCsToken_; // new + edm::EDGetTokenT eeSCMapToken_; // new->old + edm::EDGetTokenT convsToken_; // new + edm::EDGetTokenT convMapToken_; // new->old + edm::EDGetTokenT singleLegConvsToken_; // new + edm::EDGetTokenT singleLegConvMapToken_; // new->old }; + #endif diff --git a/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonGSCrysFixer.h b/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonGSCrysFixer.h index 0981f0acdc97d..7546192c7efc9 100644 --- a/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonGSCrysFixer.h +++ b/RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonGSCrysFixer.h @@ -2,65 +2,66 @@ #define RecoEgamma_EgammaPhotonProducers_GEDPhotonGSCrysFixer_h #include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/ESHandle.h" - - -#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" -#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" -#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/View.h" #include "DataFormats/Common/interface/ValueMap.h" -#include "DataFormats/EgammaCandidates/interface/PhotonCoreFwd.h" -#include "DataFormats/EgammaCandidates/interface/PhotonCore.h" -#include "DataFormats/EgammaCandidates/interface/Photon.h" #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/EgammaCandidates/interface/PhotonCoreFwd.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHit.h" -#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" + +#include "RecoEgamma/EgammaPhotonAlgos/interface/PhotonEnergyCorrector.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/CaloTopology/interface/CaloTopology.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "Geometry/Records/interface/CaloTopologyRecord.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "RecoCaloTools/Navigation/interface/CaloNavigator.h" +class GEDPhotonGSCrysFixer : public edm::stream::EDProducer<> { + public: -#include "CommonTools/CandAlgos/interface/ModifyObjectValueBase.h" + GEDPhotonGSCrysFixer (const edm::ParameterSet&); + ~GEDPhotonGSCrysFixer(); -#include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" + void beginRun(edm::Run const&, edm::EventSetup const&) override; + void produce(edm::Event&, const edm::EventSetup&) override; -#include -#include + private: + template + void + getToken(edm::EDGetTokenT& token, edm::ParameterSet const& pset, std::string const& label, std::string const& instance = "") + { + auto tag(pset.getParameter(label)); + if (!instance.empty()) + tag = edm::InputTag(tag.label(), instance, tag.process()); -class GEDPhotonGSCrysFixer : public edm::stream::EDProducer<> { -public: - explicit GEDPhotonGSCrysFixer(const edm::ParameterSet& ); - virtual ~GEDPhotonGSCrysFixer(){} - - void produce(edm::Event&, const edm::EventSetup& ) override; - void beginLuminosityBlock(edm::LuminosityBlock const&, - edm::EventSetup const&) override; - + token = consumes(tag); + } template - void getToken(edm::EDGetTokenT& token,const edm::ParameterSet& pset,const std::string& label){ - token=consumes(pset.getParameter(label)); + edm::Handle + getHandle(edm::Event const& iEvent, edm::EDGetTokenT const& token, std::string const& name) + { + edm::Handle handle; + if (!iEvent.getByToken(token, handle)) + throw cms::Exception("ProductNotFound") << name; + + return handle; } -private: - edm::EDGetTokenT oldGedPhosToken_; + + typedef edm::View PhotonView; + typedef edm::ValueMap SCRefMap; + + edm::EDGetTokenT inputPhotonsToken_; edm::EDGetTokenT newCoresToken_; - edm::EDGetTokenT ebRecHitsToken_; - edm::EDGetTokenT > newCoresToOldCoresMapToken_; - - const CaloTopology* topology_; - const CaloGeometry* geometry_; - std::unique_ptr gedRegression_; + edm::EDGetTokenT newCoresToOldSCMapToken_; + edm::EDGetTokenT ebHitsToken_; + edm::EDGetTokenT verticesToken_; + + PhotonEnergyCorrector energyCorrector_; + + CaloTopology const* topology_{0}; + CaloGeometry const* geometry_{0}; }; + #endif diff --git a/RecoEgamma/EgammaPhotonProducers/python/gsFixedConversions_cfi.py b/RecoEgamma/EgammaPhotonProducers/python/gsFixedConversions_cfi.py new file mode 100644 index 0000000000000..7a15ae9c07bde --- /dev/null +++ b/RecoEgamma/EgammaPhotonProducers/python/gsFixedConversions_cfi.py @@ -0,0 +1,7 @@ +import FWCore.ParameterSet.Config as cms + +gsFixedConversions = cms.EDProducer('ConversionGSCrysFixer', + conversions = cms.InputTag('allConversions', '', cms.InputTag.skipCurrentProcess()), + superClusters = cms.InputTag('particleFlowSuperClusterECALGSFixed'), + scMaps = cms.InputTag('gsFixedRefinedSuperClusters') +) diff --git a/RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotonCores_cfi.py b/RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotonCores_cfi.py new file mode 100644 index 0000000000000..a8fef0eb20a21 --- /dev/null +++ b/RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotonCores_cfi.py @@ -0,0 +1,8 @@ +import FWCore.ParameterSet.Config as cms + +gsFixedGEDPhotonCores = cms.EDProducer("GEDPhotonCoreGSCrysFixer", + photonCores = cms.InputTag("gedPhotonCore", '', cms.InputTag.skipCurrentProcess()), + refinedSCs = cms.InputTag('gsFixedRefinedSuperClusters'), + scs = cms.InputTag('particleFlowSuperClusterECALGSFixed'), + conversions = cms.InputTag('gsFixedConversions') +) diff --git a/RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotons_cfi.py b/RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotons_cfi.py new file mode 100644 index 0000000000000..1e07b9d23d3e8 --- /dev/null +++ b/RecoEgamma/EgammaPhotonProducers/python/gsFixedGEDPhotons_cfi.py @@ -0,0 +1,22 @@ +import FWCore.ParameterSet.Config as cms + +from RecoEgamma.EgammaTools.regressionModifier_cfi import * + +gsFixedGEDPhotons = cms.EDProducer('GEDPhotonGSCrysFixer', + photons = cms.InputTag('gedPhotons', '', cms.InputTag.skipCurrentProcess()), + newCores = cms.InputTag('gsFixedGEDPhotonCores'), + barrelEcalHits=cms.InputTag("ecalMultiAndGSWeightRecHitEB"), + primaryVertexProducer = cms.InputTag('offlinePrimaryVerticesWithBS'), + # rest for regression + minR9Barrel = cms.double(0.94), + minR9Endcap = cms.double(0.95), + endcapEcalHits = cms.InputTag('reducedEcalRecHitsEE'), + superClusterEnergyCorrFunction = cms.string("EcalClusterEnergyCorrection"), + superClusterEnergyErrorFunction = cms.string("EcalClusterEnergyUncertainty"), + superClusterCrackEnergyCorrFunction = cms.string("EcalClusterCrackCorrection"), + photonEcalEnergyCorrFunction = cms.string("EcalClusterEnergyCorrectionObjectSpecific"), + regressionConfig = regressionModifier.clone(rhoCollection = cms.InputTag("fixedGridRhoFastjetAllTmp")), + regressionWeightsFromDB = cms.bool(True), + energyRegressionWeightsFileLocation = cms.string('that this is required is dumb'), + energyRegressionWeightsDBLocation = cms.string('wgbrph') +) diff --git a/RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotonCores_cfi.py b/RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotonCores_cfi.py deleted file mode 100644 index 8ad9852d1661d..0000000000000 --- a/RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotonCores_cfi.py +++ /dev/null @@ -1,8 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -gsFixedGedPhotonCores = cms.EDProducer("GEDPhotonCoreGSCrysFixer", - orgCores=cms.InputTag("gedPhotonCore",processName=cms.InputTag.skipCurrentProcess()), - ebRecHits=cms.InputTag("reducedEcalRecHitsEB",processName=cms.InputTag.skipCurrentProcess()), ##ffs, weights dont have the gains switches set properly for some reason, doesnt matter, all we need this for is the gain so we can use orginal multifit - oldRefinedSCToNewMap=cms.InputTag("gsBrokenToGSFixedSuperClustersMap","refinedSCs"), - oldSCToNewMap=cms.InputTag("gsBrokenToGSFixedSuperClustersMap","parentSCs"), - ) diff --git a/RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotons_cfi.py b/RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotons_cfi.py deleted file mode 100644 index 2a33c7977c27e..0000000000000 --- a/RecoEgamma/EgammaPhotonProducers/python/gsFixedGedPhotons_cfi.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms -from RecoEgamma.EgammaTools.regressionModifier_cfi import regressionModifier - -gsFixedGedPhotons = cms.EDProducer("GEDPhotonGSCrysFixer", - newCores=cms.InputTag("gsFixedGedPhotonCores"), - oldPhos=cms.InputTag("gedPhotons",processName=cms.InputTag.skipCurrentProcess()), - ebRecHits=cms.InputTag("ecalMultiAndGSWeightRecHitEB"), - newCoresToOldCoresMap=cms.InputTag("gsFixedGedPhotonCores","parentCores"), - regressionConfig = regressionModifier.clone(rhoCollection=cms.InputTag("fixedGridRhoFastjetAllTmp")), - - - ) diff --git a/RecoEgamma/EgammaPhotonProducers/src/ConversionGSCrysFixer.cc b/RecoEgamma/EgammaPhotonProducers/src/ConversionGSCrysFixer.cc new file mode 100644 index 0000000000000..6627cab1c224b --- /dev/null +++ b/RecoEgamma/EgammaPhotonProducers/src/ConversionGSCrysFixer.cc @@ -0,0 +1,72 @@ +#include +/** \class ConversionGSCrysFixer + ** + ** + ** \author Yutaro Iiyama, MIT + ** + ***/ + +#include "RecoEgamma/EgammaPhotonProducers/interface/ConversionGSCrysFixer.h" + +#include "DataFormats/EgammaCandidates/interface/Conversion.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" +#include "DataFormats/Common/interface/RefToPtr.h" + +#include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" + +ConversionGSCrysFixer::ConversionGSCrysFixer(const edm::ParameterSet& config) +{ + // singleLegConversions = EGRefinedSCFixer + getToken(inputConvsToken_, config, "conversions"); + // getToken(inputSingleLegConvsToken_, config, "scMaps"); + // getToken(refinedSCsToken_, config, "scMaps"); + // getToken(refinedSCMapToken_, config, "scMaps"); + getToken(ebSCsToken_, config, "superClusters", "particleFlowSuperClusterECALBarrel"); + getToken(ebSCMapToken_, config, "scMaps", "parentSCsEB"); + getToken(eeSCsToken_, config, "superClusters", "particleFlowSuperClusterECALEndcapWithPreshower"); + getToken(eeSCMapToken_, config, "scMaps", "parentSCsEE"); + + produces(); +} + +ConversionGSCrysFixer::~ConversionGSCrysFixer() +{ +} + +void +ConversionGSCrysFixer::produce(edm::Event& _event, edm::EventSetup const&) +{ + std::auto_ptr pOutput(new reco::ConversionCollection); + + auto& inputConvs(*getHandle(_event, inputConvsToken_, "conversions")); + // auto& inputSingleLegConvs(*getHandle(_event, inputSingleLegConvsToken_, "singleLegConversions")); + // auto refinedSCs(getHandle(_event, refinedSCsToken_, "refinedSCs")); + // auto& refinedSCMap(*getHandle(_event, refinedSCMapToken_, "refinedSCMap")); + auto ebSCs(getHandle(_event, ebSCsToken_, "ebSCs")); + auto& ebSCMap(*getHandle(_event, ebSCMapToken_, "ebSCMap")); + auto eeSCs(getHandle(_event, eeSCsToken_, "eeSCs")); + auto& eeSCMap(*getHandle(_event, eeSCMapToken_, "eeSCMap")); + + for (auto& inConv : inputConvs) { + pOutput->emplace_back(inConv); + auto& newConv(pOutput->back()); + + reco::CaloClusterPtrVector clusters; + for (auto ptr : inConv.caloCluster()) { + auto* sc(static_cast(ptr.get())); + reco::SuperClusterRef newSC; + if (sc->seed()->seed().subdetId() == EcalBarrel) + newSC = GainSwitchTools::findNewRef(ptr, ebSCs, ebSCMap); + else + newSC = GainSwitchTools::findNewRef(ptr, eeSCs, eeSCMap); + + if (newSC.isNonnull()) + clusters.push_back(edm::refToPtr(newSC)); + } + + newConv.setMatchingSuperCluster(clusters); + } + + _event.put(pOutput); +} diff --git a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonCoreGSCrysFixer.cc b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonCoreGSCrysFixer.cc index b25fca6a9a3da..0b7892377c810 100644 --- a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonCoreGSCrysFixer.cc +++ b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonCoreGSCrysFixer.cc @@ -1,68 +1,90 @@ +#include + #include "RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonCoreGSCrysFixer.h" -namespace { - template edm::Handle getHandle(const edm::Event& iEvent,const edm::EDGetTokenT& token){ - edm::Handle handle; - iEvent.getByToken(token,handle); - return handle; - } -} +#include "DataFormats/EgammaCandidates/interface/PhotonCore.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" -GEDPhotonCoreGSCrysFixer::GEDPhotonCoreGSCrysFixer( const edm::ParameterSet & pset ) +GEDPhotonCoreGSCrysFixer::GEDPhotonCoreGSCrysFixer(const edm::ParameterSet& config) { - getToken(orgCoresToken_,pset,"orgCores"); - getToken(ebRecHitsToken_,pset,"ebRecHits"); - getToken(oldRefinedSCToNewMapToken_,pset,"oldRefinedSCToNewMap"); - getToken(oldSCToNewMapToken_,pset,"oldSCToNewMap"); - - produces(); - produces >("parentCores"); + getToken(inputCoresToken_, config, "photonCores"); + getToken(refinedSCsToken_, config, "refinedSCs"); + getToken(refinedSCMapToken_, config, "refinedSCs"); + getToken(ebSCsToken_, config, "scs", "particleFlowSuperClusterECALBarrel"); + getToken(ebSCMapToken_, config, "refinedSCs", "parentSCsEB"); + getToken(eeSCsToken_, config, "scs", "particleFlowSuperClusterECALEndcapWithPreshower"); + getToken(eeSCMapToken_, config, "refinedSCs", "parentSCsEE"); + getToken(convsToken_, config, "conversions"); + getToken(singleLegConvsToken_, config, "refinedSCs"); + + produces(); + produces(); // new core to old SC } +GEDPhotonCoreGSCrysFixer::~GEDPhotonCoreGSCrysFixer() +{ +} -void GEDPhotonCoreGSCrysFixer::produce( edm::Event & iEvent, const edm::EventSetup & iSetup ) +void +GEDPhotonCoreGSCrysFixer::produce(edm::Event& _event, edm::EventSetup const&) { - auto outCores = std::make_unique(); - - auto phoCoresHandle = getHandle(iEvent,orgCoresToken_); - auto& ebRecHits = *getHandle(iEvent,ebRecHitsToken_); - auto& oldRefinedSCToNewMap = *getHandle(iEvent,oldRefinedSCToNewMapToken_); - auto& oldSCToNewMap = *getHandle(iEvent,oldSCToNewMapToken_); - - std::vector parentCores; - - for(size_t coreNr=0;coreNrsize();coreNr++){ - reco::PhotonCoreRef coreRef(phoCoresHandle,coreNr); - const reco::PhotonCore& core = *coreRef; - - //passing in the old refined supercluster - if(GainSwitchTools::hasEBGainSwitchIn5x5(*core.superCluster(),&ebRecHits,topology_)){ - reco::PhotonCore newCore(core); - //these references may be null, lets see what happens! - //turns out the orginal pho may have null references, odd - if(core.superCluster().isNonnull()) newCore.setSuperCluster( oldRefinedSCToNewMap[core.superCluster()] ); - if(core.parentSuperCluster().isNonnull()) newCore.setParentSuperCluster( oldSCToNewMap[core.parentSuperCluster()] ); - - outCores->push_back(newCore); - parentCores.push_back(coreRef->superCluster()); + std::auto_ptr pOutput(new reco::PhotonCoreCollection); + + auto& inputCores(*getHandle(_event, inputCoresToken_, "photonCores")); + auto refinedSCs(getHandle(_event, refinedSCsToken_, "refinedSCs")); + auto& refinedSCMap(*getHandle(_event, refinedSCMapToken_, "refinedSCMap")); + auto ebSCs(getHandle(_event, ebSCsToken_, "ebSCs")); + auto& ebSCMap(*getHandle(_event, ebSCMapToken_, "ebSCMap")); + auto eeSCs(getHandle(_event, eeSCsToken_, "eeSCs")); + auto& eeSCMap(*getHandle(_event, eeSCMapToken_, "eeSCMap")); + auto convs(getHandle(_event, convsToken_, "conversions")); + auto singleLegConvs(getHandle(_event, singleLegConvsToken_, "singleLegConversions")); + + std::vector oldSCRefs; + + for (auto& inCore : inputCores) { + pOutput->emplace_back(); + auto& outCore(pOutput->back()); + + // NOTE: These mappings can result in NULL superclusters! + auto oldRefinedSC(inCore.superCluster()); + EBDetId seedId(oldRefinedSC->seed()->seed()); + + outCore.setSuperCluster(GainSwitchTools::findNewRef(oldRefinedSC, refinedSCs, refinedSCMap)); + + oldSCRefs.push_back(oldRefinedSC); + + auto parentSC(inCore.parentSuperCluster()); + if (parentSC.isNonnull()) { + if (parentSC->seed()->seed().subdetId() == EcalBarrel) + outCore.setParentSuperCluster(GainSwitchTools::findNewRef(parentSC, ebSCs, ebSCMap)); + else + outCore.setParentSuperCluster(GainSwitchTools::findNewRef(parentSC, eeSCs, eeSCMap)); } - } - - auto outCoresHandle = iEvent.put(std::move(outCores)); - - std::unique_ptr > parentCoresValMap(new edm::ValueMap()); - typename edm::ValueMap::Filler filler(*parentCoresValMap); - filler.insert(outCoresHandle, parentCores.begin(), parentCores.end()); - filler.fill(); - iEvent.put(std::move(parentCoresValMap),"parentCores"); -} -void GEDPhotonCoreGSCrysFixer::beginLuminosityBlock(edm::LuminosityBlock const& lb, - edm::EventSetup const& es) { - edm::ESHandle caloTopo ; - es.get().get(caloTopo); - topology_ = caloTopo.product(); -} + outCore.setPFlowPhoton(true); + outCore.setStandardPhoton(false); + // here we rely on ConversionGSCrysFixer and EGRefinedSCFixer translating conversions in the same order as the input + // super ugly and not safe but we don't have a dictionary for ValueMap + for (auto&& oldPtr : inCore.conversions()) + outCore.addConversion(reco::ConversionRef(convs, oldPtr.key())); + + for (auto&& oldPtr : inCore.conversionsOneLeg()) + outCore.addOneLegConversion(reco::ConversionRef(singleLegConvs, oldPtr.key())); + + for (auto&& seed : inCore.electronPixelSeeds()) + outCore.addElectronPixelSeed(seed); + } + + auto newCoresHandle(_event.put(pOutput)); + + std::auto_ptr pRefMap(new SCRefMap); + SCRefMap::Filler refMapFiller(*pRefMap); + refMapFiller.insert(newCoresHandle, oldSCRefs.begin(), oldSCRefs.end()); + refMapFiller.fill(); + _event.put(pRefMap); +} diff --git a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc index bbdf100772ac3..d4b7a47c1cf15 100644 --- a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc +++ b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc @@ -1,132 +1,257 @@ +#include +#include + #include "RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonGSCrysFixer.h" +#include "FWCore/Utilities/interface/isFinite.h" + +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" + +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/EgammaCandidates/interface/PhotonCore.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" + +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h" +#include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" + +typedef edm::ValueMap PhotonRefMap; + namespace { - template edm::Handle getHandle(const edm::Event& iEvent,const edm::EDGetTokenT& token){ - edm::Handle handle; - iEvent.getByToken(token,handle); - return handle; + reco::PhotonCoreRef + getNewCore(reco::Photon const& oldPho, edm::Handle const& newCores, edm::ValueMap const& scMap) + { + for (unsigned iC(0); iC != newCores->size(); ++iC) { + reco::PhotonCoreRef newCore(newCores, iC); + auto&& oldSCRef(scMap[newCore]); + if (oldSCRef.isNonnull() && oldSCRef == oldPho.superCluster()) + return newCore; + } + return reco::PhotonCoreRef(newCores.id()); } } -typedef edm::ValueMap PhotonRefMap; -typedef edm::ValueMap BoolMap; -GEDPhotonGSCrysFixer::GEDPhotonGSCrysFixer( const edm::ParameterSet & pset ) +GEDPhotonGSCrysFixer::GEDPhotonGSCrysFixer(const edm::ParameterSet& config) : + energyCorrector_(config, consumesCollector()) { - getToken(newCoresToken_,pset,"newCores"); - getToken(oldGedPhosToken_,pset,"oldPhos"); - getToken(ebRecHitsToken_,pset,"ebRecHits"); - getToken(newCoresToOldCoresMapToken_,pset,"newCoresToOldCoresMap"); - - //ripped wholesale from GEDPhotonFinalizer - if( pset.existsAs("regressionConfig") ) { - const edm::ParameterSet& iconf = pset.getParameterSet("regressionConfig"); - const std::string& mname = iconf.getParameter("modifierName"); - ModifyObjectValueBase* plugin = - ModifyObjectValueFactory::get()->create(mname,iconf); - gedRegression_.reset(plugin); - edm::ConsumesCollector sumes = consumesCollector(); - gedRegression_->setConsumes(sumes); - } else { - gedRegression_.reset(nullptr); + getToken(inputPhotonsToken_, config, "photons"); + getToken(newCoresToken_, config, "newCores"); + getToken(newCoresToOldSCMapToken_, config, "newCores"); + getToken(ebHitsToken_, config, "barrelEcalHits"); + getToken(verticesToken_, config, "primaryVertexProducer"); + + if(config.existsAs("regressionConfig")) { + auto&& collector(consumesCollector()); + energyCorrector_.gedRegression()->setConsumes(collector); } - produces(); + // output photon collection + produces(); + // new photon -> old photon produces(); - produces(); } -namespace { - - reco::PhotonCoreRef getNewCore(const reco::PhotonRef& oldPho, - edm::Handle& newCores, - edm::ValueMap newToOldCoresMap) - { - for(size_t coreNr=0;coreNrsize();coreNr++){ - reco::PhotonCoreRef coreRef(newCores,coreNr); - auto oldRef = newToOldCoresMap[coreRef]; - if( oldRef.isNonnull() && oldRef==oldPho->superCluster()){ - return coreRef; - } - } - return reco::PhotonCoreRef(newCores.id()); - } +GEDPhotonGSCrysFixer::~GEDPhotonGSCrysFixer() +{ } -void GEDPhotonGSCrysFixer::produce( edm::Event & iEvent, const edm::EventSetup & iSetup ) +void +GEDPhotonGSCrysFixer::beginRun(edm::Run const&, edm::EventSetup const& _setup) { - auto outPhos = std::make_unique(); - - if( gedRegression_ ) { - gedRegression_->setEvent(iEvent); - gedRegression_->setEventContent(iSetup); - } - + energyCorrector_.init(_setup); + + edm::ESHandle geometryHandle; + _setup.get().get(geometryHandle); + geometry_ = geometryHandle.product(); + + edm::ESHandle topologyHandle; + _setup.get().get(topologyHandle); + topology_ = topologyHandle.product(); +} + +void +GEDPhotonGSCrysFixer::produce(edm::Event& _event, const edm::EventSetup& _setup) +{ + std::auto_ptr pOutput(new reco::PhotonCollection); + + auto&& inputPhotonsHandle(getHandle(_event, inputPhotonsToken_, "photons")); + auto& inputPhotons(*inputPhotonsHandle); + auto&& newCoresHandle(getHandle(_event, newCoresToken_, "newCores")); + auto& newCoresToOldSCMap(*getHandle(_event, newCoresToOldSCMapToken_, "newCores")); + auto& ebHits(*getHandle(_event, ebHitsToken_, "ebHits")); + auto& vertices(*getHandle(_event, verticesToken_, "vertices")); - auto phosHandle = getHandle(iEvent,oldGedPhosToken_); - auto& ebRecHits = *getHandle(iEvent,ebRecHitsToken_); - auto& newCoresToOldCoresMap = *getHandle(iEvent,newCoresToOldCoresMapToken_); - auto newCoresHandle = getHandle(iEvent,newCoresToken_); + energyCorrector_.init(_setup); + if (energyCorrector_.gedRegression()) { + energyCorrector_.gedRegression()->setEvent(_event); + energyCorrector_.gedRegression()->setEventContent(_setup); + } std::vector oldPhotons; - std::vector isUpdated; - for(size_t phoNr=0;phoNrsize();phoNr++){ - reco::PhotonRef phoRef(phosHandle,phoNr); - oldPhotons.emplace_back(phoRef); + unsigned iP(0); + for (auto& inPhoton : inputPhotons) { + auto&& refToBase(inputPhotons.refAt(iP++)); + oldPhotons.emplace_back(refToBase.id(), &inPhoton, refToBase.key()); + + auto&& newCore(getNewCore(inPhoton, newCoresHandle, newCoresToOldSCMap)); - reco::PhotonCoreRef newCoreRef = getNewCore(phoRef,newCoresHandle,newCoresToOldCoresMap); - - if(newCoreRef.isNonnull()){ //okay we have to remake the photon + auto& oldSC(*inPhoton.photonCore()->superCluster()); + auto& newSC(*newCore->superCluster()); - reco::Photon newPho(*phoRef); - newPho.setPhotonCore(newCoreRef); + if (GainSwitchTools::hasEBGainSwitchIn5x5(oldSC, &ebHits, topology_)) { + auto&& caloPosition(newSC.position()); - reco::Photon::ShowerShape full5x5ShowerShape = GainSwitchTools::redoEcalShowerShape(newPho.full5x5_showerShapeVariables(),newPho.superCluster(),&ebRecHits,topology_,geometry_); - reco::Photon::ShowerShape showerShape = GainSwitchTools::redoEcalShowerShape(newPho.showerShapeVariables(),newPho.superCluster(),&ebRecHits,topology_,geometry_); + // will fix p4 later, but we apparently need the direction right + auto&& direction((caloPosition - inPhoton.vertex()).unit()); + math::XYZTLorentzVectorD p4(direction.x(), direction.y(), direction.z(), 1.); + + pOutput->emplace_back(p4, caloPosition, newCore, inPhoton.vertex()); + auto& outPhoton(pOutput->back()); - float eNewSCOverEOldSC = newPho.superCluster()->energy()/phoRef->superCluster()->energy(); - GainSwitchTools::correctHadem(showerShape,eNewSCOverEOldSC); - GainSwitchTools::correctHadem(full5x5ShowerShape,eNewSCOverEOldSC); + reco::Photon::FiducialFlags fflags; + fflags.isEB = inPhoton.isEB(); + fflags.isEE = inPhoton.isEE(); + fflags.isEBEtaGap = inPhoton.isEBEtaGap(); + fflags.isEBPhiGap = inPhoton.isEBPhiGap(); + fflags.isEERingGap = inPhoton.isEERingGap(); + fflags.isEEDeeGap = inPhoton.isEEDeeGap(); + fflags.isEBEEGap = inPhoton.isEBEEGap(); + + outPhoton.setFiducialVolumeFlags(fflags); + + reco::Photon::IsolationVariables iso04; + iso04.ecalRecHitSumEt = inPhoton.ecalRecHitSumEtConeDR04(); + iso04.hcalTowerSumEt = inPhoton.hcalTowerSumEtConeDR04(); + iso04.hcalDepth1TowerSumEt = inPhoton.hcalDepth1TowerSumEtConeDR04(); + iso04.hcalDepth2TowerSumEt = inPhoton.hcalDepth2TowerSumEtConeDR04(); + iso04.hcalTowerSumEtBc = inPhoton.hcalTowerSumEtBcConeDR04(); + iso04.hcalDepth1TowerSumEtBc = inPhoton.hcalDepth1TowerSumEtBcConeDR04(); + iso04.hcalDepth2TowerSumEtBc = inPhoton.hcalDepth2TowerSumEtBcConeDR04(); + iso04.trkSumPtSolidCone = inPhoton.trkSumPtSolidConeDR04(); + iso04.trkSumPtHollowCone = inPhoton.trkSumPtHollowConeDR04(); + iso04.nTrkSolidCone = inPhoton.nTrkSolidConeDR04(); + iso04.nTrkHollowCone = inPhoton.nTrkHollowConeDR04(); + + reco::Photon::IsolationVariables iso03; + iso03.ecalRecHitSumEt = inPhoton.ecalRecHitSumEtConeDR03(); + iso03.hcalTowerSumEt = inPhoton.hcalTowerSumEtConeDR03(); + iso03.hcalDepth1TowerSumEt = inPhoton.hcalDepth1TowerSumEtConeDR03(); + iso03.hcalDepth2TowerSumEt = inPhoton.hcalDepth2TowerSumEtConeDR03(); + iso03.hcalTowerSumEtBc = inPhoton.hcalTowerSumEtBcConeDR03(); + iso03.hcalDepth1TowerSumEtBc = inPhoton.hcalDepth1TowerSumEtBcConeDR03(); + iso03.hcalDepth2TowerSumEtBc = inPhoton.hcalDepth2TowerSumEtBcConeDR03(); + iso03.trkSumPtSolidCone = inPhoton.trkSumPtSolidConeDR03(); + iso03.trkSumPtHollowCone = inPhoton.trkSumPtHollowConeDR03(); + iso03.nTrkSolidCone = inPhoton.nTrkSolidConeDR03(); + iso03.nTrkHollowCone = inPhoton.nTrkHollowConeDR03(); + + outPhoton.setIsolationVariables(iso04, iso03); + + auto& newSeed(*newSC.seed()); + + auto&& cov(EcalClusterTools::covariances(newSeed, &ebHits, topology_, geometry_)); + auto&& locCov(EcalClusterTools::localCovariances(newSeed, &ebHits, topology_)); + auto&& cov55(noZS::EcalClusterTools::covariances(newSeed, &ebHits, topology_, geometry_)); + auto&& locCov55(noZS::EcalClusterTools::localCovariances(newSeed, &ebHits, topology_)); + + auto& oldSS(inPhoton.showerShapeVariables()); + reco::Photon::ShowerShape newSS; + + newSS.e1x5 = EcalClusterTools::e1x5(newSeed, &ebHits, topology_); + newSS.e2x5 = EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_); + newSS.e3x3 = EcalClusterTools::e3x3(newSeed, &ebHits, topology_); + newSS.e5x5 = EcalClusterTools::e5x5(newSeed, &ebHits, topology_); + newSS.maxEnergyXtal = EcalClusterTools::eMax(newSeed, &ebHits); + newSS.sigmaEtaEta = std::sqrt(cov[0]); + newSS.sigmaIetaIeta = std::sqrt(locCov[0]); + newSS.hcalDepth1OverEcal = oldSS.hcalDepth1OverEcal * oldSC.energy() / newSC.energy(); + newSS.hcalDepth2OverEcal = oldSS.hcalDepth2OverEcal * oldSC.energy() / newSC.energy(); + newSS.hcalDepth1OverEcalBc = oldSS.hcalDepth1OverEcalBc * oldSC.energy() / newSC.energy(); + newSS.hcalDepth2OverEcalBc = oldSS.hcalDepth2OverEcalBc * oldSC.energy() / newSC.energy(); + newSS.hcalTowersBehindClusters = oldSS.hcalTowersBehindClusters; + newSS.sigmaIetaIphi = locCov[1]; + newSS.sigmaIphiIphi = (edm::isFinite(locCov[2]) ? std::sqrt(locCov[2]) : 0.); + newSS.e2nd = EcalClusterTools::e2nd(newSeed, &ebHits); + newSS.eTop = EcalClusterTools::eTop(newSeed, &ebHits, topology_); + newSS.eLeft = EcalClusterTools::eLeft(newSeed, &ebHits, topology_); + newSS.eRight = EcalClusterTools::eRight(newSeed, &ebHits, topology_); + newSS.eBottom = EcalClusterTools::eBottom(newSeed, &ebHits, topology_); + newSS.e1x3 = EcalClusterTools::e1x3(newSeed, &ebHits, topology_); + newSS.e2x2 = EcalClusterTools::e2x2(newSeed, &ebHits, topology_); + newSS.e2x5Max = EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_); + newSS.e2x5Left = EcalClusterTools::e2x5Left(newSeed, &ebHits, topology_); + newSS.e2x5Right = EcalClusterTools::e2x5Right(newSeed, &ebHits, topology_); + newSS.e2x5Top = EcalClusterTools::e2x5Top(newSeed, &ebHits, topology_); + newSS.e2x5Bottom = EcalClusterTools::e2x5Bottom(newSeed, &ebHits, topology_); + newSS.effSigmaRR = oldSS.effSigmaRR; + + outPhoton.setShowerShapeVariables(newSS); + + reco::Photon::ShowerShape new55SS; + newSS.e1x5 = noZS::EcalClusterTools::e1x5(newSeed, &ebHits, topology_); + newSS.e2x5 = noZS::EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_); + newSS.e3x3 = noZS::EcalClusterTools::e3x3(newSeed, &ebHits, topology_); + newSS.e5x5 = noZS::EcalClusterTools::e5x5(newSeed, &ebHits, topology_); + new55SS.maxEnergyXtal = noZS::EcalClusterTools::eMax(newSeed, &ebHits); + new55SS.sigmaEtaEta = std::sqrt(cov55[0]); + new55SS.sigmaIetaIeta = std::sqrt(locCov55[0]); + new55SS.sigmaIetaIphi = locCov55[1]; + new55SS.sigmaIphiIphi = (edm::isFinite(locCov55[2]) ? std::sqrt(locCov55[2]) : 0.); + new55SS.e2nd = noZS::EcalClusterTools::e2nd(newSeed, &ebHits); + new55SS.eTop = noZS::EcalClusterTools::eTop(newSeed, &ebHits, topology_); + new55SS.eLeft = noZS::EcalClusterTools::eLeft(newSeed, &ebHits, topology_); + new55SS.eRight = noZS::EcalClusterTools::eRight(newSeed, &ebHits, topology_); + new55SS.eBottom = noZS::EcalClusterTools::eBottom(newSeed, &ebHits, topology_); + new55SS.e1x3 = noZS::EcalClusterTools::e1x3(newSeed, &ebHits, topology_); + new55SS.e2x2 = noZS::EcalClusterTools::e2x2(newSeed, &ebHits, topology_); + new55SS.e2x5Max = noZS::EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_); + new55SS.e2x5Left = noZS::EcalClusterTools::e2x5Left(newSeed, &ebHits, topology_); + new55SS.e2x5Right = noZS::EcalClusterTools::e2x5Right(newSeed, &ebHits, topology_); + new55SS.e2x5Top = noZS::EcalClusterTools::e2x5Top(newSeed, &ebHits, topology_); + new55SS.e2x5Bottom = noZS::EcalClusterTools::e2x5Bottom(newSeed, &ebHits, topology_); + new55SS.effSigmaRR = oldSS.effSigmaRR; + outPhoton.full5x5_setShowerShapeVariables(new55SS); - newPho.full5x5_setShowerShapeVariables(full5x5ShowerShape); - newPho.setShowerShapeVariables(showerShape); + reco::Photon::MIPVariables mipVars; + mipVars.mipChi2 = inPhoton.mipChi2(); + mipVars.mipTotEnergy = inPhoton.mipTotEnergy(); + mipVars.mipSlope = inPhoton.mipSlope(); + mipVars.mipIntercept = inPhoton.mipIntercept(); + mipVars.mipNhitCone = inPhoton.mipNhitCone(); + mipVars.mipIsHalo = inPhoton.mipIsHalo(); - if( gedRegression_ ) { - gedRegression_->modifyObject(newPho); - } + outPhoton.setMIPVariables(mipVars); - outPhos->push_back(newPho); - isUpdated.emplace_back(true); - }else{ - outPhos->push_back(*phoRef); - isUpdated.emplace_back(false); + outPhoton.setPflowIsolationVariables(inPhoton.getPflowIsolationVariables()); + + reco::Photon::PflowIDVariables pfid; + pfid.nClusterOutsideMustache = inPhoton.nClusterOutsideMustache(); + pfid.etOutsideMustache = inPhoton.etOutsideMustache(); + pfid.mva = inPhoton.pfMVA(); + + outPhoton.setPflowIDVariables(pfid); + + energyCorrector_.calculate(_event, outPhoton, newSeed.hitsAndFractions()[0].first.subdetId(), vertices, _setup); + + outPhoton.setP4(outPhoton.p4(inPhoton.getCandidateP4type())); + outPhoton.setCandidateP4type(inPhoton.getCandidateP4type()); + } + else { + pOutput->emplace_back(inPhoton); + auto& outPhoton(pOutput->back()); + outPhoton.setPhotonCore(newCore); } } - - auto&& newPhotonsHandle(iEvent.put(std::move(outPhos))); - std::unique_ptr pRefMap(new PhotonRefMap); + + edm::OrphanHandle newPhotonsHandle(_event.put(pOutput)); + + std::auto_ptr pRefMap(new PhotonRefMap); PhotonRefMap::Filler refMapFiller(*pRefMap); - std::unique_ptr bRefMap(new BoolMap); - BoolMap::Filler boolMapFiller(*bRefMap); refMapFiller.insert(newPhotonsHandle, oldPhotons.begin(), oldPhotons.end()); refMapFiller.fill(); - boolMapFiller.insert(newPhotonsHandle, isUpdated.begin(), isUpdated.end()); - boolMapFiller.fill(); - iEvent.put(std::move(pRefMap)); - iEvent.put(std::move(bRefMap)); -} - -void GEDPhotonGSCrysFixer::beginLuminosityBlock(edm::LuminosityBlock const& lb, - edm::EventSetup const& es) { - edm::ESHandle caloGeom ; - edm::ESHandle caloTopo ; - es.get().get(caloGeom); - es.get().get(caloTopo); - geometry_ = caloGeom.product(); - topology_ = caloTopo.product(); + _event.put(pRefMap); } - - - diff --git a/RecoEgamma/EgammaPhotonProducers/src/SealModule.cc b/RecoEgamma/EgammaPhotonProducers/src/SealModule.cc index 74b8428550151..78d6caf378e93 100644 --- a/RecoEgamma/EgammaPhotonProducers/src/SealModule.cc +++ b/RecoEgamma/EgammaPhotonProducers/src/SealModule.cc @@ -12,6 +12,7 @@ #include "RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonCoreProducer.h" #include "RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonProducer.h" #include "RecoEgamma/EgammaPhotonProducers/interface/ReducedEGProducer.h" +#include "RecoEgamma/EgammaPhotonProducers/interface/ConversionGSCrysFixer.h" #include "RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonCoreGSCrysFixer.h" #include "RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonGSCrysFixer.h" @@ -26,5 +27,6 @@ DEFINE_FWK_MODULE(ConversionTrackMerger); DEFINE_FWK_MODULE(GEDPhotonCoreProducer); DEFINE_FWK_MODULE(GEDPhotonProducer); DEFINE_FWK_MODULE(ReducedEGProducer); +DEFINE_FWK_MODULE(ConversionGSCrysFixer); DEFINE_FWK_MODULE(GEDPhotonCoreGSCrysFixer); DEFINE_FWK_MODULE(GEDPhotonGSCrysFixer); diff --git a/RecoEgamma/EgammaTools/interface/GainSwitchTools.h b/RecoEgamma/EgammaTools/interface/GainSwitchTools.h index 39407bced3c49..3aa0d2fc0f042 100644 --- a/RecoEgamma/EgammaTools/interface/GainSwitchTools.h +++ b/RecoEgamma/EgammaTools/interface/GainSwitchTools.h @@ -39,10 +39,15 @@ class GainSwitchTools { //needs to be multifit rec-hits currently as weights dont have gs flags set static std::vector gainSwitchedIdsIn5x5(const DetId& id,const EcalRecHitCollection* recHits,const CaloTopology* topology); - - - static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster& sc,edm::Handle scColl ); - static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster& sc,edm::Handle scColl,int maxDEta,int maxDPhi); + + template + static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster&, HANDLE const&); + template + static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster&, HANDLE const&, int maxDEta, int maxDPhi); + + // find an entry in H::element_type (a collection) that maps in M to R + template + static edm::Ref findNewRef(R const&, H const&, M const&); template static reco::GsfElectron::ShowerShape @@ -70,7 +75,59 @@ class GainSwitchTools { }; +template +edm::Ref +GainSwitchTools::findNewRef(R const& _oldRef, H const& _newHandle, M const& _map) +{ + for (unsigned iC(0); iC != _newHandle->size(); ++iC) { + edm::Ref ref(_newHandle, iC); + auto&& mappedRef(_map[ref]); + if (mappedRef.id() == _oldRef.id() && mappedRef.key() == _oldRef.key()) + return ref; + } + return edm::Ref(_newHandle.id()); +} + +template +reco::SuperClusterRef +GainSwitchTools::matchSCBySeedCrys(const reco::SuperCluster& sc, HANDLE const& scColl) +{ + for(size_t scNr=0;scNrsize();scNr++){ + if(scColl->at(scNr).seed()->seed().rawId() ==sc.seed()->seed().rawId()) + return reco::SuperClusterRef(scColl,scNr); + } + return reco::SuperClusterRef(nullptr,0); +} + +template +reco::SuperClusterRef +GainSwitchTools::matchSCBySeedCrys(const reco::SuperCluster& sc, HANDLE const& scColl,int maxDEta,int maxDPhi) +{ + reco::SuperClusterRef bestRef(scColl.id()); + int bestDIR2 = maxDEta*maxDEta+maxDPhi*maxDPhi+1; //+1 is to make it slightly bigger than max allowed + + if(sc.seed()->seed().subdetId()==EcalBarrel){ + EBDetId scDetId(sc.seed()->seed()); + + for(size_t scNr=0;scNrsize();scNr++){ + reco::SuperClusterRef matchRef(scColl,scNr); + if(matchRef->seed()->seed().subdetId()==EcalBarrel){ + EBDetId matchDetId(matchRef->seed()->seed()); + int dIEta = calDIEta(scDetId.ieta(),matchDetId.ieta()); + int dIPhi = calDIPhi(scDetId.iphi(),matchDetId.iphi()); + int dIR2 = dIEta*dIEta+dIPhi*dIPhi; + if(dIR2 reco::GsfElectron::ShowerShape diff --git a/RecoEgamma/EgammaTools/python/egammaGainSwitchFixForPAT_cff.py b/RecoEgamma/EgammaTools/python/egammaGainSwitchFixForPAT_cff.py new file mode 100644 index 0000000000000..edc0460dd8e7d --- /dev/null +++ b/RecoEgamma/EgammaTools/python/egammaGainSwitchFixForPAT_cff.py @@ -0,0 +1,48 @@ +import FWCore.ParameterSet.Config as cms + +from RecoEgamma.EgammaTools.egammaGainSwitchFix_cff import * + +# rename the products that stay in AOD event content +particleFlowEGammaGSFixed = gsFixedRefinedSuperClusters.clone( + fixedSC = 'particleFlowSuperClusterECALGSFixed', + fixedPFClusters = 'particleFlowClusterECALGSFixed' +) +gedGsfElectronCoresGSFixed = gsFixedGsfElectronCores.clone( + refinedSCs = 'particleFlowEGammaGSFixed', + scs = 'particleFlowSuperClusterECALGSFixed' +) +gedGsfElectronsGSFixed = gsFixedGsfElectrons.clone( + newCores = 'gedGsfElectronCoresGSFixed' +) +allConversionsGSFixed = gsFixedConversions.clone( + superClusters = 'particleFlowSuperClusterECALGSFixed', + scMaps = 'particleFlowEGammaGSFixed' +) +gedPhotonCoreGSFixed = gsFixedGEDPhotonCores.clone( + refinedSCs = 'particleFlowEGammaGSFixed', + scs = 'particleFlowSuperClusterECALGSFixed', + conversions = 'allConversionsGSFixed' +) +gedPhotonsGSFixed = gsFixedGEDPhotons.clone( + newCores = 'gedPhotonCoreGSFixed' +) + +gsFixedParticleFlowSuperClustering = cms.Sequence( + particleFlowRecHitECALGSFixed* + particleFlowRecHitPSGSFixed* + particleFlowClusterPSGSFixed* + particleFlowClusterECALUncorrectedGSFixed* + particleFlowClusterECALGSFixed* + particleFlowSuperClusterECALGSFixed +) + +egammaGainSwitchFixSequence = cms.Sequence( + egammaGainSwitchLocalFixSequence* + gsFixedParticleFlowSuperClustering* + particleFlowEGammaGSFixed* + gedGsfElectronCoresGSFixed* + gedGsfElectronsGSFixed* + allConversionsGSFixed* + gedPhotonCoreGSFixed* + gedPhotonsGSFixed +) diff --git a/RecoEgamma/EgammaTools/python/egammaGainSwitchFixTools.py b/RecoEgamma/EgammaTools/python/egammaGainSwitchFixTools.py index f35fc47838d0d..4a86ea77b6ef8 100644 --- a/RecoEgamma/EgammaTools/python/egammaGainSwitchFixTools.py +++ b/RecoEgamma/EgammaTools/python/egammaGainSwitchFixTools.py @@ -47,7 +47,7 @@ def customiseForAODGainSwitchFix(process,newNameSuffex=""): "particleFlowClusterECALUncorrectedGSFixed" : "particleFlowClusterECALUncorrected" + newNameSuffex, "particleFlowClusterECALGSFixed" : "particleFlowClusterECAL" + newNameSuffex, "particleFlowSuperClusterECALGSFixed" : "particleFlowSuperClusterECAL" + newNameSuffex, - "gsFixedRefinedBarrelSuperClusters" : "particleFlowEGamma" + newNameSuffex, + "gsFixedRefinedSuperClusters" : "particleFlowEGamma" + newNameSuffex, "gsFixedGsfElectronCores" : "gedGsfElectronCores" + newNameSuffex, "gsFixedGsfElectrons" : "gedGsfElectrons" + newNameSuffex, "gsFixedGedPhotonCores" : "gedPhotonCore" + newNameSuffex, diff --git a/RecoEgamma/EgammaTools/python/egammaGainSwitchFixToolsForPAT_cff.py b/RecoEgamma/EgammaTools/python/egammaGainSwitchFixToolsForPAT_cff.py new file mode 100644 index 0000000000000..5a701911b18a5 --- /dev/null +++ b/RecoEgamma/EgammaTools/python/egammaGainSwitchFixToolsForPAT_cff.py @@ -0,0 +1,35 @@ +import FWCore.ParameterSet.Config as cms + +def customizeGSFixForPAT(process): + + process.reducedEgamma.gsfElectrons = cms.InputTag("gedGsfElectronsGSFixed") + process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag("particleBasedIsolationGSFixed","gedGsfElectrons") + process.reducedEgamma.gsfElectronPFClusterIsoSources = cms.VInputTag( + cms.InputTag("electronEcalPFClusterIsolationProducerGSFixed"), + cms.InputTag("electronHcalPFClusterIsolationProducerGSFixed"), + ) + process.reducedEgamma.gsfElectronIDSources = cms.VInputTag( + cms.InputTag("eidLooseGSFixed"), + cms.InputTag("eidRobustHighEnergyGSFixed"), + cms.InputTag("eidRobustLooseGSFixed"), + cms.InputTag("eidRobustTightGSFixed"), + cms.InputTag("eidTightGSFixed"), + ) + process.reducedEgamma.photons = cms.InputTag("gedPhotonsGSFixed") + process.reducedEgamma.conversions = cms.InputTag("allConversionsGSFixed") + process.reducedEgamma.singleConversions = cms.InputTag("particleFlowEGammaGSFixed") + process.reducedEgamma.photonsPFValMap = cms.InputTag("particleBasedIsolationGSFixed","gedPhotons") + process.reducedEgamma.photonPFClusterIsoSources = cms.VInputTag( + cms.InputTag("photonEcalPFClusterIsolationProducerGSFixed"), + cms.InputTag("photonHcalPFClusterIsolationProducerGSFixed"), + ) + process.reducedEgamma.photonIDSources = cms.VInputTag( + cms.InputTag("PhotonCutBasedIDLooseGSFixed"), + cms.InputTag("PhotonCutBasedIDLooseEMGSFixed"), + cms.InputTag("PhotonCutBasedIDTightGSFixed") + ) + process.reducedEgamma.barrelEcalHits = cms.InputTag("ecalMultiAndGSWeightRecHitEB") + process.reducedEgamma.endcapEcalHits = cms.InputTag("reducedEcalRecHitsEE") + process.reducedEgamma.preshowerEcalHits = cms.InputTag("reducedEcalRecHitsES") + + return process diff --git a/RecoEgamma/EgammaTools/python/egammaGainSwitchFix_cff.py b/RecoEgamma/EgammaTools/python/egammaGainSwitchFix_cff.py index 0bc4db62c9563..c43f935797ae3 100644 --- a/RecoEgamma/EgammaTools/python/egammaGainSwitchFix_cff.py +++ b/RecoEgamma/EgammaTools/python/egammaGainSwitchFix_cff.py @@ -9,36 +9,38 @@ from RecoEcal.EgammaClusterProducers.gsFixedSuperClustering_cff import * #this module remakes the refined EGamma superclusters although it has to approximate them as there is not #enough info in AOD to properly remake them -from RecoEcal.EgammaClusterProducers.gsFixedRefinedBarrelSuperClusters_cfi import * -#this makes a make of old superclusters with the gs issue to new superclusters without the gs issue -from RecoEcal.EgammaClusterProducers.gsBrokenToGSFixedSuperClustersMap_cfi import * +from RecoEcal.EgammaClusterProducers.gsFixedRefinedSuperClusters_cfi import * #this makes makes a new colleciton of gsfelectron cores, modifying only those that have a gs eb crystal from RecoEgamma.EgammaElectronProducers.gsFixedGsfElectronCores_cfi import * #turns the cores into gsf electrons, again only modifying those which have a gs eb crystal from RecoEgamma.EgammaElectronProducers.gsFixedGsfElectrons_cfi import * -#this makes makes a new colleciton of ged photon cores, modifying only those that have a gs eb crystal -from RecoEgamma.EgammaPhotonProducers.gsFixedGedPhotonCores_cfi import * -#turns the cores into ged photons, again only modifying those which have a gs eb crystal -from RecoEgamma.EgammaPhotonProducers.gsFixedGedPhotons_cfi import * +#this makes makes a new colleciton of photon cores, modifying only those that have a gs eb crystal +from RecoEgamma.EgammaPhotonProducers.gsFixedGEDPhotonCores_cfi import * +#turns the cores into photons, again only modifying those which have a gs eb crystal +from RecoEgamma.EgammaPhotonProducers.gsFixedGEDPhotons_cfi import * +#replace the superclusters of allConversions +from RecoEgamma.EgammaPhotonProducers.gsFixedConversions_cfi import * -egammaGainSwitchFixSequence = cms.Sequence( -# bunchSpacingProducer* +egammaGainSwitchLocalFixSequence = cms.Sequence( ecalWeightLocalRecoFromSelectedDigis* - ecalMultiAndGSWeightRecHitEB* + ecalMultiAndGSWeightRecHitEB +) + +egammaGainSwitchFixSequence = cms.Sequence( + egammaGainSwitchLocalFixSequence* gsFixedParticleFlowSuperClustering* - gsFixedRefinedBarrelSuperClusters* - gsBrokenToGSFixedSuperClustersMap* + gsFixedRefinedSuperClusters* gsFixedGsfElectronCores* gsFixedGsfElectrons* - gsFixedGedPhotonCores* - gsFixedGedPhotons) + gsFixedConversions* + gsFixedGEDPhotonCores* + gsFixedGEDPhotons + ) from RecoEgamma.EgammaElectronProducers.gsSimpleFixedGsfElectrons_cfi import gsSimpleFixedGsfElectrons from RecoEgamma.EgammaElectronProducers.gsSimpleFixedPhotons_cfi import gsSimpleFixedPhotons egammaGainSwitchSimpleFixSequence = cms.Sequence( -# bunchSpacingProducer* - ecalWeightLocalRecoFromSelectedDigis* - ecalMultiAndGSWeightRecHitEB* + egammaGainSwitchLocalFixSequence* gsSimpleFixedGsfElectrons* gsSimpleFixedPhotons) diff --git a/RecoEgamma/EgammaTools/src/GainSwitchTools.cc b/RecoEgamma/EgammaTools/src/GainSwitchTools.cc index 6d567ce10f75e..0083083d6cfab 100644 --- a/RecoEgamma/EgammaTools/src/GainSwitchTools.cc +++ b/RecoEgamma/EgammaTools/src/GainSwitchTools.cc @@ -98,45 +98,6 @@ float GainSwitchTools::newRawEnergyNoFracs(const reco::SuperCluster& superClus,c } - -reco::SuperClusterRef GainSwitchTools::matchSCBySeedCrys(const reco::SuperCluster& sc,edm::Handle scColl ) -{ - for(size_t scNr=0;scNrsize();scNr++){ - reco::SuperClusterRef scRef(scColl,scNr); - if(scRef->seed()->seed().rawId() ==sc.seed()->seed().rawId()) return scRef; - } - return reco::SuperClusterRef(nullptr,0); -} - -reco::SuperClusterRef GainSwitchTools::matchSCBySeedCrys(const reco::SuperCluster& sc,edm::Handle scColl,int maxDEta,int maxDPhi) -{ - reco::SuperClusterRef bestRef(scColl.id()); - - int bestDIR2 = maxDEta*maxDEta+maxDPhi*maxDPhi+1; //+1 is to make it slightly bigger than max allowed - - if(sc.seed()->seed().subdetId()==EcalBarrel){ - EBDetId scDetId(sc.seed()->seed()); - - for(size_t scNr=0;scNrsize();scNr++){ - reco::SuperClusterRef matchRef(scColl,scNr); - if(matchRef->seed()->seed().subdetId()==EcalBarrel){ - EBDetId matchDetId(matchRef->seed()->seed()); - int dIEta = calDIEta(scDetId.ieta(),matchDetId.ieta()); - int dIPhi = calDIPhi(scDetId.iphi(),matchDetId.iphi()); - int dIR2 = dIEta*dIEta+dIPhi*dIPhi; - if(dIR2(config.getParameter("candidateProducer"))), + newToOldObjectMap_ (consumes(config.getParameter("newToOldObjectMap"))), + idMap_ (consumes >(config.getParameter("idMap"))) +{ + produces >(); +} + +ElectronIDExternalProducerRemapper::~ElectronIDExternalProducerRemapper() +{ +} + +void ElectronIDExternalProducerRemapper::produce(edm::Event& iEvent, const edm::EventSetup&) +{ + edm::Handle emObjectHandle; + iEvent.getByToken(emObjectProducer_, emObjectHandle); + + edm::Handle objectMapHandle; + iEvent.getByToken(newToOldObjectMap_, objectMapHandle); + auto& objectMap(*objectMapHandle); + + edm::Handle > idMapHandle; + iEvent.getByToken(idMap_, idMapHandle); + auto& idMap(*idMapHandle); + + std::vector retV(emObjectHandle->size(), 0.); + + for (unsigned iO(0); iO != emObjectHandle->size(); ++iO) { + CRef ref(emObjectHandle, iO); + auto oldRef(objectMap[ref]); + retV[iO] = idMap[oldRef]; + } + + std::auto_ptr > isoMap(new edm::ValueMap); + edm::ValueMap::Filler filler(*isoMap); + + filler.insert(emObjectHandle, retV.begin(), retV.end()); + filler.fill(); + + iEvent.put(isoMap); +} + + +DEFINE_FWK_MODULE(ElectronIDExternalProducerRemapper); diff --git a/RecoEgamma/ElectronIdentification/plugins/ElectronIDExternalProducerRemapper.h b/RecoEgamma/ElectronIdentification/plugins/ElectronIDExternalProducerRemapper.h new file mode 100644 index 0000000000000..f46e8948d26ff --- /dev/null +++ b/RecoEgamma/ElectronIdentification/plugins/ElectronIDExternalProducerRemapper.h @@ -0,0 +1,29 @@ +#ifndef EgammaIsolationRemappers_ElectronIDExternalProducerRemapper_h +#define EgammaIsolationRemappers_ElectronIDExternalProducerRemapper_h + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/Common/interface/Ref.h" + +#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" + +class ElectronIDExternalProducerRemapper : public edm::stream::EDProducer<> { + public: + ElectronIDExternalProducerRemapper(const edm::ParameterSet&); + ~ElectronIDExternalProducerRemapper(); + + void produce(edm::Event&, const edm::EventSetup&); + private: + typedef typename edm::refhelper::ValueTrait::value Value; + typedef edm::Ref::value> CRef; + typedef edm::ValueMap CRefMap; + + edm::EDGetTokenT emObjectProducer_; + edm::EDGetTokenT newToOldObjectMap_; + edm::EDGetTokenT > idMap_; +}; + +#endif diff --git a/RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.cc b/RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.cc new file mode 100644 index 0000000000000..90fef9be2c4f0 --- /dev/null +++ b/RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.cc @@ -0,0 +1,52 @@ +#include "RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.h" + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/Common/interface/Handle.h" + +PhotonIDExternalProducerRemapper::PhotonIDExternalProducerRemapper(const edm::ParameterSet& config) : + emObjectProducer_ (consumes(config.getParameter("candidateProducer"))), + newToOldObjectMap_ (consumes(config.getParameter("newToOldObjectMap"))), + idMap_ (consumes >(config.getParameter("idMap"))) +{ + produces >(); +} + +PhotonIDExternalProducerRemapper::~PhotonIDExternalProducerRemapper() +{ +} + +void PhotonIDExternalProducerRemapper::produce(edm::Event& iEvent, const edm::EventSetup&) +{ + edm::Handle emObjectHandle; + iEvent.getByToken(emObjectProducer_, emObjectHandle); + + edm::Handle objectMapHandle; + iEvent.getByToken(newToOldObjectMap_, objectMapHandle); + auto& objectMap(*objectMapHandle); + + edm::Handle > idMapHandle; + iEvent.getByToken(idMap_, idMapHandle); + auto& idMap(*idMapHandle); + + std::vector retV(emObjectHandle->size(), 0.); + + for (unsigned iO(0); iO != emObjectHandle->size(); ++iO) { + CRef ref(emObjectHandle, iO); + auto oldRef(objectMap[ref]); + retV[iO] = idMap[oldRef]; + } + + std::auto_ptr > isoMap(new edm::ValueMap); + edm::ValueMap::Filler filler(*isoMap); + + filler.insert(emObjectHandle, retV.begin(), retV.end()); + filler.fill(); + + iEvent.put(isoMap); +} + + +DEFINE_FWK_MODULE(PhotonIDExternalProducerRemapper); diff --git a/RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.h b/RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.h new file mode 100644 index 0000000000000..f2c270b5b2f31 --- /dev/null +++ b/RecoEgamma/ElectronIdentification/plugins/PhotonIDExternalProducerRemapper.h @@ -0,0 +1,29 @@ +#ifndef EgammaIsolationRemappers_PhotonIDExternalProducerRemapper_h +#define EgammaIsolationRemappers_PhotonIDExternalProducerRemapper_h + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/Common/interface/Ref.h" + +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" + +class PhotonIDExternalProducerRemapper : public edm::stream::EDProducer<> { + public: + PhotonIDExternalProducerRemapper(const edm::ParameterSet&); + ~PhotonIDExternalProducerRemapper(); + + void produce(edm::Event&, const edm::EventSetup&); + private: + typedef typename edm::refhelper::ValueTrait::value Value; + typedef edm::Ref::value> CRef; + typedef edm::ValueMap CRefMap; + + edm::EDGetTokenT emObjectProducer_; + edm::EDGetTokenT newToOldObjectMap_; + edm::EDGetTokenT > idMap_; +}; + +#endif diff --git a/RecoEgamma/ElectronIdentification/python/idExternalRemapForPAT_cff.py b/RecoEgamma/ElectronIdentification/python/idExternalRemapForPAT_cff.py new file mode 100644 index 0000000000000..c5ae4fe7c6480 --- /dev/null +++ b/RecoEgamma/ElectronIdentification/python/idExternalRemapForPAT_cff.py @@ -0,0 +1,57 @@ +import FWCore.ParameterSet.Config as cms + +from RecoEgamma.ElectronIdentification.idExternalRemap_cfi import * + +eidLooseGSFixed = eidLoose.clone( + candidateProducer = cms.InputTag('gedGsfElectronsGSFixed'), + newToOldObjectMap = cms.InputTag('gedGsfElectronsGSFixed'), +) + +eidRobustHighEnergyGSFixed = eidRobustHighEnergy.clone( + candidateProducer = cms.InputTag('gedGsfElectronsGSFixed'), + newToOldObjectMap = cms.InputTag('gedGsfElectronsGSFixed'), +) + +eidRobustLooseGSFixed = eidRobustLoose.clone( + candidateProducer = cms.InputTag('gedGsfElectronsGSFixed'), + newToOldObjectMap = cms.InputTag('gedGsfElectronsGSFixed'), +) + +eidRobustTightGSFixed = eidRobustTight.clone( + candidateProducer = cms.InputTag('gedGsfElectronsGSFixed'), + newToOldObjectMap = cms.InputTag('gedGsfElectronsGSFixed'), +) + +eidTightGSFixed = eidTight.clone( + candidateProducer = cms.InputTag('gedGsfElectronsGSFixed'), + newToOldObjectMap = cms.InputTag('gedGsfElectronsGSFixed'), +) + +ElectronIDExternalProducerRemapSequence = cms.Sequence( + eidLooseGSFixed + + eidRobustHighEnergyGSFixed + + eidRobustLooseGSFixed + + eidRobustTightGSFixed + + eidTightGSFixed +) + +PhotonCutBasedIDLooseGSFixed = PhotonCutBasedIDLoose.clone( + candidateProducer = cms.InputTag('gedPhotonsGSFixed'), + newToOldObjectMap = cms.InputTag('gedPhotonsGSFixed'), +) + +PhotonCutBasedIDLooseEMGSFixed = PhotonCutBasedIDLooseEM.clone( + candidateProducer = cms.InputTag('gedPhotonsGSFixed'), + newToOldObjectMap = cms.InputTag('gedPhotonsGSFixed'), +) + +PhotonCutBasedIDTightGSFixed = PhotonCutBasedIDTight.clone( + candidateProducer = cms.InputTag('gedPhotonsGSFixed'), + newToOldObjectMap = cms.InputTag('gedPhotonsGSFixed'), +) + +PhotonIDExternalProducerRemapSequence = cms.Sequence( + PhotonCutBasedIDLooseGSFixed + + PhotonCutBasedIDLooseEMGSFixed + + PhotonCutBasedIDTightGSFixed +) diff --git a/RecoEgamma/ElectronIdentification/python/idExternalRemap_cfi.py b/RecoEgamma/ElectronIdentification/python/idExternalRemap_cfi.py new file mode 100644 index 0000000000000..0725703558ddb --- /dev/null +++ b/RecoEgamma/ElectronIdentification/python/idExternalRemap_cfi.py @@ -0,0 +1,63 @@ +import FWCore.ParameterSet.Config as cms + +eidLoose = cms.EDProducer('ElectronIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGsfElectrons'), + newToOldObjectMap = cms.InputTag('gsFixedGsfElectrons'), + idMap = cms.InputTag('eidLoose', '', cms.InputTag.skipCurrentProcess()) +) + +eidRobustHighEnergy = cms.EDProducer('ElectronIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGsfElectrons'), + newToOldObjectMap = cms.InputTag('gsFixedGsfElectrons'), + idMap = cms.InputTag('eidRobustHighEnergy', '', cms.InputTag.skipCurrentProcess()) +) + +eidRobustLoose = cms.EDProducer('ElectronIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGsfElectrons'), + newToOldObjectMap = cms.InputTag('gsFixedGsfElectrons'), + idMap = cms.InputTag('eidRobustLoose', '', cms.InputTag.skipCurrentProcess()) +) + +eidRobustTight = cms.EDProducer('ElectronIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGsfElectrons'), + newToOldObjectMap = cms.InputTag('gsFixedGsfElectrons'), + idMap = cms.InputTag('eidRobustTight', '', cms.InputTag.skipCurrentProcess()) +) + +eidTight = cms.EDProducer('ElectronIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGsfElectrons'), + newToOldObjectMap = cms.InputTag('gsFixedGsfElectrons'), + idMap = cms.InputTag('eidTight', '', cms.InputTag.skipCurrentProcess()) +) + +PhotonCutBasedIDLoose = cms.EDProducer('PhotonIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGedPhoton'), + newToOldObjectMap = cms.InputTag('gsFixedGedPhoton'), + idMap = cms.InputTag('PhotonIDProdGED', 'PhotonCutBasedIDLoose', cms.InputTag.skipCurrentProcess()) +) + +PhotonCutBasedIDLooseEM = cms.EDProducer('PhotonIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGedPhoton'), + newToOldObjectMap = cms.InputTag('gsFixedGedPhoton'), + idMap = cms.InputTag('PhotonIDProdGED', 'PhotonCutBasedIDLooseEM', cms.InputTag.skipCurrentProcess()) +) + +PhotonCutBasedIDTight = cms.EDProducer('PhotonIDExternalProducerRemapper', + candidateProducer = cms.InputTag('gsFixedGedPhoton'), + newToOldObjectMap = cms.InputTag('gsFixedGedPhoton'), + idMap = cms.InputTag('PhotonIDProdGED', 'PhotonCutBasedIDTight', cms.InputTag.skipCurrentProcess()) +) + +ElectronIDExternalProducerRemapSequence = cms.Sequence( + eidLoose + + eidRobustHighEnergy + + eidRobustLoose + + eidRobustTight + + eidTight +) + +PhotonIDExternalProducerRemapSequence = cms.Sequence( + PhotonCutBasedIDLoose + + PhotonCutBasedIDLooseEM + + PhotonCutBasedIDTight +) diff --git a/RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.cc b/RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.cc new file mode 100644 index 0000000000000..66acf381364c8 --- /dev/null +++ b/RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.cc @@ -0,0 +1,91 @@ +#include "RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" + +#include "RecoParticleFlow/PFProducer/interface/GsfElectronEqual.h" +#include "RecoParticleFlow/PFProducer/interface/PhotonEqual.h" + +#include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" + +#include "FWCore/Framework/interface/MakerMacros.h" + +typedef edm::ValueMap PFPtrMap; + +PFEGFootprintGSFixLinker::PFEGFootprintGSFixLinker(edm::ParameterSet const& _config) : + electronsMapName_(_config.getParameter("ValueMapElectrons")), + photonsMapName_(_config.getParameter("ValueMapPhotons")) +{ + getToken(newCandidatesToken_, _config, "PFCandidate"); + getToken(newElectronsToken_, _config, "GsfElectrons"); + getToken(newPhotonsToken_, _config, "Photons"); + getToken(electronMapToken_, _config, "GsfElectrons"); + getToken(photonMapToken_, _config, "Photons"); + getToken(electronFootprintMapToken_, _config, "GsfElectronsFootprint"); + getToken(photonFootprintMapToken_, _config, "PhotonsFootprint"); + + // e/g collections to footprint PFs + produces(electronsMapName_); + produces(photonsMapName_); +} + +PFEGFootprintGSFixLinker::~PFEGFootprintGSFixLinker() +{ +} + +void +PFEGFootprintGSFixLinker::produce(edm::Event& _event, edm::EventSetup const&) +{ + auto&& newCandidatesHandle(getHandle(_event, newCandidatesToken_, "PFCandidate")); + auto&& newElectronsHandle(getHandle(_event, newElectronsToken_, "GsfElectrons")); + auto& electronMap(*getHandle(_event, electronMapToken_, "GsfElectronsMap")); + auto&& newPhotonsHandle(getHandle(_event, newPhotonsToken_, "Photons")); + auto& photonMap(*getHandle(_event, photonMapToken_, "PhotonsMap")); + auto& electronFootprintMap(*getHandle(_event, electronFootprintMapToken_, "GsfElectronsFootprint")); + auto& photonFootprintMap(*getHandle(_event, photonFootprintMapToken_, "PhotonsFootprint")); + + std::vector electronFootprints; + + for (unsigned iE(0); iE != newElectronsHandle->size(); ++iE) { + electronFootprints.emplace_back(); + auto& footprint(electronFootprints.back()); + + reco::GsfElectronRef ref(newElectronsHandle, iE); + auto& oldEleRef(electronMap[ref]); + auto& oldFootprint(electronFootprintMap[oldEleRef]); + // relying on PFGSFixLinker producing PF candidates in the same order + for (auto& pfref : oldFootprint) + footprint.emplace_back(newCandidatesHandle, pfref.key()); + } + + std::auto_ptr pEleFPMap(new FootprintMap); + FootprintMap::Filler eleFPMapFiller(*pEleFPMap); + eleFPMapFiller.insert(newElectronsHandle, electronFootprints.begin(), electronFootprints.end()); + eleFPMapFiller.fill(); + _event.put(pEleFPMap, electronsMapName_); + + std::vector photonFootprints; + + for (unsigned iE(0); iE != newPhotonsHandle->size(); ++iE) { + photonFootprints.emplace_back(); + auto& footprint(photonFootprints.back()); + + reco::PhotonRef ref(newPhotonsHandle, iE); + auto& oldPhoRef(photonMap[ref]); + auto& oldFootprint(photonFootprintMap[oldPhoRef]); + // relying on PFGSFixLinker producing PF candidates in the same order + for (auto& pfref : oldFootprint) + footprint.emplace_back(newCandidatesHandle, pfref.key()); + } + + std::auto_ptr pPhoFPMap(new FootprintMap); + FootprintMap::Filler phoFPMapFiller(*pPhoFPMap); + phoFPMapFiller.insert(newPhotonsHandle, photonFootprints.begin(), photonFootprints.end()); + phoFPMapFiller.fill(); + _event.put(pPhoFPMap, photonsMapName_); +} + +DEFINE_FWK_MODULE(PFEGFootprintGSFixLinker); diff --git a/RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.h b/RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.h new file mode 100644 index 0000000000000..139034c7e1a71 --- /dev/null +++ b/RecoParticleFlow/PFProducer/plugins/PFEGFootprintGSFixLinker.h @@ -0,0 +1,66 @@ +#ifndef RecoParticleFlow_PFProducer_PFEGFootprintGSFixLinker_h +#define RecoParticleFlow_PFProducer_PFEGFootprintGSFixLinker_h + +/** \class PFEGFootprintGSFixLinker + * Relink GS-fixed e/gamma objects + * \author Y. Iiyama (MIT) + */ + +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" + +#include + +class PFEGFootprintGSFixLinker : public edm::stream::EDProducer<> { + public: + explicit PFEGFootprintGSFixLinker(const edm::ParameterSet&); + ~PFEGFootprintGSFixLinker(); + + void produce(edm::Event&, const edm::EventSetup&) override; + + template + void + getToken(edm::EDGetTokenT& token, edm::ParameterSet const& pset, std::string const& label) + { + token = consumes(pset.getParameter(label)); + } + template + edm::Handle + getHandle(edm::Event const& _event, edm::EDGetTokenT const& token, std::string const& name) + { + edm::Handle handle; + if (!_event.getByToken(token, handle)) + throw cms::Exception("ProductNotFound") << name; + + return handle; + } + + private: + typedef edm::ValueMap ElectronRefMap; + typedef edm::ValueMap PhotonRefMap; + typedef std::vector Footprint; + typedef edm::ValueMap FootprintMap; + + edm::EDGetTokenT newCandidatesToken_; + edm::EDGetTokenT newElectronsToken_; + edm::EDGetTokenT newPhotonsToken_; + // new -> old map + edm::EDGetTokenT electronMapToken_; + edm::EDGetTokenT photonMapToken_; + // e/g -> footprint map + edm::EDGetTokenT electronFootprintMapToken_; + edm::EDGetTokenT photonFootprintMapToken_; + + std::string electronsMapName_; + std::string photonsMapName_; +}; + +#endif diff --git a/RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.cc b/RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.cc new file mode 100644 index 0000000000000..3baaeee55e6e0 --- /dev/null +++ b/RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.cc @@ -0,0 +1,131 @@ +#include "RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" + +#include "RecoParticleFlow/PFProducer/interface/GsfElectronEqual.h" +#include "RecoParticleFlow/PFProducer/interface/PhotonEqual.h" + +#include "RecoEgamma/EgammaTools/interface/GainSwitchTools.h" + +#include "FWCore/Framework/interface/MakerMacros.h" + +typedef edm::ValueMap PFPtrMap; + +PFGSFixLinker::PFGSFixLinker(edm::ParameterSet const& _config) : + electronsMapName_(_config.getParameter("ValueMapElectrons")), + photonsMapName_(_config.getParameter("ValueMapPhotons")) +{ + getToken(inputCandidatesToken_, _config, "PFCandidate"); + getToken(inputElectronsToken_, _config, "GsfElectrons"); + getToken(inputPhotonsToken_, _config, "Photons"); + getToken(electronMapToken_, _config, "GsfElectrons"); + getToken(photonMapToken_, _config, "Photons"); + + produces(); + // new to old + produces(); + + // e/g collections to PF + produces(electronsMapName_); + produces(photonsMapName_); +} + +PFGSFixLinker::~PFGSFixLinker() +{ +} + +void +PFGSFixLinker::produce(edm::Event& _event, edm::EventSetup const&) +{ + std::auto_ptr pOutput(new reco::PFCandidateCollection); + + auto& inCandidates(*getHandle(_event, inputCandidatesToken_, "PFCandidate")); + auto&& inElectronsHandle(getHandle(_event, inputElectronsToken_, "GsfElectrons")); + auto& electronMap(*getHandle(_event, electronMapToken_, "GsfElectronsMap")); + auto&& inPhotonsHandle(getHandle(_event, inputPhotonsToken_, "Photons")); + auto& photonMap(*getHandle(_event, photonMapToken_, "PhotonsMap")); + + std::vector oldPtrs; + std::vector pfElectronIndices(inElectronsHandle->size(), -1); + std::vector pfPhotonIndices(inPhotonsHandle->size(), -1); + + unsigned iP(0); + for (auto& inCand : inCandidates) { + oldPtrs.emplace_back(inCandidates.ptrAt(iP++)); + + pOutput->emplace_back(inCand); + auto& outCand(pOutput->back()); + + auto&& eRef(inCand.gsfElectronRef()); + if (eRef.isNonnull()) { + auto&& newERef(GainSwitchTools::findNewRef(eRef, inElectronsHandle, electronMap)); + auto& newE(*newERef); + auto& newSC(*newE.superCluster()); + + pfElectronIndices[newERef.key()] = pOutput->size() - 1; + + outCand.setGsfElectronRef(newERef); + outCand.setSuperClusterRef(newE.superCluster()); + outCand.setEcalEnergy(newSC.rawEnergy(), newE.ecalEnergy()); + outCand.setDeltaP(newE.p4Error(reco::GsfElectron::P4_COMBINATION)); + outCand.setP4(newE.p4(reco::GsfElectron::P4_COMBINATION)); + } + + auto&& phRef(inCand.photonRef()); + if (phRef.isNonnull()) { + auto&& newPhRef(GainSwitchTools::findNewRef(phRef, inPhotonsHandle, photonMap)); + auto& newPh(*newPhRef); + auto& newSC(*newPh.superCluster()); + + pfPhotonIndices[newPhRef.key()] = pOutput->size() - 1; + + outCand.setPhotonRef(newPhRef); + outCand.setSuperClusterRef(newPh.superCluster()); + outCand.setEcalEnergy(newSC.rawEnergy(), newPh.getCorrectedEnergy(reco::Photon::regression2)); + outCand.setDeltaP(newPh.getCorrectedEnergyError(reco::Photon::regression2)); + outCand.setP4(newPh.p4(reco::Photon::regression2)); + } + } + + auto&& outCandsHandle(_event.put(pOutput)); + + std::auto_ptr pPFMap(new PFPtrMap); + PFPtrMap::Filler pfMapFiller(*pPFMap); + pfMapFiller.insert(outCandsHandle, oldPtrs.begin(), oldPtrs.end()); + pfMapFiller.fill(); + _event.put(pPFMap); + + std::vector pfElectrons; + for (unsigned idx : pfElectronIndices) { + if (idx == unsigned(-1)) + pfElectrons.emplace_back(); + else + pfElectrons.emplace_back(outCandsHandle, idx); + } + + std::auto_ptr pEleMap(new PFPtrMap); + PFPtrMap::Filler eleMapFiller(*pEleMap); + eleMapFiller.insert(inElectronsHandle, pfElectrons.begin(), pfElectrons.end()); + eleMapFiller.fill(); + _event.put(pEleMap, electronsMapName_); + + std::vector pfPhotons; + for (unsigned idx : pfPhotonIndices) { + if (idx == unsigned(-1)) + pfPhotons.emplace_back(); + else + pfPhotons.emplace_back(outCandsHandle, idx); + } + + std::auto_ptr pPhoMap(new PFPtrMap); + PFPtrMap::Filler phoMapFiller(*pPhoMap); + phoMapFiller.insert(inPhotonsHandle, pfPhotons.begin(), pfPhotons.end()); + phoMapFiller.fill(); + _event.put(pPhoMap, photonsMapName_); +} + +DEFINE_FWK_MODULE(PFGSFixLinker); diff --git a/RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.h b/RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.h new file mode 100644 index 0000000000000..740c2f2b3eda5 --- /dev/null +++ b/RecoParticleFlow/PFProducer/plugins/PFGSFixLinker.h @@ -0,0 +1,62 @@ +#ifndef RecoParticleFlow_PFProducer_PFGSFixLinker_h +#define RecoParticleFlow_PFProducer_PFGSFixLinker_h + +/** \class PFGSFixLinker + * Relink GS-fixed e/gamma objects + * \author Y. Iiyama (MIT) + */ + +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" + +#include + +class PFGSFixLinker : public edm::stream::EDProducer<> { + public: + explicit PFGSFixLinker(const edm::ParameterSet&); + ~PFGSFixLinker(); + + void produce(edm::Event&, const edm::EventSetup&) override; + + template + void + getToken(edm::EDGetTokenT& token, edm::ParameterSet const& pset, std::string const& label) + { + token = consumes(pset.getParameter(label)); + } + template + edm::Handle + getHandle(edm::Event const& _event, edm::EDGetTokenT const& token, std::string const& name) + { + edm::Handle handle; + if (!_event.getByToken(token, handle)) + throw cms::Exception("ProductNotFound") << name; + + return handle; + } + + private: + typedef edm::View PFCandidateView; + typedef edm::ValueMap ElectronRefMap; + typedef edm::ValueMap PhotonRefMap; + + edm::EDGetTokenT inputCandidatesToken_; + edm::EDGetTokenT inputElectronsToken_; + edm::EDGetTokenT inputPhotonsToken_; + // new -> old map + edm::EDGetTokenT electronMapToken_; + edm::EDGetTokenT photonMapToken_; + + std::string electronsMapName_; + std::string photonsMapName_; +}; + +#endif diff --git a/RecoParticleFlow/PFProducer/python/pfEGFootprintGSFixLinker_cfi.py b/RecoParticleFlow/PFProducer/python/pfEGFootprintGSFixLinker_cfi.py new file mode 100644 index 0000000000000..11a9d17c70fdc --- /dev/null +++ b/RecoParticleFlow/PFProducer/python/pfEGFootprintGSFixLinker_cfi.py @@ -0,0 +1,11 @@ +import FWCore.ParameterSet.Config as cms + +pfEGFootprintGSFixLinker = cms.EDProducer("PFEGFootprintGSFixLinker", + PFCandidate = cms.InputTag("particleFlow", '', cms.InputTag.skipCurrentProcess()), + GsfElectrons = cms.InputTag("gsFixedGsfElectrons"), + Photons = cms.InputTag("gsFixedGEDPhotons"), + GsfElectronsFootprint = cms.InputTag('particleBasedIsolation', 'gedGsfElectrons', cms.InputTag.skipCurrentProcess()), + PhotonsFootprint = cms.InputTag('particleBasedIsolation', 'gedPhotons', cms.InputTag.skipCurrentProcess()), + ValueMapElectrons = cms.string("gedGsfElectrons"), + ValueMapPhotons = cms.string("gedPhotons") +) diff --git a/RecoParticleFlow/PFProducer/python/pfGSFixLinkerForPAT_cff.py b/RecoParticleFlow/PFProducer/python/pfGSFixLinkerForPAT_cff.py new file mode 100644 index 0000000000000..e08283bb301fa --- /dev/null +++ b/RecoParticleFlow/PFProducer/python/pfGSFixLinkerForPAT_cff.py @@ -0,0 +1,25 @@ +import FWCore.ParameterSet.Config as cms + +from RecoParticleFlow.PFProducer.pfGSFixLinker_cfi import pfGSFixLinker +from RecoParticleFlow.PFProducer.pfEGFootprintGSFixLinker_cfi import pfEGFootprintGSFixLinker + +particleFlowGSFixed = pfGSFixLinker.clone( + GsfElectrons = 'gedGsfElectronsGSFixed', + Photons = 'gedPhotonsGSFixed' +) + +particleBasedIsolationGSFixed = pfEGFootprintGSFixLinker.clone( + GsfElectrons = 'gedGsfElectronsGSFixed', + Photons = 'gedPhotonsGSFixed' +) + +from RecoParticleFlow.PFProducer.pfLinker_cff import particleFlowPtrs +particleFlowTmpPtrs = particleFlowPtrs.clone() +particleFlowPtrs = particleFlowPtrs + +particleFlowLinks = cms.Sequence( + particleFlowGSFixed + + particleBasedIsolationGSFixed + + particleFlowTmpPtrs + + particleFlowPtrs +) diff --git a/RecoParticleFlow/PFProducer/python/pfGSFixLinker_cfi.py b/RecoParticleFlow/PFProducer/python/pfGSFixLinker_cfi.py new file mode 100644 index 0000000000000..18eb2c6b4255c --- /dev/null +++ b/RecoParticleFlow/PFProducer/python/pfGSFixLinker_cfi.py @@ -0,0 +1,9 @@ +import FWCore.ParameterSet.Config as cms + +pfGSFixLinker = cms.EDProducer("PFGSFixLinker", + PFCandidate = cms.InputTag("particleFlow", '', cms.InputTag.skipCurrentProcess()), + GsfElectrons = cms.InputTag("gsFixedGsfElectrons"), + Photons = cms.InputTag("gsFixedGEDPhotons"), + ValueMapElectrons = cms.string("electrons"), + ValueMapPhotons = cms.string("photons") +)