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(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this, m_inputClusterListName, pClusterList));
33 if (!pClusterList || pClusterList->empty())
35 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
36 std::cout <<
"ClusterMergingAlgorithm: unable to find cluster list " << m_inputClusterListName << std::endl;
38 return STATUS_CODE_SUCCESS;
44 this->GetListOfCleanClusters(pClusterList, unsortedVector);
45 this->GetSortedListOfCleanClusters(unsortedVector, clusterVector);
48 this->PopulateClusterMergeMap(clusterVector, clusterMergeMap);
50 if (clusterMergeMap.empty())
53 this->MergeClusters(clusterVector, clusterMergeMap);
56 return STATUS_CODE_SUCCESS;
63 ClusterSet clusterVetoList;
65 for (
const Cluster *
const pSeedCluster : clusterVector)
67 ClusterList mergeList;
68 this->CollectAssociatedClusters(pSeedCluster, pSeedCluster, clusterMergeMap, clusterVetoList, mergeList);
69 mergeList.sort(LArClusterHelper::SortByNHits);
71 for (
const Cluster *
const pAssociatedCluster : mergeList)
73 if (clusterVetoList.count(pAssociatedCluster))
74 throw StatusCodeException(STATUS_CODE_FAILURE);
76 if (!pAssociatedCluster->IsAvailable())
77 throw StatusCodeException(STATUS_CODE_FAILURE);
79 (void) clusterVetoList.insert(pAssociatedCluster);
81 if (m_inputClusterListName.empty())
83 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*
this, pSeedCluster, pAssociatedCluster));
87 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*
this, pSeedCluster, pAssociatedCluster,
88 m_inputClusterListName, m_inputClusterListName));
96 void ClusterMergingAlgorithm::CollectAssociatedClusters(
const Cluster *
const pSeedCluster,
const ClusterMergeMap &clusterMergeMap, ClusterList& associatedClusterList)
const 98 ClusterSet clusterVetoList;
99 this->CollectAssociatedClusters(pSeedCluster, pSeedCluster, clusterMergeMap, clusterVetoList, associatedClusterList);
104 void ClusterMergingAlgorithm::CollectAssociatedClusters(
const Cluster *
const pSeedCluster,
const Cluster *
const pCurrentCluster,
const ClusterMergeMap &clusterMergeMap,
105 const ClusterSet &clusterVetoList, ClusterList &associatedClusterList)
const 107 if (clusterVetoList.count(pCurrentCluster))
112 if (iter1 == clusterMergeMap.end())
115 ClusterVector associatedClusters(iter1->second.begin(), iter1->second.end());
116 std::sort(associatedClusters.begin(), associatedClusters.end(), LArClusterHelper::SortByNHits);
118 for (
const Cluster *
const pAssociatedCluster : associatedClusters)
120 if (pAssociatedCluster == pSeedCluster)
123 if (associatedClusterList.end() != std::find(associatedClusterList.begin(), associatedClusterList.end(), pAssociatedCluster))
126 associatedClusterList.push_back(pAssociatedCluster);
127 this->CollectAssociatedClusters(pSeedCluster, pAssociatedCluster, clusterMergeMap, clusterVetoList, associatedClusterList);
139 const Cluster *
const pCluster = *iter;
141 if (!pCluster->IsAvailable())
143 pfoClusters.push_back(pCluster);
147 availableClusters.push_back(pCluster);
151 std::sort(pfoClusters.begin(), pfoClusters.end(), LArClusterHelper::SortByNHits);
152 std::sort(availableClusters.begin(), availableClusters.end(), LArClusterHelper::SortByNHits);
154 outputClusters.insert(outputClusters.end(), pfoClusters.begin(), pfoClusters.end());
155 outputClusters.insert(outputClusters.end(), availableClusters.begin(), availableClusters.end());
160 StatusCode ClusterMergingAlgorithm::ReadSettings(
const TiXmlHandle xmlHandle)
162 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
163 "InputClusterListName", m_inputClusterListName));
165 return STATUS_CODE_SUCCESS;
Header file for the cluster helper class.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
Header file for the cluster merging algorithm class.