diff --git a/RecoEgamma/EgammaElectronProducers/plugins/ElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/ElectronSeedProducer.cc index 5fc5eb39adb2d..c5f5c7097f04b 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/ElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/ElectronSeedProducer.cc @@ -250,6 +250,7 @@ void ElectronSeedProducer::fillDescriptions(edm::ConfigurationDescriptions& desc psd4.add("HGCEEInput", {"HGCalRecHit", "HGCEERecHits"}); psd4.add("HGCFHInput", {"HGCalRecHit", "HGCHEFRecHits"}); psd4.add("HGCBHInput", {"HGCalRecHit", "HGCHEBRecHits"}); + psd4.add("hgcalHitMap", {"recHitMapProducer", "hgcalRecHitMap"}); desc.add("HGCalConfig", psd4); // r/z windows diff --git a/RecoEgamma/EgammaElectronProducers/python/ecalDrivenElectronSeeds_cff.py b/RecoEgamma/EgammaElectronProducers/python/ecalDrivenElectronSeeds_cff.py index 144ccfbef43f7..90d1d4dc2f12b 100644 --- a/RecoEgamma/EgammaElectronProducers/python/ecalDrivenElectronSeeds_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/ecalDrivenElectronSeeds_cff.py @@ -19,6 +19,10 @@ endcapSuperClusters = 'particleFlowSuperClusterHGCal', allowHGCal = True, ) +phase2_hgcal.toModify( + ecalDrivenElectronSeeds.HGCalConfig, + hgcalHitMap = cms.InputTag("recHitMapProducer", "hgcalRecHitMap"), +) from Configuration.ProcessModifiers.egamma_lowPt_exclusive_cff import egamma_lowPt_exclusive egamma_lowPt_exclusive.toModify(ecalDrivenElectronSeeds, diff --git a/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h b/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h index 600f797a9e7ad..c2edaeea349b1 100644 --- a/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h +++ b/RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h @@ -9,6 +9,8 @@ #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" #include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "DataFormats/ParticleFlowReco/interface/HGCalMultiCluster.h" +#include "CommonTools/RecoAlgos/interface/MultiVectorManager.h" + #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/Records/interface/CaloGeometryRecord.h" @@ -60,9 +62,12 @@ namespace hgcal { RecHitTools rhtools_; const edm::EDGetTokenT eetok, fhtok, bhtok; + const edm::EDGetTokenT> hitMapToken_; const edm::ESGetToken caloGeometryToken_; const HGCRecHitCollection *eerh_, *fhrh_, *bhrh_; + const std::unordered_map *hitMap_; + MultiVectorManager rechitManager_; }; } // namespace hgcal diff --git a/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc b/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc index 3dbba5d869498..d43db1751974a 100644 --- a/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc +++ b/RecoLocalCalo/HGCalRecAlgos/src/ClusterTools.cc @@ -22,12 +22,18 @@ ClusterTools::ClusterTools(const edm::ParameterSet& conf, edm::ConsumesCollector : eetok(sumes.consumes(conf.getParameter("HGCEEInput"))), fhtok(sumes.consumes(conf.getParameter("HGCFHInput"))), bhtok(sumes.consumes(conf.getParameter("HGCBHInput"))), + hitMapToken_(sumes.consumes>( + conf.getParameter("hgcalHitMap"))), caloGeometryToken_{sumes.esConsumes()} {} void ClusterTools::getEvent(const edm::Event& ev) { eerh_ = &ev.get(eetok); fhrh_ = &ev.get(fhtok); bhrh_ = &ev.get(bhtok); + hitMap_ = &ev.get(hitMapToken_); + rechitManager_.addVector(*eerh_); + rechitManager_.addVector(*fhrh_); + rechitManager_.addVector(*bhrh_); } void ClusterTools::getEventSetup(const edm::EventSetup& es) { rhtools_.setGeometry(es.getData(caloGeometryToken_)); } @@ -38,57 +44,23 @@ float ClusterTools::getClusterHadronFraction(const reco::CaloCluster& clus) cons for (const auto& hit : hits) { const auto& id = hit.first; const float fraction = hit.second; - - if (id.det() == DetId::HGCalEE) { - auto it = std::find(eerh_->begin(), eerh_->end(), id); - if (it != eerh_->end()) - energy += it->energy() * fraction; - } else if (id.det() == DetId::HGCalHSi) { - auto it = std::find(fhrh_->begin(), fhrh_->end(), id); - if (it != fhrh_->end()) { - energy += it->energy() * fraction; - energyHad += it->energy() * fraction; - } - } else if (id.det() == DetId::HGCalHSc) { - auto it = std::find(bhrh_->begin(), bhrh_->end(), id); - if (it != bhrh_->end()) { - energy += it->energy() * fraction; - energyHad += it->energy() * fraction; - } - } else if (id.det() == DetId::Forward) { - switch (id.subdetId()) { - case HGCEE: { - auto it = std::find(eerh_->begin(), eerh_->end(), id); - if (it != eerh_->end()) - energy += it->energy() * fraction; - break; - } - case HGCHEF: { - auto it = std::find(fhrh_->begin(), fhrh_->end(), id); - if (it != fhrh_->end()) { - energy += it->energy() * fraction; - energyHad += it->energy() * fraction; - } - break; - } - default: - throw cms::Exception("HGCalClusterTools") << " Cluster contains hits that are not from HGCal! " << std::endl; - } - } else if (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) { - auto it = std::find(bhrh_->begin(), bhrh_->end(), id); - if (it != bhrh_->end()) { - energy += it->energy() * fraction; - energyHad += it->energy() * fraction; - } - } else { - throw cms::Exception("HGCalClusterTools") << " Cluster contains hits that are not from HGCal! " << std::endl; + auto hitIter = hitMap_->find(id.rawId()); + if (hitIter == hitMap_->end()) + continue; + unsigned int rechitIndex = hitIter->second; + float hitEnergy = rechitManager_[rechitIndex].energy() * fraction; + energy += hitEnergy; + if (id.det() == DetId::HGCalHSi || id.det() == DetId::HGCalHSc || + (id.det() == DetId::Forward && id.subdetId() == HGCHEF) || + (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap)) { + energyHad += hitEnergy; } } - float fraction = -1.f; + float hadronicFraction = -1.f; if (energy > 0.f) { - fraction = energyHad / energy; + hadronicFraction = energyHad / energy; } - return fraction; + return hadronicFraction; } math::XYZPoint ClusterTools::getMultiClusterPosition(const reco::HGCalMultiCluster& clu) const { diff --git a/RecoLocalCalo/HGCalRecProducers/plugins/HGCalMultiClusterProducer.cc b/RecoLocalCalo/HGCalRecProducers/plugins/HGCalMultiClusterProducer.cc index 1cb2a6cd88084..db393b2930852 100644 --- a/RecoLocalCalo/HGCalRecProducers/plugins/HGCalMultiClusterProducer.cc +++ b/RecoLocalCalo/HGCalRecProducers/plugins/HGCalMultiClusterProducer.cc @@ -72,6 +72,7 @@ void HGCalMultiClusterProducer::fillDescriptions(edm::ConfigurationDescriptions& 5.0, }); desc.add("HGCBHInput", edm::InputTag("HGCalRecHit", "HGCHEBRecHits")); + desc.add("hgcalHitMap", {"recHitMapProducer", "hgcalRecHitMap"}); desc.add("HGCLayerClustersSharing", edm::InputTag("hgcalMergeLayerClusters", "sharing")); desc.add("minClusters", 3); descriptions.add("hgcalMultiClusters", desc);