Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
ClusterMergingAlgorithm.cc
Go to the documentation of this file.
1
10
12
14
15using namespace pandora;
16
17namespace lar_content
18{
19
21{
22 const ClusterList *pClusterList = NULL;
23
24 if (m_inputClusterListName.empty())
25 {
26 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pClusterList));
27 }
28 else
29 {
31 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, m_inputClusterListName, pClusterList));
32 }
33
34 if (!pClusterList || pClusterList->empty())
35 {
37 std::cout << "ClusterMergingAlgorithm: unable to find cluster list " << m_inputClusterListName << std::endl;
38
39 return STATUS_CODE_SUCCESS;
40 }
41
42 while (true)
43 {
44 ClusterVector unsortedVector, clusterVector;
45 this->GetListOfCleanClusters(pClusterList, unsortedVector);
46 this->GetSortedListOfCleanClusters(unsortedVector, clusterVector);
47
48 ClusterMergeMap clusterMergeMap;
49 this->PopulateClusterMergeMap(clusterVector, clusterMergeMap);
50
51 if (clusterMergeMap.empty())
52 break;
53
54 this->MergeClusters(clusterVector, clusterMergeMap);
55 }
56
57 return STATUS_CODE_SUCCESS;
58}
59
60//------------------------------------------------------------------------------------------------------------------------------------------
61
62void ClusterMergingAlgorithm::MergeClusters(ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
63{
64 ClusterSet clusterVetoList;
65
66 for (const Cluster *const pSeedCluster : clusterVector)
67 {
68 ClusterList mergeList;
69 this->CollectAssociatedClusters(pSeedCluster, pSeedCluster, clusterMergeMap, clusterVetoList, mergeList);
70 mergeList.sort(LArClusterHelper::SortByNHits);
71
72 for (const Cluster *const pAssociatedCluster : mergeList)
73 {
74 if (clusterVetoList.count(pAssociatedCluster))
75 throw StatusCodeException(STATUS_CODE_FAILURE);
76
77 if (!pAssociatedCluster->IsAvailable())
78 throw StatusCodeException(STATUS_CODE_FAILURE);
79
80 (void)clusterVetoList.insert(pAssociatedCluster);
81
82 if (m_inputClusterListName.empty())
83 {
84 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*this, pSeedCluster, pAssociatedCluster));
85 }
86 else
87 {
88 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
90 }
91 }
92 }
93}
94
95//------------------------------------------------------------------------------------------------------------------------------------------
96
98 const Cluster *const pSeedCluster, const ClusterMergeMap &clusterMergeMap, ClusterList &associatedClusterList) const
99{
100 ClusterSet clusterVetoList;
101 this->CollectAssociatedClusters(pSeedCluster, pSeedCluster, clusterMergeMap, clusterVetoList, associatedClusterList);
102}
103
104//------------------------------------------------------------------------------------------------------------------------------------------
105
106void ClusterMergingAlgorithm::CollectAssociatedClusters(const Cluster *const pSeedCluster, const Cluster *const pCurrentCluster,
107 const ClusterMergeMap &clusterMergeMap, const ClusterSet &clusterVetoList, ClusterList &associatedClusterList) const
108{
109 if (clusterVetoList.count(pCurrentCluster))
110 return;
111
112 ClusterMergeMap::const_iterator iter1 = clusterMergeMap.find(pCurrentCluster);
113
114 if (iter1 == clusterMergeMap.end())
115 return;
116
117 ClusterVector associatedClusters(iter1->second.begin(), iter1->second.end());
118 std::sort(associatedClusters.begin(), associatedClusters.end(), LArClusterHelper::SortByNHits);
119
120 for (const Cluster *const pAssociatedCluster : associatedClusters)
121 {
122 if (pAssociatedCluster == pSeedCluster)
123 continue;
124
125 if (associatedClusterList.end() != std::find(associatedClusterList.begin(), associatedClusterList.end(), pAssociatedCluster))
126 continue;
127
128 associatedClusterList.push_back(pAssociatedCluster);
129 this->CollectAssociatedClusters(pSeedCluster, pAssociatedCluster, clusterMergeMap, clusterVetoList, associatedClusterList);
130 }
131}
132
133//------------------------------------------------------------------------------------------------------------------------------------------
134
136{
137 ClusterVector pfoClusters, availableClusters;
138
139 for (ClusterVector::const_iterator iter = inputClusters.begin(), iterEnd = inputClusters.end(); iter != iterEnd; ++iter)
140 {
141 const Cluster *const pCluster = *iter;
142
143 if (!pCluster->IsAvailable())
144 {
145 pfoClusters.push_back(pCluster);
146 }
147 else
148 {
149 availableClusters.push_back(pCluster);
150 }
151 }
152
153 std::sort(pfoClusters.begin(), pfoClusters.end(), LArClusterHelper::SortByNHits);
154 std::sort(availableClusters.begin(), availableClusters.end(), LArClusterHelper::SortByNHits);
155
156 outputClusters.insert(outputClusters.end(), pfoClusters.begin(), pfoClusters.end());
157 outputClusters.insert(outputClusters.end(), availableClusters.begin(), availableClusters.end());
158}
159
160//------------------------------------------------------------------------------------------------------------------------------------------
161
163{
165 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListName", m_inputClusterListName));
166
167 return STATUS_CODE_SUCCESS;
168}
169
170} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the cluster merging algorithm class.
Header file for the cluster helper class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
static pandora::StatusCode GetCurrentList(const pandora::Algorithm &algorithm, const T *&pT)
Get the current list.
static pandora::StatusCode MergeAndDeleteClusters(const pandora::Algorithm &algorithm, const pandora::Cluster *const pClusterToEnlarge, const pandora::Cluster *const pClusterToDelete)
Merge two clusters in the current list, enlarging one cluster and deleting the second.
static pandora::StatusCode GetList(const pandora::Algorithm &algorithm, const std::string &listName, const T *&pT)
Get a named list.
static const pandora::PandoraSettings * GetSettings(const pandora::Algorithm &algorithm)
Get the pandora settings instance.
virtual void GetListOfCleanClusters(const pandora::ClusterList *const pClusterList, pandora::ClusterVector &clusterVector) const =0
Populate cluster vector with subset of cluster list, containing clusters judged to be clean.
void CollectAssociatedClusters(const pandora::Cluster *const pSeedCluster, const ClusterMergeMap &clusterMergeMap, pandora::ClusterList &associatedClusterList) const
Collect up all clusters associations related to a given seed cluster.
virtual void PopulateClusterMergeMap(const pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const =0
Form associations between pointing clusters.
virtual pandora::StatusCode Run()
Run the algorithm.
std::string m_inputClusterListName
The name of the input cluster list. If not specified, will access current list.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
void GetSortedListOfCleanClusters(const pandora::ClusterVector &inputClusters, pandora::ClusterVector &outputClusters) const
Sort the selected clusters, so that they have a well-defined ordering.
void MergeClusters(pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
Merge associated clusters.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
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,...
Cluster class.
Definition Cluster.h:31
bool IsAvailable() const
Whether the cluster is available to be added to a particle flow object.
Definition Cluster.h:582
bool ShouldDisplayAlgorithmInfo() const
Whether to display algorithm information during processing.
StatusCodeException class.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
std::vector< const Cluster * > ClusterVector
MANAGED_CONTAINER< const Cluster * > ClusterList
std::unordered_set< const Cluster * > ClusterSet
StatusCode
The StatusCode enum.