9 #include "Pandora/AlgorithmHeaders.h"
20 ClusterGrowingAlgorithm::ClusterGrowingAlgorithm() : m_maxClusterSeparation(2.5f)
28 const ClusterList *pClusterList = NULL;
32 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pClusterList));
36 PANDORA_RETURN_RESULT_IF_AND_IF(
37 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_inputClusterListName, pClusterList));
40 if (!pClusterList || pClusterList->empty())
42 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
45 return STATUS_CODE_SUCCESS;
61 if (clusterMergeMap.empty())
67 return STATUS_CODE_SUCCESS;
75 for (ClusterVector::const_iterator iter = inputClusters.begin(), iterEnd = inputClusters.end(); iter != iterEnd; ++iter)
77 const Cluster *
const pCluster = *iter;
79 if (seedClusters.end() != std::find(seedClusters.begin(), seedClusters.end(), pCluster))
82 nonSeedClusters.push_back(pCluster);
93 for (ClusterVector::const_iterator nIter = nonSeedClusters.begin(), nIterEnd = nonSeedClusters.end(); nIter != nIterEnd; ++nIter)
95 const Cluster *
const pNonSeedCluster = *nIter;
97 const Cluster *pBestSeedCluster(NULL);
100 for (ClusterVector::const_iterator sIter = seedClusters.begin(), sIterEnd = seedClusters.end(); sIter != sIterEnd; ++sIter)
102 const Cluster *
const pThisSeedCluster = *sIter;
105 if (thisDistance < bestDistance)
107 pBestSeedCluster = pThisSeedCluster;
108 bestDistance = thisDistance;
112 if (pBestSeedCluster)
113 clusterMergeMap[pBestSeedCluster].push_back(pNonSeedCluster);
121 ClusterList parentClusterList;
122 for (
const auto &mapEntry : clusterMergeMap)
123 parentClusterList.push_back(mapEntry.first);
126 for (
const Cluster *
const pParentCluster : parentClusterList)
128 const ClusterList &clusterList(clusterMergeMap.at(pParentCluster));
130 if (clusterList.empty())
131 throw StatusCodeException(STATUS_CODE_FAILURE);
133 for (
const Cluster *
const pAssociatedCluster : clusterList)
137 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*
this, pParentCluster, pAssociatedCluster));
141 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
152 PANDORA_RETURN_RESULT_IF_AND_IF(
153 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"InputClusterListName",
m_inputClusterListName));
155 PANDORA_RETURN_RESULT_IF_AND_IF(
156 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxClusterSeparation",
m_maxClusterSeparation));
158 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.
Header file for the cluster helper class.
virtual void GetListOfSeedClusters(const pandora::ClusterVector &cleanClusters, pandora::ClusterVector &seedClusters) const =0
Select seed clusters for growing.
std::string m_inputClusterListName
The name of the input cluster list. If not specified, will access current list.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
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.
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.
BEGIN_PROLOG could also be cout
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.