Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring CalibratedClusterPtr to CalibratedPFCluster #40460

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions RecoEcal/EgammaClusterAlgos/interface/PFECALSuperClusterAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
\date July 2012
*/

typedef std::shared_ptr<CalibratedPFCluster> CalibratedClusterPtr;
typedef std::vector<CalibratedClusterPtr> CalibratedClusterPtrVector;
typedef std::vector<CalibratedPFCluster> CalibratedPFClusterVector;

class PFECALSuperClusterAlgo {
public:
Expand Down Expand Up @@ -142,19 +141,19 @@ class PFECALSuperClusterAlgo {
const EcalMustacheSCParameters* mustacheSCParams_;
const EcalSCDynamicDPhiParameters* scDynamicDPhiParams_;

CalibratedClusterPtrVector _clustersEB;
CalibratedClusterPtrVector _clustersEE;
CalibratedPFClusterVector _clustersEB;
CalibratedPFClusterVector _clustersEE;
std::unique_ptr<reco::SuperClusterCollection> superClustersEB_;
std::unique_ptr<reco::SuperClusterCollection> superClustersEE_;
const reco::PFCluster::EEtoPSAssociation* EEtoPS_;
std::shared_ptr<PFEnergyCalibration> _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_;

Expand Down
108 changes: 54 additions & 54 deletions RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DetId, float>& seedHit : seedHitsAndFractions) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_);

Expand All @@ -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
Expand All @@ -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_;
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -395,23 +395,23 @@ 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);

// Finalize the SuperCluster passing the list of clustered clusters
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<const reco::PFCluster*> bare_ptrs;
Expand All @@ -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<reco::PFCluster>());
auto ee_key_val = std::make_pair(clus.ptr().key(), edm::Ptr<reco::PFCluster>());
const auto clustops = std::equal_range(EEtoPS_->begin(), EEtoPS_->end(), ee_key_val, sortByKey);
std::vector<reco::PFCluster const*> 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;
}
Expand All @@ -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;
}
Expand All @@ -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<reco::PFCluster>());
auto ee_key_val = std::make_pair(clus.ptr().key(), edm::Ptr<reco::PFCluster>());
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
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 4 additions & 5 deletions RecoEcal/EgammaCoreTools/interface/EcalClustersGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ namespace reco {

class EcalClustersGraph {
public:
typedef std::shared_ptr<CalibratedPFCluster> CalibratedClusterPtr;
typedef std::vector<CalibratedClusterPtr> CalibratedClusterPtrVector;
typedef std::vector<std::pair<CalibratedClusterPtr, CalibratedClusterPtrVector>> EcalGraphOutput;
typedef std::vector<CalibratedPFCluster> CalibratedPFClusterVector;
typedef std::vector<std::pair<CalibratedPFCluster, CalibratedPFClusterVector>> EcalGraphOutput;

EcalClustersGraph(CalibratedClusterPtrVector clusters,
EcalClustersGraph(CalibratedPFClusterVector clusters,
int nSeeds,
const CaloTopology* topology,
const CaloSubdetectorGeometry* ebGeom,
Expand Down Expand Up @@ -95,7 +94,7 @@ namespace reco {
std::pair<double, double> computeCovariances(const CaloCluster* cluster);
std::vector<double> computeShowerShapes(const CaloCluster* cluster, bool full5x5);

CalibratedClusterPtrVector clusters_;
CalibratedPFClusterVector clusters_;
uint nSeeds_;
uint nCls_;

Expand Down
Loading