LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TrackConsolidationAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 TrackConsolidationAlgorithm::TrackConsolidationAlgorithm() :
19  m_maxTransverseDisplacement(1.f),
20  m_minAssociatedSpan(1.f),
21  m_minAssociatedFraction(0.5f)
22 {
23 }
24 
25 //------------------------------------------------------------------------------------------------------------------------------------------
26 
28  const ClusterVector &showerClustersJ, ClusterToHitMap &caloHitsToAddI, ClusterToHitMap &caloHitsToRemoveJ) const
29 {
30  for (const TwoDSlidingFitResult &slidingFitResultI : slidingFitResultListI)
31  {
32  const Cluster *const pClusterI = slidingFitResultI.GetCluster();
33  const float thisLengthSquaredI(LArClusterHelper::GetLengthSquared(pClusterI));
34 
35  for (const Cluster *const pClusterJ : showerClustersJ)
36  {
37  const float thisLengthSquaredJ(LArClusterHelper::GetLengthSquared(pClusterJ));
38 
39  if (pClusterI == pClusterJ)
40  continue;
41 
42  if (2.f * thisLengthSquaredJ > thisLengthSquaredI)
43  continue;
44 
45  this->GetReclusteredHits(slidingFitResultI, pClusterJ, caloHitsToAddI, caloHitsToRemoveJ);
46  }
47  }
48 }
49 
50 //------------------------------------------------------------------------------------------------------------------------------------------
51 
52 void TrackConsolidationAlgorithm::GetReclusteredHits(const TwoDSlidingFitResult &slidingFitResultI, const Cluster *const pClusterJ,
53  ClusterToHitMap &caloHitsToAddI, ClusterToHitMap &caloHitsToRemoveJ) const
54 {
55  const Cluster *const pClusterI(slidingFitResultI.GetCluster());
56 
57  CaloHitList associatedHits, caloHitListJ;
58  pClusterJ->GetOrderedCaloHitList().FillCaloHitList(caloHitListJ);
59 
60  float minL(std::numeric_limits<float>::max());
61  float maxL(std::numeric_limits<float>::max());
62 
63  // Loop over hits from shower clusters, and make associations with track clusters
64  // (Determine if hits from shower clusters can be used to fill gaps in track cluster)
65  //
66  // Apply the following selection:
67  // rJ = candidate hit from shower cluster
68  // rI = nearest hit on track cluster
69  // rK = projection of shower hit onto track cluster
70  //
71  // o rJ
72  // o o o o o o - - x - - - - o o o o o o o
73  // rI rK
74  //
75  // Require: rJK < std::min(rCut, rIJ, rKI)
76 
77  for (CaloHitList::const_iterator iterJ = caloHitListJ.begin(), iterEndJ = caloHitListJ.end(); iterJ != iterEndJ; ++iterJ)
78  {
79  const CaloHit *const pCaloHitJ = *iterJ;
80 
81  const CartesianVector positionJ(pCaloHitJ->GetPositionVector());
82  const CartesianVector positionI(LArClusterHelper::GetClosestPosition(positionJ, pClusterI));
83 
84  float rL(0.f), rT(0.f);
85  CartesianVector positionK(0.f, 0.f, 0.f);
86 
87  if (STATUS_CODE_SUCCESS != slidingFitResultI.GetGlobalFitProjection(positionJ, positionK))
88  continue;
89 
90  slidingFitResultI.GetLocalPosition(positionK, rL, rT);
91 
92  const float rsqIJ((positionI - positionJ).GetMagnitudeSquared());
93  const float rsqJK((positionJ - positionK).GetMagnitudeSquared());
94  const float rsqKI((positionK - positionI).GetMagnitudeSquared());
95 
97  {
98  if (associatedHits.empty())
99  {
100  minL = rL;
101  maxL = rL;
102  }
103  else
104  {
105  minL = std::min(minL, rL);
106  maxL = std::max(maxL, rL);
107  }
108 
109  associatedHits.push_back(pCaloHitJ);
110  }
111  }
112 
113  const float associatedSpan(maxL - minL);
114  const float associatedFraction(associatedHits.empty() ? 0.f : static_cast<float>(associatedHits.size()) / static_cast<float>(pClusterJ->GetNCaloHits()));
115 
116  if (associatedSpan > m_minAssociatedSpan || associatedFraction > m_minAssociatedFraction)
117  {
118  for (CaloHitList::const_iterator iterK = associatedHits.begin(), iterEndK = associatedHits.end(); iterK != iterEndK; ++iterK)
119  {
120  const CaloHit *const pCaloHit = *iterK;
121  const CaloHitList &caloHitList(caloHitsToRemoveJ[pClusterJ]);
122 
123  if (caloHitList.end() != std::find(caloHitList.begin(), caloHitList.end(), pCaloHit))
124  continue;
125 
126  caloHitsToAddI[pClusterI].push_back(pCaloHit);
127  caloHitsToRemoveJ[pClusterJ].push_back(pCaloHit);
128  }
129  }
130 }
131 
132 //------------------------------------------------------------------------------------------------------------------------------------------
133 
134 StatusCode TrackConsolidationAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
135 {
136  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
137  "MaxTransverseDisplacement", m_maxTransverseDisplacement));
138 
139  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
140  "MinAssociatedSpan", m_minAssociatedSpan));
141 
142  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
143  "MinAssociatedFraction", m_minAssociatedFraction));
144 
146 }
147 
148 } // namespace lar_content
std::unordered_map< const pandora::Cluster *, pandora::CaloHitList > ClusterToHitMap
Header file for the track consolidation algorithm class.
TFile f
Definition: plotHisto.C:6
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Int_t max
Definition: plot.C:27
intermediate_table::const_iterator const_iterator
void GetReclusteredHits(const TwoDSlidingFitResultList &slidingFitResultList, const pandora::ClusterVector &showerClusters, ClusterToHitMap &caloHitsToAdd, ClusterToHitMap &caloHitsToRemove) const
Get the list of hits to be added to track clusters and removed from shower clusters.
std::vector< TwoDSlidingFitResult > TwoDSlidingFitResultList
std::vector< art::Ptr< recob::Cluster > > ClusterVector
const pandora::Cluster * GetCluster() const
Get the address of the cluster, if originally provided.
Int_t min
Definition: plot.C:26
pandora::StatusCode GetGlobalFitProjection(const pandora::CartesianVector &inputPosition, pandora::CartesianVector &projectedPosition) const
Get projected position on global fit for a given position vector.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static float GetLengthSquared(const pandora::Cluster *const pCluster)
Get length squared of cluster.
static pandora::CartesianVector GetClosestPosition(const pandora::CartesianVector &position, const pandora::ClusterList &clusterList)
Get closest position in a list of clusters to a specified input position vector.
void GetLocalPosition(const pandora::CartesianVector &position, float &rL, float &rT) const
Get local sliding fit coordinates for a given global position.