9 #include "Pandora/AlgorithmHeaders.h" 21 TwoDSlidingFitConsolidationAlgorithm::TwoDSlidingFitConsolidationAlgorithm() :
22 m_minTrackLength(7.5
f),
23 m_maxClusterLength(15.
f),
24 m_halfWindowLayers(25)
32 const ClusterList *pClusterList = NULL;
33 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pClusterList));
45 this->
GetReclusteredHits(slidingFitResultList, showerClusters, clustersToExpand, clustersToContract);
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));
53 return STATUS_CODE_SUCCESS;
63 const Cluster *
const pCluster = *iter;
68 showerClusters.push_back(pCluster);
71 trackClusters.push_back(pCluster);
89 slidingFitResultList.push_back(slidingFitResult);
91 catch (StatusCodeException &statusCodeException)
93 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
94 throw statusCodeException;
103 ClusterList clusterList;
104 for (
const auto &mapEntry : clustersToContract)
105 clusterList.push_back(mapEntry.first);
108 for (
const Cluster *
const pCluster : clusterList)
110 const CaloHitList &caloHitListToRemove(clustersToContract.at(pCluster));
112 if (caloHitListToRemove.empty())
115 if (unavailableClusters.count(pCluster))
118 CaloHitList caloHitList, caloHitListToKeep;
119 pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
121 for (
const CaloHit *
const pCaloHit : caloHitList)
123 if (caloHitListToRemove.end() == std::find(caloHitListToRemove.begin(), caloHitListToRemove.end(), pCaloHit))
124 caloHitListToKeep.push_back(pCaloHit);
127 if (caloHitListToKeep.empty())
130 unavailableClusters.insert(pCluster);
131 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Cluster>(*
this, pCluster));
135 for (
const CaloHit *
const pCaloHit : caloHitListToRemove)
137 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RemoveFromCluster(*
this, pCluster, pCaloHit));
141 return STATUS_CODE_SUCCESS;
148 ClusterList clusterList;
150 for (
const auto &mapEntry : clustersToExpand)
152 if (!unavailableClusters.count(mapEntry.first))
153 clusterList.push_back(mapEntry.first);
158 for (
const Cluster *
const pCluster : clusterList)
160 const CaloHitList &caloHitList(clustersToExpand.at(pCluster));
162 if (caloHitList.empty())
165 if (unavailableClusters.count(pCluster))
168 unavailableClusters.insert(pCluster);
170 for (
const CaloHit *
const pCaloHit : caloHitList)
172 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToCluster(*
this, pCluster, pCaloHit));
176 return STATUS_CODE_SUCCESS;
183 if (clustersToRebuild.empty())
184 return STATUS_CODE_SUCCESS;
187 for (
const auto &mapEntry : clustersToRebuild)
189 if (!unavailableClusters.count(mapEntry.first))
190 sortedClusters.push_back(mapEntry.first);
195 for (
const Cluster *
const pCluster : sortedClusters)
197 const CaloHitList &caloHitList(clustersToRebuild.at(pCluster));
198 const Cluster *
const pClusterToDelete(pCluster);
200 if (caloHitList.empty())
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));
207 const ClusterList *pClusterList = NULL;
209 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=,
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));
216 return STATUS_CODE_SUCCESS;
223 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithm(*
this, xmlHandle,
"ClusterRebuilding",
m_reclusteringAlgorithmName));
225 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MinTrackLength",
m_minTrackLength));
227 PANDORA_RETURN_RESULT_IF_AND_IF(
228 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MaxClusterLength",
m_maxClusterLength));
230 PANDORA_RETURN_RESULT_IF_AND_IF(
231 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"SlidingFitHalfWindow",
m_halfWindowLayers));
233 return STATUS_CODE_SUCCESS;
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.
unsigned int m_halfWindowLayers
Size of layer window for sliding fit results.
std::unordered_map< const pandora::Cluster *, pandora::CaloHitList > ClusterToHitMap
float m_maxClusterLength
Maximum length of shower clusters to use in re-building.
float m_minTrackLength
Minimum length of track clusters to consolidate.
Header file for the 2D sliding fit consolidation algorithm class.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
Header file for the geometry helper class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void BuildSlidingLinearFits(const pandora::ClusterVector &trackClusters, TwoDSlidingFitResultList &slidingFitResultList) const
Apply sliding linear fits to track clusters.
Header file for the cluster helper class.
std::vector< TwoDSlidingFitResult > TwoDSlidingFitResultList
std::string m_reclusteringAlgorithmName
Name of daughter algorithm to use for cluster re-building.
pandora::StatusCode Run()
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.
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.
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.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
pandora::StatusCode AddHitsToClusters(const ClusterToHitMap &clustersToRebuild, pandora::ClusterSet &unavailableClusters) const
Add hits to clusters.
TwoDSlidingFitResult class.
pandora::StatusCode RemoveHitsFromClusters(const ClusterToHitMap &clustersToRebuild, pandora::ClusterSet &unavailableClusters) const
Remove hits from clusters.
pandora::StatusCode RebuildClusters(const ClusterToHitMap &clustersAtStart, const pandora::ClusterSet &unavailableClusters) const
Re-build clusters.