Process a tensor element, reclustering the fragments as required.
207 pFragmentCluster =
nullptr;
209 const HitType fragmentHitType(overlapResult.GetFragmentHitType());
210 const std::string ¤tListName(pAlgorithm->GetClusterListName(fragmentHitType));
212 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Cluster>(*pAlgorithm, currentListName));
214 ClusterList fragmentClusterList(overlapResult.GetFragmentClusterList());
216 const CaloHitSet caloHitSet(overlapResult.GetFragmentCaloHitList().begin(), overlapResult.GetFragmentCaloHitList().end());
219 ClusterList affectedKeyClusters;
222 for (
const Cluster *
const pCluster : affectedKeyClusters)
223 pAlgorithm->UpdateUponDeletion(pCluster);
225 for (
const Cluster *
const pCluster : fragmentClusterList)
226 pAlgorithm->UpdateUponDeletion(pCluster);
228 ClusterList clustersToRebuild;
229 ClusterSet badClusters, deletedClusters;
231 for (
const Cluster *
const pCluster : fragmentClusterList)
233 if (deletedClusters.count(pCluster))
236 if (!pCluster->IsAvailable())
237 throw StatusCodeException(STATUS_CODE_FAILURE);
239 CaloHitList clusterHitList;
240 pCluster->GetOrderedCaloHitList().FillCaloHitList(clusterHitList);
242 CaloHitList daughterHits, separateHits;
243 for (
const CaloHit *
const pCaloHit : clusterHitList)
245 if (caloHitSet.count(pCaloHit))
247 daughterHits.push_back(pCaloHit);
251 separateHits.push_back(pCaloHit);
255 if (daughterHits.empty())
256 throw StatusCodeException(STATUS_CODE_FAILURE);
258 this->
Recluster(pAlgorithm, pCluster, daughterHits, separateHits, deletedClusters, badClusters, pFragmentCluster);
261 if (badClusters.count(pFragmentCluster) || deletedClusters.count(pFragmentCluster))
262 throw StatusCodeException(STATUS_CODE_FAILURE);
267 ClusterList::iterator rebuildIter(std::find(clustersToRebuild.begin(), clustersToRebuild.end(), pCluster));
268 if (deletedClusters.count(pCluster))
270 if (clustersToRebuild.end() != rebuildIter)
271 clustersToRebuild.erase(rebuildIter);
273 else if ((clustersToRebuild.end() == rebuildIter) && (pCluster != pFragmentCluster))
275 clustersToRebuild.push_back(pCluster);
279 if (!pFragmentCluster)
280 throw StatusCodeException(STATUS_CODE_FAILURE);
283 ClusterList clustersToAddToTensor;
284 this->
RebuildClusters(pAlgorithm, clustersToRebuild, clustersToAddToTensor);
287 ClusterList newKeyClusters;
288 pAlgorithm->SelectInputClusters(&clustersToAddToTensor, newKeyClusters);
290 for (
const Cluster *
const pCluster : newKeyClusters)
291 pAlgorithm->UpdateForNewCluster(pCluster);
293 for (
const Cluster *
const pCluster : affectedKeyClusters)
294 pAlgorithm->UpdateForNewCluster(pCluster);
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.
void RebuildClusters(ThreeViewTrackFragmentsAlgorithm *const pAlgorithm, const pandora::ClusterList &modifiedClusters, pandora::ClusterList &newClusters) const
Rebuild clusters after fragmentation.
void Recluster(ThreeViewTrackFragmentsAlgorithm *const pAlgorithm, const pandora::Cluster *const pCluster, const pandora::CaloHitList &daughterHits, const pandora::CaloHitList &separateHits, pandora::ClusterSet &deletedClusters, pandora::ClusterSet &badClusters, const pandora::Cluster *&pFragmentCluster) const
Rearrange the hits in a cluster from the fragment list, using the Pandora fragmentation mechanism...
void GetAffectedKeyClusters(const TensorType &overlapTensor, const pandora::ClusterList &clustersToRemoveFromTensor, pandora::ClusterList &affectedKeyClusters) const
Get a list of the tensor key clusters for which tensor elements have been impacted by fragmentation o...