MatchedEndPointsTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArLongitudinalTrackMatching/MatchedEndPointsTool.cc
3  *
4  * @brief Implementation of the matched end point 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 MatchedEndPointsTool::MatchedEndPointsTool() : m_minMatchedFraction(0.8f), m_maxEndPointChi2(3.f)
19 {
20 }
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
25 {
26  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
27  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
28 
29  ProtoParticleVector protoParticleVector;
30  this->FindMatchedTracks(overlapTensor, protoParticleVector);
31 
32  const bool particlesMade(pAlgorithm->CreateThreeDParticles(protoParticleVector));
33  return particlesMade;
34 }
35 
36 //------------------------------------------------------------------------------------------------------------------------------------------
37 
38 void MatchedEndPointsTool::FindMatchedTracks(const TensorType &overlapTensor, ProtoParticleVector &protoParticleVector) const
39 {
40  ClusterSet usedClusters;
41  ClusterVector sortedKeyClusters;
42  overlapTensor.GetSortedKeyClusters(sortedKeyClusters);
43 
44  for (const Cluster *const pKeyCluster : sortedKeyClusters)
45  {
46  if (!pKeyCluster->IsAvailable())
47  continue;
48 
49  unsigned int nU(0), nV(0), nW(0);
50  TensorType::ElementList elementList;
51  overlapTensor.GetConnectedElements(pKeyCluster, true, elementList, nU, nV, nW);
52 
53  if (nU * nV * nW == 0)
54  continue;
55 
56  std::sort(elementList.begin(), elementList.end(), MatchedEndPointsTool::SortByChiSquared);
57 
58  for (TensorType::ElementList::const_iterator iter = elementList.begin(); iter != elementList.end(); ++iter)
59  {
60  if (usedClusters.count(iter->GetClusterU()) || usedClusters.count(iter->GetClusterV()) || usedClusters.count(iter->GetClusterW()))
61  continue;
62 
63  if (iter->GetOverlapResult().GetMatchedFraction() < m_minMatchedFraction)
64  continue;
65 
66  if (std::max(iter->GetOverlapResult().GetInnerChi2(), iter->GetOverlapResult().GetOuterChi2()) > m_maxEndPointChi2)
67  continue;
68 
69  ProtoParticle protoParticle;
70  protoParticle.m_clusterList.push_back(iter->GetClusterU());
71  protoParticle.m_clusterList.push_back(iter->GetClusterV());
72  protoParticle.m_clusterList.push_back(iter->GetClusterW());
73  protoParticleVector.push_back(protoParticle);
74 
75  usedClusters.insert(iter->GetClusterU());
76  usedClusters.insert(iter->GetClusterV());
77  usedClusters.insert(iter->GetClusterW());
78  }
79  }
80 }
81 
82 //------------------------------------------------------------------------------------------------------------------------------------------
83 
84 bool MatchedEndPointsTool::SortByChiSquared(const TensorType::Element &lhs, const TensorType::Element &rhs)
85 {
86  return (lhs.GetOverlapResult().GetInnerChi2() + lhs.GetOverlapResult().GetOuterChi2() <
87  rhs.GetOverlapResult().GetInnerChi2() + rhs.GetOverlapResult().GetOuterChi2());
88 }
89 
90 //------------------------------------------------------------------------------------------------------------------------------------------
91 
92 StatusCode MatchedEndPointsTool::ReadSettings(const TiXmlHandle xmlHandle)
93 {
94  PANDORA_RETURN_RESULT_IF_AND_IF(
95  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinMatchedFraction", m_minMatchedFraction));
96 
97  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxEndPointChi2", m_maxEndPointChi2));
98 
99  return STATUS_CODE_SUCCESS;
100 }
101 
102 } // namespace lar_content
std::vector< ProtoParticle > ProtoParticleVector
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
float m_maxEndPointChi2
The max chi2 of matched vertex and end points for particle creation.
void FindMatchedTracks(const TensorType &overlapTensor, ProtoParticleVector &protoParticleVector) const
Find matched tracks, hidden by ambiguities in the tensor.
float m_minMatchedFraction
The min matched sampling point fraction for particle creation.
pandora::ClusterList m_clusterList
List of 2D clusters in a 3D proto particle.
bool Run(ThreeViewLongitudinalTracksAlgorithm *const pAlgorithm, TensorType &overlapTensor)
Run the algorithm tool.
static int max(int a, int b)
static bool SortByChiSquared(const TensorType::Element &lhs, const TensorType::Element &rhs)
Sort tensor elements by chi-squared.
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (U clusters with current implementation)
Header file for the matched end points tool class.
virtual bool CreateThreeDParticles(const ProtoParticleVector &protoParticleVector)
Create particles using findings from recent algorithm processing.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
QTextStream & endl(QTextStream &s)
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)