Public Member Functions | Private Member Functions | Private Attributes | List of all members
lar_content::CrossGapsAssociationAlgorithm Class Reference

CrossGapsAssociationAlgorithm class. More...

#include <CrossGapsAssociationAlgorithm.h>

Inheritance diagram for lar_content::CrossGapsAssociationAlgorithm:
lar_content::ClusterAssociationAlgorithm

Public Member Functions

 CrossGapsAssociationAlgorithm ()
 Default constructor. More...
 
- Public Member Functions inherited from lar_content::ClusterAssociationAlgorithm
 ClusterAssociationAlgorithm ()
 Default constructor. 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 PopulateClusterAssociationMap (const pandora::ClusterVector &clusterVector, ClusterAssociationMap &clusterAssociationMap) const
 Populate the cluster association map. More...
 
bool IsExtremalCluster (const bool isForward, const pandora::Cluster *const pCurrentCluster, const pandora::Cluster *const pTestCluster) const
 Determine which of two clusters is extremal. More...
 
bool AreClustersAssociated (const TwoDSlidingFitResult &innerFitResult, const TwoDSlidingFitResult &outerFitResult) const
 Determine whether two clusters are associated. More...
 
bool IsAssociated (const pandora::CartesianVector &startPosition, const pandora::CartesianVector &startDirection, const TwoDSlidingFitResult &targetFitResult) const
 Sample points along the extrapolation from a starting position to a target fit result to declare cluster association. More...
 
bool IsNearCluster (const pandora::CartesianVector &samplingPoint, const TwoDSlidingFitResult &targetFitResult) const
 Whether a sampling point lies near a target 2d sliding fit result. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

unsigned int m_minClusterHits
 The minimum allowed number of hits in a clean cluster. More...
 
unsigned int m_minClusterLayers
 The minimum allowed number of layers for a clean cluster. More...
 
unsigned int m_slidingFitWindow
 The layer window for the sliding linear fits. More...
 
unsigned int m_maxSamplingPoints
 The maximum number of extension sampling points considered per association check. More...
 
float m_sampleStepSize
 The sampling step size used in association checks, units cm. More...
 
unsigned int m_maxUnmatchedSampleRun
 The maximum run of unmatched (and non-gap) samples to consider before stopping. More...
 
float m_maxOnClusterDistance
 The maximum distance between a sampling point and sliding fit to target cluster. More...
 
unsigned int m_minMatchedSamplingPoints
 Minimum number of matched sampling points to declare association. More...
 
float m_minMatchedSamplingFraction
 Minimum ratio between matched sampling points and expectation to declare association. More...
 
float m_gapTolerance
 The tolerance to use when querying whether a sampling point is in a gap, units cm. More...
 

Additional Inherited Members

- Protected Types inherited from lar_content::ClusterAssociationAlgorithm
typedef std::unordered_map< const pandora::Cluster *, ClusterAssociationClusterAssociationMap
 
- Protected Member Functions inherited from lar_content::ClusterAssociationAlgorithm
virtual pandora::StatusCode Run ()
 

Detailed Description

CrossGapsAssociationAlgorithm class.

Definition at line 23 of file CrossGapsAssociationAlgorithm.h.

Constructor & Destructor Documentation

lar_content::CrossGapsAssociationAlgorithm::CrossGapsAssociationAlgorithm ( )

Default constructor.

Definition at line 21 of file CrossGapsAssociationAlgorithm.cc.

21  :
22  m_minClusterHits(10),
25  m_maxSamplingPoints(1000),
26  m_sampleStepSize(0.5f),
31  m_gapTolerance(0.f)
32 {
33 }
float m_minMatchedSamplingFraction
Minimum ratio between matched sampling points and expectation to declare association.
unsigned int m_minClusterLayers
The minimum allowed number of layers for a clean cluster.
unsigned int m_minClusterHits
The minimum allowed number of hits in a clean cluster.
unsigned int m_maxSamplingPoints
The maximum number of extension sampling points considered per association check. ...
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
float m_gapTolerance
The tolerance to use when querying whether a sampling point is in a gap, units cm.
unsigned int m_maxUnmatchedSampleRun
The maximum run of unmatched (and non-gap) samples to consider before stopping.
float m_maxOnClusterDistance
The maximum distance between a sampling point and sliding fit to target cluster.
unsigned int m_minMatchedSamplingPoints
Minimum number of matched sampling points to declare association.
float m_sampleStepSize
The sampling step size used in association checks, units cm.

Member Function Documentation

bool lar_content::CrossGapsAssociationAlgorithm::AreClustersAssociated ( const TwoDSlidingFitResult innerFitResult,
const TwoDSlidingFitResult outerFitResult 
) const
private

Determine whether two clusters are associated.

Parameters
innerFitResulttwo dimensional sliding fit result for the inner cluster
outerFitResulttwo dimensional sliding fit result for the outer cluster
Returns
boolean

Definition at line 124 of file CrossGapsAssociationAlgorithm.cc.

125 {
126  if (outerFitResult.GetCluster()->GetInnerPseudoLayer() < innerFitResult.GetCluster()->GetInnerPseudoLayer())
127  throw pandora::StatusCodeException(STATUS_CODE_NOT_ALLOWED);
128 
129  if (outerFitResult.GetCluster()->GetInnerPseudoLayer() < innerFitResult.GetCluster()->GetOuterPseudoLayer())
130  return false;
131 
132  return (this->IsAssociated(innerFitResult.GetGlobalMaxLayerPosition(), innerFitResult.GetGlobalMaxLayerDirection(), outerFitResult) &&
133  this->IsAssociated(outerFitResult.GetGlobalMinLayerPosition(), outerFitResult.GetGlobalMinLayerDirection() * -1.f, innerFitResult));
134 }
bool IsAssociated(const pandora::CartesianVector &startPosition, const pandora::CartesianVector &startDirection, const TwoDSlidingFitResult &targetFitResult) const
Sample points along the extrapolation from a starting position to a target fit result to declare clus...
void lar_content::CrossGapsAssociationAlgorithm::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::ClusterAssociationAlgorithm.

Definition at line 37 of file CrossGapsAssociationAlgorithm.cc.

38 {
39  // ATTN May want to opt-out completely if no gap information available
40  // if (PandoraContentApi::GetGeometry(*this)->GetDetectorGapList().empty())
41  // return;
42 
43  for (const Cluster *const pCluster : *pClusterList)
44  {
45  if (pCluster->GetNCaloHits() < m_minClusterHits)
46  continue;
47 
48  if (1 + pCluster->GetOuterPseudoLayer() - pCluster->GetInnerPseudoLayer() < m_minClusterLayers)
49  continue;
50 
51  clusterVector.push_back(pCluster);
52  }
53 
54  std::sort(clusterVector.begin(), clusterVector.end(), LArClusterHelper::SortByInnerLayer);
55 }
unsigned int m_minClusterLayers
The minimum allowed number of layers for a clean cluster.
unsigned int m_minClusterHits
The minimum allowed number of hits in a clean cluster.
static bool SortByInnerLayer(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs)
Sort clusters by inner layer, then position, then pulse-height.
bool lar_content::CrossGapsAssociationAlgorithm::IsAssociated ( const pandora::CartesianVector &  startPosition,
const pandora::CartesianVector &  startDirection,
const TwoDSlidingFitResult targetFitResult 
) const
private

Sample points along the extrapolation from a starting position to a target fit result to declare cluster association.

Parameters
startPositionthe start position
startDirectionthe start direction
targetFitResultthe target fit result
Returns
boolean

Definition at line 138 of file CrossGapsAssociationAlgorithm.cc.

140 {
141  const HitType hitType(LArClusterHelper::GetClusterHitType(targetFitResult.GetCluster()));
142  unsigned int nSamplingPoints(0), nGapSamplingPoints(0), nMatchedSamplingPoints(0), nUnmatchedSampleRun(0);
143 
144  for (unsigned int iSample = 0; iSample < m_maxSamplingPoints; ++iSample)
145  {
146  ++nSamplingPoints;
147  const CartesianVector samplingPoint(startPosition + startDirection * static_cast<float>(iSample) * m_sampleStepSize);
148 
149  if (LArGeometryHelper::IsInGap(this->GetPandora(), samplingPoint, hitType, m_gapTolerance))
150  {
151  ++nGapSamplingPoints;
152  nUnmatchedSampleRun = 0; // ATTN Choose to also reset run when entering gap region
153  continue;
154  }
155 
156  if (this->IsNearCluster(samplingPoint, targetFitResult))
157  {
158  ++nMatchedSamplingPoints;
159  nUnmatchedSampleRun = 0;
160  }
161  else if (++nUnmatchedSampleRun > m_maxUnmatchedSampleRun)
162  {
163  break;
164  }
165  }
166 
167  const float expectation((targetFitResult.GetGlobalMaxLayerPosition() - targetFitResult.GetGlobalMinLayerPosition()).GetMagnitude() / m_sampleStepSize);
168  const float matchedSamplingFraction(expectation > 0.f ? static_cast<float>(nMatchedSamplingPoints) / expectation : 0.f);
169 
170  if ((nMatchedSamplingPoints > m_minMatchedSamplingPoints) || (matchedSamplingFraction > m_minMatchedSamplingFraction))
171  return true;
172 
173  return false;
174 }
float m_minMatchedSamplingFraction
Minimum ratio between matched sampling points and expectation to declare association.
enum cvn::HType HitType
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
unsigned int m_maxSamplingPoints
The maximum number of extension sampling points considered per association check. ...
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.
float m_gapTolerance
The tolerance to use when querying whether a sampling point is in a gap, units cm.
unsigned int m_maxUnmatchedSampleRun
The maximum run of unmatched (and non-gap) samples to consider before stopping.
unsigned int m_minMatchedSamplingPoints
Minimum number of matched sampling points to declare association.
bool IsNearCluster(const pandora::CartesianVector &samplingPoint, const TwoDSlidingFitResult &targetFitResult) const
Whether a sampling point lies near a target 2d sliding fit result.
float m_sampleStepSize
The sampling step size used in association checks, units cm.
bool lar_content::CrossGapsAssociationAlgorithm::IsExtremalCluster ( const bool  isForward,
const pandora::Cluster *const  pCurrentCluster,
const pandora::Cluster *const  pTestCluster 
) const
privatevirtual

Determine which of two clusters is extremal.

Parameters
isForwardwhether propagation direction is forward
pCurrentClustercurrent extremal cluster
pTestClusterpotential extremal cluster
Returns
boolean

Implements lar_content::ClusterAssociationAlgorithm.

Definition at line 108 of file CrossGapsAssociationAlgorithm.cc.

109 {
110  const unsigned int currentLayer(isForward ? pCurrentCluster->GetOuterPseudoLayer() : pCurrentCluster->GetInnerPseudoLayer());
111  const unsigned int testLayer(isForward ? pTestCluster->GetOuterPseudoLayer() : pTestCluster->GetInnerPseudoLayer());
112 
113  if (isForward && ((testLayer > currentLayer) || ((testLayer == currentLayer) && LArClusterHelper::SortByNHits(pTestCluster, pCurrentCluster))))
114  return true;
115 
116  if (!isForward && ((testLayer < currentLayer) || ((testLayer == currentLayer) && LArClusterHelper::SortByNHits(pTestCluster, pCurrentCluster))))
117  return true;
118 
119  return false;
120 }
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.
bool lar_content::CrossGapsAssociationAlgorithm::IsNearCluster ( const pandora::CartesianVector &  samplingPoint,
const TwoDSlidingFitResult targetFitResult 
) const
private

Whether a sampling point lies near a target 2d sliding fit result.

Parameters
samplingPointthe sampling point
targetFitResultthe target fit result
Returns
boolean

Definition at line 178 of file CrossGapsAssociationAlgorithm.cc.

179 {
181  targetFitResult.GetLocalPosition(samplingPoint, rL, rT);
182 
183  CartesianVector fitPosition(0.f, 0.f, 0.f);
184 
185  if (STATUS_CODE_SUCCESS == targetFitResult.GetGlobalFitPosition(rL, fitPosition))
186  {
187  if ((fitPosition - samplingPoint).GetMagnitudeSquared() < m_maxOnClusterDistance * m_maxOnClusterDistance)
188  return true;
189  }
190 
191  CartesianVector fitPositionAtX(0.f, 0.f, 0.f);
192 
193  if (STATUS_CODE_SUCCESS == targetFitResult.GetGlobalFitPositionAtX(samplingPoint.GetX(), fitPositionAtX))
194  {
195  if ((fitPositionAtX - samplingPoint).GetMagnitudeSquared() < m_maxOnClusterDistance * m_maxOnClusterDistance)
196  return true;
197  }
198 
199  return false;
200 }
static int max(int a, int b)
float m_maxOnClusterDistance
The maximum distance between a sampling point and sliding fit to target cluster.
void lar_content::CrossGapsAssociationAlgorithm::PopulateClusterAssociationMap ( const pandora::ClusterVector &  clusterVector,
ClusterAssociationMap clusterAssociationMap 
) const
privatevirtual

Populate the cluster association map.

Parameters
clusterVectorthe cluster vector
clusterAssociationMapto receive the populated cluster association map

Implements lar_content::ClusterAssociationAlgorithm.

Definition at line 59 of file CrossGapsAssociationAlgorithm.cc.

60 {
61  TwoDSlidingFitResultMap slidingFitResultMap;
62  const float slidingFitPitch(LArGeometryHelper::GetWireZPitch(this->GetPandora()));
63 
64  for (const Cluster *const pCluster : clusterVector)
65  {
66  try
67  {
68  (void)slidingFitResultMap.insert(
69  TwoDSlidingFitResultMap::value_type(pCluster, TwoDSlidingFitResult(pCluster, m_slidingFitWindow, slidingFitPitch)));
70  }
71  catch (StatusCodeException &)
72  {
73  }
74  }
75 
76  // ATTN This method assumes that clusters have been sorted by layer
77  for (ClusterVector::const_iterator iterI = clusterVector.begin(), iterIEnd = clusterVector.end(); iterI != iterIEnd; ++iterI)
78  {
79  const Cluster *const pInnerCluster = *iterI;
80  TwoDSlidingFitResultMap::const_iterator fitIterI = slidingFitResultMap.find(pInnerCluster);
81 
82  if (slidingFitResultMap.end() == fitIterI)
83  continue;
84 
85  for (ClusterVector::const_iterator iterJ = iterI, iterJEnd = clusterVector.end(); iterJ != iterJEnd; ++iterJ)
86  {
87  const Cluster *const pOuterCluster = *iterJ;
88 
89  if (pInnerCluster == pOuterCluster)
90  continue;
91 
92  TwoDSlidingFitResultMap::const_iterator fitIterJ = slidingFitResultMap.find(pOuterCluster);
93 
94  if (slidingFitResultMap.end() == fitIterJ)
95  continue;
96 
97  if (!this->AreClustersAssociated(fitIterI->second, fitIterJ->second))
98  continue;
99 
100  clusterAssociationMap[pInnerCluster].m_forwardAssociations.insert(pOuterCluster);
101  clusterAssociationMap[pOuterCluster].m_backwardAssociations.insert(pInnerCluster);
102  }
103  }
104 }
intermediate_table::const_iterator const_iterator
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
std::unordered_map< const pandora::Cluster *, TwoDSlidingFitResult > TwoDSlidingFitResultMap
bool AreClustersAssociated(const TwoDSlidingFitResult &innerFitResult, const TwoDSlidingFitResult &outerFitResult) const
Determine whether two clusters are associated.
StatusCode lar_content::CrossGapsAssociationAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
privatevirtual

Reimplemented from lar_content::ClusterAssociationAlgorithm.

Definition at line 204 of file CrossGapsAssociationAlgorithm.cc.

205 {
206  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinClusterHits", m_minClusterHits));
207 
208  PANDORA_RETURN_RESULT_IF_AND_IF(
209  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinClusterLayers", m_minClusterLayers));
210 
211  PANDORA_RETURN_RESULT_IF_AND_IF(
212  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingFitWindow", m_slidingFitWindow));
213 
214  PANDORA_RETURN_RESULT_IF_AND_IF(
215  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxSamplingPoints", m_maxSamplingPoints));
216 
217  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SampleStepSize", m_sampleStepSize));
218 
219  if (m_sampleStepSize < std::numeric_limits<float>::epsilon())
220  {
221  std::cout << "CrossGapsAssociationAlgorithm: Invalid value for SampleStepSize " << m_sampleStepSize << std::endl;
222  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
223  }
224 
225  PANDORA_RETURN_RESULT_IF_AND_IF(
226  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxUnmatchedSampleRun", m_maxUnmatchedSampleRun));
227 
228  PANDORA_RETURN_RESULT_IF_AND_IF(
229  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxOnClusterDistance", m_maxOnClusterDistance));
230 
231  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
232  XmlHelper::ReadValue(xmlHandle, "MinMatchedSamplingPoints", m_minMatchedSamplingPoints));
233 
234  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
235  XmlHelper::ReadValue(xmlHandle, "MinMatchedSamplingFraction", m_minMatchedSamplingFraction));
236 
237  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "GapTolerance", m_gapTolerance));
238 
240 }
float m_minMatchedSamplingFraction
Minimum ratio between matched sampling points and expectation to declare association.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
unsigned int m_minClusterLayers
The minimum allowed number of layers for a clean cluster.
unsigned int m_minClusterHits
The minimum allowed number of hits in a clean cluster.
unsigned int m_maxSamplingPoints
The maximum number of extension sampling points considered per association check. ...
unsigned int m_slidingFitWindow
The layer window for the sliding linear fits.
float m_gapTolerance
The tolerance to use when querying whether a sampling point is in a gap, units cm.
unsigned int m_maxUnmatchedSampleRun
The maximum run of unmatched (and non-gap) samples to consider before stopping.
float m_maxOnClusterDistance
The maximum distance between a sampling point and sliding fit to target cluster.
unsigned int m_minMatchedSamplingPoints
Minimum number of matched sampling points to declare association.
float m_sampleStepSize
The sampling step size used in association checks, units cm.
QTextStream & endl(QTextStream &s)

Member Data Documentation

float lar_content::CrossGapsAssociationAlgorithm::m_gapTolerance
private

The tolerance to use when querying whether a sampling point is in a gap, units cm.

Definition at line 79 of file CrossGapsAssociationAlgorithm.h.

float lar_content::CrossGapsAssociationAlgorithm::m_maxOnClusterDistance
private

The maximum distance between a sampling point and sliding fit to target cluster.

Definition at line 76 of file CrossGapsAssociationAlgorithm.h.

unsigned int lar_content::CrossGapsAssociationAlgorithm::m_maxSamplingPoints
private

The maximum number of extension sampling points considered per association check.

Definition at line 73 of file CrossGapsAssociationAlgorithm.h.

unsigned int lar_content::CrossGapsAssociationAlgorithm::m_maxUnmatchedSampleRun
private

The maximum run of unmatched (and non-gap) samples to consider before stopping.

Definition at line 75 of file CrossGapsAssociationAlgorithm.h.

unsigned int lar_content::CrossGapsAssociationAlgorithm::m_minClusterHits
private

The minimum allowed number of hits in a clean cluster.

Definition at line 70 of file CrossGapsAssociationAlgorithm.h.

unsigned int lar_content::CrossGapsAssociationAlgorithm::m_minClusterLayers
private

The minimum allowed number of layers for a clean cluster.

Definition at line 71 of file CrossGapsAssociationAlgorithm.h.

float lar_content::CrossGapsAssociationAlgorithm::m_minMatchedSamplingFraction
private

Minimum ratio between matched sampling points and expectation to declare association.

Definition at line 78 of file CrossGapsAssociationAlgorithm.h.

unsigned int lar_content::CrossGapsAssociationAlgorithm::m_minMatchedSamplingPoints
private

Minimum number of matched sampling points to declare association.

Definition at line 77 of file CrossGapsAssociationAlgorithm.h.

float lar_content::CrossGapsAssociationAlgorithm::m_sampleStepSize
private

The sampling step size used in association checks, units cm.

Definition at line 74 of file CrossGapsAssociationAlgorithm.h.

unsigned int lar_content::CrossGapsAssociationAlgorithm::m_slidingFitWindow
private

The layer window for the sliding linear fits.

Definition at line 72 of file CrossGapsAssociationAlgorithm.h.


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