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();
73 void BranchGrowingAlgorithm::IdentifyClusterMerges(
77 for (
const auto &mapEntry : backwardUsageMap)
78 sortedCandidates.push_back(mapEntry.first);
79 std::sort(sortedCandidates.begin(), sortedCandidates.end(), LArClusterHelper::SortByNHits);
81 for (
const Cluster *
const pCluster : sortedCandidates)
85 if (particleSeedUsageMap.empty())
86 throw StatusCodeException(STATUS_CODE_FAILURE);
89 for (
const auto &mapEntry : particleSeedUsageMap)
90 sortedSeeds.push_back(mapEntry.first);
91 std::sort(sortedSeeds.begin(), sortedSeeds.end(), LArClusterHelper::SortByNHits);
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)))
104 if ((SINGLE_ORDER == association.GetType()) && (association.GetOrder() > 1))
108 pBestParticleSeed = pParticleSeed;
109 bestType = association.
GetType();
110 bestOrder = association.GetOrder();
112 else if ((association.GetType() == bestType) && (association.GetOrder() == bestOrder))
115 pBestParticleSeed = NULL;
119 if (NULL == pBestParticleSeed)
122 seedAssociationList[pBestParticleSeed].push_back(pCluster);
128 const Cluster *
const pParticleSeed = *iter;
130 if (seedAssociationList.end() == seedAssociationList.find(pParticleSeed))
137 StatusCode BranchGrowingAlgorithm::ReadSettings(
const TiXmlHandle )
139 return STATUS_CODE_SUCCESS;
void SetType(const AssociationType associationType)
Set association type.
AssociationType GetType() const
Get association type.
AssociationType
AssociationType enum.
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterUsageMap
std::unordered_map< const pandora::Cluster *, Association > ClusterAssociationMap
std::unordered_map< const pandora::Cluster *, pandora::ClusterVector > SeedAssociationList
Header file for the cluster helper class.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
Header file for the branch growing algorithm base class.