All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AmbiguousDeltaRayTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArCosmicRay/AmbiguousDeltaRayTool.cc
3  *
4  * @brief Implementation of the ambiguous delta ray tool class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 AmbiguousDeltaRayTool::AmbiguousDeltaRayTool() : m_maxGoodMatchReducedChiSquared(1.f)
19 {
20 }
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
25 {
26  m_pParentAlgorithm = pAlgorithm;
27 
28  if (PandoraContentApi::GetSettings(*m_pParentAlgorithm)->ShouldDisplayAlgorithmInfo())
29  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
30 
31  this->ExamineConnectedElements(overlapTensor);
32 
33  // ATTN: Prevent tensor tool loop running again
34  return false;
35 }
36 
37 //------------------------------------------------------------------------------------------------------------------------------------------
38 
40 {
41  ClusterVector sortedKeyClusters;
42  overlapTensor.GetSortedKeyClusters(sortedKeyClusters);
43 
44  ClusterSet usedClusters;
45  ClusterSet usedKeyClusters;
46  ProtoParticleVector protoParticleVector;
47 
48  for (const Cluster *const pKeyCluster : sortedKeyClusters)
49  {
50  if (usedKeyClusters.count(pKeyCluster))
51  continue;
52 
53  TensorType::ElementList elementList;
54  overlapTensor.GetConnectedElements(pKeyCluster, true, elementList);
55 
56  for (const TensorType::Element &element : elementList)
57  usedKeyClusters.insert(element.GetClusterU());
58 
59  if (elementList.size() < 2)
60  continue;
61 
62  this->PickOutGoodMatches(elementList, usedClusters, protoParticleVector);
63  }
64 
65  if (!protoParticleVector.empty())
66  m_pParentAlgorithm->CreatePfos(protoParticleVector);
67 }
68 
69 //------------------------------------------------------------------------------------------------------------------------------------------
70 
72  const TensorType::ElementList &elementList, ClusterSet &usedClusters, ProtoParticleVector &protoParticleVector) const
73 {
74  bool found(false);
75 
76  do
77  {
78  found = false;
79 
80  unsigned int highestHitCount(0);
81  float bestChiSquared(std::numeric_limits<float>::max());
82  const Cluster *pBestClusterU(nullptr), *pBestClusterV(nullptr), *pBestClusterW(nullptr);
83 
84  for (const TensorType::Element &element : elementList)
85  {
86  const Cluster *const pClusterU(element.GetClusterU()), *const pClusterV(element.GetClusterV()), *const pClusterW(element.GetClusterW());
87 
88  if (usedClusters.count(pClusterU) || usedClusters.count(pClusterV) || usedClusters.count(pClusterW))
89  continue;
90 
91  const float chiSquared(element.GetOverlapResult().GetReducedChi2());
92 
93  if (chiSquared > m_maxGoodMatchReducedChiSquared)
94  continue;
95 
96  const unsigned int hitSum(pClusterU->GetNCaloHits() + pClusterV->GetNCaloHits() + pClusterW->GetNCaloHits());
97 
98  if ((hitSum > highestHitCount) || ((hitSum == highestHitCount) && (chiSquared < bestChiSquared)))
99  {
100  bestChiSquared = chiSquared;
101  highestHitCount = hitSum;
102  pBestClusterU = pClusterU;
103  pBestClusterV = pClusterV;
104  pBestClusterW = pClusterW;
105  }
106  }
107 
108  if (pBestClusterU && pBestClusterV && pBestClusterW)
109  {
110  found = true;
111  usedClusters.insert(pBestClusterU);
112  usedClusters.insert(pBestClusterV);
113  usedClusters.insert(pBestClusterW);
114 
115  ProtoParticle protoParticle;
116  protoParticle.m_clusterList.push_back(pBestClusterU);
117  protoParticle.m_clusterList.push_back(pBestClusterV);
118  protoParticle.m_clusterList.push_back(pBestClusterW);
119  protoParticleVector.push_back(protoParticle);
120  }
121  } while (found);
122 }
123 
124 //------------------------------------------------------------------------------------------------------------------------------------------
125 
126 StatusCode AmbiguousDeltaRayTool::ReadSettings(const TiXmlHandle xmlHandle)
127 {
128  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
129  XmlHelper::ReadValue(xmlHandle, "MaxGoodMatchReducedChiSquared", m_maxGoodMatchReducedChiSquared));
130 
131  return STATUS_CODE_SUCCESS;
132 }
133 
134 //------------------------------------------------------------------------------------------------------------------------------------------
135 
136 } // 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.
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)
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
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...
BEGIN_PROLOG could also be cout
bool Run(ThreeViewDeltaRayMatchingAlgorithm *const pAlgorithm, TensorType &overlapTensor)
Run the algorithm tool.