LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
AmbiguousDeltaRayTool.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 AmbiguousDeltaRayTool::AmbiguousDeltaRayTool() :
19  m_maxGoodMatchReducedChiSquared(1.f)
20 {
21 }
22 
23 //------------------------------------------------------------------------------------------------------------------------------------------
24 
26 {
27  m_pParentAlgorithm = pAlgorithm;
28 
29  if (PandoraContentApi::GetSettings(*m_pParentAlgorithm)->ShouldDisplayAlgorithmInfo())
30  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
31 
32  this->ExamineConnectedElements(overlapTensor);
33 
34  // ATTN: Prevent tensor tool loop running again
35  return false;
36 }
37 
38 //------------------------------------------------------------------------------------------------------------------------------------------
39 
41 {
42  ClusterVector sortedKeyClusters;
43  overlapTensor.GetSortedKeyClusters(sortedKeyClusters);
44 
45  ClusterSet usedClusters;
46  ClusterSet usedKeyClusters;
47  ProtoParticleVector protoParticleVector;
48 
49  for (const Cluster *const pKeyCluster : sortedKeyClusters)
50  {
51  if (usedKeyClusters.count(pKeyCluster))
52  continue;
53 
54  TensorType::ElementList elementList;
55  overlapTensor.GetConnectedElements(pKeyCluster, true, elementList);
56 
57  for (const TensorType::Element &element : elementList)
58  usedKeyClusters.insert(element.GetClusterU());
59 
60  if (elementList.size() < 2)
61  continue;
62 
63  this->PickOutGoodMatches(elementList, usedClusters, protoParticleVector);
64  }
65 
66  if (!protoParticleVector.empty())
67  m_pParentAlgorithm->CreatePfos(protoParticleVector);
68 }
69 
70 //------------------------------------------------------------------------------------------------------------------------------------------
71 
73  const TensorType::ElementList &elementList, ClusterSet &usedClusters, ProtoParticleVector &protoParticleVector) const
74 {
75  bool found(false);
76 
77  do
78  {
79  found = false;
80 
81  unsigned int highestHitCount(0);
82  float bestChiSquared(std::numeric_limits<float>::max());
83  const Cluster *pBestClusterU(nullptr), *pBestClusterV(nullptr), *pBestClusterW(nullptr);
84 
85  for (const TensorType::Element &element : elementList)
86  {
87  const Cluster *const pClusterU(element.GetClusterU()), *const pClusterV(element.GetClusterV()), *const pClusterW(element.GetClusterW());
88 
89  if (usedClusters.count(pClusterU) || usedClusters.count(pClusterV) || usedClusters.count(pClusterW))
90  continue;
91 
92  const float chiSquared(element.GetOverlapResult().GetReducedChi2());
93 
94  if (chiSquared > m_maxGoodMatchReducedChiSquared)
95  continue;
96 
97  const unsigned int hitSum(pClusterU->GetNCaloHits() + pClusterV->GetNCaloHits() + pClusterW->GetNCaloHits());
98 
99  if ((hitSum > highestHitCount) || ((hitSum == highestHitCount) && (chiSquared < bestChiSquared)))
100  {
101  bestChiSquared = chiSquared;
102  highestHitCount = hitSum;
103  pBestClusterU = pClusterU;
104  pBestClusterV = pClusterV;
105  pBestClusterW = pClusterW;
106  }
107  }
108 
109  if (pBestClusterU && pBestClusterV && pBestClusterW)
110  {
111  found = true;
112  usedClusters.insert(pBestClusterU);
113  usedClusters.insert(pBestClusterV);
114  usedClusters.insert(pBestClusterW);
115 
116  ProtoParticle protoParticle;
117  protoParticle.m_clusterList.push_back(pBestClusterU);
118  protoParticle.m_clusterList.push_back(pBestClusterV);
119  protoParticle.m_clusterList.push_back(pBestClusterW);
120  protoParticleVector.push_back(protoParticle);
121  }
122  } while (found);
123 }
124 
125 //------------------------------------------------------------------------------------------------------------------------------------------
126 
127 StatusCode AmbiguousDeltaRayTool::ReadSettings(const TiXmlHandle xmlHandle)
128 {
129  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
130  XmlHelper::ReadValue(xmlHandle, "MaxGoodMatchReducedChiSquared", m_maxGoodMatchReducedChiSquared));
131 
132  return STATUS_CODE_SUCCESS;
133 }
134 
135 //------------------------------------------------------------------------------------------------------------------------------------------
136 
137 } // namespace lar_content
std::vector< ProtoParticle > ProtoParticleVector
Header file for the ambiguous delta ray tool class.
void ExamineConnectedElements(TensorType &overlapTensor) const
Identify ambiguous matches (e.g. 3:2:1) and, if possible, create pfos out of the best 1:1:1 cluster m...
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
ThreeViewDeltaRayMatchingAlgorithm * m_pParentAlgorithm
Address of the parent matching algorithm.
TFile f
Definition: plotHisto.C:6
pandora::ClusterList m_clusterList
List of 2D 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
bool CreatePfos(ProtoParticleVector &protoParticleVector)
Create delta ray pfos maxmising completeness by searching for and merging in any stray clusters...
float m_maxGoodMatchReducedChiSquared
The maximum reduced chi squared value of a good 1:1:1 match.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void PickOutGoodMatches(const TensorType::ElementList &elementList, pandora::ClusterSet &usedClusters, ProtoParticleVector &protoParticleVector) const
Identify the best 1:1:1 match in a group of connected elements and from it create a pfo...
bool Run(ThreeViewDeltaRayMatchingAlgorithm *const pAlgorithm, TensorType &overlapTensor)
Run the algorithm tool.