9 #include "Pandora/AlgorithmHeaders.h" 21 LongitudinalExtensionAlgorithm::LongitudinalExtensionAlgorithm() :
22 m_clusterMinLength(5.
f),
23 m_clusterMinLayerOccupancy(0.75
f),
24 m_nodeMaxDisplacement(1.5
f),
25 m_nodeMaxCosRelativeAngle(0.906
f),
26 m_emissionMaxLongitudinalDisplacement(15.
f),
27 m_emissionMaxTransverseDisplacement(2.5
f),
28 m_emissionMaxCosRelativeAngle(0.985
f)
38 const Cluster *
const pCluster = *iter;
46 clusterVector.push_back(pCluster);
65 catch (StatusCodeException &)
92 const Cluster *
const pClusterI(clusterI.
GetCluster());
93 const Cluster *
const pClusterJ(clusterJ.
GetCluster());
95 if (pClusterI == pClusterJ)
109 catch (StatusCodeException &)
116 throw StatusCodeException(STATUS_CODE_FAILURE);
118 const CartesianVector &vertexPositionI(targetVertexI.
GetPosition());
119 const CartesianVector &vertexPositionJ(targetVertexJ.
GetPosition());
120 const CartesianVector &vertexDirectionI(targetVertexI.
GetDirection());
121 const CartesianVector &vertexDirectionJ(targetVertexJ.
GetDirection());
124 const float distanceSquared((vertexPositionI - vertexPositionJ).GetMagnitudeSquared());
130 if (targetVertexI.
GetRms() > 1.f || targetVertexJ.
GetRms() > 1.f)
141 if (distanceSquared < m_nodeMaxDisplacement * m_nodeMaxDisplacement)
143 const float cosTheta(-vertexDirectionI.GetDotProduct(vertexDirectionJ));
158 const float cosTheta(-vertexDirectionI.GetDotProduct(vertexDirectionJ));
159 const float cosThetaI((vertexPositionI - vertexPositionJ).GetUnitVector().GetDotProduct(vertexDirectionI));
160 const float cosThetaJ((vertexPositionJ - vertexPositionI).GetUnitVector().GetDotProduct(vertexDirectionJ));
162 float rT1(0.
f), rL1(0.
f), rT2(0.
f), rL2(0.
f);
166 if ((rL1 > -2.5
f && rL1 < std::min(0.66
f * clusterLengthJ, m_emissionMaxLongitudinalDisplacement)) &&
180 (void)clusterAssociationMatrix[pClusterI].insert(
181 ClusterAssociationMap::value_type(pClusterJ,
ClusterAssociation(vertexTypeI, vertexTypeJ, associationType, clusterLengthJ)));
182 (void)clusterAssociationMatrix[pClusterJ].insert(
183 ClusterAssociationMap::value_type(pClusterI,
ClusterAssociation(vertexTypeJ, vertexTypeI, associationType, clusterLengthI)));
201 for (
const auto &mapEntry : inputAssociationMatrix)
202 sortedInputClusters.push_back(mapEntry.first);
205 for (
const Cluster *
const pCluster1 : sortedInputClusters)
209 for (
const Cluster *
const pCluster2 : sortedInputClusters)
211 if (pCluster1 == pCluster2)
217 if (associationMap1.end() == iter12)
221 if (associationMap2.end() == iter21)
227 bool isAssociated(
true);
230 for (
const auto &mapEntry : associationMap1)
231 sortedAssociationClusters.push_back(mapEntry.first);
234 for (
const Cluster *
const pCluster3 : sortedAssociationClusters)
239 if (associationMap2.end() == iter23)
245 association13.GetDaughter() != association23.
GetDaughter())
247 isAssociated =
false;
254 (void)clusterAssociationMatrix[pCluster1].insert(ClusterAssociationMap::value_type(pCluster2, association12));
255 (void)clusterAssociationMatrix[pCluster2].insert(ClusterAssociationMap::value_type(pCluster1, association21));
264 for (
const auto &mapEntry : clusterAssociationMatrix)
265 sortedClusters.push_back(mapEntry.first);
268 for (
const Cluster *
const pParentCluster : sortedClusters)
272 const Cluster *pBestClusterInner(
nullptr);
275 const Cluster *pBestClusterOuter(
nullptr);
279 for (
const auto &mapEntry : clusterAssociationMap)
280 sortedAssociationClusters.push_back(mapEntry.first);
283 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
285 const ClusterAssociation &clusterAssociation(clusterAssociationMap.at(pDaughterCluster));
290 if (clusterAssociation.GetFigureOfMerit() > bestAssociationInner.
GetFigureOfMerit())
292 bestAssociationInner = clusterAssociation;
295 pBestClusterInner = pDaughterCluster;
297 pBestClusterInner =
nullptr;
304 if (clusterAssociation.GetFigureOfMerit() > bestAssociationOuter.
GetFigureOfMerit())
306 bestAssociationOuter = clusterAssociation;
309 pBestClusterOuter = pDaughterCluster;
311 pBestClusterOuter =
nullptr;
316 if (pBestClusterInner)
317 (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterInner, bestAssociationInner));
319 if (pBestClusterOuter)
320 (void)intermediateAssociationMatrix[pParentCluster].insert(ClusterAssociationMap::value_type(pBestClusterOuter, bestAssociationOuter));
325 for (
const auto &mapEntry : intermediateAssociationMatrix)
326 intermediateSortedClusters.push_back(mapEntry.first);
329 for (
const Cluster *
const pParentCluster : intermediateSortedClusters)
334 for (
const auto &mapEntry : parentAssociationMap)
335 sortedAssociationClusters.push_back(mapEntry.first);
338 for (
const Cluster *
const pDaughterCluster : sortedAssociationClusters)
340 const ClusterAssociation &parentToDaughterAssociation(parentAssociationMap.at(pDaughterCluster));
344 if (intermediateAssociationMatrix.end() == iter5)
351 if (daughterAssociationMap.end() == iter6)
356 if (parentToDaughterAssociation.GetParent() == daughterToParentAssociation.
GetDaughter() &&
357 parentToDaughterAssociation.GetDaughter() == daughterToParentAssociation.
GetParent())
359 ClusterList &parentList(clusterMergeMap[pParentCluster]);
361 if (parentList.end() == std::find(parentList.begin(), parentList.end(), pDaughterCluster))
362 parentList.push_back(pDaughterCluster);
372 PANDORA_RETURN_RESULT_IF_AND_IF(
373 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"ClusterMinLength",
m_clusterMinLength));
375 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
378 PANDORA_RETURN_RESULT_IF_AND_IF(
379 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"NodeMaxDisplacement",
m_nodeMaxDisplacement));
381 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
384 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
387 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
390 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
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.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void FillClusterAssociationMatrix(const pandora::ClusterVector &clusterVector, ClusterAssociationMatrix &clusterAssociationMatrix) const
Fill the cluster association matrix.
float m_clusterMinLayerOccupancy
float m_emissionMaxTransverseDisplacement
std::vector< LArPointingCluster > LArPointingClusterList
static void GetImpactParameters(const LArPointingCluster::Vertex &pointingVertex, const LArPointingCluster::Vertex &targetVertex, float &longitudinal, float &transverse)
Calculate impact parameters between a pair of pointing vertices.
float m_nodeMaxCosRelativeAngle
ClusterAssociation class.
static float GetLength(const LArPointingCluster &pointingCluster)
Calculate distance squared between inner and outer vertices of pointing cluster.
LArPointingCluster class.
const pandora::Cluster * GetCluster() const
Get the address of the cluster.
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.
float m_nodeMaxDisplacement
Header file for the cluster helper class.
bool IsInitialized() const
Whether the vertex has been initialized.
AssociationType
Association enumeration.
float m_emissionMaxCosRelativeAngle
std::unordered_map< const pandora::Cluster *, ClusterAssociation > ClusterAssociationMap
std::unordered_map< const pandora::Cluster *, ClusterAssociationMap > ClusterAssociationMatrix
float m_emissionMaxLongitudinalDisplacement
static float GetLayerOccupancy(const pandora::Cluster *const pCluster)
Fraction of occupied layers in cluster.
const pandora::CartesianVector & GetDirection() const
Get the vertex direction.
float GetRms() const
Get rms from vertex fit.
void FillClusterMergeMap(const ClusterAssociationMatrix &clusterAssociationMatrix, ClusterMergeMap &clusterMergeMap) const
Fill the cluster merge map.
VertexType GetParent() const
Get parent.
Header file for the longitudinal extension algorithm class.
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.
VertexType GetDaughter() const
Get daughter.
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...
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
bool IsInnerVertex() const
Is this the inner vertex.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
const pandora::CartesianVector & GetPosition() const
Get the vertex position.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
VertexType
Vertex enumeration.
float GetFigureOfMerit() const
Get figure of merit.