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

TwoDSlidingFitSplittingAndSwitchingAlgorithm class. More...

#include "TwoDSlidingFitSplittingAndSwitchingAlgorithm.h"

Inheritance diagram for lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm:
lar_content::CrossedTrackSplittingAlgorithm

Public Member Functions

 TwoDSlidingFitSplittingAndSwitchingAlgorithm ()
 Default constructor. More...
 

Protected Member Functions

virtual pandora::StatusCode Run ()
 
virtual pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
virtual pandora::StatusCode PreparationStep (const pandora::ClusterVector &clusterVector)
 Perform any preparatory actions, such as caching information for subsequent expensive calculations. More...
 
virtual pandora::StatusCode TidyUpStep ()
 Tidy up any information cached in e.g. the preparation step. More...
 
virtual pandora::StatusCode FindBestSplitPosition (const TwoDSlidingFitResult &slidingFit1, const TwoDSlidingFitResult &slidingFit2, pandora::CartesianVector &splitPosition, pandora::CartesianVector &direction1, pandora::CartesianVector &direction2) const =0
 Find the best split position and direction for a pair of clusters. More...
 

Private Member Functions

void GetListOfCleanClusters (const pandora::ClusterList *const pClusterList, pandora::ClusterVector &clusterVector) const
 Populate cluster vector with subset of cluster list, containing clusters judged to be clean. More...
 
void BuildSlidingFitResultMap (const pandora::ClusterVector &clusterVector, TwoDSlidingFitResultMap &slidingFitResultMap) const
 Build the map of sliding fit results. More...
 
void SplitCluster (const pandora::Cluster *const pCluster, const pandora::CartesianVector &splitPosition, const pandora::CartesianVector &splitDirection, pandora::CaloHitList &firstCaloHitList, pandora::CaloHitList &secondCaloHitList) const
 Split cluster at a given position and direction. More...
 
pandora::StatusCode ReplaceClusters (const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::CartesianVector &splitPosition, const pandora::CartesianVector &firstDirection, const pandora::CartesianVector &secondDirection) const
 Replace crossed clusters with un-crossed clusters. More...
 

Private Attributes

unsigned int m_halfWindowLayers
 half window layers for sliding linear fot More...
 
float m_minClusterLength
 minimum length of clusters More...
 

Detailed Description

Constructor & Destructor Documentation

lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::TwoDSlidingFitSplittingAndSwitchingAlgorithm ( )

Default constructor.

Definition at line 21 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

21  :
24 {
25 }
unsigned int m_halfWindowLayers
half window layers for sliding linear fot
TFile f
Definition: plotHisto.C:6

Member Function Documentation

void lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::BuildSlidingFitResultMap ( const pandora::ClusterVector &  clusterVector,
TwoDSlidingFitResultMap slidingFitResultMap 
) const
private

Build the map of sliding fit results.

Parameters
clusterVectorthe input cluster vector
slidingFitResultMapthe output sliding fit result map

Definition at line 132 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

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

Referenced by Run().

134 {
135  for (ClusterVector::const_iterator iter = clusterVector.begin(), iterEnd = clusterVector.end(); iter != iterEnd; ++iter)
136  {
137  if (slidingFitResultMap.end() == slidingFitResultMap.find(*iter))
138  {
139  try
140  {
141  const float slidingFitPitch(LArGeometryHelper::GetWirePitch(this->GetPandora(), LArClusterHelper::GetClusterHitType(*iter)));
142  const TwoDSlidingFitResult slidingFitResult(*iter, m_halfWindowLayers, slidingFitPitch);
143 
144  if (!slidingFitResultMap.insert(TwoDSlidingFitResultMap::value_type(*iter, slidingFitResult)).second)
145  throw StatusCodeException(STATUS_CODE_FAILURE);
146  }
147  catch (StatusCodeException &statusCodeException)
148  {
149  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
150  throw statusCodeException;
151  }
152  }
153  }
154 }
unsigned int m_halfWindowLayers
half window layers for sliding linear fot
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 pandora::StatusCode lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::FindBestSplitPosition ( const TwoDSlidingFitResult slidingFit1,
const TwoDSlidingFitResult slidingFit2,
pandora::CartesianVector &  splitPosition,
pandora::CartesianVector &  direction1,
pandora::CartesianVector &  direction2 
) const
protectedpure virtual

Find the best split position and direction for a pair of clusters.

Parameters
slidingFit1the sliding linear fit to the first cluster
slidingFit2the sliding linear fit to the second cluster
splitPositionthe output split position
direction1the output direction of the first new cluster
direction2the output direction of the second new cluster

Implemented in lar_content::CrossedTrackSplittingAlgorithm.

Referenced by Run().

void lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::GetListOfCleanClusters ( const pandora::ClusterList *const  pClusterList,
pandora::ClusterVector &  clusterVector 
) const
private

Populate cluster vector with subset of cluster list, containing clusters judged to be clean.

Parameters
pClusterListaddress of the cluster list
clusterVectorto receive the populated cluster vector

Definition at line 115 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

References lar_content::LArClusterHelper::GetLengthSquared(), m_minClusterLength, and lar_content::LArClusterHelper::SortByNHits().

Referenced by Run().

116 {
117  for (ClusterList::const_iterator iter = pClusterList->begin(), iterEnd = pClusterList->end(); iter != iterEnd; ++iter)
118  {
119  const Cluster *const pCluster = *iter;
120 
122  continue;
123 
124  clusterVector.push_back(pCluster);
125  }
126 
127  std::sort(clusterVector.begin(), clusterVector.end(), LArClusterHelper::SortByNHits);
128 }
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.
intermediate_table::const_iterator const_iterator
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.
StatusCode lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::PreparationStep ( const pandora::ClusterVector &  clusterVector)
protectedvirtual

Perform any preparatory actions, such as caching information for subsequent expensive calculations.

Parameters
clusterVectorthe cluster vector

Reimplemented in lar_content::CrossedTrackSplittingAlgorithm.

Definition at line 101 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

Referenced by Run().

102 {
103  return STATUS_CODE_SUCCESS;
104 }
StatusCode lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
protectedvirtual

Reimplemented in lar_content::CrossedTrackSplittingAlgorithm.

Definition at line 215 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

References m_halfWindowLayers, and m_minClusterLength.

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

216 {
217  PANDORA_RETURN_RESULT_IF_AND_IF(
218  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "HalfWindowLayers", m_halfWindowLayers));
219 
220  PANDORA_RETURN_RESULT_IF_AND_IF(
221  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinClusterLength", m_minClusterLength));
222 
223  return STATUS_CODE_SUCCESS;
224 }
unsigned int m_halfWindowLayers
half window layers for sliding linear fot
StatusCode lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::ReplaceClusters ( const pandora::Cluster *const  pCluster1,
const pandora::Cluster *const  pCluster2,
const pandora::CartesianVector &  splitPosition,
const pandora::CartesianVector &  firstDirection,
const pandora::CartesianVector &  secondDirection 
) const
private

Replace crossed clusters with un-crossed clusters.

Parameters
pCluster1the first cluster to be deleted
pCluster2the second cluster to be deleted
splitPositionthe split position
firstDirectionthe direction of the first new cluster
secondDirectionthe direction of the second new cluster

Definition at line 181 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

References SplitCluster().

Referenced by Run().

183 {
184  // Split cluster into two hit lists (note the convention for 'firstDirection' and 'secondDirection')
185  PandoraContentApi::Cluster::Parameters firstParameters, secondParameters;
186 
187  this->SplitCluster(pCluster1, splitPosition, firstDirection, firstParameters.m_caloHitList, secondParameters.m_caloHitList);
188  this->SplitCluster(pCluster2, splitPosition, secondDirection, secondParameters.m_caloHitList, firstParameters.m_caloHitList);
189 
190  if (firstParameters.m_caloHitList.empty() || secondParameters.m_caloHitList.empty())
191  return STATUS_CODE_NOT_ALLOWED;
192 
193  // Begin cluster fragmentation operations
194  ClusterList clusterList;
195  clusterList.push_back(pCluster1);
196  clusterList.push_back(pCluster2);
197 
198  std::string clusterListToSaveName, clusterListToDeleteName;
199  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
200  PandoraContentApi::InitializeFragmentation(*this, clusterList, clusterListToDeleteName, clusterListToSaveName));
201 
202  // Create new clusters
203  const Cluster *pFirstCluster(NULL), *pSecondCluster(NULL);
204  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, firstParameters, pFirstCluster));
205  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, secondParameters, pSecondCluster));
206 
207  // End cluster fragmentation operations
208  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::EndFragmentation(*this, clusterListToSaveName, clusterListToDeleteName));
209 
210  return STATUS_CODE_SUCCESS;
211 }
void SplitCluster(const pandora::Cluster *const pCluster, const pandora::CartesianVector &splitPosition, const pandora::CartesianVector &splitDirection, pandora::CaloHitList &firstCaloHitList, pandora::CaloHitList &secondCaloHitList) const
Split cluster at a given position and direction.
StatusCode lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::Run ( )
protectedvirtual

Definition at line 29 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

References BuildSlidingFitResultMap(), f, FindBestSplitPosition(), lar_content::TwoDSlidingFitResult::GetCluster(), GetListOfCleanClusters(), PreparationStep(), ReplaceClusters(), and TidyUpStep().

30 {
31  const ClusterList *pClusterList = NULL;
32  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pClusterList));
33 
34  // Get ordered list of clean clusters
35  ClusterVector clusterVector;
36  this->GetListOfCleanClusters(pClusterList, clusterVector);
37 
38  // Calculate sliding fit results for clean clusters
39  TwoDSlidingFitResultMap slidingFitResultMap;
40  this->BuildSlidingFitResultMap(clusterVector, slidingFitResultMap);
41 
42  // May choose to cache information here, for subsequent expensive calculations
43  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->PreparationStep(clusterVector));
44 
45  // Loop over clusters, identify split positions, perform splits
46  for (ClusterVector::iterator iter1 = clusterVector.begin(), iterEnd1 = clusterVector.end(); iter1 != iterEnd1; ++iter1)
47  {
48  if (NULL == *iter1)
49  continue;
50 
51  TwoDSlidingFitResultMap::iterator sIter1 = slidingFitResultMap.find(*iter1);
52 
53  if (slidingFitResultMap.end() == sIter1)
54  continue;
55 
56  const TwoDSlidingFitResult &slidingFitResult1(sIter1->second);
57 
58  for (ClusterVector::iterator iter2 = iter1, iterEnd2 = iterEnd1; iter2 != iterEnd2; ++iter2)
59  {
60  if (NULL == *iter2)
61  continue;
62 
63  TwoDSlidingFitResultMap::iterator sIter2 = slidingFitResultMap.find(*iter2);
64 
65  if (slidingFitResultMap.end() == sIter2)
66  continue;
67 
68  const TwoDSlidingFitResult &slidingFitResult2(sIter2->second);
69 
70  if (slidingFitResult1.GetCluster() == slidingFitResult2.GetCluster())
71  continue;
72 
73  CartesianVector splitPosition(0.f, 0.f, 0.f);
74  CartesianVector firstDirection(0.f, 0.f, 0.f);
75  CartesianVector secondDirection(0.f, 0.f, 0.f);
76 
77  if (STATUS_CODE_SUCCESS != this->FindBestSplitPosition(slidingFitResult1, slidingFitResult2, splitPosition, firstDirection, secondDirection))
78  continue;
79 
80  const Cluster *const pCluster1 = slidingFitResult1.GetCluster();
81  const Cluster *const pCluster2 = slidingFitResult2.GetCluster();
82 
83  if (STATUS_CODE_SUCCESS != this->ReplaceClusters(pCluster1, pCluster2, splitPosition, firstDirection, secondDirection))
84  continue;
85 
86  slidingFitResultMap.erase(sIter1);
87  slidingFitResultMap.erase(sIter2);
88 
89  *iter1 = NULL;
90  *iter2 = NULL;
91 
92  break;
93  }
94  }
95 
96  return this->TidyUpStep();
97 }
intermediate_table::iterator iterator
virtual pandora::StatusCode FindBestSplitPosition(const TwoDSlidingFitResult &slidingFit1, const TwoDSlidingFitResult &slidingFit2, pandora::CartesianVector &splitPosition, pandora::CartesianVector &direction1, pandora::CartesianVector &direction2) const =0
Find the best split position and direction for a pair of clusters.
TFile f
Definition: plotHisto.C:6
virtual pandora::StatusCode TidyUpStep()
Tidy up any information cached in e.g. the preparation step.
pandora::StatusCode ReplaceClusters(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::CartesianVector &splitPosition, const pandora::CartesianVector &firstDirection, const pandora::CartesianVector &secondDirection) const
Replace crossed clusters with un-crossed clusters.
std::unordered_map< const pandora::Cluster *, TwoDSlidingFitResult > TwoDSlidingFitResultMap
void GetListOfCleanClusters(const pandora::ClusterList *const pClusterList, pandora::ClusterVector &clusterVector) const
Populate cluster vector with subset of cluster list, containing clusters judged to be clean...
std::vector< art::Ptr< recob::Cluster > > ClusterVector
virtual pandora::StatusCode PreparationStep(const pandora::ClusterVector &clusterVector)
Perform any preparatory actions, such as caching information for subsequent expensive calculations...
void BuildSlidingFitResultMap(const pandora::ClusterVector &clusterVector, TwoDSlidingFitResultMap &slidingFitResultMap) const
Build the map of sliding fit results.
void lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::SplitCluster ( const pandora::Cluster *const  pCluster,
const pandora::CartesianVector &  splitPosition,
const pandora::CartesianVector &  splitDirection,
pandora::CaloHitList &  firstCaloHitList,
pandora::CaloHitList &  secondCaloHitList 
) const
private

Split cluster at a given position and direction.

Parameters
pClusterthe cluster
splitPositionthe position at which to split the cluster
splitDirectionthe direction of the un-crossed cluster
firstCaloHitListthe hits to be added to the first new cluster
secondCaloHitListthe hits to be added to the second new cluster

Definition at line 158 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

Referenced by ReplaceClusters().

160 {
161  CaloHitList caloHitsToDistribute;
162  pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitsToDistribute);
163 
164  for (CaloHitList::const_iterator iter = caloHitsToDistribute.begin(), iterEnd = caloHitsToDistribute.end(); iter != iterEnd; ++iter)
165  {
166  const CaloHit *const pCaloHit = *iter;
167 
168  if (splitDirection.GetDotProduct((pCaloHit->GetPositionVector() - splitPosition)) > 0.f)
169  {
170  firstCaloHitList.push_back(pCaloHit);
171  }
172  else
173  {
174  secondCaloHitList.push_back(pCaloHit);
175  }
176  }
177 }
intermediate_table::const_iterator const_iterator
StatusCode lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::TidyUpStep ( )
protectedvirtual

Tidy up any information cached in e.g. the preparation step.

Reimplemented in lar_content::CrossedTrackSplittingAlgorithm.

Definition at line 108 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.cc.

Referenced by Run().

109 {
110  return STATUS_CODE_SUCCESS;
111 }

Member Data Documentation

unsigned int lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::m_halfWindowLayers
private

half window layers for sliding linear fot

Definition at line 99 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.h.

Referenced by BuildSlidingFitResultMap(), and ReadSettings().

float lar_content::TwoDSlidingFitSplittingAndSwitchingAlgorithm::m_minClusterLength
private

minimum length of clusters

Definition at line 100 of file TwoDSlidingFitSplittingAndSwitchingAlgorithm.h.

Referenced by GetListOfCleanClusters(), and ReadSettings().


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