LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::BoundedRegionClusterMergingAlgorithm Class Reference

BoundedRegionClusterMergingAlgorithm class. More...

#include "BoundedRegionClusterMergingAlgorithm.h"

Inheritance diagram for lar_content::BoundedRegionClusterMergingAlgorithm:
lar_content::ClusterMergingAlgorithm

Public Member Functions

 BoundedRegionClusterMergingAlgorithm ()
 

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)
 
void GetListOfBoundedRegionClusters (const pandora::ClusterList *const pClusterList, pandora::ClusterVector &clusterVector) const
 Populate cluster vector with all clusters starting in the defined region. More...
 
bool AreClustersAssociated (const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const
 Compare two clusters and decide if they should be associated with each other. More...
 
void GetListOfCleanClusters (const pandora::ClusterList *const pClusterList, pandora::ClusterVector &clusterVector) const
 Populate cluster vector with subset of cluster list, containing clusters judged to be clean. More...
 
void PopulateClusterMergeMap (const pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
 Form associations between pointing clusters. More...
 
void MergeClusters (pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
 Merge associated clusters. More...
 
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. More...
 
void CollectAssociatedClusters (const pandora::Cluster *const pSeedCluster, const pandora::Cluster *const pCurrentCluster, const ClusterMergeMap &clusterMergeMap, const pandora::ClusterSet &clusterVetoList, pandora::ClusterList &associatedClusterList) const
 Collect up all clusters associations related to a given seed cluster. More...
 
void GetSortedListOfCleanClusters (const pandora::ClusterVector &inputClusters, pandora::ClusterVector &outputClusters) const
 Sort the selected clusters, so that they have a well-defined ordering. More...
 

Protected Attributes

std::string m_inputClusterListName
 The name of the input cluster list. If not specified, will access current list. More...
 

Private Attributes

float m_xRegionMin
 Minimum x value of the bounded region box. More...
 
float m_xRegionMax
 Maximum x value of the bounded region box. More...
 
float m_zRegionMin
 Minimum z value (wire dimension) of the bounded region box. More...
 
float m_zRegionMax
 Maximum z value (wire dimension) of the bounded region box. More...
 
float m_maxDistance
 Maximum distance below which clusters can be associated. More...
 
unsigned int m_minClusterHits
 Threshold on the size of clusters to be considered for merging. More...
 

Detailed Description

Member Typedef Documentation

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

Definition at line 31 of file BoundedRegionClusterMergingAlgorithm.h.

Constructor & Destructor Documentation

lar_content::BoundedRegionClusterMergingAlgorithm::BoundedRegionClusterMergingAlgorithm ( )

Definition at line 20 of file BoundedRegionClusterMergingAlgorithm.cc.

20  :
21  m_xRegionMin(-100.f),
22  m_xRegionMax(0.f),
23  m_zRegionMin(235.f),
24  m_zRegionMax(400.f),
25  m_maxDistance(10.f),
27 {
28 }
TFile f
Definition: plotHisto.C:6
float m_maxDistance
Maximum distance below which clusters can be associated.
float m_xRegionMin
Minimum x value of the bounded region box.
float m_zRegionMax
Maximum z value (wire dimension) of the bounded region box.
float m_xRegionMax
Maximum x value of the bounded region box.
unsigned int m_minClusterHits
Threshold on the size of clusters to be considered for merging.
float m_zRegionMin
Minimum z value (wire dimension) of the bounded region box.

Member Function Documentation

bool lar_content::BoundedRegionClusterMergingAlgorithm::AreClustersAssociated ( const pandora::Cluster *const  pCluster1,
const pandora::Cluster *const  pCluster2 
) const
protected

Compare two clusters and decide if they should be associated with each other.

Parameters
pCluster1pointer to the first cluster
pCluster2pointer to the second cluster
Returns
whether the clusters should be associated or not

Definition at line 125 of file BoundedRegionClusterMergingAlgorithm.cc.

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

Referenced by PopulateClusterMergeMap().

126 {
127  const float distance{LArClusterHelper::GetClosestDistance(pCluster1, pCluster2)};
128  return distance < m_maxDistance;
129 }
float m_maxDistance
Maximum distance below which clusters can be associated.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.
void lar_content::ClusterMergingAlgorithm::CollectAssociatedClusters ( const pandora::Cluster *const  pSeedCluster,
const ClusterMergeMap clusterMergeMap,
pandora::ClusterList &  associatedClusterList 
) const
protectedinherited

Collect up all clusters associations related to a given seed cluster.

Parameters
pSeedClusterpointer to the initial cluster
clusterMergeMapthe map of cluster associations
associatedClusterListthe output list of associated clusters
void lar_content::ClusterMergingAlgorithm::CollectAssociatedClusters ( const pandora::Cluster *const  pSeedCluster,
const pandora::Cluster *const  pCurrentCluster,
const ClusterMergeMap clusterMergeMap,
const pandora::ClusterSet &  clusterVetoList,
pandora::ClusterList &  associatedClusterList 
) const
protectedinherited

Collect up all clusters associations related to a given seed cluster.

Parameters
pSeedClusterpointer to the initial cluster
pCurrentClusterpointer to the current cluster
clusterMergeMapthe map of cluster associations
clusterVetoListthe list of clusters that have already been merged
associatedClusterListthe output list of associated clusters
void lar_content::BoundedRegionClusterMergingAlgorithm::GetListOfBoundedRegionClusters ( const pandora::ClusterList *const  pClusterList,
pandora::ClusterVector &  clusterVector 
) const
protected

Populate cluster vector with all clusters starting in the defined region.

Parameters
pClusterListpointer to the list of all 2D clusters
clusterVectorto receive the clusters within the bounded region

Definition at line 72 of file BoundedRegionClusterMergingAlgorithm.cc.

References f, lar_content::LArClusterHelper::GetClusterBoundingBox(), m_minClusterHits, m_xRegionMax, m_xRegionMin, m_zRegionMax, m_zRegionMin, and lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

74 {
75  for (const Cluster *const pCluster : *pClusterList)
76  {
77  if (!pCluster->IsAvailable())
78  continue;
79 
80  if (pCluster->GetNCaloHits() < m_minClusterHits)
81  continue;
82 
83  CartesianVector minimumPos(0.f, 0.f, 0.f), maximumPos(0.f, 0.f, 0.f);
84  LArClusterHelper::GetClusterBoundingBox(pCluster, minimumPos, maximumPos);
85  (void)maximumPos; // To get rid of an unused variable warning
86 
87  if (minimumPos.GetX() > m_xRegionMin && minimumPos.GetX() < m_xRegionMax && minimumPos.GetZ() > m_zRegionMin && minimumPos.GetZ() < m_zRegionMax)
88  clusterVector.emplace_back(pCluster);
89  }
90 
91  if (!clusterVector.empty())
92  std::sort(clusterVector.begin(), clusterVector.end(), LArClusterHelper::SortByNHits);
93 }
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.
TFile f
Definition: plotHisto.C:6
static void GetClusterBoundingBox(const pandora::Cluster *const pCluster, pandora::CartesianVector &minimumCoordinate, pandora::CartesianVector &maximumCoordinate)
Get minimum and maximum X, Y and Z positions of the calo hits in a cluster.
float m_xRegionMin
Minimum x value of the bounded region box.
float m_zRegionMax
Maximum z value (wire dimension) of the bounded region box.
float m_xRegionMax
Maximum x value of the bounded region box.
unsigned int m_minClusterHits
Threshold on the size of clusters to be considered for merging.
float m_zRegionMin
Minimum z value (wire dimension) of the bounded region box.
void lar_content::BoundedRegionClusterMergingAlgorithm::GetListOfCleanClusters ( const pandora::ClusterList *const  pClusterList,
pandora::ClusterVector &  clusterVector 
) const
protectedvirtual

Populate cluster vector with subset of cluster list, containing clusters judged to be clean.

Parameters
pClusterListaddress of the cluster list
clusterVectorto receive the populated cluster vector

Implements lar_content::ClusterMergingAlgorithm.

Definition at line 133 of file BoundedRegionClusterMergingAlgorithm.cc.

134 {
135 }
void lar_content::ClusterMergingAlgorithm::GetSortedListOfCleanClusters ( const pandora::ClusterVector &  inputClusters,
pandora::ClusterVector &  outputClusters 
) const
protectedinherited

Sort the selected clusters, so that they have a well-defined ordering.

Parameters
inputClustersthe input vector of clusters
outputClustersthe output vector of clusters

Definition at line 135 of file ClusterMergingAlgorithm.cc.

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 }
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
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void lar_content::ClusterMergingAlgorithm::MergeClusters ( pandora::ClusterVector &  clusterVector,
ClusterMergeMap clusterMergeMap 
) const
protectedinherited

Merge associated clusters.

Parameters
clusterVectorthe vector of clean clusters
clusterMergeMapthe matrix of cluster associations

Definition at line 62 of file ClusterMergingAlgorithm.cc.

Referenced by Run().

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, !=,
89  PandoraContentApi::MergeAndDeleteClusters(*this, pSeedCluster, pAssociatedCluster, m_inputClusterListName, m_inputClusterListName));
90  }
91  }
92  }
93 }
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 CollectAssociatedClusters(const pandora::Cluster *const pSeedCluster, const ClusterMergeMap &clusterMergeMap, pandora::ClusterList &associatedClusterList) const
Collect up all clusters associations related to a given seed cluster.
void lar_content::BoundedRegionClusterMergingAlgorithm::PopulateClusterMergeMap ( const pandora::ClusterVector &  clusterVector,
ClusterMergeMap clusterMergeMap 
) const
protectedvirtual

Form associations between pointing clusters.

Parameters
clusterVectorthe vector of clean clusters
clusterMergeMapthe matrix of cluster associations

Implements lar_content::ClusterMergingAlgorithm.

Definition at line 97 of file BoundedRegionClusterMergingAlgorithm.cc.

References AreClustersAssociated().

Referenced by Run().

98 {
99  ClusterVector usedClusters;
100 
101  for (unsigned int i = 0; i < clusterVector.size() - 1; ++i)
102  {
103  const Cluster *const pCluster1{clusterVector.at(i)};
104 
105  for (unsigned int j = i + 1; j < clusterVector.size(); ++j)
106  {
107  const Cluster *const pCluster2{clusterVector.at(j)};
108  if (!pCluster2->IsAvailable())
109  continue;
110 
111  if (std::find(usedClusters.begin(), usedClusters.end(), pCluster2) != usedClusters.end())
112  continue;
113 
114  if (this->AreClustersAssociated(pCluster1, pCluster2))
115  {
116  clusterMergeMap[pCluster1].emplace_back(pCluster2);
117  usedClusters.emplace_back(pCluster2);
118  }
119  }
120  }
121 }
bool AreClustersAssociated(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2) const
Compare two clusters and decide if they should be associated with each other.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
StatusCode lar_content::BoundedRegionClusterMergingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
protectedvirtual

Reimplemented from lar_content::ClusterMergingAlgorithm.

Definition at line 139 of file BoundedRegionClusterMergingAlgorithm.cc.

References m_maxDistance, m_minClusterHits, m_xRegionMax, m_xRegionMin, m_zRegionMax, m_zRegionMin, and lar_content::ClusterMergingAlgorithm::ReadSettings().

140 {
141  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumX", m_xRegionMin));
142  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaximumX", m_xRegionMax));
143  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumZ", m_zRegionMin));
144  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaximumZ", m_zRegionMax));
145 
146  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxDistance", m_maxDistance));
147 
148  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinClusterHits", m_minClusterHits));
149  return ClusterMergingAlgorithm::ReadSettings(xmlHandle);
150 }
float m_maxDistance
Maximum distance below which clusters can be associated.
float m_xRegionMin
Minimum x value of the bounded region box.
float m_zRegionMax
Maximum z value (wire dimension) of the bounded region box.
float m_xRegionMax
Maximum x value of the bounded region box.
unsigned int m_minClusterHits
Threshold on the size of clusters to be considered for merging.
float m_zRegionMin
Minimum z value (wire dimension) of the bounded region box.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
StatusCode lar_content::BoundedRegionClusterMergingAlgorithm::Run ( )
protectedvirtual

Reimplemented from lar_content::ClusterMergingAlgorithm.

Definition at line 30 of file BoundedRegionClusterMergingAlgorithm.cc.

References GetListOfBoundedRegionClusters(), lar_content::ClusterMergingAlgorithm::m_inputClusterListName, lar_content::ClusterMergingAlgorithm::MergeClusters(), and PopulateClusterMergeMap().

31 {
32  const ClusterList *pClusterList{nullptr};
33 
34  if (m_inputClusterListName.empty())
35  {
36  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pClusterList));
37  }
38  else
39  {
40  PANDORA_RETURN_RESULT_IF_AND_IF(
41  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, m_inputClusterListName, pClusterList));
42  }
43 
44  if (!pClusterList || pClusterList->empty())
45  {
46  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
47  std::cout << "BoundedRegionClusterMergingAlgorithm: unable to find cluster list " << m_inputClusterListName << std::endl;
48 
49  return STATUS_CODE_SUCCESS;
50  }
51 
52  while (true)
53  {
54  ClusterVector clusterVector;
55  ClusterMergeMap clusterMergeMap;
56  this->GetListOfBoundedRegionClusters(pClusterList, clusterVector);
57  if (clusterVector.size() < 2)
58  break;
59 
60  this->PopulateClusterMergeMap(clusterVector, clusterMergeMap);
61  if (clusterMergeMap.empty())
62  break;
63 
64  this->MergeClusters(clusterVector, clusterMergeMap);
65  }
66 
67  return STATUS_CODE_SUCCESS;
68 }
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.
void GetListOfBoundedRegionClusters(const pandora::ClusterList *const pClusterList, pandora::ClusterVector &clusterVector) const
Populate cluster vector with all clusters starting in the defined region.
void PopulateClusterMergeMap(const pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
Form associations between pointing clusters.
void MergeClusters(pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
Merge associated clusters.
std::vector< art::Ptr< recob::Cluster > > ClusterVector

Member Data Documentation

std::string lar_content::ClusterMergingAlgorithm::m_inputClusterListName
protectedinherited

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

Definition at line 83 of file ClusterMergingAlgorithm.h.

Referenced by Run().

float lar_content::BoundedRegionClusterMergingAlgorithm::m_maxDistance
private

Maximum distance below which clusters can be associated.

Definition at line 72 of file BoundedRegionClusterMergingAlgorithm.h.

Referenced by AreClustersAssociated(), and ReadSettings().

unsigned int lar_content::BoundedRegionClusterMergingAlgorithm::m_minClusterHits
private

Threshold on the size of clusters to be considered for merging.

Definition at line 73 of file BoundedRegionClusterMergingAlgorithm.h.

Referenced by GetListOfBoundedRegionClusters(), and ReadSettings().

float lar_content::BoundedRegionClusterMergingAlgorithm::m_xRegionMax
private

Maximum x value of the bounded region box.

Definition at line 69 of file BoundedRegionClusterMergingAlgorithm.h.

Referenced by GetListOfBoundedRegionClusters(), and ReadSettings().

float lar_content::BoundedRegionClusterMergingAlgorithm::m_xRegionMin
private

Minimum x value of the bounded region box.

Definition at line 68 of file BoundedRegionClusterMergingAlgorithm.h.

Referenced by GetListOfBoundedRegionClusters(), and ReadSettings().

float lar_content::BoundedRegionClusterMergingAlgorithm::m_zRegionMax
private

Maximum z value (wire dimension) of the bounded region box.

Definition at line 71 of file BoundedRegionClusterMergingAlgorithm.h.

Referenced by GetListOfBoundedRegionClusters(), and ReadSettings().

float lar_content::BoundedRegionClusterMergingAlgorithm::m_zRegionMin
private

Minimum z value (wire dimension) of the bounded region box.

Definition at line 70 of file BoundedRegionClusterMergingAlgorithm.h.

Referenced by GetListOfBoundedRegionClusters(), and ReadSettings().


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