9 #include "Pandora/AlgorithmHeaders.h" 20 void BranchGrowingAlgorithm::FindAssociatedClusters(
const Cluster *
const pParticleSeed,
ClusterVector &candidateClusters,
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;
41 const AssociationType associationType(this->AreClustersAssociated(pAssociatedCluster, pCandidateCluster));
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) sortedCandidates.push_back(mapEntry.first);
78 std::sort(sortedCandidates.begin(), sortedCandidates.end(), LArClusterHelper::SortByNHits);
80 for (
const Cluster *
const pCluster : sortedCandidates)
84 if (particleSeedUsageMap.empty())
85 throw StatusCodeException(STATUS_CODE_FAILURE);
88 for (
const auto &mapEntry : particleSeedUsageMap) sortedSeeds.push_back(mapEntry.first);
89 std::sort(sortedSeeds.begin(), sortedSeeds.end(), LArClusterHelper::SortByNHits);
91 const Cluster *pBestParticleSeed = NULL;
95 for (
const Cluster *
const pParticleSeed : sortedSeeds)
97 const Association &association(particleSeedUsageMap.at(pParticleSeed));
99 if ((association.GetType() > bestType) || ((association.GetType() == bestType) && (association.GetOrder() < bestOrder)))
102 if ((SINGLE_ORDER == association.GetType()) && (association.GetOrder() > 1))
106 pBestParticleSeed = pParticleSeed;
107 bestType = association.
GetType();
108 bestOrder = association.GetOrder();
110 else if ((association.GetType() == bestType) && (association.GetOrder() == bestOrder))
113 pBestParticleSeed = NULL;
117 if (NULL == pBestParticleSeed)
120 seedAssociationList[pBestParticleSeed].push_back(pCluster);
126 const Cluster *
const pParticleSeed = *iter;
128 if (seedAssociationList.end() == seedAssociationList.find(pParticleSeed))
135 StatusCode BranchGrowingAlgorithm::ReadSettings(
const TiXmlHandle )
137 return STATUS_CODE_SUCCESS;
void SetType(const AssociationType associationType)
Set association type.
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterUsageMap
AssociationType GetType() const
Get association type.
AssociationType
AssociationType enum.
std::unordered_map< const pandora::Cluster *, pandora::ClusterVector > SeedAssociationList
Header file for the cluster helper class.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
std::unordered_map< const pandora::Cluster *, Association > ClusterAssociationMap
Header file for the branch growing algorithm base class.