5#ifndef RECON_TEMPLATEDCLUSTERFINDER_H_
6#define RECON_TEMPLATEDCLUSTERFINDER_H_
36template <
class HitType,
class WeightClass>
53 void add(
const HitType* hit) {
67 void add(
const HitType* hit,
double x,
double y,
double z) {
88 void cluster(
double seed_threshold,
double cutoff) {
89 int ncluster = clusters_.size();
90 double minwgt = cutoff;
93 std::sort(clusters_.begin(), clusters_.end(),
compClusters);
101 for (
size_t i = 0; i < clusters_.size(); i++) {
102 if (clusters_[i].empty())
continue;
104 bool iseed = (clusters_[i].energy() >= seed_threshold);
113 for (
size_t j = i + 1; j < clusters_.size(); j++) {
114 if (clusters_[j].empty() ||
115 (!iseed && clusters_[j].energy() < seed_threshold))
118 double wgt = wgt_(clusters_[i], clusters_[j]);
119 if (!any || wgt < minwgt) {
129 transition_weights_.insert(std::pair<int, double>(ncluster, minwgt));
131 if (any && minwgt < cutoff) {
133 if (clusters_[mi].energy() < clusters_[mj].energy()) {
137 clusters_[mi].add(clusters_[mj]);
138 clusters_[mj].clear();
143 }
while (minwgt < cutoff && ncluster > 1);
148 for (
const auto& cl : clusters_) {
149 if (!cl.empty() && cl.energy() >= seed_threshold) {
150 final_clusters_.push_back(cl);
151 }
else if (cl.energy() < seed_threshold) {
175 std::map<int, double>
getWeights()
const {
return transition_weights_; }
180 std::vector<ClusterType>
getClusters()
const {
return final_clusters_; }
192 std::map<int, double> transition_weights_;
193 std::vector<ClusterType> clusters_;
194 std::vector<ClusterType> final_clusters_;
In-memory tool for working on clusters during reconstruction.
A templated agglomerative clustering algorithm.
void cluster(double seed_threshold, double cutoff)
Run the clustering algorithm.
int getNLoops() const
Get the number of iterations performed.
std::vector< ClusterType > getClusters() const
Get the final clusters after filtering by seed threshold.
void add(const HitType *hit)
Add a hit to be clustered using its stored position.
double getYMax() const
Get the final weight (minimum distance between remaining clusters).
std::map< int, double > getWeights() const
Get the transition weights (cluster count -> minimum weight at that step).
std::vector< ClusterType > getAllClusters() const
Get all clusters including empty ones (for debugging).
int getNSeeds() const
Get the number of seed clusters found.
void add(const HitType &hit)
Add a hit to be clustered using its stored position.
static bool compClusters(const ClusterType &a, const ClusterType &b)
Compare clusters by energy (descending order).
void add(const HitType *hit, double x, double y, double z)
Add a hit with explicit position (e.g., from geometry).
An in-memory representation of a cluster being built during reconstruction.
double energy() const
Get the total energy of the cluster.
void add(const HitType *hit)
Add a hit to the cluster using its stored position.