9 #include "Pandora/PandoraInputTypes.h"
11 #include "Pandora/PandoraInputTypes.h"
12 #include "Pandora/PandoraInternal.h"
13 #include "Pandora/StatusCodes.h"
15 #include "Objects/Cluster.h"
32 for (
typename TheMatrix::const_iterator iter1 = this->
begin(), iter1End = this->
end(); iter1 != iter1End; ++iter1)
35 ClusterList clusterList1, clusterList2;
36 this->GetConnectedElements(iter1->first, ignoreUnavailable, tempElementList, clusterList1, clusterList2);
38 const Cluster *pCluster1(
nullptr), *pCluster2(
nullptr);
39 if (!this->DefaultAmbiguityFunction(clusterList1, clusterList2, pCluster1, pCluster2))
43 if (iter1->first != pCluster1)
46 if (!pCluster1 || !pCluster2)
49 typename OverlapList::const_iterator iter2 = iter1->second.find(pCluster2);
50 if (iter1->second.end() == iter2)
51 throw StatusCodeException(STATUS_CODE_FAILURE);
54 elementList.push_back(element);
57 std::sort(elementList.begin(), elementList.end());
64 const ClusterList &clusterList1,
const ClusterList &clusterList2,
const Cluster *&pCluster1,
const Cluster *&pCluster2)
const
66 if ((1 != clusterList1.size()) || (1 != clusterList2.size()))
69 pCluster1 = *(clusterList1.begin());
70 pCluster2 = *(clusterList2.begin());
79 const pandora::Cluster *
const pCluster,
const bool ignoreUnavailable,
ElementList &elementList,
unsigned int &n1,
unsigned int &n2)
const
81 ClusterList clusterList1, clusterList2;
82 this->GetConnectedElements(pCluster, ignoreUnavailable, elementList, clusterList1, clusterList2);
83 n1 = clusterList1.size();
84 n2 = clusterList2.size();
92 for (
typename TheMatrix::const_iterator iter1 = this->
begin(), iter1End = this->
end(); iter1 != iter1End; ++iter1)
93 sortedKeyClusters.push_back(iter1->first);
95 std::sort(sortedKeyClusters.begin(), sortedKeyClusters.end(), LArClusterHelper::SortByNHits);
100 template <
typename T>
103 OverlapList &overlapList = m_overlapMatrix[pCluster1];
104 typename OverlapList::const_iterator iter = overlapList.find(pCluster2);
106 if (overlapList.end() != iter)
107 throw pandora::StatusCodeException(pandora::STATUS_CODE_ALREADY_PRESENT);
109 if (!overlapList.insert(
typename OverlapList::value_type(pCluster2, overlapResult)).second)
110 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
112 ClusterList &navigation12(m_clusterNavigationMap12[pCluster1]);
113 ClusterList &navigation21(m_clusterNavigationMap21[pCluster2]);
115 if (navigation12.end() == std::find(navigation12.begin(), navigation12.end(), pCluster2))
116 navigation12.push_back(pCluster2);
117 if (navigation21.end() == std::find(navigation21.begin(), navigation21.end(), pCluster1))
118 navigation21.push_back(pCluster1);
123 template <
typename T>
126 typename TheMatrix::iterator iter1 = m_overlapMatrix.find(pCluster1);
128 if (m_overlapMatrix.end() == iter1)
129 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
131 typename OverlapList::iterator iter2 = iter1->second.find(pCluster2);
133 if (iter1->second.end() == iter2)
134 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
136 iter2->second = overlapResult;
141 template <
typename T>
144 ClusterList additionalRemovals;
146 if (m_clusterNavigationMap12.erase(pCluster) > 0)
148 typename TheMatrix::iterator iter = m_overlapMatrix.find(pCluster);
150 if (m_overlapMatrix.end() != iter)
151 m_overlapMatrix.erase(iter);
153 for (ClusterNavigationMap::iterator navIter = m_clusterNavigationMap21.begin(); navIter != m_clusterNavigationMap21.end();)
155 ClusterNavigationMap::iterator thisIter = navIter++;
156 ClusterList::iterator listIter = std::find(thisIter->second.begin(), thisIter->second.end(), pCluster);
158 if (thisIter->second.end() != listIter)
159 thisIter->second.erase(listIter);
161 if (thisIter->second.empty())
162 additionalRemovals.push_back(thisIter->first);
166 if (m_clusterNavigationMap21.erase(pCluster) > 0)
168 for (
typename TheMatrix::iterator iter1 = m_overlapMatrix.begin(), iter1End = m_overlapMatrix.end(); iter1 != iter1End; ++iter1)
170 typename OverlapList::iterator iter = iter1->second.find(pCluster);
172 if (iter1->second.end() != iter)
173 iter1->second.erase(iter);
176 for (ClusterNavigationMap::iterator navIter = m_clusterNavigationMap12.begin(); navIter != m_clusterNavigationMap12.end();)
178 ClusterNavigationMap::iterator thisIter = navIter++;
179 ClusterList::iterator listIter = std::find(thisIter->second.begin(), thisIter->second.end(), pCluster);
181 if (thisIter->second.end() != listIter)
182 thisIter->second.erase(listIter);
184 if (thisIter->second.empty())
185 additionalRemovals.push_back(thisIter->first);
189 additionalRemovals.sort(LArClusterHelper::SortByNHits);
191 for (ClusterList::const_iterator iter = additionalRemovals.begin(), iterEnd = additionalRemovals.end(); iter != iterEnd; ++iter)
192 this->RemoveCluster(*iter);
197 template <
typename T>
199 ClusterList &clusterList1, ClusterList &clusterList2)
const
201 ClusterList localClusterList1, localClusterList2;
202 this->ExploreConnections(pCluster, ignoreUnavailable, localClusterList1, localClusterList2);
206 clusterList1.clear();
207 clusterList2.clear();
209 for (
typename TheMatrix::const_iterator iter1 = this->
begin(), iter1End = this->
end(); iter1 != iter1End; ++iter1)
211 if (localClusterList1.end() == std::find(localClusterList1.begin(), localClusterList1.end(), iter1->first))
214 for (
typename OverlapList::const_iterator iter2 = iter1->second.begin(), iter2End = iter1->second.end(); iter2 != iter2End; ++iter2)
216 if (ignoreUnavailable && (!iter1->first->IsAvailable() || !iter2->first->IsAvailable()))
219 Element
element(iter1->first, iter2->first, iter2->second);
220 elementList.push_back(
element);
222 if (clusterList1.end() == std::find(clusterList1.begin(), clusterList1.end(), iter1->first))
223 clusterList1.push_back(iter1->first);
224 if (clusterList2.end() == std::find(clusterList2.begin(), clusterList2.end(), iter2->first))
225 clusterList2.push_back(iter2->first);
229 std::sort(elementList.begin(), elementList.end());
234 template <
typename T>
236 const Cluster *
const pCluster,
const bool ignoreUnavailable, ClusterList &clusterList1, ClusterList &clusterList2)
const
238 if (ignoreUnavailable && !pCluster->IsAvailable())
241 const HitType hitType(LArClusterHelper::GetClusterHitType(pCluster));
242 const bool clusterFromView1(
243 !m_clusterNavigationMap12.empty() && (LArClusterHelper::GetClusterHitType(m_clusterNavigationMap12.begin()->first) == hitType));
244 const bool clusterFromView2(
245 !m_clusterNavigationMap21.empty() && (LArClusterHelper::GetClusterHitType(m_clusterNavigationMap21.begin()->first) == hitType));
247 if (clusterFromView1 == clusterFromView2)
248 throw StatusCodeException(STATUS_CODE_FAILURE);
250 ClusterList &clusterList(clusterFromView1 ? clusterList1 : clusterList2);
251 const ClusterNavigationMap &navigationMap(clusterFromView1 ? m_clusterNavigationMap12 : m_clusterNavigationMap21);
253 if (clusterList.end() != std::find(clusterList.begin(), clusterList.end(), pCluster))
256 clusterList.push_back(pCluster);
257 ClusterNavigationMap::const_iterator iter = navigationMap.find(pCluster);
259 if (navigationMap.end() == iter)
260 throw StatusCodeException(STATUS_CODE_FAILURE);
262 for (ClusterList::const_iterator cIter = iter->second.begin(), cIterEnd = iter->second.end(); cIter != cIterEnd; ++cIter)
263 this->ExploreConnections(*cIter, ignoreUnavailable, clusterList1, clusterList2);
std::vector< Element > ElementList
Header file for the lar overlap matrix class.
Header file for the cluster helper class.
auto end(FixedBins< T, C > const &) noexcept
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterNavigationMap
std::unordered_map< const pandora::Cluster *, OverlapResult > OverlapList
auto begin(FixedBins< T, C > const &) noexcept
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
std::vector< art::Ptr< recob::Cluster > > ClusterVector
Header file for the lar track two view overlap result class.