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)
100 catch (StatusCodeException &) {}
115 const LArPointingCluster::Vertex &pointingVertex(useInner ? pointingCluster.GetInnerVertex() : pointingCluster.GetOuterVertex());
119 outputPointingClusterList.push_back(pointingCluster);
127 const float maxLongitudinalDisplacement((pointingVertex2.
GetPosition() - pointingVertex1.
GetPosition()).GetMagnitude());
134 return (isAssociated1 && isAssociated2);
141 if (maxZ - minZ < std::numeric_limits<float>::epsilon())
165 for (
const auto &mapEntry : inputAssociationMatrix) sortedInputClusters.push_back(mapEntry.first);
168 for (
const Cluster *
const pCluster1 : sortedInputClusters)
172 for (
const Cluster *
const pCluster2 : sortedInputClusters)
174 if (pCluster1 == pCluster2)
180 if (associationMap1.end() == iter12)
184 if (associationMap2.end() == iter21)
190 bool isAssociated(
true);
193 for (
const auto &mapEntry : associationMap1) sortedAssociationClusters.push_back(mapEntry.first);
196 for (
const Cluster *
const pCluster3 : sortedAssociationClusters)
201 if (associationMap2.end() == iter23)
206 if (association12.
GetParent() == association13.GetParent() &&
208 association13.GetDaughter() != association23.
GetDaughter())
210 isAssociated =
false;
217 (void) clusterAssociationMatrix[pCluster1].insert(ClusterAssociationMap::value_type(pCluster2, association12));
218 (void) clusterAssociationMatrix[pCluster2].insert(ClusterAssociationMap::value_type(pCluster1, association21));
228 for (
const auto &mapEntry : clusterAssociationMatrix) sortedClusters.push_back(mapEntry.first);
231 for (
const Cluster *
const pParentCluster : sortedClusters)
235 const Cluster *pBestClusterInner(
nullptr);
238 const Cluster *pBestClusterOuter(
nullptr);
242 for (
const auto &mapEntry : clusterAssociationMap) sortedAssociationClusters.push_back(mapEntry.first);
245 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
247 const ClusterAssociation &clusterAssociation(clusterAssociationMap.at(pDaughterCluster));
252 if (clusterAssociation.GetFigureOfMerit() > bestAssociationInner.
GetFigureOfMerit())
254 bestAssociationInner = clusterAssociation;
255 pBestClusterInner = pDaughterCluster;
262 if (clusterAssociation.GetFigureOfMerit() > bestAssociationOuter.
GetFigureOfMerit())
264 bestAssociationOuter = clusterAssociation;
265 pBestClusterOuter = pDaughterCluster;
270 if (pBestClusterInner)
271 (void) intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterInner, bestAssociationInner));
273 if (pBestClusterOuter)
274 (void) intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterOuter, bestAssociationOuter));
280 for (
const auto &mapEntry : intermediateAssociationMatrix) intermediateSortedClusters.push_back(mapEntry.first);
283 for (
const Cluster *
const pParentCluster : intermediateSortedClusters)
288 for (
const auto &mapEntry : parentAssociationMap) sortedAssociationClusters.push_back(mapEntry.first);
291 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
293 const ClusterAssociation &parentToDaughterAssociation(parentAssociationMap.at(pDaughterCluster));
297 if (intermediateAssociationMatrix.end() == iter5)
304 if (daughterAssociationMap.end() == iter6)
309 if (parentToDaughterAssociation.GetParent() == daughterToParentAssociation.
GetDaughter() &&
310 parentToDaughterAssociation.GetDaughter() == daughterToParentAssociation.
GetParent())
312 ClusterList &parentList(clusterMergeMap[pParentCluster]);
314 if (parentList.end() == std::find(parentList.begin(), parentList.end(), pDaughterCluster))
315 parentList.push_back(pDaughterCluster);
325 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
328 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
331 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
334 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
338 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
339 "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.
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterAssociationMatrix
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.
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)
float m_maxTransverseDisplacement
std::vector< art::Ptr< recob::Cluster > > ClusterVector
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
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.
const pandora::CartesianVector & GetPosition() const
Get the vertex position.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::unordered_map< const pandora::Cluster *, ClusterAssociation > ClusterAssociationMap
Header file for the cross gaps extension algorithm class.
float GetFigureOfMerit() const
Get figure of merit.