All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TwoViewMatchingControl.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArThreeDBase/TwoViewMatchingControl.cc
3  *
4  * @brief Implementation of the two view matching control class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
17 
18 using namespace pandora;
19 
20 namespace lar_content
21 {
22 
23 template <typename T>
25  NViewMatchingControl(pAlgorithm),
26  m_pInputClusterList1(nullptr),
27  m_pInputClusterList2(nullptr)
28 {
29 }
30 
31 //------------------------------------------------------------------------------------------------------------------------------------------
32 
33 template <typename T>
35 {
36 }
37 
38 //------------------------------------------------------------------------------------------------------------------------------------------
39 
40 template <typename T>
42 {
43  return m_overlapMatrix;
44 }
45 
46 //------------------------------------------------------------------------------------------------------------------------------------------
47 
48 template <typename T>
49 unsigned int TwoViewMatchingControl<T>::GetHitTypeIndex(const pandora::HitType hitType)
50 {
51  HitTypeToIndexMap::const_iterator iter = m_hitTypeToIndexMap.find(hitType);
52 
53  if ((iter != m_hitTypeToIndexMap.end()) && (iter->second != 1) && (iter->second != 2))
54  throw StatusCodeException(STATUS_CODE_FAILURE);
55 
56  return iter == m_hitTypeToIndexMap.end() ? 0 : iter->second;
57 }
58 
59 //------------------------------------------------------------------------------------------------------------------------------------------
60 
61 template <typename T>
62 void TwoViewMatchingControl<T>::UpdateForNewCluster(const Cluster *const pNewCluster)
63 {
64  const HitType hitType(LArClusterHelper::GetClusterHitType(pNewCluster));
65  HitTypeToIndexMap::const_iterator iter = m_hitTypeToIndexMap.find(hitType);
66 
67  if ((m_hitTypeToIndexMap.end() == iter) || ((1 != iter->second) && (2 != iter->second)))
68  throw StatusCodeException(STATUS_CODE_FAILURE);
69 
70  ClusterList &clusterList((1 == iter->second) ? m_clusterList1 : m_clusterList2);
71 
72  if (clusterList.end() != std::find(clusterList.begin(), clusterList.end(), pNewCluster))
73  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
74 
75  clusterList.push_back(pNewCluster);
76 
77  const ClusterList &clusterList2((1 == iter->second) ? m_clusterList2 : m_clusterList1);
78 
79  ClusterVector clusterVector2(clusterList2.begin(), clusterList2.end());
80  std::sort(clusterVector2.begin(), clusterVector2.end(), LArClusterHelper::SortByNHits);
81 
82  for (const Cluster *const pCluster2 : clusterVector2)
83  {
84  if (1 == iter->second)
85  {
86  m_pAlgorithm->CalculateOverlapResult(pNewCluster, pCluster2);
87  }
88  else
89  {
90  m_pAlgorithm->CalculateOverlapResult(pCluster2, pNewCluster);
91  }
92  }
93 }
94 
95 //------------------------------------------------------------------------------------------------------------------------------------------
96 
97 template <typename T>
98 void TwoViewMatchingControl<T>::UpdateUponDeletion(const Cluster *const pDeletedCluster)
99 {
100  ClusterList::iterator iter1 = std::find(m_clusterList1.begin(), m_clusterList1.end(), pDeletedCluster);
101  ClusterList::iterator iter2 = std::find(m_clusterList2.begin(), m_clusterList2.end(), pDeletedCluster);
102 
103  if (m_clusterList1.end() != iter1)
104  m_clusterList1.erase(iter1);
105 
106  if (m_clusterList2.end() != iter2)
107  m_clusterList2.erase(iter2);
108 
109  m_overlapMatrix.RemoveCluster(pDeletedCluster);
110 }
111 
112 //------------------------------------------------------------------------------------------------------------------------------------------
113 
114 template <typename T>
115 const std::string &TwoViewMatchingControl<T>::GetClusterListName(const HitType hitType) const
116 {
117  HitTypeToIndexMap::const_iterator iter = m_hitTypeToIndexMap.find(hitType);
118  if (m_hitTypeToIndexMap.end() == iter)
119  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
120 
121  if ((1 != iter->second) && (2 != iter->second))
122  throw StatusCodeException(STATUS_CODE_FAILURE);
123 
124  return ((1 == iter->second) ? m_inputClusterListName1 : m_inputClusterListName2);
125 }
126 
127 //------------------------------------------------------------------------------------------------------------------------------------------
128 
129 template <typename T>
130 const pandora::ClusterList &TwoViewMatchingControl<T>::GetInputClusterList(const HitType hitType) const
131 {
132  HitTypeToIndexMap::const_iterator iter = m_hitTypeToIndexMap.find(hitType);
133  if (m_hitTypeToIndexMap.end() == iter)
134  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
135 
136  if ((1 == iter->second) && m_pInputClusterList1)
137  return (*m_pInputClusterList1);
138 
139  if ((2 == iter->second) && m_pInputClusterList2)
140  return (*m_pInputClusterList2);
141 
142  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
143 }
144 
145 //------------------------------------------------------------------------------------------------------------------------------------------
146 
147 template <typename T>
148 const pandora::ClusterList &TwoViewMatchingControl<T>::GetSelectedClusterList(const HitType hitType) const
149 {
150  HitTypeToIndexMap::const_iterator iter = m_hitTypeToIndexMap.find(hitType);
151  if (m_hitTypeToIndexMap.end() == iter)
152  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
153 
154  if ((1 != iter->second) && (2 != iter->second))
155  throw StatusCodeException(STATUS_CODE_FAILURE);
156 
157  return ((1 == iter->second) ? m_clusterList1 : m_clusterList2);
158 }
159 
160 //------------------------------------------------------------------------------------------------------------------------------------------
161 
162 template <typename T>
164 {
165  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=,
166  PandoraContentApi::GetList(*m_pAlgorithm, m_inputClusterListName1, m_pInputClusterList1));
167  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=,
168  PandoraContentApi::GetList(*m_pAlgorithm, m_inputClusterListName2, m_pInputClusterList2));
169 
170  if (!m_pInputClusterList1 || !m_pInputClusterList2)
171  {
172  if (PandoraContentApi::GetSettings(*m_pAlgorithm)->ShouldDisplayAlgorithmInfo())
173  std::cout << "TwoViewMatchingControl: one or more input cluster lists unavailable." << std::endl;
174 
175  throw StatusCodeException(STATUS_CODE_SUCCESS);
176  }
177 
178  if (!m_pInputClusterList1->empty())
179  m_hitTypeToIndexMap.insert(HitTypeToIndexMap::value_type(LArClusterHelper::GetClusterHitType(m_pInputClusterList1->front()), 1));
180 
181  if (!m_pInputClusterList2->empty())
182  m_hitTypeToIndexMap.insert(HitTypeToIndexMap::value_type(LArClusterHelper::GetClusterHitType(m_pInputClusterList2->front()), 2));
183 
184  m_pAlgorithm->SelectInputClusters(m_pInputClusterList1, m_clusterList1);
185  m_pAlgorithm->SelectInputClusters(m_pInputClusterList2, m_clusterList2);
186 }
187 
188 //------------------------------------------------------------------------------------------------------------------------------------------
189 
190 template <typename T>
192 {
193  m_pAlgorithm->PrepareInputClusters(m_clusterList1);
194  m_pAlgorithm->PrepareInputClusters(m_clusterList2);
195 }
196 
197 //------------------------------------------------------------------------------------------------------------------------------------------
198 
199 template <typename T>
201 {
202  m_overlapMatrix.Clear();
203  m_hitTypeToIndexMap.clear();
204 
205  m_pInputClusterList1 = nullptr;
206  m_pInputClusterList2 = nullptr;
207 
208  m_clusterList1.clear();
209  m_clusterList2.clear();
210 }
211 
212 //------------------------------------------------------------------------------------------------------------------------------------------
213 
214 template <typename T>
216 {
217  ClusterVector clusterVector1(m_clusterList1.begin(), m_clusterList1.end());
218  ClusterVector clusterVector2(m_clusterList2.begin(), m_clusterList2.end());
219  std::sort(clusterVector1.begin(), clusterVector1.end(), LArClusterHelper::SortByNHits);
220  std::sort(clusterVector2.begin(), clusterVector2.end(), LArClusterHelper::SortByNHits);
221 
222  for (const Cluster *const pCluster1 : clusterVector1)
223  {
224  for (const Cluster *const pCluster2 : clusterVector2)
225  m_pAlgorithm->CalculateOverlapResult(pCluster1, pCluster2);
226  }
227 }
228 
229 //------------------------------------------------------------------------------------------------------------------------------------------
230 
231 template <typename T>
232 StatusCode TwoViewMatchingControl<T>::ReadSettings(const TiXmlHandle xmlHandle)
233 {
234  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListName1", m_inputClusterListName1));
235  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListName2", m_inputClusterListName2));
236 
237  return STATUS_CODE_SUCCESS;
238 }
239 
240 template class TwoViewMatchingControl<float>;
243 
244 } // namespace lar_content
static bool SortByNHits(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs)
Sort clusters by number of hits, then layer span, then inner layer, then position, then pulse-height.
void UpdateForNewCluster(const pandora::Cluster *const pNewCluster)
Update to reflect addition of a new cluster to the problem space.
TwoViewMatchingControl class.
const std::string & GetClusterListName(const pandora::HitType hitType) const
Get the cluster list name corresponding to a specified hit type.
NViewMatchingControl class.
void TidyUp()
Tidy member variables.
MatrixType & GetOverlapMatrix()
Get the overlap matrix.
void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster)
Update to reflect cluster deletion.
MatchingBaseAlgorithm class.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
void SelectAllInputClusters()
Select a subset of input clusters for processing in this algorithm.
const pandora::ClusterList & GetInputClusterList(const pandora::HitType hitType) const
Get the input cluster list corresponding to a specified hit type.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read settings from xml.
Header file for the cluster helper class.
void PrepareAllInputClusters()
Perform any preparatory steps required on the input clusters, e.g. caching expensive fit results...
unsigned int GetHitTypeIndex(const pandora::HitType hitType)
Get the index of an input hit type returning 0 if not found in map.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
const pandora::ClusterList & GetSelectedClusterList(const pandora::HitType hitType) const
Get the selected cluster list corresponding to a specified hit type.
void PerformMainLoop()
Main loop over cluster combinations in order to populate the overlap container. Responsible for calli...
std::vector< art::Ptr< recob::Cluster > > ClusterVector
Header file for the two view matching control class.
Header file for the lar track two view overlap result class.
OverlapMatrix class.
BEGIN_PROLOG could also be cout
Header file for the three dimension algorithm base class.