Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
TwoViewMatchingControl.cc
Go to the documentation of this file.
1
10
12
14
17
18using namespace pandora;
19
20namespace lar_content
21{
22
23template <typename T>
25 NViewMatchingControl(pAlgorithm),
26 m_pInputClusterList1(nullptr),
27 m_pInputClusterList2(nullptr)
28{
29}
30
31//------------------------------------------------------------------------------------------------------------------------------------------
32
33template <typename T>
35{
36}
37
38//------------------------------------------------------------------------------------------------------------------------------------------
40template <typename T>
45
46//------------------------------------------------------------------------------------------------------------------------------------------
47
48template <typename T>
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;
59//------------------------------------------------------------------------------------------------------------------------------------------
61template <typename T>
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
97template <typename T>
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
114template <typename T>
115const 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
129template <typename T>
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
147template <typename T>
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
162template <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 {
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
190template <typename T>
192{
193 m_pAlgorithm->PrepareInputClusters(m_clusterList1);
194 m_pAlgorithm->PrepareInputClusters(m_clusterList2);
195}
196
197//------------------------------------------------------------------------------------------------------------------------------------------
198
199template <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
214template <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
231template <typename T>
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
240template class TwoViewMatchingControl<float>;
243
244} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the cluster helper class.
Header file for the lar track two view overlap result class.
Header file for the three dimension algorithm base class.
#define PANDORA_THROW_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:55
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the two view matching control class.
static pandora::StatusCode GetList(const pandora::Algorithm &algorithm, const std::string &listName, const T *&pT)
Get a named list.
static const pandora::PandoraSettings * GetSettings(const pandora::Algorithm &algorithm)
Get the pandora settings instance.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
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,...
const std::string & GetClusterListName(const pandora::HitType hitType) const
Get the cluster list name corresponding to a specified hit type.
void PrepareAllInputClusters()
Perform any preparatory steps required on the input clusters, e.g. caching expensive fit results.
const pandora::ClusterList & GetInputClusterList(const pandora::HitType hitType) const
Get the input cluster list corresponding to a specified hit type.
void UpdateForNewCluster(const pandora::Cluster *const pNewCluster)
Update to reflect addition of a new cluster to the problem space.
TwoViewMatchingControl(MatchingBaseAlgorithm *const pAlgorithm)
Constructor.
unsigned int GetHitTypeIndex(const pandora::HitType hitType)
Get the index of an input hit type returning 0 if not found in map.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read settings from xml.
void SelectAllInputClusters()
Select a subset of input clusters for processing in this algorithm.
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...
MatrixType & GetOverlapMatrix()
Get the overlap matrix.
void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster)
Update to reflect cluster deletion.
Cluster class.
Definition Cluster.h:31
bool ShouldDisplayAlgorithmInfo() const
Whether to display algorithm information during processing.
StatusCodeException class.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
HitType
Calorimeter hit type enum.
std::vector< const Cluster * > ClusterVector
MANAGED_CONTAINER< const Cluster * > ClusterList
StatusCode
The StatusCode enum.