LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::ClusterGrowingAlgorithm Class Referenceabstract

ClusterGrowingAlgorithm class. More...

#include "ClusterGrowingAlgorithm.h"

Inheritance diagram for lar_content::ClusterGrowingAlgorithm:
lar_content::DeltaRayGrowingAlgorithm lar_content::SimpleClusterGrowingAlgorithm

Public Member Functions

 ClusterGrowingAlgorithm ()
 Default constructor. More...
 

Protected Types

typedef std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
 

Protected Member Functions

virtual pandora::StatusCode Run ()
 
virtual pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
virtual void GetListOfCleanClusters (const pandora::ClusterList *const pClusterList, pandora::ClusterVector &cleanClusters) const =0
 Populate cluster vector with the subset of clusters judged to be clean. More...
 
virtual void GetListOfSeedClusters (const pandora::ClusterVector &cleanClusters, pandora::ClusterVector &seedClusters) const =0
 Select seed clusters for growing. More...
 

Private Member Functions

void GetListOfNonSeedClusters (const pandora::ClusterVector &inputClusters, const pandora::ClusterVector &seedClusters, pandora::ClusterVector &nonSeedClusters) const
 Get List of non-seed clusters. More...
 
void PopulateClusterMergeMap (const pandora::ClusterVector &seedClusters, const pandora::ClusterVector &nonSeedClusters, ClusterMergeMap &clusterMergeMap) const
 Identify a set of cluster merges. More...
 
void MergeClusters (const ClusterMergeMap &clusterMergeMap) const
 Merge clusters. More...
 

Private Attributes

std::string m_inputClusterListName
 The name of the input cluster list. If not specified, will access current list. More...
 
float m_maxClusterSeparation
 Maximum distance at which clusters can be joined. More...
 

Detailed Description

ClusterGrowingAlgorithm class.

Definition at line 21 of file ClusterGrowingAlgorithm.h.

Member Typedef Documentation

typedef std::unordered_map<const pandora::Cluster*, pandora::ClusterList> lar_content::ClusterGrowingAlgorithm::ClusterMergeMap
protected

Definition at line 33 of file ClusterGrowingAlgorithm.h.

Constructor & Destructor Documentation

lar_content::ClusterGrowingAlgorithm::ClusterGrowingAlgorithm ( )

Default constructor.

Definition at line 20 of file ClusterGrowingAlgorithm.cc.

20  :
22 {
23 }
float m_maxClusterSeparation
Maximum distance at which clusters can be joined.
TFile f
Definition: plotHisto.C:6

Member Function Documentation

virtual void lar_content::ClusterGrowingAlgorithm::GetListOfCleanClusters ( const pandora::ClusterList *const  pClusterList,
pandora::ClusterVector &  cleanClusters 
) const
protectedpure virtual

Populate cluster vector with the subset of clusters judged to be clean.

Parameters
pClusterListaddress of the cluster list
cleanClustersthe output vector of clean clusters

Implemented in lar_content::SimpleClusterGrowingAlgorithm, and lar_content::DeltaRayGrowingAlgorithm.

Referenced by Run().

void lar_content::ClusterGrowingAlgorithm::GetListOfNonSeedClusters ( const pandora::ClusterVector &  inputClusters,
const pandora::ClusterVector &  seedClusters,
pandora::ClusterVector &  nonSeedClusters 
) const
private

Get List of non-seed clusters.

Parameters
inputClustersthe input vector of clean clusters
seedClustersthe input vector of seed clusters
nonSeedClustersthe output vector of non-seed clusters

Definition at line 72 of file ClusterGrowingAlgorithm.cc.

References lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

74 {
75  for (ClusterVector::const_iterator iter = inputClusters.begin(), iterEnd = inputClusters.end(); iter != iterEnd; ++iter)
76  {
77  const Cluster *const pCluster = *iter;
78 
79  if (seedClusters.end() != std::find(seedClusters.begin(), seedClusters.end(), pCluster))
80  continue;
81 
82  nonSeedClusters.push_back(pCluster);
83  }
84 
85  std::sort(nonSeedClusters.begin(), nonSeedClusters.end(), LArClusterHelper::SortByNHits);
86 }
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.
intermediate_table::const_iterator const_iterator
virtual void lar_content::ClusterGrowingAlgorithm::GetListOfSeedClusters ( const pandora::ClusterVector &  cleanClusters,
pandora::ClusterVector &  seedClusters 
) const
protectedpure virtual

Select seed clusters for growing.

Parameters
cleanClustersthe input vector of clean clusters
seedClustersthe output vector of seed clusters

Implemented in lar_content::SimpleClusterGrowingAlgorithm, and lar_content::DeltaRayGrowingAlgorithm.

Referenced by Run().

void lar_content::ClusterGrowingAlgorithm::MergeClusters ( const ClusterMergeMap clusterMergeMap) const
private

Merge clusters.

Parameters
clusterMergeMapthe map of clusters to be merged

Definition at line 119 of file ClusterGrowingAlgorithm.cc.

References m_inputClusterListName, and lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

120 {
121  ClusterList parentClusterList;
122  for (const auto &mapEntry : clusterMergeMap) parentClusterList.push_back(mapEntry.first);
123  parentClusterList.sort(LArClusterHelper::SortByNHits);
124 
125  for (const Cluster *const pParentCluster : parentClusterList)
126  {
127  const ClusterList &clusterList(clusterMergeMap.at(pParentCluster));
128 
129  if (clusterList.empty())
130  throw StatusCodeException(STATUS_CODE_FAILURE);
131 
132  for (const Cluster *const pAssociatedCluster : clusterList)
133  {
134  if (m_inputClusterListName.empty())
135  {
136  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*this, pParentCluster, pAssociatedCluster));
137  }
138  else
139  {
140  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*this, pParentCluster, pAssociatedCluster,
142  }
143  }
144  }
145 }
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::string m_inputClusterListName
The name of the input cluster list. If not specified, will access current list.
void lar_content::ClusterGrowingAlgorithm::PopulateClusterMergeMap ( const pandora::ClusterVector &  seedClusters,
const pandora::ClusterVector &  nonSeedClusters,
ClusterMergeMap clusterMergeMap 
) const
private

Identify a set of cluster merges.

Parameters
seedClustersthe input vector of seed clusters
nonSeedClustersthe input vector of non-seed clusters
clusterMergeMapthe output map of cluster merges

Definition at line 90 of file ClusterGrowingAlgorithm.cc.

References lar_content::LArClusterHelper::GetClosestDistance(), and m_maxClusterSeparation.

Referenced by Run().

92 {
93  for (ClusterVector::const_iterator nIter = nonSeedClusters.begin(), nIterEnd = nonSeedClusters.end(); nIter != nIterEnd; ++nIter)
94  {
95  const Cluster *const pNonSeedCluster = *nIter;
96 
97  const Cluster *pBestSeedCluster(NULL);
98  float bestDistance(m_maxClusterSeparation);
99 
100  for (ClusterVector::const_iterator sIter = seedClusters.begin(), sIterEnd = seedClusters.end(); sIter != sIterEnd; ++sIter)
101  {
102  const Cluster *const pThisSeedCluster = *sIter;
103  const float thisDistance(LArClusterHelper::GetClosestDistance(pNonSeedCluster, pThisSeedCluster));
104 
105  if (thisDistance < bestDistance)
106  {
107  pBestSeedCluster = pThisSeedCluster;
108  bestDistance = thisDistance;
109  }
110  }
111 
112  if (pBestSeedCluster)
113  clusterMergeMap[pBestSeedCluster].push_back(pNonSeedCluster);
114  }
115 }
float m_maxClusterSeparation
Maximum distance at which clusters can be joined.
intermediate_table::const_iterator const_iterator
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.
StatusCode lar_content::ClusterGrowingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
protectedvirtual

Reimplemented in lar_content::DeltaRayGrowingAlgorithm, and lar_content::SimpleClusterGrowingAlgorithm.

Definition at line 149 of file ClusterGrowingAlgorithm.cc.

References m_inputClusterListName, and m_maxClusterSeparation.

Referenced by lar_content::SimpleClusterGrowingAlgorithm::ReadSettings(), and lar_content::DeltaRayGrowingAlgorithm::ReadSettings().

150 {
151  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
152  "InputClusterListName", m_inputClusterListName));
153 
154  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
155  "MaxClusterSeparation", m_maxClusterSeparation));
156 
157  return STATUS_CODE_SUCCESS;
158 }
float m_maxClusterSeparation
Maximum distance at which clusters can be joined.
std::string m_inputClusterListName
The name of the input cluster list. If not specified, will access current list.
StatusCode lar_content::ClusterGrowingAlgorithm::Run ( )
protectedvirtual

Definition at line 27 of file ClusterGrowingAlgorithm.cc.

References GetListOfCleanClusters(), GetListOfNonSeedClusters(), GetListOfSeedClusters(), m_inputClusterListName, MergeClusters(), and PopulateClusterMergeMap().

28 {
29  const ClusterList *pClusterList = NULL;
30 
31  if (m_inputClusterListName.empty())
32  {
33  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pClusterList));
34  }
35  else
36  {
37  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, m_inputClusterListName, pClusterList));
38  }
39 
40  if (!pClusterList || pClusterList->empty())
41  {
42  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
43  std::cout << "ClusterGrowingAlgorithm: unable to find cluster list " << m_inputClusterListName << std::endl;
44 
45  return STATUS_CODE_SUCCESS;
46  }
47 
48  ClusterVector inputClusters, seedClusters;
49  this->GetListOfCleanClusters(pClusterList, inputClusters);
50  this->GetListOfSeedClusters(inputClusters, seedClusters);
51 
52  while (true)
53  {
54  ClusterVector currentClusters, nonSeedClusters;
55  this->GetListOfCleanClusters(pClusterList, currentClusters);
56  this->GetListOfNonSeedClusters(currentClusters, seedClusters, nonSeedClusters);
57 
58  ClusterMergeMap clusterMergeMap;
59  this->PopulateClusterMergeMap(seedClusters, nonSeedClusters, clusterMergeMap);
60 
61  if (clusterMergeMap.empty())
62  break;
63 
64  this->MergeClusters(clusterMergeMap);
65  }
66 
67  return STATUS_CODE_SUCCESS;
68 }
void GetListOfNonSeedClusters(const pandora::ClusterVector &inputClusters, const pandora::ClusterVector &seedClusters, pandora::ClusterVector &nonSeedClusters) const
Get List of non-seed clusters.
void MergeClusters(const ClusterMergeMap &clusterMergeMap) const
Merge clusters.
virtual void GetListOfCleanClusters(const pandora::ClusterList *const pClusterList, pandora::ClusterVector &cleanClusters) const =0
Populate cluster vector with the subset of clusters judged to be clean.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
std::string m_inputClusterListName
The name of the input cluster list. If not specified, will access current list.
virtual void GetListOfSeedClusters(const pandora::ClusterVector &cleanClusters, pandora::ClusterVector &seedClusters) const =0
Select seed clusters for growing.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void PopulateClusterMergeMap(const pandora::ClusterVector &seedClusters, const pandora::ClusterVector &nonSeedClusters, ClusterMergeMap &clusterMergeMap) const
Identify a set of cluster merges.

Member Data Documentation

std::string lar_content::ClusterGrowingAlgorithm::m_inputClusterListName
private

The name of the input cluster list. If not specified, will access current list.

Definition at line 80 of file ClusterGrowingAlgorithm.h.

Referenced by MergeClusters(), ReadSettings(), and Run().

float lar_content::ClusterGrowingAlgorithm::m_maxClusterSeparation
private

Maximum distance at which clusters can be joined.

Definition at line 82 of file ClusterGrowingAlgorithm.h.

Referenced by PopulateClusterMergeMap(), and ReadSettings().


The documentation for this class was generated from the following files: