LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::TwoDSlidingFitConsolidationAlgorithm Class Referenceabstract

TwoDSlidingFitConsolidationAlgorithm class. More...

#include "TwoDSlidingFitConsolidationAlgorithm.h"

Inheritance diagram for lar_content::TwoDSlidingFitConsolidationAlgorithm:
lar_content::TrackConsolidationAlgorithm

Public Member Functions

 TwoDSlidingFitConsolidationAlgorithm ()
 Default constructor. More...
 

Protected Types

typedef std::unordered_map< const pandora::Cluster *, pandora::CaloHitList > ClusterToHitMap
 

Protected Member Functions

pandora::StatusCode Run ()
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
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. More...
 

Private Member Functions

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. More...
 
void BuildSlidingLinearFits (const pandora::ClusterVector &trackClusters, TwoDSlidingFitResultList &slidingFitResultList) const
 Apply sliding linear fits to track clusters. More...
 
pandora::StatusCode RemoveHitsFromClusters (const ClusterToHitMap &clustersToRebuild, pandora::ClusterSet &unavailableClusters) const
 Remove hits from clusters. More...
 
pandora::StatusCode AddHitsToClusters (const ClusterToHitMap &clustersToRebuild, pandora::ClusterSet &unavailableClusters) const
 Add hits to clusters. More...
 
pandora::StatusCode RebuildClusters (const ClusterToHitMap &clustersAtStart, const pandora::ClusterSet &unavailableClusters) const
 Re-build clusters. More...
 

Private Attributes

std::string m_reclusteringAlgorithmName
 Name of daughter algorithm to use for cluster re-building. More...
 
float m_minTrackLength
 Minimum length of track clusters to consolidate. More...
 
float m_maxClusterLength
 Maximum length of shower clusters to use in re-building. More...
 
unsigned int m_halfWindowLayers
 Size of layer window for sliding fit results. More...
 

Detailed Description

Member Typedef Documentation

typedef std::unordered_map<const pandora::Cluster *, pandora::CaloHitList> lar_content::TwoDSlidingFitConsolidationAlgorithm::ClusterToHitMap
protected

Definition at line 35 of file TwoDSlidingFitConsolidationAlgorithm.h.

Constructor & Destructor Documentation

lar_content::TwoDSlidingFitConsolidationAlgorithm::TwoDSlidingFitConsolidationAlgorithm ( )

Default constructor.

Definition at line 21 of file TwoDSlidingFitConsolidationAlgorithm.cc.

21  :
22  m_minTrackLength(7.5f),
25 {
26 }
unsigned int m_halfWindowLayers
Size of layer window for sliding fit results.
float m_maxClusterLength
Maximum length of shower clusters to use in re-building.
float m_minTrackLength
Minimum length of track clusters to consolidate.
TFile f
Definition: plotHisto.C:6

Member Function Documentation

StatusCode lar_content::TwoDSlidingFitConsolidationAlgorithm::AddHitsToClusters ( const ClusterToHitMap clustersToRebuild,
pandora::ClusterSet &  unavailableClusters 
) const
private

Add hits to clusters.

Parameters
clustersToRebuildthe list of hits to be added to clusters
unavailableClustersthe list of modified clusters

Definition at line 145 of file TwoDSlidingFitConsolidationAlgorithm.cc.

References lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

146 {
147  ClusterList clusterList;
148 
149  for (const auto &mapEntry : clustersToExpand)
150  {
151  if (!unavailableClusters.count(mapEntry.first))
152  clusterList.push_back(mapEntry.first);
153  }
154 
155  clusterList.sort(LArClusterHelper::SortByNHits);
156 
157  for (const Cluster *const pCluster : clusterList)
158  {
159  const CaloHitList &caloHitList(clustersToExpand.at(pCluster));
160 
161  if (caloHitList.empty())
162  continue;
163 
164  if (unavailableClusters.count(pCluster))
165  continue;
166 
167  unavailableClusters.insert(pCluster);
168 
169  for (const CaloHit *const pCaloHit : caloHitList)
170  {
171  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToCluster(*this, pCluster, pCaloHit));
172  }
173  }
174 
175  return STATUS_CODE_SUCCESS;
176 }
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 lar_content::TwoDSlidingFitConsolidationAlgorithm::BuildSlidingLinearFits ( const pandora::ClusterVector &  trackClusters,
TwoDSlidingFitResultList slidingFitResultList 
) const
private

Apply sliding linear fits to track clusters.

Parameters
trackClustersthe input vector of track-like clusters
slidingFitResultListthe output list of sliding linear fits

Definition at line 80 of file TwoDSlidingFitConsolidationAlgorithm.cc.

References lar_content::LArClusterHelper::GetClusterHitType(), lar_content::LArGeometryHelper::GetWirePitch(), and m_halfWindowLayers.

Referenced by Run().

81 {
82  for (ClusterVector::const_iterator iter = trackClusters.begin(), iterEnd = trackClusters.end(); iter != iterEnd; ++iter)
83  {
84  try
85  {
86  const float slidingFitPitch(LArGeometryHelper::GetWirePitch(this->GetPandora(), LArClusterHelper::GetClusterHitType(*iter)));
87  const TwoDSlidingFitResult slidingFitResult(*iter, m_halfWindowLayers, slidingFitPitch);
88  slidingFitResultList.push_back(slidingFitResult);
89  }
90  catch (StatusCodeException &statusCodeException)
91  {
92  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
93  throw statusCodeException;
94  }
95  }
96 }
unsigned int m_halfWindowLayers
Size of layer window for sliding fit results.
intermediate_table::const_iterator const_iterator
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static float GetWirePitch(const pandora::Pandora &pandora, const pandora::HitType view, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
virtual void lar_content::TwoDSlidingFitConsolidationAlgorithm::GetReclusteredHits ( const TwoDSlidingFitResultList slidingFitResultList,
const pandora::ClusterVector &  showerClusters,
ClusterToHitMap caloHitsToAdd,
ClusterToHitMap caloHitsToRemove 
) const
protectedpure virtual

Get the list of hits to be added or removed from clusters.

Parameters
slidingFitResultListthe list of sliding linear fits to track clusters
showerClustersthe vector of shower clusters
caloHitsToAddthe output map of hits to be added to clusters
caloHitsToRemovethe output map of hits to be removed from clusters

Implemented in lar_content::TrackConsolidationAlgorithm.

Referenced by Run().

StatusCode lar_content::TwoDSlidingFitConsolidationAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
protected

Definition at line 220 of file TwoDSlidingFitConsolidationAlgorithm.cc.

References m_halfWindowLayers, m_maxClusterLength, m_minTrackLength, and m_reclusteringAlgorithmName.

Referenced by lar_content::TrackConsolidationAlgorithm::ReadSettings().

221 {
222  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithm(*this, xmlHandle, "ClusterRebuilding", m_reclusteringAlgorithmName));
223 
224  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinTrackLength", m_minTrackLength));
225 
226  PANDORA_RETURN_RESULT_IF_AND_IF(
227  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxClusterLength", m_maxClusterLength));
228 
229  PANDORA_RETURN_RESULT_IF_AND_IF(
230  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingFitHalfWindow", m_halfWindowLayers));
231 
232  return STATUS_CODE_SUCCESS;
233 }
unsigned int m_halfWindowLayers
Size of layer window for sliding fit results.
float m_maxClusterLength
Maximum length of shower clusters to use in re-building.
float m_minTrackLength
Minimum length of track clusters to consolidate.
std::string m_reclusteringAlgorithmName
Name of daughter algorithm to use for cluster re-building.
StatusCode lar_content::TwoDSlidingFitConsolidationAlgorithm::RebuildClusters ( const ClusterToHitMap clustersAtStart,
const pandora::ClusterSet &  unavailableClusters 
) const
private

Re-build clusters.

Parameters
clustersAtStartthe initial mapping of clusters to hits
unavailableClustersthe list of unavailable clusters

Definition at line 180 of file TwoDSlidingFitConsolidationAlgorithm.cc.

References m_reclusteringAlgorithmName, and lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

181 {
182  if (clustersToRebuild.empty())
183  return STATUS_CODE_SUCCESS;
184 
185  ClusterVector sortedClusters;
186  for (const auto &mapEntry : clustersToRebuild)
187  {
188  if (!unavailableClusters.count(mapEntry.first))
189  sortedClusters.push_back(mapEntry.first);
190  }
191 
192  std::sort(sortedClusters.begin(), sortedClusters.end(), LArClusterHelper::SortByNHits);
193 
194  for (const Cluster *const pCluster : sortedClusters)
195  {
196  const CaloHitList &caloHitList(clustersToRebuild.at(pCluster));
197  const Cluster *const pClusterToDelete(pCluster);
198 
199  if (caloHitList.empty())
200  continue;
201 
202  std::string currentClusterListName;
203  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentListName<Cluster>(*this, currentClusterListName));
204  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Cluster>(*this, pClusterToDelete));
205 
206  const ClusterList *pClusterList = NULL;
207  std::string newClusterListName;
208  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=,
209  PandoraContentApi::RunClusteringAlgorithm(*this, m_reclusteringAlgorithmName, pClusterList, newClusterListName));
210 
211  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Cluster>(*this, newClusterListName, currentClusterListName));
212  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Cluster>(*this, currentClusterListName));
213  }
214 
215  return STATUS_CODE_SUCCESS;
216 }
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.
std::string m_reclusteringAlgorithmName
Name of daughter algorithm to use for cluster re-building.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
StatusCode lar_content::TwoDSlidingFitConsolidationAlgorithm::RemoveHitsFromClusters ( const ClusterToHitMap clustersToRebuild,
pandora::ClusterSet &  unavailableClusters 
) const
private

Remove hits from clusters.

Parameters
clustersToRebuildthe list of hits to be removed from clusters
unavailableClustersthe list of deleted clusters

Definition at line 100 of file TwoDSlidingFitConsolidationAlgorithm.cc.

References lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

101 {
102  ClusterList clusterList;
103  for (const auto &mapEntry : clustersToContract)
104  clusterList.push_back(mapEntry.first);
105  clusterList.sort(LArClusterHelper::SortByNHits);
106 
107  for (const Cluster *const pCluster : clusterList)
108  {
109  const CaloHitList &caloHitListToRemove(clustersToContract.at(pCluster));
110 
111  if (caloHitListToRemove.empty())
112  continue;
113 
114  if (unavailableClusters.count(pCluster))
115  continue;
116 
117  CaloHitList caloHitList, caloHitListToKeep;
118  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
119 
120  for (const CaloHit *const pCaloHit : caloHitList)
121  {
122  if (caloHitListToRemove.end() == std::find(caloHitListToRemove.begin(), caloHitListToRemove.end(), pCaloHit))
123  caloHitListToKeep.push_back(pCaloHit);
124  }
125 
126  if (caloHitListToKeep.empty())
127  {
128  // ATTN clustersToContract and unavailable clusters now contain dangling pointers
129  unavailableClusters.insert(pCluster);
130  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Cluster>(*this, pCluster));
131  continue;
132  }
133 
134  for (const CaloHit *const pCaloHit : caloHitListToRemove)
135  {
136  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RemoveFromCluster(*this, pCluster, pCaloHit));
137  }
138  }
139 
140  return STATUS_CODE_SUCCESS;
141 }
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.
StatusCode lar_content::TwoDSlidingFitConsolidationAlgorithm::Run ( )
protected

Definition at line 30 of file TwoDSlidingFitConsolidationAlgorithm.cc.

References AddHitsToClusters(), BuildSlidingLinearFits(), GetReclusteredHits(), RebuildClusters(), RemoveHitsFromClusters(), and SortInputClusters().

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 }
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.
std::vector< TwoDSlidingFitResult > TwoDSlidingFitResultList
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.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
pandora::StatusCode AddHitsToClusters(const ClusterToHitMap &clustersToRebuild, pandora::ClusterSet &unavailableClusters) const
Add hits to clusters.
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.
void lar_content::TwoDSlidingFitConsolidationAlgorithm::SortInputClusters ( const pandora::ClusterList *const  pClusterList,
pandora::ClusterVector &  trackClusters,
pandora::ClusterVector &  showerClusters 
) const
private

Sort input cluster list into track-like clusters and shower-like clusters.

Parameters
pClusterListthe input cluster list
trackClustersthe output vector of track-like clusters
showerClustersthe output vector of shower-like clusters

Definition at line 58 of file TwoDSlidingFitConsolidationAlgorithm.cc.

References lar_content::LArClusterHelper::GetLengthSquared(), m_maxClusterLength, m_minTrackLength, and lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

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 }
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.
float m_maxClusterLength
Maximum length of shower clusters to use in re-building.
float m_minTrackLength
Minimum length of track clusters to consolidate.
intermediate_table::const_iterator const_iterator
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.

Member Data Documentation

unsigned int lar_content::TwoDSlidingFitConsolidationAlgorithm::m_halfWindowLayers
private

Size of layer window for sliding fit results.

Definition at line 94 of file TwoDSlidingFitConsolidationAlgorithm.h.

Referenced by BuildSlidingLinearFits(), and ReadSettings().

float lar_content::TwoDSlidingFitConsolidationAlgorithm::m_maxClusterLength
private

Maximum length of shower clusters to use in re-building.

Definition at line 93 of file TwoDSlidingFitConsolidationAlgorithm.h.

Referenced by ReadSettings(), and SortInputClusters().

float lar_content::TwoDSlidingFitConsolidationAlgorithm::m_minTrackLength
private

Minimum length of track clusters to consolidate.

Definition at line 92 of file TwoDSlidingFitConsolidationAlgorithm.h.

Referenced by ReadSettings(), and SortInputClusters().

std::string lar_content::TwoDSlidingFitConsolidationAlgorithm::m_reclusteringAlgorithmName
private

Name of daughter algorithm to use for cluster re-building.

Definition at line 91 of file TwoDSlidingFitConsolidationAlgorithm.h.

Referenced by ReadSettings(), and RebuildClusters().


The documentation for this class was generated from the following files: