TwoViewSimpleTracksTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArTwoViewMatching/TwoViewSimpleTracksTool.cc
3  *
4  * @brief Implementation of the clear showers 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 TwoViewSimpleTracksTool::TwoViewSimpleTracksTool() :
19  m_minMatchedFraction(0.2f),
20  m_minMatchingScore(0.9f),
21  m_minMatchedSamplingPoints(5),
22  m_minXOverlapFraction(0.5f)
23 {
24 }
25 
26 //------------------------------------------------------------------------------------------------------------------------------------------
27 
29 {
30  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
31  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
32 
33  ProtoParticleVector protoParticleVector;
34  this->FindBestTrack(overlapMatrix, protoParticleVector);
35 
36  return pAlgorithm->CreateThreeDParticles(protoParticleVector);
37 }
38 
39 //------------------------------------------------------------------------------------------------------------------------------------------
40 
41 void TwoViewSimpleTracksTool::FindBestTrack(const MatrixType &overlapMatrix, ProtoParticleVector &protoParticleVector) const
42 {
43  ClusterVector sortedKeyClusters;
44  overlapMatrix.GetSortedKeyClusters(sortedKeyClusters);
45 
46  for (const Cluster *const pKeyCluster : sortedKeyClusters)
47  {
48  if (!pKeyCluster->IsAvailable())
49  continue;
50 
51  unsigned int n0(0), n1(0);
52  MatrixType::ElementList elementList;
53  overlapMatrix.GetConnectedElements(pKeyCluster, true, elementList, n0, n1);
54 
55  if (elementList.empty())
56  continue;
57 
58  for (MatrixType::ElementList::const_reverse_iterator iIter = elementList.rbegin(); iIter != elementList.rend(); ++iIter)
59  {
60  if (this->PassesElementCuts(iIter))
61  {
62  if ((nullptr == iIter->GetCluster1()) || (nullptr == iIter->GetCluster2()))
63  continue;
64 
65  ProtoParticle protoParticle;
66  protoParticle.m_clusterList.push_back(iIter->GetCluster1());
67  protoParticle.m_clusterList.push_back(iIter->GetCluster2());
68  protoParticleVector.push_back(protoParticle);
69 
70  return;
71  }
72  }
73  }
74 }
75 
76 //------------------------------------------------------------------------------------------------------------------------------------------
77 
78 bool TwoViewSimpleTracksTool::PassesElementCuts(MatrixType::ElementList::const_reverse_iterator eIter) const
79 {
80  if (!eIter->GetOverlapResult().IsInitialized())
81  return false;
82 
83  if (eIter->GetOverlapResult().GetLocallyMatchedFraction() < m_minMatchedFraction)
84  return false;
85 
86  if (eIter->GetOverlapResult().GetMatchingScore() < m_minMatchingScore)
87  return false;
88 
89  if (eIter->GetOverlapResult().GetNMatchedReUpsampledSamplingPoints() < m_minMatchedSamplingPoints)
90  return false;
91 
92  const TwoViewXOverlap &xOverlap(eIter->GetOverlapResult().GetTwoViewXOverlap());
93 
94  if (!((xOverlap.GetXOverlapFraction0() > m_minXOverlapFraction) && (xOverlap.GetXOverlapFraction1() > m_minXOverlapFraction)))
95  {
96  return false;
97  }
98 
99  return true;
100 }
101 
102 //------------------------------------------------------------------------------------------------------------------------------------------
103 
104 StatusCode TwoViewSimpleTracksTool::ReadSettings(const TiXmlHandle xmlHandle)
105 {
106  PANDORA_RETURN_RESULT_IF_AND_IF(
107  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinMatchedFraction", m_minMatchedFraction));
108 
109  PANDORA_RETURN_RESULT_IF_AND_IF(
110  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinMatchingScore", m_minMatchingScore));
111 
112  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
113  XmlHelper::ReadValue(xmlHandle, "MinMatchedSamplingPoints", m_minMatchedSamplingPoints));
114 
115  PANDORA_RETURN_RESULT_IF_AND_IF(
116  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinXOverlapFraction", m_minXOverlapFraction));
117 
118  return STATUS_CODE_SUCCESS;
119 }
120 
121 } // namespace lar_content
std::vector< ProtoParticle > ProtoParticleVector
bool Run(TwoViewTransverseTracksAlgorithm *const pAlgorithm, MatrixType &overlapMatrix)
Run the algorithm tool.
float m_minMatchingScore
The min global matching score for particle creation.
unsigned int m_minMatchedSamplingPoints
The min number of matched sampling points for particle creation.
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (view 1 clusters with current implementation) ...
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
bool PassesElementCuts(MatrixType::ElementList::const_reverse_iterator eIter) const
Whether a provided (iterator to a) matrix element passes the selection cuts for particle creation...
pandora::ClusterList m_clusterList
List of 2D clusters in a 3D proto particle.
float m_minMatchedFraction
The min matched sampling point fraction for particle creation.
float m_minXOverlapFraction
The min x overlap fraction (in each view) for particle creation.
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
TwoViewXOverlap class.
virtual bool CreateThreeDParticles(const ProtoParticleVector &protoParticleVector)
Create particles using findings from recent algorithm processing.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
void FindBestTrack(const MatrixType &overlapMatrix, ProtoParticleVector &protoParticleVector) const
Find best track match as a simple way to (try to) resolve ambiguities in the matrix.
QTextStream & endl(QTextStream &s)