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