LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::TransverseExtensionAlgorithm Class Reference

TransverseExtensionAlgorithm class. More...

#include "TransverseExtensionAlgorithm.h"

Inheritance diagram for lar_content::TransverseExtensionAlgorithm:
lar_content::ClusterExtensionAlgorithm lar_content::ClusterMergingAlgorithm

Public Member Functions

 TransverseExtensionAlgorithm ()
 Default constructor. More...
 

Protected Types

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

Protected Member Functions

void PopulateClusterMergeMap (const pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMatrix) const
 Form associations between pointing clusters. More...
 
virtual pandora::StatusCode Run ()
 
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 Member Functions

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 FillClusterAssociationMatrix (const pandora::ClusterVector &clusterVector, ClusterAssociationMatrix &clusterAssociationMatrix) const
 Fill the cluster association matrix. More...
 
void FillClusterMergeMap (const ClusterAssociationMatrix &clusterAssociationMatrix, ClusterMergeMap &clusterMergeMap) const
 Fill the cluster merge map. More...
 
void FillClusterAssociationMatrix (const LArPointingCluster &parentCluster, const pandora::Cluster *const pDaughterCluster, ClusterAssociationMatrix &clusterAssociationMatrix) const
 Form associations between parent and daughter clusters. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

float m_minClusterLength
 
float m_maxLongitudinalDisplacement
 
float m_maxTransverseDisplacement
 

Detailed Description

Member Typedef Documentation

typedef std::unordered_map<const pandora::Cluster*, ClusterAssociation> lar_content::ClusterExtensionAlgorithm::ClusterAssociationMap
protectedinherited

Definition at line 97 of file ClusterExtensionAlgorithm.h.

typedef std::unordered_map<const pandora::Cluster*, ClusterAssociationMap> lar_content::ClusterExtensionAlgorithm::ClusterAssociationMatrix
protectedinherited

Definition at line 98 of file ClusterExtensionAlgorithm.h.

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

Definition at line 27 of file ClusterMergingAlgorithm.h.

Constructor & Destructor Documentation

lar_content::TransverseExtensionAlgorithm::TransverseExtensionAlgorithm ( )

Member Function Documentation

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::TransverseExtensionAlgorithm::FillClusterAssociationMatrix ( const pandora::ClusterVector &  clusterVector,
ClusterAssociationMatrix clusterAssociationMatrix 
) const
privatevirtual

Fill the cluster association matrix.

Parameters
clusterVectorthe input vector of clusters
clusterAssociationMatrixthe matrix of associations

Implements lar_content::ClusterExtensionAlgorithm.

Referenced by GetListOfCleanClusters().

void lar_content::TransverseExtensionAlgorithm::FillClusterAssociationMatrix ( const LArPointingCluster parentCluster,
const pandora::Cluster *const  pDaughterCluster,
ClusterAssociationMatrix clusterAssociationMatrix 
) const
private

Form associations between parent and daughter clusters.

Parameters
parentClusterthe parent pointing cluster
pDaughterClusterthe address of the daughter cluster
clusterAssociationMatrixthe matrix of cluster associations
void lar_content::TransverseExtensionAlgorithm::FillClusterMergeMap ( const ClusterAssociationMatrix clusterAssociationMatrix,
ClusterMergeMap clusterMergeMap 
) const
privatevirtual

Fill the cluster merge map.

Parameters
clusterAssociationMatrixthe matrix of cluster associations
clusterMergeMapthe map of cluster merges

Implements lar_content::ClusterExtensionAlgorithm.

Definition at line 130 of file TransverseExtensionAlgorithm.cc.

References lar_content::ClusterExtensionAlgorithm::ClusterAssociation::GetFigureOfMerit(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::INNER, max, lar_content::ClusterExtensionAlgorithm::ClusterAssociation::OUTER, lar_content::LArClusterHelper::SortByNHits(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::STRONG, and lar_content::ClusterExtensionAlgorithm::ClusterAssociation::WEAK.

131 {
132  ClusterAssociationMatrix daughterToParentMatrix;
133 
134  // Loop over parent clusters and select nearby daughter clusters that are closer than another parent cluster
135  ClusterVector sortedParentClusters;
136  for (const auto &mapEntry : parentToDaughterMatrix) sortedParentClusters.push_back(mapEntry.first);
137  std::sort(sortedParentClusters.begin(), sortedParentClusters.end(), LArClusterHelper::SortByNHits);
138 
139  for (const Cluster *const pParentCluster : sortedParentClusters)
140  {
141  const ClusterAssociationMap &daughterToAssociationMap(parentToDaughterMatrix.at(pParentCluster));
142 
143  float maxDisplacementInner(std::numeric_limits<float>::max());
144  float maxDisplacementOuter(std::numeric_limits<float>::max());
145 
146  // Find the nearest parent cluster
147  ClusterVector sortedLocalDaughterClusters;
148  for (const auto &mapEntry : daughterToAssociationMap) sortedLocalDaughterClusters.push_back(mapEntry.first);
149  std::sort(sortedLocalDaughterClusters.begin(), sortedLocalDaughterClusters.end(), LArClusterHelper::SortByNHits);
150 
151  for (const Cluster *const pDaughterCluster : sortedLocalDaughterClusters)
152  {
153  const ClusterAssociation &clusterAssociation(daughterToAssociationMap.at(pDaughterCluster));
154 
155  if (clusterAssociation.GetAssociation() == ClusterAssociation::WEAK)
156  {
157  if (clusterAssociation.GetParent() == ClusterAssociation::INNER && clusterAssociation.GetFigureOfMerit() < maxDisplacementInner)
158  maxDisplacementInner = clusterAssociation.GetFigureOfMerit();
159 
160  if (clusterAssociation.GetParent() == ClusterAssociation::OUTER && clusterAssociation.GetFigureOfMerit() < maxDisplacementOuter)
161  maxDisplacementOuter = clusterAssociation.GetFigureOfMerit();
162  }
163  }
164 
165  // Select daughter clusters that are closer than the nearest parent cluster
166  for (const Cluster *const pDaughterCluster : sortedLocalDaughterClusters)
167  {
168  const ClusterAssociation &clusterAssociation(daughterToAssociationMap.at(pDaughterCluster));
169 
170  if (clusterAssociation.GetAssociation() == ClusterAssociation::STRONG)
171  {
172  if (clusterAssociation.GetParent() == ClusterAssociation::INNER && clusterAssociation.GetFigureOfMerit() < maxDisplacementInner)
173  (void) daughterToParentMatrix[pDaughterCluster].insert(ClusterAssociationMap::value_type(pParentCluster, clusterAssociation));
174 
175  if (clusterAssociation.GetParent() == ClusterAssociation::OUTER && clusterAssociation.GetFigureOfMerit() < maxDisplacementOuter)
176  (void) daughterToParentMatrix[pDaughterCluster].insert(ClusterAssociationMap::value_type(pParentCluster, clusterAssociation));
177  }
178  }
179  }
180 
181  // Loop over daughter clusters and select the nearest parent clusters
182  ClusterVector sortedDaughterClusters;
183  for (const auto &mapEntry : daughterToParentMatrix) sortedDaughterClusters.push_back(mapEntry.first);
184  std::sort(sortedDaughterClusters.begin(), sortedDaughterClusters.end(), LArClusterHelper::SortByNHits);
185 
186  // Loop over parent clusters and select nearby daughter clusters that are closer than another parent cluster
187  for (const Cluster *const pDaughterCluster : sortedDaughterClusters)
188  {
189  const ClusterAssociationMap &parentToAssociationMap(daughterToParentMatrix.at(pDaughterCluster));
190 
191  const Cluster *pParentCluster(nullptr);
192  float minDisplacement(std::numeric_limits<float>::max());
193 
194  ClusterVector sortedLocalParentClusters;
195  for (const auto &mapEntry : parentToAssociationMap) sortedLocalParentClusters.push_back(mapEntry.first);
196  std::sort(sortedLocalParentClusters.begin(), sortedLocalParentClusters.end(), LArClusterHelper::SortByNHits);
197 
198  for (const Cluster *const pCandidateParentCluster : sortedLocalParentClusters)
199  {
200  const ClusterAssociation &clusterAssociation(parentToAssociationMap.at(pCandidateParentCluster));
201 
202  if (clusterAssociation.GetFigureOfMerit() < minDisplacement)
203  {
204  minDisplacement = clusterAssociation.GetFigureOfMerit();
205  pParentCluster = pCandidateParentCluster;
206  }
207  }
208 
209  if (pParentCluster)
210  {
211  ClusterList &parentList(clusterMergeMap[pParentCluster]);
212 
213  if (parentList.end() == std::find(parentList.begin(), parentList.end(), pDaughterCluster))
214  parentList.push_back(pDaughterCluster);
215 
216  ClusterList &daughterList(clusterMergeMap[pDaughterCluster]);
217 
218  if (daughterList.end() == std::find(daughterList.begin(), daughterList.end(), pParentCluster))
219  daughterList.push_back(pParentCluster);
220  }
221  }
222 }
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 *, ClusterAssociationMap > ClusterAssociationMatrix
Int_t max
Definition: plot.C:27
std::vector< art::Ptr< recob::Cluster > > ClusterVector
std::unordered_map< const pandora::Cluster *, ClusterAssociation > ClusterAssociationMap
void lar_content::TransverseExtensionAlgorithm::GetListOfCleanClusters ( const pandora::ClusterList *const  pClusterList,
pandora::ClusterVector &  clusterVector 
) const
privatevirtual

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 30 of file TransverseExtensionAlgorithm.cc.

References f, FillClusterAssociationMatrix(), lar_content::LArClusterHelper::GetClosestDistance(), lar_content::LArPointingCluster::GetCluster(), lar_content::LArClusterHelper::GetExtremalCoordinates(), lar_content::LArPointingClusterHelper::GetImpactParameters(), lar_content::LArPointingCluster::GetInnerVertex(), lar_content::LArClusterHelper::GetLengthSquared(), lar_content::LArPointingCluster::GetOuterVertex(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::INNER, m_maxLongitudinalDisplacement, m_maxTransverseDisplacement, m_minClusterLength, lar_content::ClusterExtensionAlgorithm::ClusterAssociation::OUTER, lar_content::LArClusterHelper::SortByNHits(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::STRONG, and lar_content::ClusterExtensionAlgorithm::ClusterAssociation::WEAK.

31 {
32  for (ClusterList::const_iterator iter = pClusterList->begin(), iterEnd = pClusterList->end(); iter != iterEnd; ++iter)
33  clusterVector.push_back(*iter);
34 
35  std::sort(clusterVector.begin(), clusterVector.end(), LArClusterHelper::SortByNHits);
36 }
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
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 133 of file ClusterMergingAlgorithm.cc.

134 {
135  ClusterVector pfoClusters, availableClusters;
136 
137  for (ClusterVector::const_iterator iter = inputClusters.begin(), iterEnd = inputClusters.end(); iter != iterEnd; ++iter)
138  {
139  const Cluster *const pCluster = *iter;
140 
141  if (!pCluster->IsAvailable())
142  {
143  pfoClusters.push_back(pCluster);
144  }
145  else
146  {
147  availableClusters.push_back(pCluster);
148  }
149  }
150 
151  std::sort(pfoClusters.begin(), pfoClusters.end(), LArClusterHelper::SortByNHits);
152  std::sort(availableClusters.begin(), availableClusters.end(), LArClusterHelper::SortByNHits);
153 
154  outputClusters.insert(outputClusters.end(), pfoClusters.begin(), pfoClusters.end());
155  outputClusters.insert(outputClusters.end(), availableClusters.begin(), availableClusters.end());
156 }
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 61 of file ClusterMergingAlgorithm.cc.

62 {
63  ClusterSet clusterVetoList;
64 
65  for (const Cluster *const pSeedCluster : clusterVector)
66  {
67  ClusterList mergeList;
68  this->CollectAssociatedClusters(pSeedCluster, pSeedCluster, clusterMergeMap, clusterVetoList, mergeList);
69  mergeList.sort(LArClusterHelper::SortByNHits);
70 
71  for (const Cluster *const pAssociatedCluster : mergeList)
72  {
73  if (clusterVetoList.count(pAssociatedCluster))
74  throw StatusCodeException(STATUS_CODE_FAILURE);
75 
76  if (!pAssociatedCluster->IsAvailable())
77  throw StatusCodeException(STATUS_CODE_FAILURE);
78 
79  (void) clusterVetoList.insert(pAssociatedCluster);
80 
81  if (m_inputClusterListName.empty())
82  {
83  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*this, pSeedCluster, pAssociatedCluster));
84  }
85  else
86  {
87  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::MergeAndDeleteClusters(*this, pSeedCluster, pAssociatedCluster,
89  }
90  }
91  }
92 }
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::ClusterExtensionAlgorithm::PopulateClusterMergeMap ( const pandora::ClusterVector &  clusterVector,
ClusterMergeMap clusterMergeMap 
) const
protectedvirtualinherited

Form associations between pointing clusters.

Parameters
clusterVectorthe vector of clean clusters
clusterMergeMapthe matrix of cluster associations

Implements lar_content::ClusterMergingAlgorithm.

Definition at line 18 of file ClusterExtensionAlgorithm.cc.

19 {
20  ClusterAssociationMatrix clusterAssociationMatrix;
21  this->FillClusterAssociationMatrix(clusterVector, clusterAssociationMatrix);
22  this->FillClusterMergeMap(clusterAssociationMatrix, clusterMergeMap);
23 }
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterAssociationMatrix
virtual void FillClusterMergeMap(const ClusterAssociationMatrix &clusterAssociationMatrix, ClusterMergeMap &clusterMergeMap) const =0
Fill the cluster merge map.
virtual void FillClusterAssociationMatrix(const pandora::ClusterVector &clusterVector, ClusterAssociationMatrix &clusterAssociationMatrix) const =0
Fill the cluster association matrix.
StatusCode lar_content::TransverseExtensionAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
privatevirtual

Reimplemented from lar_content::ClusterMergingAlgorithm.

Definition at line 226 of file TransverseExtensionAlgorithm.cc.

References m_maxLongitudinalDisplacement, m_maxTransverseDisplacement, m_minClusterLength, and lar_content::ClusterMergingAlgorithm::ReadSettings().

227 {
228  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
229  "MinClusterLength", m_minClusterLength));
230 
231  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
232  "MaxLongitudinalDisplacement", m_maxLongitudinalDisplacement));
233 
234  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
235  "MaxTransverseDisplacement", m_maxTransverseDisplacement));
236 
237  return ClusterExtensionAlgorithm::ReadSettings(xmlHandle);
238 }
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
StatusCode lar_content::ClusterMergingAlgorithm::Run ( )
protectedvirtualinherited

Definition at line 20 of file ClusterMergingAlgorithm.cc.

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  {
30  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, m_inputClusterListName, pClusterList));
31  }
32 
33  if (!pClusterList || pClusterList->empty())
34  {
35  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
36  std::cout << "ClusterMergingAlgorithm: unable to find cluster list " << m_inputClusterListName << std::endl;
37 
38  return STATUS_CODE_SUCCESS;
39  }
40 
41  while (true)
42  {
43  ClusterVector unsortedVector, clusterVector;
44  this->GetListOfCleanClusters(pClusterList, unsortedVector);
45  this->GetSortedListOfCleanClusters(unsortedVector, clusterVector);
46 
47  ClusterMergeMap clusterMergeMap;
48  this->PopulateClusterMergeMap(clusterVector, clusterMergeMap);
49 
50  if (clusterMergeMap.empty())
51  break;
52 
53  this->MergeClusters(clusterVector, clusterMergeMap);
54  }
55 
56  return STATUS_CODE_SUCCESS;
57 }
std::string m_inputClusterListName
The name of the input cluster list. If not specified, will access current list.
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...
virtual void PopulateClusterMergeMap(const pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const =0
Form associations between pointing clusters.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void MergeClusters(pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
Merge associated clusters.
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.

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 82 of file ClusterMergingAlgorithm.h.

float lar_content::TransverseExtensionAlgorithm::m_maxLongitudinalDisplacement
private

Definition at line 48 of file TransverseExtensionAlgorithm.h.

Referenced by GetListOfCleanClusters(), and ReadSettings().

float lar_content::TransverseExtensionAlgorithm::m_maxTransverseDisplacement
private

Definition at line 49 of file TransverseExtensionAlgorithm.h.

Referenced by GetListOfCleanClusters(), and ReadSettings().

float lar_content::TransverseExtensionAlgorithm::m_minClusterLength
private

Definition at line 47 of file TransverseExtensionAlgorithm.h.

Referenced by GetListOfCleanClusters(), and ReadSettings().


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