Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
RemovalBaseTool.cc
Go to the documentation of this file.
1
10
12
14
15using namespace pandora;
16
17namespace lar_content
18{
19
20RemovalBaseTool::RemovalBaseTool() : m_minSeparation(1.f), m_distanceToLine(0.5f)
21{
22}
23
24//------------------------------------------------------------------------------------------------------------------------------------------
25
26bool RemovalBaseTool::PassElementChecks(const TensorType::Element &element, const HitType hitType) const
27{
28 const Cluster *pMuonCluster(nullptr), *const pDeltaRayCluster(element.GetCluster(hitType));
29
30 if (m_pParentAlgorithm->GetMuonCluster(element.GetOverlapResult().GetCommonMuonPfoList(), hitType, pMuonCluster) != STATUS_CODE_SUCCESS)
31 return false;
32
33 const float separation(LArClusterHelper::GetClosestDistance(pDeltaRayCluster, pMuonCluster));
34
35 return separation <= m_minSeparation;
36}
37
38//------------------------------------------------------------------------------------------------------------------------------------------
39
40bool RemovalBaseTool::IsMuonEndpoint(const TensorType::Element &element, const bool ignoreHitType, const HitType hitTypeToIgnore) const
41{
42 for (const HitType hitType : {TPC_VIEW_U, TPC_VIEW_V, TPC_VIEW_W})
43 {
44 if (ignoreHitType && (hitType == hitTypeToIgnore))
45 continue;
46
47 const Cluster *pMuonCluster(nullptr), *const pDeltaRayCluster(element.GetCluster(hitType));
48
49 if (m_pParentAlgorithm->GetMuonCluster(element.GetOverlapResult().GetCommonMuonPfoList(), hitType, pMuonCluster) != STATUS_CODE_SUCCESS)
50 return true;
51
52 float xMinDR(-std::numeric_limits<float>::max()), xMaxDR(+std::numeric_limits<float>::max());
53 pDeltaRayCluster->GetClusterSpanX(xMinDR, xMaxDR);
54
55 float xMinCR(-std::numeric_limits<float>::max()), xMaxCR(+std::numeric_limits<float>::max());
56 pMuonCluster->GetClusterSpanX(xMinCR, xMaxCR);
57
58 if ((xMinDR < xMinCR) || (xMaxDR > xMaxCR))
59 return true;
60
61 float zMinDR(-std::numeric_limits<float>::max()), zMaxDR(+std::numeric_limits<float>::max());
62 pDeltaRayCluster->GetClusterSpanZ(xMinDR, xMaxDR, zMinDR, zMaxDR);
63
64 float zMinCR(-std::numeric_limits<float>::max()), zMaxCR(+std::numeric_limits<float>::max());
65 pMuonCluster->GetClusterSpanZ(xMinCR, xMaxCR, zMinCR, zMaxCR);
66
67 if ((zMinDR < zMinCR) || (zMaxDR > zMaxCR))
68 return true;
69 }
70
71 return false;
72}
73
74//------------------------------------------------------------------------------------------------------------------------------------------
75
76bool RemovalBaseTool::IsBestElement(const TensorType::Element &element, const HitType hitType, const TensorType::ElementList &elementList,
77 const ClusterSet &modifiedClusters) const
78{
79 const float chiSquared(element.GetOverlapResult().GetReducedChi2());
80 const unsigned int hitSum(element.GetClusterU()->GetNCaloHits() + element.GetClusterV()->GetNCaloHits() + element.GetClusterW()->GetNCaloHits());
81
82 for (const TensorType::Element &testElement : elementList)
83 {
84 if (modifiedClusters.count(testElement.GetClusterU()) || modifiedClusters.count(testElement.GetClusterV()) ||
85 modifiedClusters.count(testElement.GetClusterW()))
86 continue;
87
88 if (testElement.GetCluster(hitType) != element.GetCluster(hitType))
89 continue;
90
91 if ((testElement.GetClusterU() == element.GetClusterU()) && (testElement.GetClusterV() == element.GetClusterV()) &&
92 (testElement.GetClusterW() == element.GetClusterW()))
93 continue;
94
95 const unsigned int testHitSum(
96 testElement.GetClusterU()->GetNCaloHits() + testElement.GetClusterV()->GetNCaloHits() + testElement.GetClusterW()->GetNCaloHits());
97 const float testChiSquared(testElement.GetOverlapResult().GetReducedChi2());
98
99 if ((testHitSum < hitSum) || ((testHitSum == hitSum) && (testChiSquared > chiSquared)))
100 continue;
101
102 if (this->PassElementChecks(testElement, hitType))
103 return false;
104 }
105
106 return true;
107}
108
109//------------------------------------------------------------------------------------------------------------------------------------------
110
112 const CartesianVector &hitPosition, const CartesianVector &lineStart, const CartesianVector &lineEnd, const float distanceToLine) const
113{
114 CartesianVector lineDirection(lineStart - lineEnd);
115 lineDirection = lineDirection.GetUnitVector();
116
117 const float transverseDistanceFromLine(lineDirection.GetCrossProduct(hitPosition - lineStart).GetMagnitude());
118
119 if (transverseDistanceFromLine > distanceToLine)
120 return false;
121
122 return true;
123}
124
125//------------------------------------------------------------------------------------------------------------------------------------------
126
127bool RemovalBaseTool::IsInLineSegment(const CartesianVector &lowerBoundary, const CartesianVector &upperBoundary, const CartesianVector &point) const
128{
129 const float segmentBoundaryGradient = (-1.f) * (upperBoundary.GetX() - lowerBoundary.GetX()) / (upperBoundary.GetZ() - lowerBoundary.GetZ());
130 const float xPointOnUpperLine((point.GetZ() - upperBoundary.GetZ()) / segmentBoundaryGradient + upperBoundary.GetX());
131 const float xPointOnLowerLine((point.GetZ() - lowerBoundary.GetZ()) / segmentBoundaryGradient + lowerBoundary.GetX());
132
133 if (std::fabs(xPointOnUpperLine - point.GetX()) < std::numeric_limits<float>::epsilon())
134 return true;
135
136 if (std::fabs(xPointOnLowerLine - point.GetX()) < std::numeric_limits<float>::epsilon())
137 return true;
138
139 if ((point.GetX() > xPointOnUpperLine) && (point.GetX() > xPointOnLowerLine))
140 return false;
141
142 if ((point.GetX() < xPointOnUpperLine) && (point.GetX() < xPointOnLowerLine))
143 return false;
144
145 return true;
146}
147
148//------------------------------------------------------------------------------------------------------------------------------------------
149
150void RemovalBaseTool::FindExtrapolatedHits(const Cluster *const pCluster, const CartesianVector &lowerBoundary,
151 const CartesianVector &upperBoundary, CaloHitList &collectedHits) const
152{
153 CaloHitList caloHitList;
154 pCluster->GetOrderedCaloHitList().FillCaloHitList(caloHitList);
155
156 for (const CaloHit *const pCaloHit : caloHitList)
157 {
158 if (!this->IsInLineSegment(lowerBoundary, upperBoundary, pCaloHit->GetPositionVector()))
159 continue;
160
161 if (!this->IsCloseToLine(pCaloHit->GetPositionVector(), lowerBoundary, upperBoundary, m_distanceToLine))
162 continue;
163
164 collectedHits.push_back(pCaloHit);
165 }
166}
167
168//------------------------------------------------------------------------------------------------------------------------------------------
169
170StatusCode RemovalBaseTool::ProjectDeltaRayPositions(const TensorType::Element &element, const HitType hitType, CartesianPointVector &projectedPositions) const
171{
173
174 hitTypes.erase(std::find(hitTypes.begin(), hitTypes.end(), hitType));
175
176 const Cluster *const pCluster1(element.GetCluster(hitTypes[0]));
177 const Cluster *const pCluster2(element.GetCluster(hitTypes[1]));
178
179 return m_pParentAlgorithm->GetProjectedPositions(pCluster1, pCluster2, projectedPositions);
180}
181
182//------------------------------------------------------------------------------------------------------------------------------------------
183
185{
186 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinSeparation", m_minSeparation));
187
188 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "DistanceToLine", m_distanceToLine));
189
190 return STATUS_CODE_SUCCESS;
191}
192
193} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the cluster helper class.
Header file for the removal base tool class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
ThreeViewDeltaRayMatchingAlgorithm * m_pParentAlgorithm
Address of the parent matching algorithm.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.
pandora::StatusCode GetProjectedPositions(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, pandora::CartesianPointVector &projectedPositions) const
Use two clusters from different views to calculate projected positions in the remaining third view.
pandora::StatusCode GetMuonCluster(const pandora::PfoList &commonMuonPfoList, const pandora::HitType hitType, const pandora::Cluster *&pMuonCluster) const
Return the cluster of the common cosmic ray pfo in a given view (function demands there to be only on...
float m_distanceToLine
The maximum perpendicular distance of a position to a line for it to be considered close.
virtual bool PassElementChecks(const TensorType::Element &element, const pandora::HitType hitType) const =0
Determine whether element satifies simple checks.
std::vector< pandora::HitType > HitTypeVector
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)=0
Read the algorithm settings.
void FindExtrapolatedHits(const pandora::Cluster *const pCluster, const pandora::CartesianVector &lowerBoundary, const pandora::CartesianVector &upperBoundary, pandora::CaloHitList &collectedHits) const
Collect the hits that are closest to and can be projected onto a defined line.
float m_minSeparation
The minimum delta ray - parent muon cluster separation required to investigate a delta/cosmic ray clu...
bool IsCloseToLine(const pandora::CartesianVector &hitPosition, const pandora::CartesianVector &lineStart, const pandora::CartesianVector &lineEnd, const float distanceToLine) const
Whether a given position is close to a defined line.
pandora::StatusCode ProjectDeltaRayPositions(const TensorType::Element &element, const pandora::HitType hitType, pandora::CartesianPointVector &projectedPositions) const
Use two views of a delta ray pfo to calculate projected positions in a given third view.
bool IsInLineSegment(const pandora::CartesianVector &lowerBoundary, const pandora::CartesianVector &upperBoundary, const pandora::CartesianVector &point) const
Whether the projection of a given position lies on a defined line.
bool IsMuonEndpoint(const TensorType::Element &element, const bool ignoreHitType, const pandora::HitType hitTypeToIgnore=pandora::TPC_VIEW_U) const
Determine whether the matched clusters suggest that the delta ray is at the endpoint of the cosmic ra...
RemovalBaseTool()
Default constructor.
bool IsBestElement(const TensorType::Element &element, const pandora::HitType hitType, const TensorType::ElementList &elementList, const pandora::ClusterSet &modifiedClusters) const
Determine whether the input element is the best to use to modify the contaminated cluster (best is de...
CaloHit class.
Definition CaloHit.h:26
CartesianVector class.
float GetX() const
Get the cartesian x coordinate.
CartesianVector GetUnitVector() const
Get a unit vector in the direction of the cartesian vector.
float GetZ() const
Get the cartesian z coordinate.
float GetMagnitude() const
Get the magnitude.
CartesianVector GetCrossProduct(const CartesianVector &rhs) const
Get the cross product of the cartesian vector with a second cartesian vector.
Cluster class.
Definition Cluster.h:31
const OrderedCaloHitList & GetOrderedCaloHitList() const
Get the ordered calo hit list.
Definition Cluster.h:470
void GetClusterSpanX(float &xmin, float &xmax) const
Get minimum and maximum X positions of the calo hits in this cluster.
Definition Cluster.cc:169
void GetClusterSpanZ(const float xmin, const float xmax, float &zmin, float &zmax) const
Get upper and lower Z positions of the calo hits in a cluster in range xmin to xmax.
Definition Cluster.cc:198
void FillCaloHitList(CaloHitList &caloHitList) const
Fill a provided calo hit list with all the calo hits in the ordered calo hit list.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
HitType
Calorimeter hit type enum.
std::vector< CartesianVector > CartesianPointVector
std::unordered_set< const Cluster * > ClusterSet
MANAGED_CONTAINER< const CaloHit * > CaloHitList
StatusCode
The StatusCode enum.