9 #include "Pandora/AlgorithmHeaders.h" 22 CrossGapsExtensionAlgorithm::CrossGapsExtensionAlgorithm() :
23 m_minClusterLength(5.
f),
24 m_minGapFraction(0.5
f),
25 m_maxGapTolerance(2.
f),
26 m_maxTransverseDisplacement(2.5
f),
27 m_maxRelativeAngle(10.
f)
39 for (
const Cluster *
const pCluster : *pClusterList)
44 clusterVector.push_back(pCluster);
62 const float zInner(pointingVertexInner.GetPosition().GetZ());
67 const float zOuter(pointingVertexOuter.GetPosition().GetZ());
72 if (!this->
IsAssociated(pointingVertexInner, pointingVertexOuter))
75 const Cluster *
const pClusterInner(pointingClusterInner.GetCluster());
76 const Cluster *
const pClusterOuter(pointingClusterOuter.GetCluster());
81 (void)clusterAssociationMatrix[pClusterInner].insert(ClusterAssociationMap::value_type(pClusterOuter,
83 (void)clusterAssociationMatrix[pClusterOuter].insert(ClusterAssociationMap::value_type(pClusterInner,
97 for (
const Cluster *
const pCluster : clusterVector)
103 catch (StatusCodeException &)
120 const LArPointingCluster::Vertex &pointingVertex(useInner ? pointingCluster.GetInnerVertex() : pointingCluster.GetOuterVertex());
124 outputPointingClusterList.push_back(pointingCluster);
134 const float maxLongitudinalDisplacement((pointingVertex2.
GetPosition() - pointingVertex1.
GetPosition()).GetMagnitude());
137 maxLongitudinalDisplacement + 1.f, maxTransverseDisplacementAdjusted,
m_maxRelativeAngle));
139 maxLongitudinalDisplacement + 1.f, maxTransverseDisplacementAdjusted,
m_maxRelativeAngle));
141 return (isAssociated1 && isAssociated2);
148 if (maxZ - minZ < std::numeric_limits<float>::epsilon())
172 for (
const auto &mapEntry : inputAssociationMatrix)
173 sortedInputClusters.push_back(mapEntry.first);
176 for (
const Cluster *
const pCluster1 : sortedInputClusters)
180 for (
const Cluster *
const pCluster2 : sortedInputClusters)
182 if (pCluster1 == pCluster2)
188 if (associationMap1.end() == iter12)
192 if (associationMap2.end() == iter21)
198 bool isAssociated(
true);
201 for (
const auto &mapEntry : associationMap1)
202 sortedAssociationClusters.push_back(mapEntry.first);
205 for (
const Cluster *
const pCluster3 : sortedAssociationClusters)
210 if (associationMap2.end() == iter23)
216 association13.GetDaughter() != association23.
GetDaughter())
218 isAssociated =
false;
225 (void)clusterAssociationMatrix[pCluster1].insert(ClusterAssociationMap::value_type(pCluster2, association12));
226 (void)clusterAssociationMatrix[pCluster2].insert(ClusterAssociationMap::value_type(pCluster1, association21));
235 for (
const auto &mapEntry : clusterAssociationMatrix)
236 sortedClusters.push_back(mapEntry.first);
239 for (
const Cluster *
const pParentCluster : sortedClusters)
243 const Cluster *pBestClusterInner(
nullptr);
246 const Cluster *pBestClusterOuter(
nullptr);
250 for (
const auto &mapEntry : clusterAssociationMap)
251 sortedAssociationClusters.push_back(mapEntry.first);
254 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
256 const ClusterAssociation &clusterAssociation(clusterAssociationMap.at(pDaughterCluster));
261 if (clusterAssociation.GetFigureOfMerit() > bestAssociationInner.
GetFigureOfMerit())
263 bestAssociationInner = clusterAssociation;
264 pBestClusterInner = pDaughterCluster;
271 if (clusterAssociation.GetFigureOfMerit() > bestAssociationOuter.
GetFigureOfMerit())
273 bestAssociationOuter = clusterAssociation;
274 pBestClusterOuter = pDaughterCluster;
279 if (pBestClusterInner)
280 (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterInner, bestAssociationInner));
282 if (pBestClusterOuter)
283 (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterOuter, bestAssociationOuter));
288 for (
const auto &mapEntry : intermediateAssociationMatrix)
289 intermediateSortedClusters.push_back(mapEntry.first);
292 for (
const Cluster *
const pParentCluster : intermediateSortedClusters)
297 for (
const auto &mapEntry : parentAssociationMap)
298 sortedAssociationClusters.push_back(mapEntry.first);
301 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
303 const ClusterAssociation &parentToDaughterAssociation(parentAssociationMap.at(pDaughterCluster));
307 if (intermediateAssociationMatrix.end() == iter5)
314 if (daughterAssociationMap.end() == iter6)
319 if (parentToDaughterAssociation.GetParent() == daughterToParentAssociation.
GetDaughter() &&
320 parentToDaughterAssociation.GetDaughter() == daughterToParentAssociation.
GetParent())
322 ClusterList &parentList(clusterMergeMap[pParentCluster]);
324 if (parentList.end() == std::find(parentList.begin(), parentList.end(), pDaughterCluster))
325 parentList.push_back(pDaughterCluster);
335 PANDORA_RETURN_RESULT_IF_AND_IF(
336 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MinClusterLength",
m_minClusterLength));
338 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MinGapFraction",
m_minGapFraction));
340 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxGapTolerance",
m_maxGapTolerance));
342 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
346 PANDORA_RETURN_RESULT_IF_AND_IF(
347 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxCosRelativeAngle", maxCosRelativeAngle));
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 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.
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 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...
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...
ClusterAssociation class.
void FillClusterMergeMap(const ClusterAssociationMatrix &clusterAssociationMatrix, ClusterMergeMap &clusterMergeMap) const
Fill the cluster merge map.
LArPointingCluster class.
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.
Header file for the geometry helper class.
const pandora::Cluster * GetCluster() const
Get the address of the cluster.
Header file for the cluster helper class.
void FillClusterAssociationMatrix(const pandora::ClusterVector &clusterVector, ClusterAssociationMatrix &clusterAssociationMatrix) const
Fill the cluster association matrix.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::unordered_map< const pandora::Cluster *, ClusterAssociation > ClusterAssociationMap
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterAssociationMatrix
float m_maxTransverseDisplacement
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.
VertexType GetParent() const
Get parent.
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.
VertexType GetDaughter() const
Get daughter.
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
std::vector< art::Ptr< recob::Cluster > > ClusterVector
const pandora::CartesianVector & GetPosition() const
Get the vertex position.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Header file for the cross gaps extension algorithm class.
float GetFigureOfMerit() const
Get figure of merit.