ThreeViewMatchingControl.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArThreeDBase/ThreeViewMatchingControl.cc
3  *
4  * @brief Implementation of the three view matching control class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
15 
18 
19 using namespace pandora;
20 
21 namespace lar_content
22 {
23 
24 template <typename T>
26  NViewMatchingControl(pAlgorithm),
27  m_pInputClusterListU(nullptr),
28  m_pInputClusterListV(nullptr),
29  m_pInputClusterListW(nullptr)
30 {
31 }
32 
33 //------------------------------------------------------------------------------------------------------------------------------------------
34 
35 template <typename T>
37 {
38 }
39 
40 //------------------------------------------------------------------------------------------------------------------------------------------
41 
42 template <typename T>
44 {
45  return m_overlapTensor;
46 }
47 
48 //------------------------------------------------------------------------------------------------------------------------------------------
49 
50 template <typename T>
51 void ThreeViewMatchingControl<T>::UpdateForNewCluster(const Cluster *const pNewCluster)
52 {
53  const HitType hitType(LArClusterHelper::GetClusterHitType(pNewCluster));
54 
55  if (!((TPC_VIEW_U == hitType) || (TPC_VIEW_V == hitType) || (TPC_VIEW_W == hitType)))
56  throw StatusCodeException(STATUS_CODE_FAILURE);
57 
58  ClusterList &clusterList((TPC_VIEW_U == hitType) ? m_clusterListU : (TPC_VIEW_V == hitType) ? m_clusterListV : m_clusterListW);
59 
60  if (clusterList.end() != std::find(clusterList.begin(), clusterList.end(), pNewCluster))
61  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
62 
63  clusterList.push_back(pNewCluster);
64 
65  const ClusterList &clusterList2((TPC_VIEW_U == hitType) ? m_clusterListV : m_clusterListU);
66  const ClusterList &clusterList3((TPC_VIEW_W == hitType) ? m_clusterListV : m_clusterListW);
67 
68  ClusterVector clusterVector2(clusterList2.begin(), clusterList2.end());
69  ClusterVector clusterVector3(clusterList3.begin(), clusterList3.end());
70  std::sort(clusterVector2.begin(), clusterVector2.end(), LArClusterHelper::SortByNHits);
71  std::sort(clusterVector3.begin(), clusterVector3.end(), LArClusterHelper::SortByNHits);
72 
73  for (const Cluster *const pCluster2 : clusterVector2)
74  {
75  for (const Cluster *const pCluster3 : clusterVector3)
76  {
77  if (TPC_VIEW_U == hitType)
78  {
79  m_pAlgorithm->CalculateOverlapResult(pNewCluster, pCluster2, pCluster3);
80  }
81  else if (TPC_VIEW_V == hitType)
82  {
83  m_pAlgorithm->CalculateOverlapResult(pCluster2, pNewCluster, pCluster3);
84  }
85  else
86  {
87  m_pAlgorithm->CalculateOverlapResult(pCluster2, pCluster3, pNewCluster);
88  }
89  }
90  }
91 }
92 
93 //------------------------------------------------------------------------------------------------------------------------------------------
94 
95 template <typename T>
96 void ThreeViewMatchingControl<T>::UpdateUponDeletion(const Cluster *const pDeletedCluster)
97 {
98  ClusterList::iterator iterU = std::find(m_clusterListU.begin(), m_clusterListU.end(), pDeletedCluster);
99  ClusterList::iterator iterV = std::find(m_clusterListV.begin(), m_clusterListV.end(), pDeletedCluster);
100  ClusterList::iterator iterW = std::find(m_clusterListW.begin(), m_clusterListW.end(), pDeletedCluster);
101 
102  if (m_clusterListU.end() != iterU)
103  m_clusterListU.erase(iterU);
104 
105  if (m_clusterListV.end() != iterV)
106  m_clusterListV.erase(iterV);
107 
108  if (m_clusterListW.end() != iterW)
109  m_clusterListW.erase(iterW);
110 
111  m_overlapTensor.RemoveCluster(pDeletedCluster);
112 }
113 
114 //------------------------------------------------------------------------------------------------------------------------------------------
115 
116 template <typename T>
118 {
119  if (TPC_VIEW_U == hitType)
121 
122  if (TPC_VIEW_V == hitType)
124 
125  if (TPC_VIEW_W == hitType)
127 
128  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
129 }
130 
131 //------------------------------------------------------------------------------------------------------------------------------------------
132 
133 template <typename T>
134 const pandora::ClusterList &ThreeViewMatchingControl<T>::GetInputClusterList(const HitType hitType) const
135 {
136  if ((TPC_VIEW_U == hitType) && m_pInputClusterListU)
137  return (*m_pInputClusterListU);
138 
139  if ((TPC_VIEW_V == hitType) && m_pInputClusterListV)
140  return (*m_pInputClusterListV);
141 
142  if ((TPC_VIEW_W == hitType) && m_pInputClusterListW)
143  return (*m_pInputClusterListW);
144 
145  throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
146 }
147 
148 //------------------------------------------------------------------------------------------------------------------------------------------
149 
150 template <typename T>
151 const pandora::ClusterList &ThreeViewMatchingControl<T>::GetSelectedClusterList(const HitType hitType) const
152 {
153  if (TPC_VIEW_U == hitType)
154  return m_clusterListU;
155 
156  if (TPC_VIEW_V == hitType)
157  return m_clusterListV;
158 
159  if (TPC_VIEW_W == hitType)
160  return m_clusterListW;
161 
162  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
163 }
164 
165 //------------------------------------------------------------------------------------------------------------------------------------------
166 
167 template <typename T>
169 {
170  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=,
171  PandoraContentApi::GetList(*m_pAlgorithm, m_inputClusterListNameU, m_pInputClusterListU));
172  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=,
173  PandoraContentApi::GetList(*m_pAlgorithm, m_inputClusterListNameV, m_pInputClusterListV));
174  PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=,
175  PandoraContentApi::GetList(*m_pAlgorithm, m_inputClusterListNameW, m_pInputClusterListW));
176 
178  {
179  if (PandoraContentApi::GetSettings(*m_pAlgorithm)->ShouldDisplayAlgorithmInfo())
180  std::cout << "ThreeViewMatchingControl: one or more input cluster lists unavailable." << std::endl;
181 
182  throw StatusCodeException(STATUS_CODE_SUCCESS);
183  }
184 
188 }
189 
190 //------------------------------------------------------------------------------------------------------------------------------------------
191 
192 template <typename T>
194 {
198 }
199 
200 //------------------------------------------------------------------------------------------------------------------------------------------
201 
202 template <typename T>
204 {
206 
207  m_pInputClusterListU = nullptr;
208  m_pInputClusterListV = nullptr;
209  m_pInputClusterListW = nullptr;
210 
211  m_clusterListU.clear();
212  m_clusterListV.clear();
213  m_clusterListW.clear();
214 }
215 
216 //------------------------------------------------------------------------------------------------------------------------------------------
217 
218 template <typename T>
220 {
221  ClusterVector clusterVectorU(m_clusterListU.begin(), m_clusterListU.end());
222  ClusterVector clusterVectorV(m_clusterListV.begin(), m_clusterListV.end());
223  ClusterVector clusterVectorW(m_clusterListW.begin(), m_clusterListW.end());
224  std::sort(clusterVectorU.begin(), clusterVectorU.end(), LArClusterHelper::SortByNHits);
225  std::sort(clusterVectorV.begin(), clusterVectorV.end(), LArClusterHelper::SortByNHits);
226  std::sort(clusterVectorW.begin(), clusterVectorW.end(), LArClusterHelper::SortByNHits);
227 
228  for (const Cluster *const pClusterU : clusterVectorU)
229  {
230  for (const Cluster *const pClusterV : clusterVectorV)
231  {
232  for (const Cluster *const pClusterW : clusterVectorW)
233  m_pAlgorithm->CalculateOverlapResult(pClusterU, pClusterV, pClusterW);
234  }
235  }
236 }
237 
238 //------------------------------------------------------------------------------------------------------------------------------------------
239 
240 template <typename T>
241 StatusCode ThreeViewMatchingControl<T>::ReadSettings(const TiXmlHandle xmlHandle)
242 {
243  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListNameU", m_inputClusterListNameU));
244  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListNameV", m_inputClusterListNameV));
245  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListNameW", m_inputClusterListNameW));
246 
247  return STATUS_CODE_SUCCESS;
248 }
249 
250 template class ThreeViewMatchingControl<float>;
256 
257 } // namespace lar_content
ThreeViewMatchingControl class.
pandora::ClusterList m_clusterListW
The selected modified cluster list W.
pandora::ClusterList m_clusterListU
The selected modified cluster list U.
intermediate_table::iterator iterator
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.
OverlapTensor class.
std::string m_inputClusterListNameW
The name of the view W cluster list.
NViewMatchingControl class.
MatchingBaseAlgorithm * m_pAlgorithm
The address of the matching base algorithm.
TensorType & GetOverlapTensor()
Get the overlap tensor.
pandora::ClusterList m_clusterListV
The selected modified cluster list V.
enum cvn::HType HitType
void PerformMainLoop()
Main loop over cluster combinations in order to populate the overlap container. Responsible for calli...
std::string string
Definition: nybbler.cc:12
virtual void CalculateOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3=nullptr)=0
Calculate cluster overlap result and store in container.
virtual void SelectInputClusters(const pandora::ClusterList *const pInputClusterList, pandora::ClusterList &selectedClusterList) const
Select a subset of input clusters for processing in this algorithm.
MatchingBaseAlgorithm class.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
void UpdateForNewCluster(const pandora::Cluster *const pNewCluster)
Update to reflect addition of a new cluster to the problem space.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read settings from xml.
void Clear()
Clear overlap tensor.
std::string m_inputClusterListNameV
The name of the view V cluster list.
void PrepareAllInputClusters()
Perform any preparatory steps required on the input clusters, e.g. caching expensive fit results...
virtual void PrepareInputClusters(pandora::ClusterList &preparedClusterList)
Perform any preparatory steps required on the input clusters, e.g. caching expensive fit results...
Header file for the cluster helper class.
const std::string & GetClusterListName(const pandora::HitType hitType) const
Get the cluster list name corresponding to a specified hit type.
Header file for the lar shower overlap result class.
const pandora::ClusterList * m_pInputClusterListU
Address of the input cluster list U.
const pandora::ClusterList & GetInputClusterList(const pandora::HitType hitType) const
Get the input cluster list corresponding to a specified hit type.
TensorType m_overlapTensor
The overlap tensor.
Header file for the lar track overlap result class.
const pandora::ClusterList * m_pInputClusterListV
Address of the input cluster list V.
Header file for the three view matching control class.
const pandora::ClusterList * m_pInputClusterListW
Address of the input cluster list W.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
const pandora::ClusterList & GetSelectedClusterList(const pandora::HitType hitType) const
Get the selected cluster list corresponding to a specified hit type.
void RemoveCluster(const pandora::Cluster *const pCluster)
Remove entries from tensor corresponding to specified cluster.
std::string m_inputClusterListNameU
The name of the view U cluster list.
void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster)
Update to reflect cluster deletion.
void SelectAllInputClusters()
Select a subset of input clusters for processing in this algorithm.
QTextStream & endl(QTextStream &s)
Header file for the three dimension algorithm base class.