24 currentSeedAssociations.push_back(pParticleSeed);
26 unsigned int associationOrder(1);
28 while (!currentSeedAssociations.empty())
30 for (ClusterVector::iterator iterI = candidateClusters.begin(), iterIEnd = candidateClusters.end(); iterI != iterIEnd; ++iterI)
32 const Cluster *
const pCandidateCluster = *iterI;
34 if (NULL == pCandidateCluster)
37 for (ClusterVector::iterator iterJ = currentSeedAssociations.begin(), iterJEnd = currentSeedAssociations.end(); iterJ != iterJEnd; ++iterJ)
39 const Cluster *
const pAssociatedCluster = *iterJ;
43 if (
NONE == associationType)
47 Association association(associationOrder, associationType);
48 const Association &existingAssociation = forwardUsageMap[pParticleSeed][pCandidateCluster];
53 if (pParticleSeed != pAssociatedCluster)
54 association.
SetType(std::min(association.
GetType(), backwardUsageMap[pAssociatedCluster][pParticleSeed].GetType()));
56 forwardUsageMap[pParticleSeed][pCandidateCluster] = association;
57 backwardUsageMap[pCandidateCluster][pParticleSeed] = association;
60 newSeedAssociations.push_back(pCandidateCluster);
65 currentSeedAssociations = newSeedAssociations;
66 newSeedAssociations.clear();
77 for (
const auto &mapEntry : backwardUsageMap)
78 sortedCandidates.push_back(mapEntry.first);
81 for (
const Cluster *
const pCluster : sortedCandidates)
85 if (particleSeedUsageMap.empty())
89 for (
const auto &mapEntry : particleSeedUsageMap)
90 sortedSeeds.push_back(mapEntry.first);
93 const Cluster *pBestParticleSeed = NULL;
95 unsigned int bestOrder(std::numeric_limits<unsigned int>::max());
97 for (
const Cluster *
const pParticleSeed : sortedSeeds)
99 const Association &association(particleSeedUsageMap.at(pParticleSeed));
101 if ((association.
GetType() > bestType) || ((association.
GetType() == bestType) && (association.
GetOrder() < bestOrder)))
108 pBestParticleSeed = pParticleSeed;
109 bestType = association.
GetType();
112 else if ((association.
GetType() == bestType) && (association.
GetOrder() == bestOrder))
115 pBestParticleSeed = NULL;
119 if (NULL == pBestParticleSeed)
122 seedAssociationList[pBestParticleSeed].push_back(pCluster);
126 for (ClusterVector::const_iterator iter = particleSeedVector.begin(), iterEnd = particleSeedVector.end(); iter != iterEnd; ++iter)
128 const Cluster *
const pParticleSeed = *iter;
130 if (seedAssociationList.end() == seedAssociationList.find(pParticleSeed))
unsigned int GetOrder() const
Get association order.
void SetType(const AssociationType associationType)
Set association type.
AssociationType GetType() const
Get association type.
std::unordered_map< const pandora::Cluster *, pandora::ClusterVector > SeedAssociationList
std::unordered_map< const pandora::Cluster *, Association > ClusterAssociationMap
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
void FindAssociatedClusters(const pandora::Cluster *const pParticleSeed, pandora::ClusterVector &candidateClusters, ClusterUsageMap &forwardUsageMap, ClusterUsageMap &backwardUsageMap) const
Find clusters associated with a particle seed.
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterUsageMap
virtual AssociationType AreClustersAssociated(const pandora::Cluster *const pClusterSeed, const pandora::Cluster *const pCluster) const =0
Determine whether two clusters are associated.
void IdentifyClusterMerges(const pandora::ClusterVector &particleSeedVector, const ClusterUsageMap &backwardUsageMap, SeedAssociationList &seedAssociationList) const
Identify cluster merges.
static bool SortByNHits(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs)
Sort clusters by number of hits, then layer span, then inner layer, then position,...