LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
NearbyClusterMopUpAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
13 
15 
16 using namespace pandora;
17 
18 namespace lar_content
19 {
20 
21 NearbyClusterMopUpAlgorithm::NearbyClusterMopUpAlgorithm() :
22  m_minHitsInCluster(5),
23  m_vertexProximity(5.f),
24  m_minClusterSeparation(2.5f),
25  m_touchingDistance(0.001f)
26 {
27 }
28 
29 //------------------------------------------------------------------------------------------------------------------------------------------
30 
31 void NearbyClusterMopUpAlgorithm::ClusterMopUp(const ClusterList &pfoClusters, const ClusterList &remnantClusters) const
32 {
33  ClusterAssociationMap clusterAssociationMap;
34 
35  const VertexList *pVertexList(NULL);
36  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pVertexList));
37  const Vertex *const pVertex(((pVertexList->size() == 1) && (VERTEX_3D == (*(pVertexList->begin()))->GetVertexType())) ? *(pVertexList->begin()) : NULL);
38 
39  ClusterVector sortedPfoClusters(pfoClusters.begin(), pfoClusters.end());
40  std::sort(sortedPfoClusters.begin(), sortedPfoClusters.end(), LArClusterHelper::SortByNHits);
41 
42  ClusterVector sortedRemnantClusters(remnantClusters.begin(), remnantClusters.end());
43  std::sort(sortedRemnantClusters.begin(), sortedRemnantClusters.end(), LArClusterHelper::SortByNHits);
44 
45  for (const Cluster *const pClusterP : sortedPfoClusters)
46  {
47  const HitType hitType(LArClusterHelper::GetClusterHitType(pClusterP));
48  const CartesianVector vertexPosition2D(!pVertex ? CartesianVector(0.f, 0.f, 0.f) :
49  LArGeometryHelper::ProjectPosition(this->GetPandora(), pVertex->GetPosition(), hitType));
50 
51  const float innerPV((vertexPosition2D - pClusterP->GetCentroid(pClusterP->GetInnerPseudoLayer())).GetMagnitude());
52  const float outerPV((vertexPosition2D - pClusterP->GetCentroid(pClusterP->GetOuterPseudoLayer())).GetMagnitude());
53 
54  for (const Cluster *const pClusterR : sortedRemnantClusters)
55  {
56  if (pClusterR->GetNCaloHits() < m_minHitsInCluster)
57  continue;
58 
59  const float innerRV((vertexPosition2D - pClusterR->GetCentroid(pClusterR->GetInnerPseudoLayer())).GetMagnitude());
60  const float outerRV((vertexPosition2D - pClusterR->GetCentroid(pClusterR->GetOuterPseudoLayer())).GetMagnitude());
61 
62  // ATTN Could use pointing clusters here, for consistency with other vertex association mechanics
63  if (pVertex && (((innerPV < m_vertexProximity) || (outerPV < m_vertexProximity)) && ((innerRV < m_vertexProximity) || (outerRV < m_vertexProximity))))
64  continue;
65 
66  const float innerRP(LArClusterHelper::GetClosestDistance(pClusterR->GetCentroid(pClusterR->GetInnerPseudoLayer()), pClusterP));
67  const float outerRP(LArClusterHelper::GetClosestDistance(pClusterR->GetCentroid(pClusterR->GetOuterPseudoLayer()), pClusterP));
68 
69  const float minSeparation(std::min(innerRP, outerRP));
70 
71  if (minSeparation > m_minClusterSeparation)
72  continue;
73 
74  // ATTN Use of ClusterMopUp base algorithm assumes bigger figure of merit means better association
75  if (m_touchingDistance < std::numeric_limits<float>::epsilon())
76  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
77 
78  AssociationDetails &associationDetails(clusterAssociationMap[pClusterR]);
79  const float figureOfMerit((minSeparation < m_touchingDistance) ? 1.f / m_touchingDistance : 1.f / minSeparation);
80 
81  if (!associationDetails.insert(AssociationDetails::value_type(pClusterP, figureOfMerit)).second)
82  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
83  }
84  }
85 
86  this->MakeClusterMerges(clusterAssociationMap);
87 }
88 
89 //------------------------------------------------------------------------------------------------------------------------------------------
90 
91 StatusCode NearbyClusterMopUpAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
92 {
93  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
94  "MinHitsInCluster", m_minHitsInCluster));
95 
96  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
97  "VertexProximity", m_vertexProximity));
98 
99  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
100  "MinClusterSeparation", m_minClusterSeparation));
101 
102  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
103  "TouchingDistance", m_touchingDistance));
104 
105  return ClusterMopUpBaseAlgorithm::ReadSettings(xmlHandle);
106 }
107 
108 } // namespace lar_content
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.
virtual void MakeClusterMerges(const ClusterAssociationMap &clusterAssociationMap) const
Make the cluster merges specified in the cluster association map, using list name information in the ...
std::unordered_map< const pandora::Cluster *, float > AssociationDetails
std::unordered_map< const pandora::Cluster *, AssociationDetails > ClusterAssociationMap
float m_vertexProximity
Distance between cluster inner/outer centroid and vtx to declare cluster vtx associated.
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
TFile f
Definition: plotHisto.C:6
Header file for the geometry helper class.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
unsigned int m_minHitsInCluster
Minimum number of hits in order to consider a cluster.
float m_touchingDistance
Threshold (small) distance below which parent and daughter clusters are declated touching.
Header file for the cluster helper class.
void ClusterMopUp(const pandora::ClusterList &pfoClusters, const pandora::ClusterList &remnantClusters) const
Cluster mop up for a single view. This function is responsible for instructing pandora to make cluste...
float m_minClusterSeparation
Minimum distance between parent and daughter clusters to declare clusters associated.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Int_t min
Definition: plot.C:26
Header file for the nearby cluster mop up algorithm class.
std::list< Vertex > VertexList
Definition: DCEL.h:178
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.