Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
DeltaRayRemovalTool.cc
Go to the documentation of this file.
1
10
13
15
17
18using namespace pandora;
19
20namespace lar_content
21{
22
24 m_slidingFitWindow(10000),
25 m_minDeviationFromTransverse(0.35f),
26 m_contaminationWindow(5.f),
27 m_significantHitThreshold(3),
28 m_minDistanceFromMuon(1.f),
29 m_maxDistanceToCollected(1.f)
30{
31}
32
33//------------------------------------------------------------------------------------------------------------------------------------------
34
36{
37 m_pParentAlgorithm = pAlgorithm;
38
40 std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
41
42 bool changesMade(false);
43
44 ClusterVector sortedKeyClusters;
45 overlapTensor.GetSortedKeyClusters(sortedKeyClusters);
46
47 ClusterSet usedKeyClusters;
48 for (const Cluster *const pKeyCluster : sortedKeyClusters)
49 {
50 if (usedKeyClusters.count(pKeyCluster))
51 continue;
52
53 TensorType::ElementList elementList;
54 overlapTensor.GetConnectedElements(pKeyCluster, true, elementList);
55
56 for (const TensorType::Element &element : elementList)
57 usedKeyClusters.insert(element.GetClusterU());
58
59 const bool changesMadeInIteration = this->RemoveDeltaRayHits(elementList);
60
61 changesMade = (changesMade ? changesMade : changesMadeInIteration);
62 }
63
64 return changesMade;
65}
66
67//------------------------------------------------------------------------------------------------------------------------------------------
68
69bool DeltaRayRemovalTool::RemoveDeltaRayHits(const TensorType::ElementList &elementList) const
70{
71 ClusterSet modifiedClusters, checkedClusters;
72
73 for (const TensorType::Element &element : elementList)
74 {
75 for (const HitType hitType : {TPC_VIEW_U, TPC_VIEW_V, TPC_VIEW_W})
76 {
77 const Cluster *pDeltaRayCluster(element.GetCluster(hitType));
78 const ParticleFlowObject *const pMuonPfo(element.GetOverlapResult().GetCommonMuonPfoList().front());
79
80 if (checkedClusters.count(pDeltaRayCluster))
81 continue;
82
83 // ATTN: The underlying tensor will update during this loop, do not proceed if element has been modified
84 if ((modifiedClusters.count(element.GetClusterU())) || (modifiedClusters.count(element.GetClusterV())) ||
85 (modifiedClusters.count(element.GetClusterW())))
86 continue;
87
88 if (!this->PassElementChecks(element, hitType))
89 continue;
90
91 if (!this->IsContaminated(element, hitType))
92 continue;
93
94 if (!this->IsBestElement(element, hitType, elementList, modifiedClusters))
95 continue;
96
97 checkedClusters.insert(pDeltaRayCluster);
98
99 CaloHitList deltaRayHits;
100 if (m_pParentAlgorithm->CollectHitsFromMuon(nullptr, nullptr, pDeltaRayCluster, pMuonPfo, m_minDistanceFromMuon,
101 m_maxDistanceToCollected, deltaRayHits) != STATUS_CODE_SUCCESS)
102 continue;
103
104 modifiedClusters.insert(pDeltaRayCluster);
105
106 this->SplitMuonCluster(element, hitType, deltaRayHits);
107 }
108 }
109
110 return !modifiedClusters.empty();
111}
112
113//------------------------------------------------------------------------------------------------------------------------------------------
114
115bool DeltaRayRemovalTool::PassElementChecks(const TensorType::Element &element, const HitType hitType) const
116{
117 // ATTN: Avoid endpoints, topological michel reconstruction is very ambiguous
118 if (this->IsMuonEndpoint(element, false))
119 return false;
120
121 return RemovalBaseTool::PassElementChecks(element, hitType);
122}
123
124//------------------------------------------------------------------------------------------------------------------------------------------
125
126bool DeltaRayRemovalTool::IsContaminated(const TensorType::Element &element, const HitType hitType) const
127{
128 const Cluster *pMuonCluster(nullptr), *const pDeltaRayCluster(element.GetCluster(hitType));
129
130 if (m_pParentAlgorithm->GetMuonCluster(element.GetOverlapResult().GetCommonMuonPfoList(), hitType, pMuonCluster) != STATUS_CODE_SUCCESS)
131 return false;
132
133 const float slidingFitPitch(LArGeometryHelper::GetWireZPitch(this->GetPandora()));
134 const TwoDSlidingFitResult slidingFitResult(pMuonCluster, m_slidingFitWindow, slidingFitPitch);
135
136 CartesianVector muonDirection(0.f, 0.f, 0.f);
137 slidingFitResult.GetGlobalDirection(slidingFitResult.GetLayerFitResultMap().begin()->second.GetGradient(), muonDirection);
138
139 const CartesianVector xAxis(1.f, 0.f, 0.f);
140 const bool isTransverse((muonDirection.GetOpeningAngle(xAxis) < m_minDeviationFromTransverse) ||
141 ((M_PI - muonDirection.GetOpeningAngle(xAxis)) < m_minDeviationFromTransverse));
142
143 if (isTransverse)
144 return false;
145
146 CartesianVector deltaRayVertex(0.f, 0.f, 0.f), muonVertex(0.f, 0.f, 0.f);
147 LArClusterHelper::GetClosestPositions(pDeltaRayCluster, pMuonCluster, deltaRayVertex, muonVertex);
148
149 CaloHitList minusMuonHits, minusDeltaRayHits, plusMuonHits, plusDeltaRayHits;
150 const CartesianVector minusPosition(muonVertex - (muonDirection * m_contaminationWindow));
151 const CartesianVector plusPosition(muonVertex + (muonDirection * m_contaminationWindow));
152
153 this->FindExtrapolatedHits(pMuonCluster, muonVertex, minusPosition, minusMuonHits);
154 this->FindExtrapolatedHits(pMuonCluster, muonVertex, plusPosition, plusMuonHits);
155 this->FindExtrapolatedHits(pDeltaRayCluster, muonVertex, minusPosition, minusDeltaRayHits);
156 this->FindExtrapolatedHits(pDeltaRayCluster, muonVertex, plusPosition, plusDeltaRayHits);
157
158 if ((minusMuonHits.size() < m_significantHitThreshold) && (plusMuonHits.size() < m_significantHitThreshold))
159 return true;
160
161 if ((minusMuonHits.size() < m_significantHitThreshold) && (minusDeltaRayHits.size() >= m_significantHitThreshold) &&
162 (plusDeltaRayHits.size() < m_significantHitThreshold) && (plusMuonHits.size() >= m_significantHitThreshold))
163 {
164 return true;
165 }
166
167 if ((plusMuonHits.size() < m_significantHitThreshold) && (plusDeltaRayHits.size() >= m_significantHitThreshold) &&
168 (minusDeltaRayHits.size() < m_significantHitThreshold) && (minusMuonHits.size() >= m_significantHitThreshold))
169 {
170 return true;
171 }
172
173 return false;
174}
175
176//------------------------------------------------------------------------------------------------------------------------------------------
177
178void DeltaRayRemovalTool::SplitMuonCluster(const TensorType::Element &element, const HitType hitType, const CaloHitList &deltaRayHits) const
179{
180 const Cluster *pDeltaRayCluster(element.GetCluster(hitType)), *pMuonCluster(nullptr);
181
182 if (m_pParentAlgorithm->GetMuonCluster(element.GetOverlapResult().GetCommonMuonPfoList(), hitType, pMuonCluster) != STATUS_CODE_SUCCESS)
183 throw StatusCodeException(STATUS_CODE_FAILURE);
184
186 m_pParentAlgorithm->UpdateUponDeletion(pDeltaRayCluster);
187
188 m_pParentAlgorithm->SplitMuonCluster(m_pParentAlgorithm->GetClusterListName(hitType), pMuonCluster, deltaRayHits, pDeltaRayCluster);
189
190 ClusterVector clusterVector;
191 PfoVector pfoVector;
192 clusterVector.push_back(pMuonCluster);
193 pfoVector.push_back(element.GetOverlapResult().GetCommonMuonPfoList().front());
194 clusterVector.push_back(pDeltaRayCluster);
195 pfoVector.push_back(nullptr);
196 m_pParentAlgorithm->UpdateForNewClusters(clusterVector, pfoVector);
197}
198
199//------------------------------------------------------------------------------------------------------------------------------------------
200
202{
204 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingFitWindow", m_slidingFitWindow));
205
206 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
207 XmlHelper::ReadValue(xmlHandle, "MinDeviationFromTransverse", m_minDeviationFromTransverse));
208
210 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ContaminationWindow", m_contaminationWindow));
211
212 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
213 XmlHelper::ReadValue(xmlHandle, "SignificantHitThreshold", m_significantHitThreshold));
214
216 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinDistanceFromMuon", m_minDistanceFromMuon));
217
219 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MaxDistanceToCollected", m_maxDistanceToCollected));
220
221 return STATUS_CODE_SUCCESS;
222}
223
224} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the delta ray removal tool class.
Header file for the cluster helper class.
Header file for the geometry helper class.
Header file for the lar two dimensional sliding fit result class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
static const pandora::PandoraSettings * GetSettings(const pandora::Algorithm &algorithm)
Get the pandora settings instance.
float m_maxDistanceToCollected
The maximim distance of a hit from the projected delta ray hits required for removal.
unsigned int m_significantHitThreshold
The threshold number of hits which define significant contimination.
virtual bool PassElementChecks(const TensorType::Element &element, const pandora::HitType hitType) const
Determine whether element satifies simple checks.
bool RemoveDeltaRayHits(const TensorType::ElementList &elementList) const
Remove hits from cosmic ray clusters that belong to a child delta ray.
DeltaRayRemovalTool()
Default constructor.
unsigned int m_slidingFitWindow
The sliding fit window used in cosmic ray parameterisations.
float m_contaminationWindow
The distance in which to search for delta ray contamination in the cosmic ray track.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
float m_minDistanceFromMuon
The minimum distance of a hit from the cosmic ray track required for removal.
void SplitMuonCluster(const TensorType::Element &element, const pandora::HitType hitType, const pandora::CaloHitList &deltaRayHits) const
Remove collected delta ray hits from the cosmic ray pfo.
bool Run(ThreeViewDeltaRayMatchingAlgorithm *const pAlgorithm, TensorType &overlapTensor)
Run the algorithm tool.
bool IsContaminated(const TensorType::Element &element, const pandora::HitType hitType) const
Determine whether the cosmic ray cluster under investigation has delta ray contamination.
float m_minDeviationFromTransverse
The minimum deviation from transverse required to avoid mistakes.
ThreeViewDeltaRayMatchingAlgorithm::MatchingType::TensorType TensorType
ThreeViewDeltaRayMatchingAlgorithm * m_pParentAlgorithm
Address of the parent matching algorithm.
static void GetClosestPositions(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, pandora::CartesianVector &position1, pandora::CartesianVector &position2)
Get pair of closest positions for a pair of clusters.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster)
Update to reflect cluster deletion.
pandora::StatusCode CollectHitsFromMuon(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pThirdViewCluster, const pandora::ParticleFlowObject *const pParentMuon, const float minDistanceFromMuon, const float maxDistanceToCollected, pandora::CaloHitList &collectedHits) const
In one view, pull out any hits from a cosmic ray cluster that belong to the child delta ray cluster.
void UpdateForNewClusters(const pandora::ClusterVector &newClusterVector, const pandora::PfoVector &pfoVector)
Add a new cluster to algorithm ownership maps and, if it a delta ray cluster, to the underlying match...
void SplitMuonCluster(const std::string &clusterListName, const pandora::Cluster *const pMuonCluster, const pandora::CaloHitList &collectedHits, const pandora::Cluster *&pDeltaRayCluster) const
Move a list of hits from a cosmic ray cluster into the given child delta ray cluster.
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...
const std::string & GetClusterListName(const pandora::HitType hitType) const
Get the cluster list name corresponding to a specified hit type.
virtual bool PassElementChecks(const TensorType::Element &element, const pandora::HitType hitType) const =0
Determine whether element satifies simple checks.
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.
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...
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...
const LayerFitResultMap & GetLayerFitResultMap() const
Get the layer fit result map.
void GetGlobalDirection(const float dTdL, pandora::CartesianVector &direction) const
Get global direction coordinates for given sliding linear fit gradient.
CartesianVector class.
float GetOpeningAngle(const CartesianVector &rhs) const
Get the opening angle of the cartesian vector with respect to a second cartesian vector.
Cluster class.
Definition Cluster.h:31
bool ShouldDisplayAlgorithmInfo() const
Whether to display algorithm information during processing.
ParticleFlowObject class.
const std::string & GetType() const
Get the type.
Definition Process.h:102
const Pandora & GetPandora() const
Get the associated pandora instance.
Definition Process.h:116
const std::string & GetInstanceName() const
Get the instance name.
Definition Process.h:109
StatusCodeException class.
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< const Cluster * > ClusterVector
std::vector< const ParticleFlowObject * > PfoVector
std::unordered_set< const Cluster * > ClusterSet
MANAGED_CONTAINER< const CaloHit * > CaloHitList
StatusCode
The StatusCode enum.