diff --git a/RecoEcal/EgammaClusterAlgos/interface/PFECALSuperClusterAlgo.h b/RecoEcal/EgammaClusterAlgos/interface/PFECALSuperClusterAlgo.h index b311b99333ad8..4be158c0906a7 100644 --- a/RecoEcal/EgammaClusterAlgos/interface/PFECALSuperClusterAlgo.h +++ b/RecoEcal/EgammaClusterAlgos/interface/PFECALSuperClusterAlgo.h @@ -61,8 +61,7 @@ \date July 2012 */ -typedef std::shared_ptr CalibratedClusterPtr; -typedef std::vector CalibratedClusterPtrVector; +typedef std::vector CalibratedPFClusterVector; class PFECALSuperClusterAlgo { public: @@ -142,19 +141,19 @@ class PFECALSuperClusterAlgo { const EcalMustacheSCParameters* mustacheSCParams_; const EcalSCDynamicDPhiParameters* scDynamicDPhiParams_; - CalibratedClusterPtrVector _clustersEB; - CalibratedClusterPtrVector _clustersEE; + CalibratedPFClusterVector _clustersEB; + CalibratedPFClusterVector _clustersEE; std::unique_ptr superClustersEB_; std::unique_ptr superClustersEE_; const reco::PFCluster::EEtoPSAssociation* EEtoPS_; std::shared_ptr _pfEnergyCalibration; clustering_type _clustype; energy_weight _eweight; - void buildAllSuperClusters(CalibratedClusterPtrVector&, double seedthresh); - void buildAllSuperClustersMustacheOrBox(CalibratedClusterPtrVector&, double seedthresh); - void buildAllSuperClustersDeepSC(CalibratedClusterPtrVector&, double seedthresh); - void buildSuperClusterMustacheOrBox(CalibratedClusterPtr&, CalibratedClusterPtrVector&); - void finalizeSuperCluster(CalibratedClusterPtr& seed, CalibratedClusterPtrVector& clustered, bool isEE); + void buildAllSuperClusters(CalibratedPFClusterVector&, double seedthresh); + void buildAllSuperClustersMustacheOrBox(CalibratedPFClusterVector&, double seedthresh); + void buildAllSuperClustersDeepSC(CalibratedPFClusterVector&, double seedthresh); + void buildSuperClusterMustacheOrBox(CalibratedPFCluster&, CalibratedPFClusterVector&); + void finalizeSuperCluster(CalibratedPFCluster& seed, CalibratedPFClusterVector& clustered, bool isEE); bool verbose_; diff --git a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc index 15c7a82c9325f..02adbeebc0fa5 100644 --- a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc +++ b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc @@ -38,38 +38,38 @@ namespace { return energy * std::sqrt(v.perp2() / v.mag2()); } - bool greaterByEt(const CalibratedClusterPtr& x, const CalibratedClusterPtr& y) { + bool greaterByEt(const CalibratedPFCluster& x, const CalibratedPFCluster& y) { const math::XYZPoint zero(0, 0, 0); - const double xpt = ptFast(x->energy(), x->ptr()->position(), zero); - const double ypt = ptFast(y->energy(), y->ptr()->position(), zero); + const double xpt = ptFast(x.energy(), x.ptr()->position(), zero); + const double ypt = ptFast(y.energy(), y.ptr()->position(), zero); return xpt > ypt; } - bool isSeed(const CalibratedClusterPtr& x, double threshold, bool useETcut) { + bool isSeed(const CalibratedPFCluster& x, double threshold, bool useETcut) { const math::XYZPoint zero(0, 0, 0); - double e_or_et = x->energy(); + double e_or_et = x.energy(); if (useETcut) - e_or_et = ptFast(e_or_et, x->ptr()->position(), zero); + e_or_et = ptFast(e_or_et, x.ptr()->position(), zero); return e_or_et > threshold; } - bool isLinkedByRecHit(const CalibratedClusterPtr& x, - const CalibratedClusterPtr& seed, + bool isLinkedByRecHit(const CalibratedPFCluster& x, + const CalibratedPFCluster& seed, const double threshold, const double majority, const double maxDEta, const double maxDPhi) { - if (seed->energy_nocalib() < threshold) { + if (seed.energy_nocalib() < threshold) { return false; } - const double dEta = std::abs(seed->eta() - x->eta()); - const double dPhi = std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi())); + const double dEta = std::abs(seed.eta() - x.eta()); + const double dPhi = std::abs(TVector2::Phi_mpi_pi(seed.phi() - x.phi())); if (maxDEta < dEta || maxDPhi < dPhi) { return false; } // now see if the clusters overlap in rechits - const auto& seedHitsAndFractions = seed->ptr()->hitsAndFractions(); - const auto& xHitsAndFractions = x->ptr()->hitsAndFractions(); + const auto& seedHitsAndFractions = seed.ptr()->hitsAndFractions(); + const auto& xHitsAndFractions = x.ptr()->hitsAndFractions(); double x_rechits_tot = xHitsAndFractions.size(); double x_rechits_match = 0.0; for (const std::pair& seedHit : seedHitsAndFractions) { @@ -82,26 +82,26 @@ namespace { return x_rechits_match / x_rechits_tot > majority; } - bool isClustered(const CalibratedClusterPtr& x, - const CalibratedClusterPtr seed, + bool isClustered(const CalibratedPFCluster& x, + const CalibratedPFCluster seed, const PFECALSuperClusterAlgo::clustering_type type, const EcalMustacheSCParameters* mustache_params, const EcalSCDynamicDPhiParameters* dynamic_dphi_params, const bool dyn_dphi, const double etawidthSuperCluster, const double phiwidthSuperCluster) { - const double dphi = std::abs(TVector2::Phi_mpi_pi(seed->phi() - x->phi())); + const double dphi = std::abs(TVector2::Phi_mpi_pi(seed.phi() - x.phi())); const bool passes_dphi = ((!dyn_dphi && dphi < phiwidthSuperCluster) || (dyn_dphi && reco::MustacheKernel::inDynamicDPhiWindow( - dynamic_dphi_params, seed->eta(), seed->phi(), x->energy_nocalib(), x->eta(), x->phi()))); + dynamic_dphi_params, seed.eta(), seed.phi(), x.energy_nocalib(), x.eta(), x.phi()))); if (type == PFECALSuperClusterAlgo::kBOX) { - return (std::abs(seed->eta() - x->eta()) < etawidthSuperCluster && passes_dphi); + return (std::abs(seed.eta() - x.eta()) < etawidthSuperCluster && passes_dphi); } if (type == PFECALSuperClusterAlgo::kMustache) { return (passes_dphi && reco::MustacheKernel::inMustache( - mustache_params, seed->eta(), seed->phi(), x->energy_nocalib(), x->eta(), x->phi())); + mustache_params, seed.eta(), seed.phi(), x.energy_nocalib(), x.eta(), x.phi())); } return false; } @@ -219,16 +219,16 @@ void PFECALSuperClusterAlgo::loadAndSortPFClusters(const edm::Event& iEvent) { if (cluster->caloID().detectors() == 0 && cluster->hitsAndFractions().empty()) continue; - CalibratedClusterPtr calib_cluster(new CalibratedPFCluster(cluster)); + CalibratedPFCluster calib_cluster(cluster); switch (cluster->layer()) { case PFLayer::ECAL_BARREL: - if (calib_cluster->energy() > threshPFClusterBarrel_) { + if (calib_cluster.energy() > threshPFClusterBarrel_) { _clustersEB.push_back(calib_cluster); } break; case PFLayer::HGCAL: case PFLayer::ECAL_ENDCAP: - if (calib_cluster->energy() > threshPFClusterEndcap_) { + if (calib_cluster.energy() > threshPFClusterEndcap_) { _clustersEE.push_back(calib_cluster); } break; @@ -268,14 +268,14 @@ void PFECALSuperClusterAlgo::run() { buildAllSuperClusters(_clustersEE, threshPFClusterSeedEndcap_); } -void PFECALSuperClusterAlgo::buildAllSuperClusters(CalibratedClusterPtrVector& clusters, double seedthresh) { +void PFECALSuperClusterAlgo::buildAllSuperClusters(CalibratedPFClusterVector& clusters, double seedthresh) { if (_clustype == PFECALSuperClusterAlgo::kMustache || _clustype == PFECALSuperClusterAlgo::kBOX) buildAllSuperClustersMustacheOrBox(clusters, seedthresh); else if (_clustype == PFECALSuperClusterAlgo::kDeepSC) buildAllSuperClustersDeepSC(clusters, seedthresh); } -void PFECALSuperClusterAlgo::buildAllSuperClustersMustacheOrBox(CalibratedClusterPtrVector& clusters, +void PFECALSuperClusterAlgo::buildAllSuperClustersMustacheOrBox(CalibratedPFClusterVector& clusters, double seedthresh) { auto seedable = std::bind(isSeed, _1, seedthresh, threshIsET_); @@ -291,7 +291,7 @@ void PFECALSuperClusterAlgo::buildAllSuperClustersMustacheOrBox(CalibratedCluste } } -void PFECALSuperClusterAlgo::buildAllSuperClustersDeepSC(CalibratedClusterPtrVector& clusters, double seedthresh) { +void PFECALSuperClusterAlgo::buildAllSuperClustersDeepSC(CalibratedPFClusterVector& clusters, double seedthresh) { auto seedable = std::bind(isSeed, _1, seedthresh, threshIsET_); // EcalClustersGraph utility class for DeepSC algorithm application // make sure only seeds appear at the front of the list of clusters @@ -318,20 +318,20 @@ void PFECALSuperClusterAlgo::buildAllSuperClustersDeepSC(CalibratedClusterPtrVec reco::EcalClustersGraph::EcalGraphOutput windows = ecalClusterGraph_.getGraphOutput(); for (auto& [seed, clustered] : windows) { bool isEE = false; - if (seed->ptr()->layer() == PFLayer::ECAL_ENDCAP) + if (seed.ptr()->layer() == PFLayer::ECAL_ENDCAP) isEE = true; finalizeSuperCluster(seed, clustered, isEE); } } -void PFECALSuperClusterAlgo::buildSuperClusterMustacheOrBox(CalibratedClusterPtr& seed, - CalibratedClusterPtrVector& clusters) { - CalibratedClusterPtrVector clustered; +void PFECALSuperClusterAlgo::buildSuperClusterMustacheOrBox(CalibratedPFCluster& seed, + CalibratedPFClusterVector& clusters) { + CalibratedPFClusterVector clustered; double etawidthSuperCluster = 0.0; double phiwidthSuperCluster = 0.0; bool isEE = false; - switch (seed->ptr()->layer()) { + switch (seed.ptr()->layer()) { case PFLayer::ECAL_BARREL: phiwidthSuperCluster = phiwidthSuperClusterBarrel_; etawidthSuperCluster = etawidthSuperClusterBarrel_; @@ -376,15 +376,15 @@ void PFECALSuperClusterAlgo::buildSuperClusterMustacheOrBox(CalibratedClusterPtr if (verbose_) { edm::LogInfo("PFClustering") << "Dumping cluster detail"; - edm::LogVerbatim("PFClustering") << "\tPassed seed: e = " << seed->energy_nocalib() << " eta = " << seed->eta() - << " phi = " << seed->phi() << std::endl; + edm::LogVerbatim("PFClustering") << "\tPassed seed: e = " << seed.energy_nocalib() << " eta = " << seed.eta() + << " phi = " << seed.phi() << std::endl; for (auto clus = clusters.cbegin(); clus != not_clustered; ++clus) { - edm::LogVerbatim("PFClustering") << "\t\tClustered cluster: e = " << (*clus)->energy_nocalib() - << " eta = " << (*clus)->eta() << " phi = " << (*clus)->phi() << std::endl; + edm::LogVerbatim("PFClustering") << "\t\tClustered cluster: e = " << (*clus).energy_nocalib() + << " eta = " << (*clus).eta() << " phi = " << (*clus).phi() << std::endl; } for (auto clus = not_clustered; clus != clusters.end(); ++clus) { - edm::LogVerbatim("PFClustering") << "\tNon-Clustered cluster: e = " << (*clus)->energy_nocalib() - << " eta = " << (*clus)->eta() << " phi = " << (*clus)->phi() << std::endl; + edm::LogVerbatim("PFClustering") << "\tNon-Clustered cluster: e = " << (*clus).energy_nocalib() + << " eta = " << (*clus).eta() << " phi = " << (*clus).phi() << std::endl; } } @@ -395,14 +395,14 @@ void PFECALSuperClusterAlgo::buildSuperClusterMustacheOrBox(CalibratedClusterPtr } else { throw cms::Exception("PFECALSuperClusterAlgo::buildSuperCluster") << "Cluster is not seedable!" << std::endl - << "\tNon-Clustered cluster: e = " << (*not_clustered)->energy_nocalib() - << " eta = " << (*not_clustered)->eta() << " phi = " << (*not_clustered)->phi() << std::endl; + << "\tNon-Clustered cluster: e = " << (*not_clustered).energy_nocalib() << " eta = " << (*not_clustered).eta() + << " phi = " << (*not_clustered).phi() << std::endl; } } // move the clustered clusters out of available cluster list // and into a temporary vector for building the SC - CalibratedClusterPtrVector clustered_tmp(clusters.begin(), not_clustered); + CalibratedPFClusterVector clustered_tmp(clusters.begin(), not_clustered); clustered = clustered_tmp; clusters.erase(clusters.begin(), not_clustered); @@ -410,8 +410,8 @@ void PFECALSuperClusterAlgo::buildSuperClusterMustacheOrBox(CalibratedClusterPtr finalizeSuperCluster(seed, clustered, isEE); } -void PFECALSuperClusterAlgo::finalizeSuperCluster(CalibratedClusterPtr& seed, - CalibratedClusterPtrVector& clustered, +void PFECALSuperClusterAlgo::finalizeSuperCluster(CalibratedPFCluster& seed, + CalibratedPFClusterVector& clustered, bool isEE) { // need the vector of raw pointers for a PF width class std::vector bare_ptrs; @@ -421,18 +421,18 @@ void PFECALSuperClusterAlgo::finalizeSuperCluster(CalibratedClusterPtr& seed, for (const auto& clus : clustered) { double ePS1 = 0.0; double ePS2 = 0.0; - energyweight = clus->energy_nocalib(); - bare_ptrs.push_back(clus->ptr().get()); + energyweight = clus.energy_nocalib(); + bare_ptrs.push_back(clus.ptr().get()); // update EE calibrated super cluster energies if (isEE) { - auto ee_key_val = std::make_pair(clus->ptr().key(), edm::Ptr()); + auto ee_key_val = std::make_pair(clus.ptr().key(), edm::Ptr()); const auto clustops = std::equal_range(EEtoPS_->begin(), EEtoPS_->end(), ee_key_val, sortByKey); std::vector psClusterPointers; for (auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) { psClusterPointers.push_back(i_ps->second.get()); } auto calibratedEnergies = _pfEnergyCalibration->calibrateEndcapClusterEnergies( - *(clus->ptr()), psClusterPointers, *channelStatus_, applyCrackCorrections_); + *(clus.ptr()), psClusterPointers, *channelStatus_, applyCrackCorrections_); ePS1 = calibratedEnergies.ps1Energy; ePS2 = calibratedEnergies.ps2Energy; } @@ -446,21 +446,21 @@ void PFECALSuperClusterAlgo::finalizeSuperCluster(CalibratedClusterPtr& seed, case kRaw: // energyweight is initialized to raw cluster energy break; case kCalibratedNoPS: - energyweight = clus->energy() - ePS1 - ePS2; + energyweight = clus.energy() - ePS1 - ePS2; break; case kCalibratedTotal: - energyweight = clus->energy(); + energyweight = clus.energy(); break; default: break; } - const math::XYZPoint& cluspos = clus->ptr()->position(); + const math::XYZPoint& cluspos = clus.ptr()->position(); posX += energyweight * cluspos.X(); posY += energyweight * cluspos.Y(); posZ += energyweight * cluspos.Z(); energyweighttot += energyweight; - corrSCEnergy += clus->energy(); + corrSCEnergy += clus.energy(); corrPS1Energy += ePS1; corrPS2Energy += ePS2; } @@ -471,19 +471,19 @@ void PFECALSuperClusterAlgo::finalizeSuperCluster(CalibratedClusterPtr& seed, // now build the supercluster reco::SuperCluster new_sc(corrSCEnergy, math::XYZPoint(posX, posY, posZ)); new_sc.setCorrectedEnergy(corrSCEnergy); - new_sc.setSeed(clustered.front()->ptr()); + new_sc.setSeed(clustered.front().ptr()); new_sc.setPreshowerEnergy(corrPS1Energy + corrPS2Energy); new_sc.setPreshowerEnergyPlane1(corrPS1Energy); new_sc.setPreshowerEnergyPlane2(corrPS2Energy); for (const auto& clus : clustered) { - new_sc.addCluster(clus->ptr()); + new_sc.addCluster(clus.ptr()); - auto& hits_and_fractions = clus->ptr()->hitsAndFractions(); + auto& hits_and_fractions = clus.ptr()->hitsAndFractions(); for (auto& hit_and_fraction : hits_and_fractions) { new_sc.addHitAndFraction(hit_and_fraction.first, hit_and_fraction.second); } if (isEE) { - auto ee_key_val = std::make_pair(clus->ptr().key(), edm::Ptr()); + auto ee_key_val = std::make_pair(clus.ptr().key(), edm::Ptr()); const auto clustops = std::equal_range(EEtoPS_->begin(), EEtoPS_->end(), ee_key_val, sortByKey); // EE rechits should be uniquely matched to sets of pre-shower // clusters at this point, so we throw an exception if otherwise @@ -530,7 +530,7 @@ void PFECALSuperClusterAlgo::finalizeSuperCluster(CalibratedClusterPtr& seed, double scEtBS = ptFast(new_sc.energy(), new_sc.position(), beamSpot_->position()); if (scEtBS > threshSuperClusterEt_) { - switch (seed->ptr()->layer()) { + switch (seed.ptr()->layer()) { case PFLayer::ECAL_BARREL: if (isOOTCollection_) { DetId seedId = new_sc.seed()->seed(); diff --git a/RecoEcal/EgammaCoreTools/interface/EcalClustersGraph.h b/RecoEcal/EgammaCoreTools/interface/EcalClustersGraph.h index 5a22442fd4721..798af02a67e15 100644 --- a/RecoEcal/EgammaCoreTools/interface/EcalClustersGraph.h +++ b/RecoEcal/EgammaCoreTools/interface/EcalClustersGraph.h @@ -52,11 +52,10 @@ namespace reco { class EcalClustersGraph { public: - typedef std::shared_ptr CalibratedClusterPtr; - typedef std::vector CalibratedClusterPtrVector; - typedef std::vector> EcalGraphOutput; + typedef std::vector CalibratedPFClusterVector; + typedef std::vector> EcalGraphOutput; - EcalClustersGraph(CalibratedClusterPtrVector clusters, + EcalClustersGraph(CalibratedPFClusterVector clusters, int nSeeds, const CaloTopology* topology, const CaloSubdetectorGeometry* ebGeom, @@ -95,7 +94,7 @@ namespace reco { std::pair computeCovariances(const CaloCluster* cluster); std::vector computeShowerShapes(const CaloCluster* cluster, bool full5x5); - CalibratedClusterPtrVector clusters_; + CalibratedPFClusterVector clusters_; uint nSeeds_; uint nCls_; diff --git a/RecoEcal/EgammaCoreTools/src/EcalClustersGraph.cc b/RecoEcal/EgammaCoreTools/src/EcalClustersGraph.cc index a9fa485603dca..dcfb52abe1bb4 100644 --- a/RecoEcal/EgammaCoreTools/src/EcalClustersGraph.cc +++ b/RecoEcal/EgammaCoreTools/src/EcalClustersGraph.cc @@ -5,10 +5,9 @@ using namespace std; using namespace reco; using namespace reco::DeepSCInputs; -typedef std::shared_ptr CalibratedClusterPtr; -typedef std::vector CalibratedClusterPtrVector; +typedef std::vector CalibratedPFClusterVector; -EcalClustersGraph::EcalClustersGraph(CalibratedClusterPtrVector clusters, +EcalClustersGraph::EcalClustersGraph(CalibratedPFClusterVector clusters, int nSeeds, const CaloTopology* topology, const CaloSubdetectorGeometry* ebGeom, @@ -135,9 +134,9 @@ std::array EcalClustersGraph::dynamicWindow(double seedEta) const { void EcalClustersGraph::initWindows() { for (uint is = 0; is < nSeeds_; is++) { - const auto& seedLocal = clusterPosition((*clusters_[is]).ptr().get()); - double seed_eta = clusters_[is]->eta(); - double seed_phi = clusters_[is]->phi(); + const auto& seedLocal = clusterPosition((clusters_[is]).ptr().get()); + double seed_eta = clusters_[is].eta(); + double seed_phi = clusters_[is].phi(); const auto& width = dynamicWindow(seed_eta); // Add a self loop on the seed node graphMap_.addEdge(is, is); @@ -151,9 +150,9 @@ void EcalClustersGraph::initWindows() { for (uint icl = is + 1; icl < nCls_; icl++) { if (is == icl) continue; - const auto& clusterLocal = clusterPosition((*clusters_[icl]).ptr().get()); - double cl_eta = clusters_[icl]->eta(); - double cl_phi = clusters_[icl]->phi(); + const auto& clusterLocal = clusterPosition((clusters_[icl]).ptr().get()); + double cl_eta = clusters_[icl].eta(); + double cl_phi = clusters_[icl].phi(); double dphi = deltaPhi(seed_phi, cl_phi); double deta = deltaEta(seed_eta, cl_eta); @@ -365,7 +364,7 @@ void EcalClustersGraph::fillVariables() { // Looping on all the seeds (window) for (uint is = 0; is < nSeeds_; is++) { - const auto seedPointer = (*clusters_[is]).ptr().get(); + const auto seedPointer = (clusters_[is]).ptr().get(); std::vector unscaledClusterFeatures; const auto& outEdges = graphMap_.getOutEdges(is); size_t ncls = outEdges.size(); @@ -377,7 +376,7 @@ void EcalClustersGraph::fillVariables() { // Loop on all the clusters for (const auto ic : outEdges) { LogTrace("EcalClustersGraph") << "seed: " << is << ", out edge --> " << ic; - const auto clPointer = (*clusters_[ic]).ptr().get(); + const auto clPointer = (clusters_[ic]).ptr().get(); const auto& clusterFeatures = computeVariables(seedPointer, clPointer); for (const auto& [key, val] : clusterFeatures) { LogTrace("EcalCluster") << key << "=" << val; @@ -427,8 +426,8 @@ EcalClustersGraph::EcalGraphOutput EcalClustersGraph::getGraphOutput() { EcalClustersGraph::EcalGraphOutput finalWindows_; const auto& finalSuperClusters_ = graphMap_.getGraphOutput(); for (const auto& [is, cls] : finalSuperClusters_) { - CalibratedClusterPtr seed = clusters_[is]; - CalibratedClusterPtrVector clusters_inWindow; + CalibratedPFCluster seed = clusters_[is]; + CalibratedPFClusterVector clusters_inWindow; for (const auto& ic : cls) { clusters_inWindow.push_back(clusters_[ic]); }