LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ConnectedRemnantsTool.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 ConnectedRemnantsTool::ConnectedRemnantsTool() :
21  m_maxClusterSeparation(10.f)
22 {
23 }
24 
25 //------------------------------------------------------------------------------------------------------------------------------------------
26 
27 bool ConnectedRemnantsTool::Run(ThreeDRemnantsAlgorithm *const pAlgorithm, TensorType &overlapTensor)
28 {
29  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
30  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
31 
32  ProtoParticleVector protoParticleVector; ClusterMergeMap clusterMergeMap;
33  this->FindConnectedShowers(overlapTensor, protoParticleVector, clusterMergeMap);
34 
35  const bool particlesMade(pAlgorithm->CreateThreeDParticles(protoParticleVector));
36  const bool mergesMade(pAlgorithm->MakeClusterMerges(clusterMergeMap));
37 
38  return (particlesMade||mergesMade);
39 }
40 
41 //------------------------------------------------------------------------------------------------------------------------------------------
42 
43 void ConnectedRemnantsTool::FindConnectedShowers(const TensorType &overlapTensor, ProtoParticleVector &protoParticleVector,
44  ClusterMergeMap &clusterMergeMap) const
45 {
46  ClusterSet usedClusters;
47  ClusterVector sortedKeyClusters;
48  overlapTensor.GetSortedKeyClusters(sortedKeyClusters);
49 
50  for (const Cluster *const pKeyCluster : sortedKeyClusters)
51  {
52  if (!pKeyCluster->IsAvailable())
53  continue;
54 
55  TensorType::ElementList connectedElements;
56  overlapTensor.GetConnectedElements(pKeyCluster, true, connectedElements);
57 
58  ClusterVector clusterVectorU, clusterVectorV, clusterVectorW;
59  this->GetClusters(connectedElements, usedClusters, clusterVectorU, clusterVectorV, clusterVectorW);
60 
61  if (clusterVectorU.empty() || clusterVectorV.empty() || clusterVectorW.empty())
62  continue;
63 
64  usedClusters.insert(clusterVectorU.begin(), clusterVectorU.end());
65  usedClusters.insert(clusterVectorV.begin(), clusterVectorV.end());
66  usedClusters.insert(clusterVectorW.begin(), clusterVectorW.end());
67 
68  if (!(this->IsConnected(clusterVectorU) && this->IsConnected(clusterVectorV) && this->IsConnected(clusterVectorW)))
69  continue;
70 
71  const Cluster *const pClusterU = clusterVectorU.front();
72  const Cluster *const pClusterV = clusterVectorV.front();
73  const Cluster *const pClusterW = clusterVectorW.front();
74 
75  ProtoParticle protoParticle;
76  protoParticle.m_clusterListU.push_back(pClusterU);
77  protoParticle.m_clusterListV.push_back(pClusterV);
78  protoParticle.m_clusterListW.push_back(pClusterW);
79  protoParticleVector.push_back(protoParticle);
80 
81  this->FillMergeMap(pClusterU, clusterVectorU, clusterMergeMap);
82  this->FillMergeMap(pClusterV, clusterVectorV, clusterMergeMap);
83  this->FillMergeMap(pClusterW, clusterVectorW, clusterMergeMap);
84  }
85 }
86 
87 //------------------------------------------------------------------------------------------------------------------------------------------
88 
89 void ConnectedRemnantsTool::GetClusters(const TensorType::ElementList &elementList, const ClusterSet &usedClusters,
90  ClusterVector &clusterVectorU, ClusterVector &clusterVectorV, ClusterVector &clusterVectorW) const
91 {
92  for (const TensorType::Element &element : elementList)
93  {
94  if (usedClusters.count(element.GetClusterU()) || usedClusters.count(element.GetClusterV()) || usedClusters.count(element.GetClusterW()))
95  continue;
96 
97  clusterVectorU.push_back(element.GetClusterU());
98  clusterVectorV.push_back(element.GetClusterV());
99  clusterVectorW.push_back(element.GetClusterW());
100  }
101 }
102 
103 //------------------------------------------------------------------------------------------------------------------------------------------
104 
105 void ConnectedRemnantsTool::FillMergeMap(const Cluster *const pFirstCluster, const ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
106 {
107  if (clusterVector.empty())
108  throw StatusCodeException(STATUS_CODE_FAILURE);
109 
110  for (const Cluster *const pSecondCluster : clusterVector)
111  {
112  if (pFirstCluster == pSecondCluster)
113  continue;
114 
115  ClusterList &clusterList(clusterMergeMap[pFirstCluster]);
116 
117  if (clusterList.end() == std::find(clusterList.begin(), clusterList.end(), pSecondCluster))
118  clusterList.push_back(pSecondCluster);
119  }
120 }
121 
122 //------------------------------------------------------------------------------------------------------------------------------------------
123 
124 bool ConnectedRemnantsTool::IsConnected(const ClusterVector &clusterVector) const
125 {
126  for (const Cluster *const pCluster1 : clusterVector)
127  {
128  for (const Cluster *const pCluster2 : clusterVector)
129  {
130  if (pCluster1 == pCluster2)
131  continue;
132 
134  return false;
135  }
136  }
137 
138  return true;
139 }
140 
141 //------------------------------------------------------------------------------------------------------------------------------------------
142 
143 StatusCode ConnectedRemnantsTool::ReadSettings(const TiXmlHandle xmlHandle)
144 {
145  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
146  "MaxClusterSeparation", m_maxClusterSeparation));
147 
148  return STATUS_CODE_SUCCESS;
149 }
150 
151 } // namespace lar_content
std::vector< ProtoParticle > ProtoParticleVector
void FindConnectedShowers(const TensorType &overlapTensor, ProtoParticleVector &protoParticleVector, ClusterMergeMap &clusterMergeMap) const
Identify candidate particles.
bool Run(ThreeDRemnantsAlgorithm *const pAlgorithm, TensorType &overlapTensor)
Run the algorithm tool.
virtual bool CreateThreeDParticles(const ProtoParticleVector &protoParticleVector)
Create particles using findings from recent algorithm processing.
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
TFile f
Definition: plotHisto.C:6
void FillMergeMap(const pandora::Cluster *const pCluster, const pandora::ClusterVector &clusterVector, ClusterMergeMap &clusterMergeMap) const
Fill map of clusters to be merged.
pandora::ClusterList m_clusterListW
List of 2D W clusters in a 3D proto particle.
std::vector< Element > ElementList
Header file for the cluster helper class.
pandora::ClusterList m_clusterListV
List of 2D V clusters in a 3D proto particle.
pandora::ClusterList m_clusterListU
List of 2D U clusters in a 3D proto particle.
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (U clusters with current implementation)
std::vector< art::Ptr< recob::Cluster > > ClusterVector
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
void GetClusters(const TensorType::ElementList &connectedElements, const pandora::ClusterSet &usedClusters, pandora::ClusterVector &clusterVectorU, pandora::ClusterVector &clusterVectorV, pandora::ClusterVector &clusterVectorW) const
Separate connected clusters into cluster lists by view.
bool IsConnected(const pandora::ClusterVector &clusterVector) const
Check whether all clusters in a list are spatially connected.
ThreeDRemnantsAlgorithm class.
Header file for the connected remnants tool class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.
virtual bool MakeClusterMerges(const ClusterMergeMap &clusterMergeMap)
Merge clusters together.