LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::CrossGapsExtensionAlgorithm Class Reference

CrossGapsExtensionAlgorithm class. More...

#include "CrossGapsExtensionAlgorithm.h"

Inheritance diagram for lar_content::CrossGapsExtensionAlgorithm:
lar_content::ClusterExtensionAlgorithm lar_content::ClusterMergingAlgorithm

Public Member Functions

 CrossGapsExtensionAlgorithm ()
 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 BuildPointingClusterList (const pandora::ClusterVector &clusterVector, LArPointingClusterList &innerPointingClusterList, LArPointingClusterList &outerPointingClusterList) const
 Build lists of pointing clusters that are adjacent to a detector gap. More...
 
void BuildPointingClusterList (const bool useInner, const LArPointingClusterList &inputPointingClusterList, LArPointingClusterList &outputPointingClusterList) const
 Build a list of pointing clusters that are adjacent to a detector gap. More...
 
bool IsAssociated (const LArPointingCluster::Vertex &pointingVertex1, const LArPointingCluster::Vertex &pointingVertex2) const
 Use pointing information to determine whether two clusters are associated. More...
 
bool IsAcrossGap (const float minZ, const float maxZ, const pandora::HitType hitType) const
 Determine whether a start and end position sit either side of a gap. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

float m_minClusterLength
 
float m_minGapFraction
 
float m_maxGapTolerance
 
float m_maxTransverseDisplacement
 
float m_maxRelativeAngle
 

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::CrossGapsExtensionAlgorithm::CrossGapsExtensionAlgorithm ( )

Member Function Documentation

void lar_content::CrossGapsExtensionAlgorithm::BuildPointingClusterList ( const pandora::ClusterVector &  clusterVector,
LArPointingClusterList innerPointingClusterList,
LArPointingClusterList outerPointingClusterList 
) const
private

Build lists of pointing clusters that are adjacent to a detector gap.

Parameters
clusterVectorthe input vector of clusters
innerPointingClusterListthe pointing clusters whose inner vertex is close to a detector gap
outerPointingClusterListthe pointing clusters whose outer vertex is close to a detector gap

Referenced by FillClusterAssociationMatrix().

void lar_content::CrossGapsExtensionAlgorithm::BuildPointingClusterList ( const bool  useInner,
const LArPointingClusterList inputPointingClusterList,
LArPointingClusterList outputPointingClusterList 
) const
private

Build a list of pointing clusters that are adjacent to a detector gap.

Parameters
useInnercheck the inner vertex
inputPointingClusterListthe input list of pointing clusters
outputPointingClusterListthe output list of pointing clusters

Definition at line 115 of file CrossGapsExtensionAlgorithm.cc.

References lar_content::LArClusterHelper::GetClusterHitType(), lar_content::LArGeometryHelper::IsInGap(), and m_maxGapTolerance.

117 {
118  for (const LArPointingCluster &pointingCluster : inputPointingClusterList)
119  {
120  const LArPointingCluster::Vertex &pointingVertex(useInner ? pointingCluster.GetInnerVertex() : pointingCluster.GetOuterVertex());
121  const HitType hitType(LArClusterHelper::GetClusterHitType(pointingCluster.GetCluster()));
122 
123  if (LArGeometryHelper::IsInGap(this->GetPandora(), pointingVertex.GetPosition(), hitType, m_maxGapTolerance))
124  outputPointingClusterList.push_back(pointingCluster);
125  }
126 }
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static bool IsInGap(const pandora::Pandora &pandora, const pandora::CartesianVector &testPoint2D, const pandora::HitType hitType, const float gapTolerance=0.f)
Whether a 2D test point lies in a registered gap with the associated hit type.
HitType
Definition: HitType.h:12
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
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::CrossGapsExtensionAlgorithm::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.

Definition at line 52 of file CrossGapsExtensionAlgorithm.cc.

References BuildPointingClusterList(), lar_content::LArClusterHelper::GetClusterHitType(), lar_content::LArClusterHelper::GetLengthSquared(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::INNER, IsAcrossGap(), IsAssociated(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::OUTER, and lar_content::ClusterExtensionAlgorithm::ClusterAssociation::STRONG.

53 {
54  // Build lists of pointing clusters in proximity to gaps
55  LArPointingClusterList innerPointingClusterList, outerPointingClusterList;
56  this->BuildPointingClusterList(clusterVector, innerPointingClusterList, outerPointingClusterList);
57 
58  // Form associations between pairs of pointing clusters
59  for (const LArPointingCluster &pointingClusterInner : innerPointingClusterList)
60  {
61  const LArPointingCluster::Vertex &pointingVertexInner(pointingClusterInner.GetInnerVertex());
62  const float zInner(pointingVertexInner.GetPosition().GetZ());
63 
64  for (const LArPointingCluster &pointingClusterOuter : outerPointingClusterList)
65  {
66  const LArPointingCluster::Vertex &pointingVertexOuter(pointingClusterOuter.GetOuterVertex());
67  const float zOuter(pointingVertexOuter.GetPosition().GetZ());
68 
69  if (!this->IsAcrossGap(zOuter, zInner, LArClusterHelper::GetClusterHitType(pointingClusterInner.GetCluster())))
70  continue;
71 
72  if (!this->IsAssociated(pointingVertexInner, pointingVertexOuter))
73  continue;
74 
75  const Cluster *const pClusterInner(pointingClusterInner.GetCluster());
76  const Cluster *const pClusterOuter(pointingClusterOuter.GetCluster());
77 
78  const float lengthSquaredInner(LArClusterHelper::GetLengthSquared(pClusterInner));
79  const float lengthSquaredOuter(LArClusterHelper::GetLengthSquared(pClusterOuter));
80 
81  (void)clusterAssociationMatrix[pClusterInner].insert(ClusterAssociationMap::value_type(pClusterOuter,
82  ClusterAssociation(ClusterAssociation::INNER, ClusterAssociation::OUTER, ClusterAssociation::STRONG, lengthSquaredOuter)));
83  (void)clusterAssociationMatrix[pClusterOuter].insert(ClusterAssociationMap::value_type(pClusterInner,
84  ClusterAssociation(ClusterAssociation::OUTER, ClusterAssociation::INNER, ClusterAssociation::STRONG, lengthSquaredInner)));
85  }
86  }
87 }
void BuildPointingClusterList(const pandora::ClusterVector &clusterVector, LArPointingClusterList &innerPointingClusterList, LArPointingClusterList &outerPointingClusterList) const
Build lists of pointing clusters that are adjacent to a detector gap.
std::vector< LArPointingCluster > LArPointingClusterList
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
bool IsAcrossGap(const float minZ, const float maxZ, const pandora::HitType hitType) const
Determine whether a start and end position sit either side of a gap.
bool IsAssociated(const LArPointingCluster::Vertex &pointingVertex1, const LArPointingCluster::Vertex &pointingVertex2) const
Use pointing information to determine whether two clusters are associated.
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
void lar_content::CrossGapsExtensionAlgorithm::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 161 of file CrossGapsExtensionAlgorithm.cc.

References f, lar_content::ClusterExtensionAlgorithm::ClusterAssociation::GetDaughter(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::GetFigureOfMerit(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::GetParent(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::INNER, lar_content::ClusterExtensionAlgorithm::ClusterAssociation::NONE, lar_content::ClusterExtensionAlgorithm::ClusterAssociation::OUTER, lar_content::LArClusterHelper::SortByNHits(), and lar_content::ClusterExtensionAlgorithm::ClusterAssociation::UNDEFINED.

162 {
163  // Decide which associations will become merges
164  // To make the merge A <-> B, both A -> B and B -> A must be strong associations
165  // with the largest figures of merit of all the A -> X and B -> Y associations
166 
167  // First step: remove double-counting from the map of associations
168  // i.e. if the map has A <-> B, B <-> C, A <-> C, then remove A <-> C
169  ClusterAssociationMatrix clusterAssociationMatrix;
170 
171  ClusterVector sortedInputClusters;
172  for (const auto &mapEntry : inputAssociationMatrix)
173  sortedInputClusters.push_back(mapEntry.first);
174  std::sort(sortedInputClusters.begin(), sortedInputClusters.end(), LArClusterHelper::SortByNHits);
175 
176  for (const Cluster *const pCluster1 : sortedInputClusters)
177  {
178  const ClusterAssociationMap &associationMap1(inputAssociationMatrix.at(pCluster1));
179 
180  for (const Cluster *const pCluster2 : sortedInputClusters)
181  {
182  if (pCluster1 == pCluster2)
183  continue;
184 
185  const ClusterAssociationMap &associationMap2(inputAssociationMatrix.at(pCluster2));
186 
187  ClusterAssociationMap::const_iterator iter12 = associationMap1.find(pCluster2);
188  if (associationMap1.end() == iter12)
189  continue;
190 
191  ClusterAssociationMap::const_iterator iter21 = associationMap2.find(pCluster1);
192  if (associationMap2.end() == iter21)
193  continue;
194 
195  const ClusterAssociation &association12(iter12->second);
196  const ClusterAssociation &association21(iter21->second);
197 
198  bool isAssociated(true);
199 
200  ClusterVector sortedAssociationClusters;
201  for (const auto &mapEntry : associationMap1)
202  sortedAssociationClusters.push_back(mapEntry.first);
203  std::sort(sortedAssociationClusters.begin(), sortedAssociationClusters.end(), LArClusterHelper::SortByNHits);
204 
205  for (const Cluster *const pCluster3 : sortedAssociationClusters)
206  {
207  const ClusterAssociation &association13(associationMap1.at(pCluster3));
208 
209  ClusterAssociationMap::const_iterator iter23 = associationMap2.find(pCluster3);
210  if (associationMap2.end() == iter23)
211  continue;
212 
213  const ClusterAssociation &association23(iter23->second);
214 
215  if (association12.GetParent() == association13.GetParent() && association23.GetParent() == association21.GetParent() &&
216  association13.GetDaughter() != association23.GetDaughter())
217  {
218  isAssociated = false;
219  break;
220  }
221  }
222 
223  if (isAssociated)
224  {
225  (void)clusterAssociationMatrix[pCluster1].insert(ClusterAssociationMap::value_type(pCluster2, association12));
226  (void)clusterAssociationMatrix[pCluster2].insert(ClusterAssociationMap::value_type(pCluster1, association21));
227  }
228  }
229  }
230 
231  // Second step: find the best associations A -> X and B -> Y
232  ClusterAssociationMatrix intermediateAssociationMatrix;
233 
234  ClusterVector sortedClusters;
235  for (const auto &mapEntry : clusterAssociationMatrix)
236  sortedClusters.push_back(mapEntry.first);
237  std::sort(sortedClusters.begin(), sortedClusters.end(), LArClusterHelper::SortByNHits);
238 
239  for (const Cluster *const pParentCluster : sortedClusters)
240  {
241  const ClusterAssociationMap &clusterAssociationMap(clusterAssociationMatrix.at(pParentCluster));
242 
243  const Cluster *pBestClusterInner(nullptr);
244  ClusterAssociation bestAssociationInner(ClusterAssociation::UNDEFINED, ClusterAssociation::UNDEFINED, ClusterAssociation::NONE, 0.f);
245 
246  const Cluster *pBestClusterOuter(nullptr);
247  ClusterAssociation bestAssociationOuter(ClusterAssociation::UNDEFINED, ClusterAssociation::UNDEFINED, ClusterAssociation::NONE, 0.f);
248 
249  ClusterVector sortedAssociationClusters;
250  for (const auto &mapEntry : clusterAssociationMap)
251  sortedAssociationClusters.push_back(mapEntry.first);
252  std::sort(sortedAssociationClusters.begin(), sortedAssociationClusters.end(), LArClusterHelper::SortByNHits);
253 
254  for (const Cluster *const pDaughterCluster : sortedAssociationClusters)
255  {
256  const ClusterAssociation &clusterAssociation(clusterAssociationMap.at(pDaughterCluster));
257 
258  // Inner associations
259  if (clusterAssociation.GetParent() == ClusterAssociation::INNER)
260  {
261  if (clusterAssociation.GetFigureOfMerit() > bestAssociationInner.GetFigureOfMerit())
262  {
263  bestAssociationInner = clusterAssociation;
264  pBestClusterInner = pDaughterCluster;
265  }
266  }
267 
268  // Outer associations
269  if (clusterAssociation.GetParent() == ClusterAssociation::OUTER)
270  {
271  if (clusterAssociation.GetFigureOfMerit() > bestAssociationOuter.GetFigureOfMerit())
272  {
273  bestAssociationOuter = clusterAssociation;
274  pBestClusterOuter = pDaughterCluster;
275  }
276  }
277  }
278 
279  if (pBestClusterInner)
280  (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterInner, bestAssociationInner));
281 
282  if (pBestClusterOuter)
283  (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterOuter, bestAssociationOuter));
284  }
285 
286  // Third step: make the merge if A -> X and B -> Y is in fact A -> B and B -> A
287  ClusterVector intermediateSortedClusters;
288  for (const auto &mapEntry : intermediateAssociationMatrix)
289  intermediateSortedClusters.push_back(mapEntry.first);
290  std::sort(intermediateSortedClusters.begin(), intermediateSortedClusters.end(), LArClusterHelper::SortByNHits);
291 
292  for (const Cluster *const pParentCluster : intermediateSortedClusters)
293  {
294  const ClusterAssociationMap &parentAssociationMap(intermediateAssociationMatrix.at(pParentCluster));
295 
296  ClusterVector sortedAssociationClusters;
297  for (const auto &mapEntry : parentAssociationMap)
298  sortedAssociationClusters.push_back(mapEntry.first);
299  std::sort(sortedAssociationClusters.begin(), sortedAssociationClusters.end(), LArClusterHelper::SortByNHits);
300 
301  for (const Cluster *const pDaughterCluster : sortedAssociationClusters)
302  {
303  const ClusterAssociation &parentToDaughterAssociation(parentAssociationMap.at(pDaughterCluster));
304 
305  ClusterAssociationMatrix::const_iterator iter5 = intermediateAssociationMatrix.find(pDaughterCluster);
306 
307  if (intermediateAssociationMatrix.end() == iter5)
308  continue;
309 
310  const ClusterAssociationMap &daughterAssociationMap(iter5->second);
311 
312  ClusterAssociationMap::const_iterator iter6 = daughterAssociationMap.find(pParentCluster);
313 
314  if (daughterAssociationMap.end() == iter6)
315  continue;
316 
317  const ClusterAssociation &daughterToParentAssociation(iter6->second);
318 
319  if (parentToDaughterAssociation.GetParent() == daughterToParentAssociation.GetDaughter() &&
320  parentToDaughterAssociation.GetDaughter() == daughterToParentAssociation.GetParent())
321  {
322  ClusterList &parentList(clusterMergeMap[pParentCluster]);
323 
324  if (parentList.end() == std::find(parentList.begin(), parentList.end(), pDaughterCluster))
325  parentList.push_back(pDaughterCluster);
326  }
327  }
328  }
329 }
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
TFile f
Definition: plotHisto.C:6
std::unordered_map< const pandora::Cluster *, ClusterAssociation > ClusterAssociationMap
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterAssociationMatrix
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void lar_content::CrossGapsExtensionAlgorithm::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 33 of file CrossGapsExtensionAlgorithm.cc.

References lar_content::LArClusterHelper::GetLengthSquared(), m_minClusterLength, and lar_content::LArClusterHelper::SortByNHits().

34 {
35  // ATTN May want to opt-out completely if no gap information available
36  // if (PandoraContentApi::GetGeometry(*this)->GetDetectorGapList().empty())
37  // return;
38 
39  for (const Cluster *const pCluster : *pClusterList)
40  {
42  continue;
43 
44  clusterVector.push_back(pCluster);
45  }
46 
47  std::sort(clusterVector.begin(), clusterVector.end(), LArClusterHelper::SortByNHits);
48 }
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.
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.
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
bool lar_content::CrossGapsExtensionAlgorithm::IsAcrossGap ( const float  minZ,
const float  maxZ,
const pandora::HitType  hitType 
) const
private

Determine whether a start and end position sit either side of a gap.

Parameters
minZthe start position
maxZthe end position
hitTypethe hitType

Definition at line 146 of file CrossGapsExtensionAlgorithm.cc.

References lar_content::LArGeometryHelper::CalculateGapDeltaZ(), and m_minGapFraction.

Referenced by FillClusterAssociationMatrix().

147 {
148  if (maxZ - minZ < std::numeric_limits<float>::epsilon())
149  return false;
150 
151  const float gapDeltaZ(LArGeometryHelper::CalculateGapDeltaZ(this->GetPandora(), minZ, maxZ, hitType));
152 
153  if (gapDeltaZ / (maxZ - minZ) < m_minGapFraction)
154  return false;
155 
156  return true;
157 }
static float CalculateGapDeltaZ(const pandora::Pandora &pandora, const float minZ, const float maxZ, const pandora::HitType hitType)
Calculate the total distance within a given 2D region that is composed of detector gaps...
bool lar_content::CrossGapsExtensionAlgorithm::IsAssociated ( const LArPointingCluster::Vertex pointingVertex1,
const LArPointingCluster::Vertex pointingVertex2 
) const
private

Use pointing information to determine whether two clusters are associated.

Parameters
pointingVertex1the first pointing vertex
pointingVertex2the second pointing vertex

Definition at line 130 of file CrossGapsExtensionAlgorithm.cc.

References lar_content::LArPointingCluster::Vertex::GetCluster(), lar_content::LArClusterHelper::GetClusterHitType(), lar_content::LArPointingCluster::Vertex::GetPosition(), lar_content::LArGeometryHelper::GetWirePitchRatio(), lar_content::LArPointingClusterHelper::IsEmission(), m_maxRelativeAngle, and m_maxTransverseDisplacement.

Referenced by FillClusterAssociationMatrix().

131 {
132  const float ratio{LArGeometryHelper::GetWirePitchRatio(this->GetPandora(), LArClusterHelper::GetClusterHitType(pointingVertex1.GetCluster()))};
133  const float maxTransverseDisplacementAdjusted{ratio * m_maxTransverseDisplacement};
134  const float maxLongitudinalDisplacement((pointingVertex2.GetPosition() - pointingVertex1.GetPosition()).GetMagnitude());
135 
136  const bool isAssociated1(LArPointingClusterHelper::IsEmission(pointingVertex1.GetPosition(), pointingVertex2, -1.f,
137  maxLongitudinalDisplacement + 1.f, maxTransverseDisplacementAdjusted, m_maxRelativeAngle));
138  const bool isAssociated2(LArPointingClusterHelper::IsEmission(pointingVertex2.GetPosition(), pointingVertex1, -1.f,
139  maxLongitudinalDisplacement + 1.f, maxTransverseDisplacementAdjusted, m_maxRelativeAngle));
140 
141  return (isAssociated1 && isAssociated2);
142 }
static float GetWirePitchRatio(const pandora::Pandora &pandora, const pandora::HitType view)
Return the ratio of the wire pitch of the specified view to the minimum wire pitch for the detector...
static bool IsEmission(const pandora::CartesianVector &parentVertex, const LArPointingCluster::Vertex &daughterVertex, const float minLongitudinalDistance, const float maxLongitudinalDistance, const float maxTransverseDistance, const float angularAllowance)
Whether pointing vertex is emitted from a given position.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
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.

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::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 }
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.
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterAssociationMatrix
StatusCode lar_content::CrossGapsExtensionAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
privatevirtual

Reimplemented from lar_content::ClusterMergingAlgorithm.

Definition at line 333 of file CrossGapsExtensionAlgorithm.cc.

References m_maxGapTolerance, m_maxRelativeAngle, m_maxTransverseDisplacement, m_minClusterLength, m_minGapFraction, and lar_content::ClusterMergingAlgorithm::ReadSettings().

334 {
335  PANDORA_RETURN_RESULT_IF_AND_IF(
336  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinClusterLength", m_minClusterLength));
337 
338  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinGapFraction", m_minGapFraction));
339 
340  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxGapTolerance", m_maxGapTolerance));
341 
342  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
343  XmlHelper::ReadValue(xmlHandle, "MaxTransverseDisplacement", m_maxTransverseDisplacement));
344 
345  float maxCosRelativeAngle(std::cos(m_maxRelativeAngle * M_PI / 180.0));
346  PANDORA_RETURN_RESULT_IF_AND_IF(
347  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxCosRelativeAngle", maxCosRelativeAngle));
348  m_maxRelativeAngle = (180.0 / M_PI) * std::acos(maxCosRelativeAngle);
349 
350  return ClusterExtensionAlgorithm::ReadSettings(xmlHandle);
351 }
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(
31  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, m_inputClusterListName, pClusterList));
32  }
33 
34  if (!pClusterList || pClusterList->empty())
35  {
36  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
37  std::cout << "ClusterMergingAlgorithm: unable to find cluster list " << m_inputClusterListName << std::endl;
38 
39  return STATUS_CODE_SUCCESS;
40  }
41 
42  while (true)
43  {
44  ClusterVector unsortedVector, clusterVector;
45  this->GetListOfCleanClusters(pClusterList, unsortedVector);
46  this->GetSortedListOfCleanClusters(unsortedVector, clusterVector);
47 
48  ClusterMergeMap clusterMergeMap;
49  this->PopulateClusterMergeMap(clusterVector, clusterMergeMap);
50 
51  if (clusterMergeMap.empty())
52  break;
53 
54  this->MergeClusters(clusterVector, clusterMergeMap);
55  }
56 
57  return STATUS_CODE_SUCCESS;
58 }
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.
void MergeClusters(pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
Merge associated clusters.
void GetSortedListOfCleanClusters(const pandora::ClusterVector &inputClusters, pandora::ClusterVector &outputClusters) const
Sort the selected clusters, so that they have a well-defined ordering.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
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.

float lar_content::CrossGapsExtensionAlgorithm::m_maxGapTolerance
private

Definition at line 75 of file CrossGapsExtensionAlgorithm.h.

Referenced by BuildPointingClusterList(), and ReadSettings().

float lar_content::CrossGapsExtensionAlgorithm::m_maxRelativeAngle
private

Definition at line 77 of file CrossGapsExtensionAlgorithm.h.

Referenced by IsAssociated(), and ReadSettings().

float lar_content::CrossGapsExtensionAlgorithm::m_maxTransverseDisplacement
private

Definition at line 76 of file CrossGapsExtensionAlgorithm.h.

Referenced by IsAssociated(), and ReadSettings().

float lar_content::CrossGapsExtensionAlgorithm::m_minClusterLength
private

Definition at line 73 of file CrossGapsExtensionAlgorithm.h.

Referenced by GetListOfCleanClusters(), and ReadSettings().

float lar_content::CrossGapsExtensionAlgorithm::m_minGapFraction
private

Definition at line 74 of file CrossGapsExtensionAlgorithm.h.

Referenced by IsAcrossGap(), and ReadSettings().


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