9 #include "Pandora/AlgorithmHeaders.h"
20 StatusCode ClusterMergingAlgorithm::Run()
22 const ClusterList *pClusterList = NULL;
24 if (m_inputClusterListName.empty())
26 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pClusterList));
30 PANDORA_RETURN_RESULT_IF_AND_IF(
31 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this, m_inputClusterListName, pClusterList));
34 if (!pClusterList || pClusterList->empty())
36 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
37 std::cout <<
"ClusterMergingAlgorithm: unable to find cluster list " << m_inputClusterListName << std::endl;
39 return STATUS_CODE_SUCCESS;
45 this->GetListOfCleanClusters(pClusterList, unsortedVector);
46 this->GetSortedListOfCleanClusters(unsortedVector, clusterVector);
49 this->PopulateClusterMergeMap(clusterVector, clusterMergeMap);
51 if (clusterMergeMap.empty())
54 this->MergeClusters(clusterVector, clusterMergeMap);
57 return STATUS_CODE_SUCCESS;
64 ClusterSet clusterVetoList;
66 for (
const Cluster *
const pSeedCluster : clusterVector)
68 ClusterList mergeList;
69 this->CollectAssociatedClusters(pSeedCluster, pSeedCluster, clusterMergeMap, clusterVetoList, mergeList);
70 mergeList.sort(LArClusterHelper::SortByNHits);
72 for (
const Cluster *
const pAssociatedCluster : mergeList)
74 if (clusterVetoList.count(pAssociatedCluster))
75 throw StatusCodeException(STATUS_CODE_FAILURE);
77 if (!pAssociatedCluster->IsAvailable())
78 throw StatusCodeException(STATUS_CODE_FAILURE);
80 (
void)clusterVetoList.insert(pAssociatedCluster);
82 if (m_inputClusterListName.empty())
84 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*
this, pSeedCluster, pAssociatedCluster));
88 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
89 PandoraContentApi::MergeAndDeleteClusters(*
this, pSeedCluster, pAssociatedCluster, m_inputClusterListName, m_inputClusterListName));
97 void ClusterMergingAlgorithm::CollectAssociatedClusters(
98 const Cluster *
const pSeedCluster,
const ClusterMergeMap &clusterMergeMap, ClusterList &associatedClusterList)
const
100 ClusterSet clusterVetoList;
101 this->CollectAssociatedClusters(pSeedCluster, pSeedCluster, clusterMergeMap, clusterVetoList, associatedClusterList);
106 void ClusterMergingAlgorithm::CollectAssociatedClusters(
const Cluster *
const pSeedCluster,
const Cluster *
const pCurrentCluster,
107 const ClusterMergeMap &clusterMergeMap,
const ClusterSet &clusterVetoList, ClusterList &associatedClusterList)
const
109 if (clusterVetoList.count(pCurrentCluster))
112 ClusterMergeMap::const_iterator iter1 = clusterMergeMap.find(pCurrentCluster);
114 if (iter1 == clusterMergeMap.end())
117 ClusterVector associatedClusters(iter1->second.begin(), iter1->second.end());
118 std::sort(associatedClusters.begin(), associatedClusters.end(), LArClusterHelper::SortByNHits);
120 for (
const Cluster *
const pAssociatedCluster : associatedClusters)
122 if (pAssociatedCluster == pSeedCluster)
125 if (associatedClusterList.end() != std::find(associatedClusterList.begin(), associatedClusterList.end(), pAssociatedCluster))
128 associatedClusterList.push_back(pAssociatedCluster);
129 this->CollectAssociatedClusters(pSeedCluster, pAssociatedCluster, clusterMergeMap, clusterVetoList, associatedClusterList);
139 for (ClusterVector::const_iterator iter = inputClusters.begin(), iterEnd = inputClusters.end(); iter != iterEnd; ++iter)
141 const Cluster *
const pCluster = *iter;
143 if (!pCluster->IsAvailable())
145 pfoClusters.push_back(pCluster);
149 availableClusters.push_back(pCluster);
153 std::sort(pfoClusters.begin(), pfoClusters.end(), LArClusterHelper::SortByNHits);
154 std::sort(availableClusters.begin(), availableClusters.end(), LArClusterHelper::SortByNHits);
156 outputClusters.insert(outputClusters.end(), pfoClusters.begin(), pfoClusters.end());
157 outputClusters.insert(outputClusters.end(), availableClusters.begin(), availableClusters.end());
162 StatusCode ClusterMergingAlgorithm::ReadSettings(
const TiXmlHandle xmlHandle)
164 PANDORA_RETURN_RESULT_IF_AND_IF(
165 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"InputClusterListName", m_inputClusterListName));
167 return STATUS_CODE_SUCCESS;
Header file for the cluster helper class.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
std::vector< art::Ptr< recob::Cluster > > ClusterVector
BEGIN_PROLOG could also be cout
Header file for the cluster merging algorithm class.