Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
ClusterManager.cc
Go to the documentation of this file.
1
10
11#include "Objects/Cluster.h"
12
14
15#include <algorithm>
16
17namespace pandora
18{
19
22{
23 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->CreateInitialLists());
24}
25
26//------------------------------------------------------------------------------------------------------------------------------------------
27
32
33//------------------------------------------------------------------------------------------------------------------------------------------
34
37{
38 pCluster = nullptr;
39
40 try
41 {
43 throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
44
45 NameToListMap::iterator iter = m_nameToListMap.find(m_currentListName);
46
47 if (m_nameToListMap.end() == iter)
48 throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
49
50 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, factory.Create(parameters, pCluster));
51
52 if (!pCluster)
53 throw StatusCodeException(STATUS_CODE_FAILURE);
54
55 iter->second->push_back(pCluster);
56 return STATUS_CODE_SUCCESS;
57 }
58 catch (StatusCodeException &statusCodeException)
59 {
60 std::cout << "Failed to create cluster: " << statusCodeException.ToString() << std::endl;
61 delete pCluster;
62 pCluster = nullptr;
63 return statusCodeException.GetStatusCode();
64 }
65}
66
67//------------------------------------------------------------------------------------------------------------------------------------------
68
70{
71 return this->Modifiable(pCluster)->AlterMetadata(metadata);
72}
73
74//------------------------------------------------------------------------------------------------------------------------------------------
75
76template <>
77bool ClusterManager::IsAvailable(const Cluster *const pCluster) const
78{
79 return pCluster->IsAvailable();
80}
81
82template <>
83bool ClusterManager::IsAvailable(const ClusterList *const pClusterList) const
84{
85 bool isAvailable(true);
86
87 for (const Cluster *const pCluster : *pClusterList)
88 isAvailable &= this->IsAvailable(pCluster);
89
90 return isAvailable;
91}
92
93//------------------------------------------------------------------------------------------------------------------------------------------
94
95template <>
96void ClusterManager::SetAvailability(const Cluster *const pCluster, bool isAvailable) const
97{
98 this->Modifiable(pCluster)->SetAvailability(isAvailable);
99}
100
101template <>
102void ClusterManager::SetAvailability(const ClusterList *const pClusterList, bool isAvailable) const
103{
104 for (const Cluster *const pCluster : *pClusterList)
105 this->SetAvailability(pCluster, isAvailable);
106}
107
108//------------------------------------------------------------------------------------------------------------------------------------------
109
110StatusCode ClusterManager::AddToCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
111{
112 return this->Modifiable(pCluster)->AddCaloHit(pCaloHit);
113}
114
115//------------------------------------------------------------------------------------------------------------------------------------------
116
117StatusCode ClusterManager::RemoveFromCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
118{
119 return this->Modifiable(pCluster)->RemoveCaloHit(pCaloHit);
120}
121
122//------------------------------------------------------------------------------------------------------------------------------------------
123
124StatusCode ClusterManager::AddIsolatedToCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
125{
126 return this->Modifiable(pCluster)->AddIsolatedCaloHit(pCaloHit);
127}
128
129//------------------------------------------------------------------------------------------------------------------------------------------
130
131StatusCode ClusterManager::RemoveIsolatedFromCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
132{
133 return this->Modifiable(pCluster)->RemoveIsolatedCaloHit(pCaloHit);
134}
135
136//------------------------------------------------------------------------------------------------------------------------------------------
137
138StatusCode ClusterManager::MergeAndDeleteClusters(const Cluster *const pClusterToEnlarge, const Cluster *const pClusterToDelete, const std::string &enlargeListName,
139 const std::string &deleteListName)
140{
141 if (pClusterToEnlarge == pClusterToDelete)
142 return STATUS_CODE_INVALID_PARAMETER;
143
144 NameToListMap::iterator enlargeListIter = m_nameToListMap.find(enlargeListName);
145 NameToListMap::iterator deleteListIter = m_nameToListMap.find(deleteListName);
146
147 if ((m_nameToListMap.end() == enlargeListIter) || (m_nameToListMap.end() == deleteListIter))
148 return STATUS_CODE_NOT_INITIALIZED;
149
150 ClusterList::iterator clusterToEnlargeIter = std::find(enlargeListIter->second->begin(), enlargeListIter->second->end(), pClusterToEnlarge);
151 ClusterList::iterator clusterToDeleteIter = std::find(deleteListIter->second->begin(), deleteListIter->second->end(), pClusterToDelete);
152
153 if ((enlargeListIter->second->end() == clusterToEnlargeIter) || (deleteListIter->second->end() == clusterToDeleteIter))
154 return STATUS_CODE_NOT_FOUND;
155
156 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->Modifiable(pClusterToEnlarge)->AddHitsFromSecondCluster(pClusterToDelete));
157
158 clusterToDeleteIter = deleteListIter->second->erase(clusterToDeleteIter);
159 delete pClusterToDelete;
160
161 return STATUS_CODE_SUCCESS;
162}
163
164//------------------------------------------------------------------------------------------------------------------------------------------
165
166StatusCode ClusterManager::AddTrackAssociation(const Cluster *const pCluster, const Track *const pTrack) const
167{
168 return this->Modifiable(pCluster)->AddTrackAssociation(pTrack);
169}
170
171//------------------------------------------------------------------------------------------------------------------------------------------
172
173StatusCode ClusterManager::RemoveTrackAssociation(const Cluster *const pCluster, const Track *const pTrack) const
174{
175 return this->Modifiable(pCluster)->RemoveTrackAssociation(pTrack);
176}
177
178//------------------------------------------------------------------------------------------------------------------------------------------
179
181{
182 for (const NameToListMap::value_type &mapEntry : m_nameToListMap)
183 {
184 for (const Cluster *const pCluster : *mapEntry.second)
185 {
186 const TrackList trackList(pCluster->GetAssociatedTrackList());
187
188 for (const Track *const pTrack : trackList)
189 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->RemoveTrackAssociation(pCluster, pTrack));
190 }
191 }
192
193 return STATUS_CODE_SUCCESS;
194}
195
196//------------------------------------------------------------------------------------------------------------------------------------------
197
199{
200 NameToListMap::const_iterator iter = m_nameToListMap.find(m_currentListName);
201
202 if (m_nameToListMap.end() == iter)
203 return STATUS_CODE_NOT_INITIALIZED;
204
205 for (const Cluster *const pCluster : *iter->second)
206 {
207 const TrackList trackList(pCluster->GetAssociatedTrackList());
208
209 danglingTracks.insert(danglingTracks.end(), trackList.begin(), trackList.end());
210
211 for (const Track *const pTrack : trackList)
212 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->RemoveTrackAssociation(pCluster, pTrack));
213 }
214
215 return STATUS_CODE_SUCCESS;
216}
217
218//------------------------------------------------------------------------------------------------------------------------------------------
219
221{
222 for (TrackToClusterMap::const_iterator iter = trackToClusterList.begin(), iterEnd = trackToClusterList.end(); iter != iterEnd; ++iter)
223 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->RemoveTrackAssociation(iter->second, iter->first));
224
225 return STATUS_CODE_SUCCESS;
226}
227
228} // namespace pandora
Header file for the cluster class.
Header file for the cluster manager class.
Header file for the object factory class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
AlgorithmObjectManager class.
bool m_canMakeNewObjects
Whether the manager is allowed to make new objects when requested by algorithms.
virtual StatusCode EraseAllContent()
Erase all manager content.
CaloHit class.
Definition CaloHit.h:26
Cluster class.
Definition Cluster.h:31
bool IsAvailable() const
Whether the cluster is available to be added to a particle flow object.
Definition Cluster.h:582
StatusCode AddTrackAssociation(const Track *const pTrack)
Add an association between the cluster and a track.
Definition Cluster.cc:666
bool IsAvailable(const T *const pT) const
Is a cluster, or a list of clusters, available to add to a particle flow object.
StatusCode RemoveFromCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
Remove a calo hit from a cluster.
StatusCode RemoveIsolatedFromCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
Remove an isolated calo hit from a cluster.
StatusCode RemoveTrackAssociation(const Cluster *const pCluster, const Track *const pTrack) const
Remove an association between a cluster and a track.
void SetAvailability(const T *const pT, bool isAvailable) const
Set availability of a cluster, or a list of clusters, to be added to a particle flow object.
StatusCode AddToCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
Add a calo hit to a cluster.
StatusCode RemoveCurrentTrackAssociations(TrackList &danglingTracks) const
Remove cluster to track associations from all clusters in the current list.
StatusCode RemoveAllTrackAssociations() const
Remove all cluster to track associations.
StatusCode MergeAndDeleteClusters(const Cluster *const pClusterToEnlarge, const Cluster *const pClusterToDelete, const std::string &enlargeListName, const std::string &deleteListName)
Merge two clusters from two specified lists, enlarging one cluster and deleting the second.
StatusCode RemoveTrackAssociations(const TrackToClusterMap &trackToClusterList) const
Remove a specified list of cluster to track associations.
StatusCode AddIsolatedToCluster(const Cluster *const pCluster, const CaloHit *const pCaloHit)
Add an isolated calo hit to a cluster. This is not counted as a regular calo hit: it contributes only...
ClusterManager(const Pandora *const pPandora)
Constructor.
StatusCode AddTrackAssociation(const Cluster *const pCluster, const Track *const pTrack) const
Add an association between a cluster and a track.
StatusCode Create(const object_creation::Cluster::Parameters &parameters, const Cluster *&pCluster, const ObjectFactory< object_creation::Cluster::Parameters, object_creation::Cluster::Object > &factory)
Create cluster.
StatusCode AlterMetadata(const Cluster *const pCluster, const object_creation::Cluster::Metadata &metadata) const
Alter the metadata information stored in a cluster.
std::string m_currentListName
The name of the current list.
Definition Manager.h:181
virtual T * Modifiable(const T *const pT) const
Access a modifiable object, when provided with address to const object.
Definition Manager.cc:288
NameToListMap m_nameToListMap
The name to list map.
Definition Manager.h:178
virtual StatusCode CreateInitialLists()
Create initial lists.
Definition Manager.cc:274
ObjectFactory class responsible for extended pandora object creation.
virtual StatusCode Create(const Parameters &parameters, const Object *&pObject) const =0
Create an object with the given parameters.
Pandora class.
Definition Pandora.h:40
StatusCodeException class.
std::string ToString() const
Get status code as a string.
StatusCode GetStatusCode() const
Get status code.
Track class.
Definition Track.h:26
MANAGED_CONTAINER< const Cluster * > ClusterList
MANAGED_CONTAINER< const Track * > TrackList
std::unordered_map< const Track *, const Cluster * > TrackToClusterMap
StatusCode
The StatusCode enum.