Fill the cluster merge map.
201 for (
const auto &mapEntry : inputAssociationMatrix)
202 sortedInputClusters.push_back(mapEntry.first);
205 for (
const Cluster *
const pCluster1 : sortedInputClusters)
209 for (
const Cluster *
const pCluster2 : sortedInputClusters)
211 if (pCluster1 == pCluster2)
217 if (associationMap1.end() == iter12)
221 if (associationMap2.end() == iter21)
224 const ClusterAssociation &association12(iter12->second);
225 const ClusterAssociation &association21(iter21->second);
227 bool isAssociated(
true);
230 for (
const auto &mapEntry : associationMap1)
231 sortedAssociationClusters.push_back(mapEntry.first);
234 for (
const Cluster *
const pCluster3 : sortedAssociationClusters)
236 const ClusterAssociation &association13(associationMap1.at(pCluster3));
239 if (associationMap2.end() == iter23)
242 const ClusterAssociation &association23(iter23->second);
244 if (association12.GetParent() == association13.GetParent() && association23.GetParent() == association21.GetParent() &&
245 association13.GetDaughter() != association23.GetDaughter())
247 isAssociated =
false;
254 (void)clusterAssociationMatrix[pCluster1].insert(ClusterAssociationMap::value_type(pCluster2, association12));
255 (void)clusterAssociationMatrix[pCluster2].insert(ClusterAssociationMap::value_type(pCluster1, association21));
264 for (
const auto &mapEntry : clusterAssociationMatrix)
265 sortedClusters.push_back(mapEntry.first);
268 for (
const Cluster *
const pParentCluster : sortedClusters)
272 const Cluster *pBestClusterInner(
nullptr);
275 const Cluster *pBestClusterOuter(
nullptr);
279 for (
const auto &mapEntry : clusterAssociationMap)
280 sortedAssociationClusters.push_back(mapEntry.first);
283 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
285 const ClusterAssociation &clusterAssociation(clusterAssociationMap.at(pDaughterCluster));
290 if (clusterAssociation.GetFigureOfMerit() > bestAssociationInner.GetFigureOfMerit())
292 bestAssociationInner = clusterAssociation;
295 pBestClusterInner = pDaughterCluster;
297 pBestClusterInner =
nullptr;
304 if (clusterAssociation.GetFigureOfMerit() > bestAssociationOuter.GetFigureOfMerit())
306 bestAssociationOuter = clusterAssociation;
309 pBestClusterOuter = pDaughterCluster;
311 pBestClusterOuter =
nullptr;
316 if (pBestClusterInner)
317 (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterInner, bestAssociationInner));
319 if (pBestClusterOuter)
320 (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterOuter, bestAssociationOuter));
325 for (
const auto &mapEntry : intermediateAssociationMatrix)
326 intermediateSortedClusters.push_back(mapEntry.first);
329 for (
const Cluster *
const pParentCluster : intermediateSortedClusters)
334 for (
const auto &mapEntry : parentAssociationMap)
335 sortedAssociationClusters.push_back(mapEntry.first);
338 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
340 const ClusterAssociation &parentToDaughterAssociation(parentAssociationMap.at(pDaughterCluster));
344 if (intermediateAssociationMatrix.end() == iter5)
351 if (daughterAssociationMap.end() == iter6)
354 const ClusterAssociation &daughterToParentAssociation(iter6->second);
356 if (parentToDaughterAssociation.GetParent() == daughterToParentAssociation.GetDaughter() &&
357 parentToDaughterAssociation.GetDaughter() == daughterToParentAssociation.GetParent())
359 ClusterList &parentList(clusterMergeMap[pParentCluster]);
361 if (parentList.end() == std::find(parentList.begin(), parentList.end(), pDaughterCluster))
362 parentList.push_back(pDaughterCluster);
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 *, ClusterAssociation > ClusterAssociationMap
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterAssociationMatrix
std::vector< art::Ptr< recob::Cluster > > ClusterVector