Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
TwoDSlidingFitConsolidationAlgorithm.cc
Go to the documentation of this file.
1
10
13
15
16using namespace pandora;
17
18namespace lar_content
19{
20
22 m_minTrackLength(7.5f),
23 m_maxClusterLength(15.f),
24 m_halfWindowLayers(25)
25{
26}
27
28//------------------------------------------------------------------------------------------------------------------------------------------
29
31{
32 const ClusterList *pClusterList = NULL;
33 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pClusterList));
34
35 // Select tracks and showers for re-clustering (Note: samples not mutually exclusive)
36 ClusterVector trackClusters, showerClusters;
37 this->SortInputClusters(pClusterList, trackClusters, showerClusters);
38
39 // Build sliding linear fits from track clusters
40 TwoDSlidingFitResultList slidingFitResultList;
41 this->BuildSlidingLinearFits(trackClusters, slidingFitResultList);
42
43 // Recluster the hits
44 ClusterToHitMap clustersToExpand, clustersToContract;
45 this->GetReclusteredHits(slidingFitResultList, showerClusters, clustersToExpand, clustersToContract);
46
47 // Consolidate and re-build clusters
48 ClusterSet unavailableClusters;
49 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->RemoveHitsFromClusters(clustersToContract, unavailableClusters));
50 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->AddHitsToClusters(clustersToExpand, unavailableClusters));
51 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->RebuildClusters(clustersToContract, unavailableClusters));
52
53 return STATUS_CODE_SUCCESS;
54}
55
56//------------------------------------------------------------------------------------------------------------------------------------------
57
59 const ClusterList *const pClusterList, ClusterVector &trackClusters, ClusterVector &showerClusters) const
60{
61 for (ClusterList::const_iterator iter = pClusterList->begin(), iterEnd = pClusterList->end(); iter != iterEnd; ++iter)
62 {
63 const Cluster *const pCluster = *iter;
64
65 const float thisLengthSquared(LArClusterHelper::GetLengthSquared(pCluster));
66
67 if (thisLengthSquared < m_maxClusterLength * m_maxClusterLength)
68 showerClusters.push_back(pCluster);
69
70 if (thisLengthSquared > m_minTrackLength * m_minTrackLength)
71 trackClusters.push_back(pCluster);
72 }
73
74 std::sort(trackClusters.begin(), trackClusters.end(), LArClusterHelper::SortByNHits);
75 std::sort(showerClusters.begin(), showerClusters.end(), LArClusterHelper::SortByNHits);
76}
77
78//------------------------------------------------------------------------------------------------------------------------------------------
79
81{
82 const float slidingFitPitch(LArGeometryHelper::GetWireZPitch(this->GetPandora()));
83
84 for (ClusterVector::const_iterator iter = trackClusters.begin(), iterEnd = trackClusters.end(); iter != iterEnd; ++iter)
85 {
86 try
87 {
88 const TwoDSlidingFitResult slidingFitResult(*iter, m_halfWindowLayers, slidingFitPitch);
89 slidingFitResultList.push_back(slidingFitResult);
90 }
91 catch (StatusCodeException &statusCodeException)
92 {
93 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
94 throw statusCodeException;
95 }
96 }
97}
98
99//------------------------------------------------------------------------------------------------------------------------------------------
100
102{
103 ClusterList clusterList;
104 for (const auto &mapEntry : clustersToContract)
105 clusterList.push_back(mapEntry.first);
106 clusterList.sort(LArClusterHelper::SortByNHits);
107
108 for (const Cluster *const pCluster : clusterList)
109 {
110 const CaloHitList &caloHitListToRemove(clustersToContract.at(pCluster));
111
112 if (caloHitListToRemove.empty())
113 continue;
114
115 if (unavailableClusters.count(pCluster))
116 continue;
117
118 CaloHitList caloHitList, caloHitListToKeep;
119 pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
120
121 for (const CaloHit *const pCaloHit : caloHitList)
122 {
123 if (caloHitListToRemove.end() == std::find(caloHitListToRemove.begin(), caloHitListToRemove.end(), pCaloHit))
124 caloHitListToKeep.push_back(pCaloHit);
125 }
126
127 if (caloHitListToKeep.empty())
128 {
129 // ATTN clustersToContract and unavailable clusters now contain dangling pointers
130 unavailableClusters.insert(pCluster);
131 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Cluster>(*this, pCluster));
132 continue;
133 }
134
135 for (const CaloHit *const pCaloHit : caloHitListToRemove)
136 {
137 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RemoveFromCluster(*this, pCluster, pCaloHit));
138 }
139 }
140
141 return STATUS_CODE_SUCCESS;
142}
143
144//------------------------------------------------------------------------------------------------------------------------------------------
145
147{
148 ClusterList clusterList;
149
150 for (const auto &mapEntry : clustersToExpand)
151 {
152 if (!unavailableClusters.count(mapEntry.first))
153 clusterList.push_back(mapEntry.first);
154 }
155
156 clusterList.sort(LArClusterHelper::SortByNHits);
157
158 for (const Cluster *const pCluster : clusterList)
159 {
160 const CaloHitList &caloHitList(clustersToExpand.at(pCluster));
161
162 if (caloHitList.empty())
163 continue;
164
165 if (unavailableClusters.count(pCluster))
166 continue;
167
168 unavailableClusters.insert(pCluster);
169
170 for (const CaloHit *const pCaloHit : caloHitList)
171 {
172 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToCluster(*this, pCluster, pCaloHit));
173 }
174 }
175
176 return STATUS_CODE_SUCCESS;
177}
178
179//------------------------------------------------------------------------------------------------------------------------------------------
180
181StatusCode TwoDSlidingFitConsolidationAlgorithm::RebuildClusters(const ClusterToHitMap &clustersToRebuild, const ClusterSet &unavailableClusters) const
182{
183 if (clustersToRebuild.empty())
184 return STATUS_CODE_SUCCESS;
185
186 ClusterVector sortedClusters;
187 for (const auto &mapEntry : clustersToRebuild)
188 {
189 if (!unavailableClusters.count(mapEntry.first))
190 sortedClusters.push_back(mapEntry.first);
191 }
192
193 std::sort(sortedClusters.begin(), sortedClusters.end(), LArClusterHelper::SortByNHits);
194
195 for (const Cluster *const pCluster : sortedClusters)
196 {
197 const CaloHitList &caloHitList(clustersToRebuild.at(pCluster));
198 const Cluster *const pClusterToDelete(pCluster);
199
200 if (caloHitList.empty())
201 continue;
202
203 std::string currentClusterListName;
204 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentListName<Cluster>(*this, currentClusterListName));
205 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Cluster>(*this, pClusterToDelete));
206
207 const ClusterList *pClusterList = NULL;
208 std::string newClusterListName;
209 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=,
210 PandoraContentApi::RunClusteringAlgorithm(*this, m_reclusteringAlgorithmName, pClusterList, newClusterListName));
211
212 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Cluster>(*this, newClusterListName, currentClusterListName));
213 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Cluster>(*this, currentClusterListName));
214 }
215
216 return STATUS_CODE_SUCCESS;
217}
218
219//------------------------------------------------------------------------------------------------------------------------------------------
220
222{
223 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithm(*this, xmlHandle, "ClusterRebuilding", m_reclusteringAlgorithmName));
224
225 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinTrackLength", m_minTrackLength));
226
228 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxClusterLength", m_maxClusterLength));
229
231 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingFitHalfWindow", m_halfWindowLayers));
232
233 return STATUS_CODE_SUCCESS;
234}
235
236} // 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 geometry helper class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the 2D sliding fit consolidation algorithm class.
static pandora::StatusCode ReplaceCurrentList(const pandora::Algorithm &algorithm, const std::string &newListName)
Replace the current list with a pre-saved list; use this new list as a permanent replacement for the ...
static pandora::StatusCode RunClusteringAlgorithm(const pandora::Algorithm &algorithm, const std::string &clusteringAlgorithmName, const pandora::ClusterList *&pNewClusterList, std::string &newClusterListName)
Run a clustering algorithm (an algorithm that will create new cluster objects)
static pandora::StatusCode GetCurrentList(const pandora::Algorithm &algorithm, const T *&pT)
Get the current list.
static pandora::StatusCode AddToCluster(const pandora::Algorithm &algorithm, const pandora::Cluster *const pCluster, const T *const pT)
Add a calo hit, or a list of calo hits, to a cluster.
static pandora::StatusCode RemoveFromCluster(const pandora::Algorithm &algorithm, const pandora::Cluster *const pCluster, const pandora::CaloHit *const pCaloHit)
Remove a calo hit from a cluster. Note this function will not remove the final calo hit from a cluste...
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,...
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
pandora::StatusCode RemoveHitsFromClusters(const ClusterToHitMap &clustersToRebuild, pandora::ClusterSet &unavailableClusters) const
Remove hits from clusters.
float m_maxClusterLength
Maximum length of shower clusters to use in re-building.
std::string m_reclusteringAlgorithmName
Name of daughter algorithm to use for cluster re-building.
unsigned int m_halfWindowLayers
Size of layer window for sliding fit results.
pandora::StatusCode AddHitsToClusters(const ClusterToHitMap &clustersToRebuild, pandora::ClusterSet &unavailableClusters) const
Add hits to clusters.
void SortInputClusters(const pandora::ClusterList *const pClusterList, pandora::ClusterVector &trackClusters, pandora::ClusterVector &showerClusters) const
Sort input cluster list into track-like clusters and shower-like clusters.
virtual void GetReclusteredHits(const TwoDSlidingFitResultList &slidingFitResultList, const pandora::ClusterVector &showerClusters, ClusterToHitMap &caloHitsToAdd, ClusterToHitMap &caloHitsToRemove) const =0
Get the list of hits to be added or removed from clusters.
float m_minTrackLength
Minimum length of track clusters to consolidate.
std::unordered_map< const pandora::Cluster *, pandora::CaloHitList > ClusterToHitMap
void BuildSlidingLinearFits(const pandora::ClusterVector &trackClusters, TwoDSlidingFitResultList &slidingFitResultList) const
Apply sliding linear fits to track clusters.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
pandora::StatusCode RebuildClusters(const ClusterToHitMap &clustersAtStart, const pandora::ClusterSet &unavailableClusters) const
Re-build clusters.
CaloHit class.
Definition CaloHit.h:26
Cluster class.
Definition Cluster.h:31
const Pandora & GetPandora() const
Get the associated pandora instance.
Definition Process.h:116
StatusCodeException class.
StatusCode GetStatusCode() const
Get status code.
static StatusCode ProcessAlgorithm(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &description, std::string &algorithmName)
Process an algorithm described in an xml element with a matching "description = .....
Definition XmlHelper.cc:16
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
std::vector< TwoDSlidingFitResult > TwoDSlidingFitResultList
std::vector< const Cluster * > ClusterVector
MANAGED_CONTAINER< const Cluster * > ClusterList
std::unordered_set< const Cluster * > ClusterSet
MANAGED_CONTAINER< const CaloHit * > CaloHitList
StatusCode
The StatusCode enum.