9 #include "Pandora/AlgorithmHeaders.h" 20 ClusterGrowingAlgorithm::ClusterGrowingAlgorithm() :
21 m_maxClusterSeparation(2.5
f)
29 const ClusterList *pClusterList = NULL;
33 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pClusterList));
37 PANDORA_RETURN_RESULT_IF_AND_IF(
38 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_inputClusterListName, pClusterList));
41 if (!pClusterList || pClusterList->empty())
43 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
44 std::cout <<
"ClusterGrowingAlgorithm: unable to find cluster list " <<
m_inputClusterListName << std::endl;
46 return STATUS_CODE_SUCCESS;
62 if (clusterMergeMap.empty())
68 return STATUS_CODE_SUCCESS;
78 const Cluster *
const pCluster = *iter;
80 if (seedClusters.end() != std::find(seedClusters.begin(), seedClusters.end(), pCluster))
83 nonSeedClusters.push_back(pCluster);
96 const Cluster *
const pNonSeedCluster = *nIter;
98 const Cluster *pBestSeedCluster(NULL);
103 const Cluster *
const pThisSeedCluster = *sIter;
106 if (thisDistance < bestDistance)
108 pBestSeedCluster = pThisSeedCluster;
109 bestDistance = thisDistance;
113 if (pBestSeedCluster)
114 clusterMergeMap[pBestSeedCluster].push_back(pNonSeedCluster);
122 ClusterList parentClusterList;
123 for (
const auto &mapEntry : clusterMergeMap)
124 parentClusterList.push_back(mapEntry.first);
127 for (
const Cluster *
const pParentCluster : parentClusterList)
129 const ClusterList &clusterList(clusterMergeMap.at(pParentCluster));
131 if (clusterList.empty())
132 throw StatusCodeException(STATUS_CODE_FAILURE);
134 for (
const Cluster *
const pAssociatedCluster : clusterList)
138 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*
this, pParentCluster, pAssociatedCluster));
142 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
153 PANDORA_RETURN_RESULT_IF_AND_IF(
154 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"InputClusterListName",
m_inputClusterListName));
156 PANDORA_RETURN_RESULT_IF_AND_IF(
157 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxClusterSeparation",
m_maxClusterSeparation));
159 return STATUS_CODE_SUCCESS;
Header file for the cluster growing algorithm class.
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, then pulse-height.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
virtual pandora::StatusCode Run()
void GetListOfNonSeedClusters(const pandora::ClusterVector &inputClusters, const pandora::ClusterVector &seedClusters, pandora::ClusterVector &nonSeedClusters) const
Get List of non-seed clusters.
float m_maxClusterSeparation
Maximum distance at which clusters can be joined.
void MergeClusters(const ClusterMergeMap &clusterMergeMap) const
Merge clusters.
virtual void GetListOfCleanClusters(const pandora::ClusterList *const pClusterList, pandora::ClusterVector &cleanClusters) const =0
Populate cluster vector with the subset of clusters judged to be clean.
Header file for the cluster helper class.
std::string m_inputClusterListName
The name of the input cluster list. If not specified, will access current list.
virtual void GetListOfSeedClusters(const pandora::ClusterVector &cleanClusters, pandora::ClusterVector &seedClusters) const =0
Select seed clusters for growing.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void PopulateClusterMergeMap(const pandora::ClusterVector &seedClusters, const pandora::ClusterVector &nonSeedClusters, ClusterMergeMap &clusterMergeMap) const
Identify a set of cluster merges.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.