LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::CosmicRayExtensionAlgorithm Class Reference

CosmicRayExtensionAlgorithm class. More...

#include "CosmicRayExtensionAlgorithm.h"

Inheritance diagram for lar_content::CosmicRayExtensionAlgorithm:
lar_content::ClusterExtensionAlgorithm lar_content::ClusterMergingAlgorithm

Public Member Functions

 CosmicRayExtensionAlgorithm ()
 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 &clusterI, const LArPointingCluster &clusterJ, ClusterAssociationMatrix &clusterAssociationMatrix) const
 Form association between two pointing clusters. More...
 
float CalculateRms (const pandora::Cluster *const pCluster, const pandora::CartesianVector &position, const pandora::CartesianVector &direction) const
 Calculate RMS deviation of a cluster with respect to the reference line. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

float m_minClusterLength
 
float m_minSeedClusterLength
 
float m_maxLongitudinalDisplacement
 
float m_maxTransverseDisplacement
 
float m_minCosRelativeAngle
 
float m_maxAverageRms
 

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

Member Function Documentation

float lar_content::CosmicRayExtensionAlgorithm::CalculateRms ( const pandora::Cluster *const  pCluster,
const pandora::CartesianVector &  position,
const pandora::CartesianVector &  direction 
) const
private

Calculate RMS deviation of a cluster with respect to the reference line.

Parameters
pClusterthe input cluster
positionthe intercept of the reference line
directionthe direction of the reference line

Definition at line 343 of file CosmicRayExtensionAlgorithm.cc.

References f.

Referenced by FillClusterAssociationMatrix().

344 {
345  float totalChi2(0.f);
346  float totalHits(0.f);
347 
348  CaloHitList caloHitList;
349  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
350 
351  for (CaloHitList::const_iterator iter = caloHitList.begin(), iterEnd = caloHitList.end(); iter != iterEnd; ++iter)
352  {
353  const CaloHit *const pCaloHit = *iter;
354 
355  const CartesianVector hitPosition(pCaloHit->GetPositionVector());
356  const CartesianVector predictedPosition(position + direction * direction.GetDotProduct(hitPosition - position));
357 
358  totalChi2 += (predictedPosition - hitPosition).GetMagnitudeSquared();
359  totalHits += 1.f;
360  }
361 
362  if (totalHits > 0.f)
363  return std::sqrt(totalChi2/totalHits);
364 
365  return 0.f;
366 }
TFile f
Definition: plotHisto.C:6
intermediate_table::const_iterator const_iterator
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::CosmicRayExtensionAlgorithm::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::CosmicRayExtensionAlgorithm::FillClusterAssociationMatrix ( const LArPointingCluster clusterI,
const LArPointingCluster clusterJ,
ClusterAssociationMatrix clusterAssociationMatrix 
) const
private

Form association between two pointing clusters.

Parameters
clusterIthe first pointing cluster
clusterJthe second pointing cluster
clusterAssociationMatrixthe matrix of cluster associations

Definition at line 85 of file CosmicRayExtensionAlgorithm.cc.

References CalculateRms(), f, lar_content::LArPointingClusterHelper::GetClosestVertices(), lar_content::LArPointingCluster::GetCluster(), lar_content::LArPointingCluster::GetInnerVertex(), lar_content::LArPointingClusterHelper::GetLengthSquared(), lar_content::LArPointingCluster::GetOuterVertex(), lar_content::LArPointingCluster::Vertex::GetPosition(), lar_content::ClusterExtensionAlgorithm::ClusterAssociation::INNER, lar_content::LArPointingCluster::Vertex::IsInitialized(), lar_content::LArPointingCluster::Vertex::IsInnerVertex(), m_maxAverageRms, m_maxLongitudinalDisplacement, m_maxTransverseDisplacement, m_minCosRelativeAngle, m_minSeedClusterLength, max, min, lar_content::ClusterExtensionAlgorithm::ClusterAssociation::OUTER, and lar_content::ClusterExtensionAlgorithm::ClusterAssociation::STRONG.

87 {
88  const Cluster *const pClusterI(clusterI.GetCluster());
89  const Cluster *const pClusterJ(clusterJ.GetCluster());
90 
91  if (pClusterI == pClusterJ)
92  return;
93 
94  // Get closest pair of vertices
95  LArPointingCluster::Vertex clusterVertexI, clusterVertexJ;
96 
97  try
98  {
99  LArPointingClusterHelper::GetClosestVertices(clusterI, clusterJ, clusterVertexI, clusterVertexJ);
100  }
101  catch (StatusCodeException &)
102  {
103  return;
104  }
105 
106  // (Just in case...)
107  if (!(clusterVertexI.IsInitialized() && clusterVertexJ.IsInitialized()))
108  throw StatusCodeException(STATUS_CODE_FAILURE);
109 
110  const CartesianVector vertexI(clusterVertexI.GetPosition());
111  const CartesianVector vertexJ(clusterVertexJ.GetPosition());
112 
113  const CartesianVector endI(clusterVertexI.IsInnerVertex() ? clusterI.GetOuterVertex().GetPosition() : clusterI.GetInnerVertex().GetPosition());
114  const CartesianVector endJ(clusterVertexJ.IsInnerVertex() ? clusterJ.GetOuterVertex().GetPosition() : clusterJ.GetInnerVertex().GetPosition());
115 
116  // Requirements on length
117  const float lengthSquaredI(LArPointingClusterHelper::GetLengthSquared(clusterI));
118  const float lengthSquaredJ(LArPointingClusterHelper::GetLengthSquared(clusterJ));
119 
120  if (std::max(lengthSquaredI, lengthSquaredJ) < m_minSeedClusterLength * m_minSeedClusterLength)
121  return;
122 
123  // Requirements on proximity
124  const float distanceSquaredIJ((vertexI - vertexJ).GetMagnitudeSquared());
125 
127  return;
128 
129  // Requirements on pointing information
130  const CartesianVector directionI((endI - vertexI).GetUnitVector());
131  const CartesianVector directionJ((endJ - vertexJ).GetUnitVector());
132 
133  const float cosTheta(-directionI.GetDotProduct(directionJ));
134  const float cosThetaCut(-1.f + 2.f * m_minCosRelativeAngle);
135 
136  if (cosTheta < cosThetaCut)
137  return;
138 
139  // Requirements on overlap between clusters
140  const CartesianVector directionIJ((endJ - endI).GetUnitVector());
141  const CartesianVector directionJI((endI - endJ).GetUnitVector());
142 
143  const float overlapL(directionIJ.GetDotProduct(vertexJ - vertexI));
144  const float overlapT(directionIJ.GetCrossProduct(vertexJ - vertexI).GetMagnitude());
145 
146  if (overlapL < -1.f || overlapL * overlapL > 2.f * std::min(lengthSquaredI, lengthSquaredJ) ||
147  overlapT > m_maxTransverseDisplacement + std::fabs(overlapL) * std::tan(5.f * M_PI / 180.f))
148  return;
149 
150  // Calculate RMS deviations on composite cluster
151  const float rms1(this->CalculateRms(pClusterI, endI, directionIJ));
152  const float rms2(this->CalculateRms(pClusterJ, endJ, directionJI));
153 
154  const float rms(0.5f * (rms1 + rms2));
155  const float rmsCut(2.f * m_maxAverageRms * (cosTheta - cosThetaCut) / (1.0 - cosThetaCut));
156 
157  if (rms > rmsCut)
158  return;
159 
160  // Record the association
161  const ClusterAssociation::VertexType vertexTypeI(clusterVertexI.IsInnerVertex() ? ClusterAssociation::INNER : ClusterAssociation::OUTER);
162  const ClusterAssociation::VertexType vertexTypeJ(clusterVertexJ.IsInnerVertex() ? ClusterAssociation::INNER : ClusterAssociation::OUTER);
164 
165  (void) clusterAssociationMatrix[pClusterI].insert(ClusterAssociationMap::value_type(pClusterJ,
166  ClusterAssociation(vertexTypeI, vertexTypeJ, associationType, lengthSquaredJ)));
167 
168  (void) clusterAssociationMatrix[pClusterJ].insert(ClusterAssociationMap::value_type(pClusterI,
169  ClusterAssociation(vertexTypeJ, vertexTypeI, associationType, lengthSquaredI)));
170 }
static void GetClosestVertices(const bool useX, const bool useY, const bool useZ, const LArPointingCluster &pointingClusterI, const LArPointingCluster &pointingClusterJ, LArPointingCluster::Vertex &closestVertexI, LArPointingCluster::Vertex &closestVertexJ)
Given a pair of pointing clusters, receive the closest or farthest pair of vertices.
TFile f
Definition: plotHisto.C:6
Int_t max
Definition: plot.C:27
float CalculateRms(const pandora::Cluster *const pCluster, const pandora::CartesianVector &position, const pandora::CartesianVector &direction) const
Calculate RMS deviation of a cluster with respect to the reference line.
Int_t min
Definition: plot.C:26
static float GetLengthSquared(const LArPointingCluster &pointingCluster)
Calculate distance squared between inner and outer vertices of pointing cluster.
void lar_content::CosmicRayExtensionAlgorithm::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 174 of file CosmicRayExtensionAlgorithm.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.

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

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

34 {
35  for (ClusterList::const_iterator iter = pClusterList->begin(), iterEnd = pClusterList->end(); iter != iterEnd; ++iter)
36  {
37  const Cluster *const pCluster = *iter;
38 
40  continue;
41 
42  clusterVector.push_back(pCluster);
43  }
44 
45  std::sort(clusterVector.begin(), clusterVector.end(), LArClusterHelper::SortByNHits);
46 }
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
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 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::CosmicRayExtensionAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
privatevirtual

Reimplemented from lar_content::ClusterMergingAlgorithm.

Definition at line 370 of file CosmicRayExtensionAlgorithm.cc.

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

371 {
372  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
373  "MinClusterLength", m_minClusterLength));
374 
375  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
376  "MinSeedClusterLength", m_minSeedClusterLength));
377 
378  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
379  "MaxLongitudinalDisplacement", m_maxLongitudinalDisplacement));
380 
381  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
382  "MaxTransverseDisplacement", m_maxTransverseDisplacement));
383 
384  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
385  "MinCosRelativeAngle", m_minCosRelativeAngle));
386 
387  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
388  "MaxAverageRms", m_maxAverageRms));
389 
390  return ClusterExtensionAlgorithm::ReadSettings(xmlHandle);
391 }
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::CosmicRayExtensionAlgorithm::m_maxAverageRms
private

Definition at line 63 of file CosmicRayExtensionAlgorithm.h.

Referenced by FillClusterAssociationMatrix(), and ReadSettings().

float lar_content::CosmicRayExtensionAlgorithm::m_maxLongitudinalDisplacement
private

Definition at line 60 of file CosmicRayExtensionAlgorithm.h.

Referenced by FillClusterAssociationMatrix(), and ReadSettings().

float lar_content::CosmicRayExtensionAlgorithm::m_maxTransverseDisplacement
private

Definition at line 61 of file CosmicRayExtensionAlgorithm.h.

Referenced by FillClusterAssociationMatrix(), and ReadSettings().

float lar_content::CosmicRayExtensionAlgorithm::m_minClusterLength
private

Definition at line 58 of file CosmicRayExtensionAlgorithm.h.

Referenced by GetListOfCleanClusters(), and ReadSettings().

float lar_content::CosmicRayExtensionAlgorithm::m_minCosRelativeAngle
private

Definition at line 62 of file CosmicRayExtensionAlgorithm.h.

Referenced by FillClusterAssociationMatrix(), and ReadSettings().

float lar_content::CosmicRayExtensionAlgorithm::m_minSeedClusterLength
private

Definition at line 59 of file CosmicRayExtensionAlgorithm.h.

Referenced by FillClusterAssociationMatrix(), and ReadSettings().


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