From 6d2115d6fdfe250ad67b11f214155b15887ad712 Mon Sep 17 00:00:00 2001 From: Sam Harper Date: Wed, 25 Jan 2017 16:31:44 +0000 Subject: [PATCH 1/2] fixing bug in showershape calculations --- .../plugins/GsfElectronGSCrysFixer.cc | 8 +++++--- .../EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc index 93705d5e4bce8..8421d9eea9fa3 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronGSCrysFixer.cc @@ -156,13 +156,15 @@ void GsfElectronGSCrysFixer::produce( edm::Event & iEvent, const edm::EventSetup 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()/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_ ) gedRegression_->modifyObject(newEle); } diff --git a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc index d4b7a47c1cf15..7e64c95bd12a9 100644 --- a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc +++ b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc @@ -191,10 +191,10 @@ GEDPhotonGSCrysFixer::produce(edm::Event& _event, const edm::EventSetup& _setup) 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.e1x5 = noZS::EcalClusterTools::e1x5(newSeed, &ebHits, topology_); + new55SS.e2x5 = noZS::EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_); + new55SS.e3x3 = noZS::EcalClusterTools::e3x3(newSeed, &ebHits, topology_); + new55SS.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]); From 4bdc5e7d60532969e6e64eac171473e9404f7f80 Mon Sep 17 00:00:00 2001 From: Sam Harper Date: Wed, 25 Jan 2017 16:32:28 +0000 Subject: [PATCH 2/2] fixing bug where the same cluster could be assigned to two superclusters --- .../src/EGRefinedSCFixer.cc | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc b/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc index a6271e83afdc1..ded9f18441817 100644 --- a/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc +++ b/RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc @@ -64,7 +64,8 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> { static std::unordered_set getListOfClusterSeedIdsForNewSC(const reco::SuperCluster& orgRefinedSC, const reco::SuperCluster& orgSC, - const reco::SuperCluster& fixedSC); + const reco::SuperCluster& fixedSC, + const std::vector >& clustersAddedToAnySC); static std::vector > getClustersFromSeedIds(const std::unordered_set& seedIds,const edm::Handle >& inClusters); @@ -73,7 +74,8 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> { makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedSC, const reco::SuperCluster& orgSC, const reco::SuperCluster& fixedSC, - const edm::Handle >& fixedClusters); + const edm::Handle >& fixedClusters, + const std::vector >& clustersAddedToAnySC); private: typedef edm::View PFClusterView; @@ -171,6 +173,8 @@ 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) @@ -196,6 +200,19 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet std::vector mappedSCsEB(fixedEBSCs->size()); std::vector mappedSCsEE(fixedEESCs->size()); + std::vector > clusterAddedToAnyEBSC; + for(auto& refinedSC : *orgRefinedSCs){ + if(refinedSC.seed()->seed().subdetId() == EcalBarrel) { + reco::SuperClusterRef parentSC = GainSwitchTools::matchSCBySeedCrys(refinedSC,orgEBSCs); + if(parentSC.isNonnull()) { + auto clusAdded = getSubClustersMissing(refinedSC,*parentSC); + for(auto clusPtr : clusAdded) clusterAddedToAnyEBSC.push_back(clusPtr); + }else{ //no parent supercluster, all superclusters in this supercluster are addded + for(auto clusPtr : refinedSC.clusters()) clusterAddedToAnyEBSC.push_back(clusPtr); + } + } + } + for (unsigned iO(0); iO != orgRefinedSCs->size(); ++iO) { auto& orgRefinedSC(orgRefinedSCs->at(iO)); mappedRefinedSCs.emplace_back(orgRefinedSCs, iO); @@ -210,12 +227,16 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet 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 + // Sam: its very unlikely, if not impossible. To be replaced the gain switched crystal must be within +/-1 crystal a hybrid supercluster seed crystal because of ecalSelectedDigis. You could only get a shift larger than 1 if you had two supercluster seed crystals very close together and even then I'm not sure its possible. if (fixedEBSC.isNonnull()) { mappedSCsEB[fixedEBSC.key()] = orgEBSC; - auto fixedRefinedSC(makeFixedRefinedBarrelSC(orgRefinedSC, *orgEBSC, *fixedEBSC, fixedPFClusters)); + auto fixedRefinedSC(makeFixedRefinedBarrelSC(orgRefinedSC, *orgEBSC, *fixedEBSC, fixedPFClusters,clusterAddedToAnyEBSC)); fixedRefinedSCs->push_back(fixedRefinedSC); + // std::cout<<" org refined "<push_back(orgRefinedSC); } + // Put the PF SC maps in Event std::auto_ptr pEBSCRefMap(new SCRefMap); SCRefMap::Filler ebSCMapFiller(*pEBSCRefMap); @@ -341,21 +363,35 @@ EGRefinedSCFixer::getSubClustersMissing(const reco::SuperCluster& lhs, std::unordered_set EGRefinedSCFixer::getListOfClusterSeedIdsForNewSC(const reco::SuperCluster& orgRefinedSC, const reco::SuperCluster& orgSC, - const reco::SuperCluster& fixedSC) + const reco::SuperCluster& fixedSC, + const std::vector >& clustersAddedToAnySC) { auto clusAdded = getSubClustersMissing(orgRefinedSC,orgSC); auto clusRemoved = getSubClustersMissing(orgSC,orgRefinedSC); + 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()){ + + //first check if the cluster was removed by the refining process + bool notRemoved = std::find_if(clusRemoved.begin(),clusRemoved.end(),compFunc)==clusRemoved.end(); + + //now check if it was assigned to another supercluster (it wont be picked up by the previous + //check if the parent supercluster picked it up during reclustering) + //if its a cluster which is added to any supercluster it wont add it + //its okay if it was added to this supercluster as we will add it in below + bool notAddedToASuperCluster = std::find_if(clustersAddedToAnySC.begin(), + clustersAddedToAnySC.end(),compFunc)==clustersAddedToAnySC.end(); + + if(notRemoved && notAddedToASuperCluster){ detIdsOfClustersForNewSC.insert(clus->seed().rawId()); } } - for(auto clus : clusAdded) + for(auto clus : clusAdded){ detIdsOfClustersForNewSC.insert(clus->seed().rawId()); + } return detIdsOfClustersForNewSC; } @@ -381,9 +417,10 @@ reco::SuperCluster EGRefinedSCFixer::makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedSC, const reco::SuperCluster& orgSC, const reco::SuperCluster& fixedSC, - const edm::Handle >& fixedClusters) + const edm::Handle >& fixedClusters, + const std::vector >& clustersAddedToAnySC) { - auto listOfSeedIds = getListOfClusterSeedIdsForNewSC(orgRefinedSC,orgSC,fixedSC); + auto listOfSeedIds = getListOfClusterSeedIdsForNewSC(orgRefinedSC,orgSC,fixedSC,clustersAddedToAnySC); // make sure the seed cluster is in the listOfSeedIds unsigned seedSeedId(fixedSC.seed()->seed().rawId());