25 m_nMaxMatrixToolRepeats(10),
26 m_minClusterCaloHits(3),
27 m_maxDistanceFromPrediction(2.f),
28 m_maxGoodMatchReducedChiSquared(1.f),
29 m_minDistanceFromMuon(1.f),
30 m_maxDistanceToCollected(1.f)
44 if ((hitTypeIndex != 1) && (hitTypeIndex != 2))
47 hitTypeVector.push_back(hitType);
59 if ((hitTypeIndex != 1) && (hitTypeIndex != 2))
60 return element.GetOverlapResult().GetBestMatchedAvailableCluster();
62 return hitTypeIndex == 1 ? element.GetCluster1() : element.GetCluster2();
80 this->
GetMatchingControl().GetOverlapMatrix().SetOverlapResult(pCluster1, pCluster2, overlapResult);
88 float xMin1(0.f), xMax1(0.f), xMin2(0.f), xMax2(0.f);
92 const float xOverlap(std::min(xMax1, xMax2) - std::max(xMin1, xMin2));
94 if (xOverlap < std::numeric_limits<float>::epsilon())
95 return STATUS_CODE_NOT_FOUND;
100 if (commonMuonPfoList.empty())
101 return STATUS_CODE_NOT_FOUND;
106 if (status != STATUS_CODE_SUCCESS)
113 if (matchedClusterList.empty())
114 return STATUS_CODE_NOT_FOUND;
116 float reducedChiSquared(std::numeric_limits<float>::max());
117 const Cluster *
const pBestMatchedCluster =
118 this->
GetBestMatchedCluster(pCluster1, pCluster2, commonMuonPfoList, matchedClusterList, reducedChiSquared);
121 if (pBestMatchedCluster && (pBestMatchedCluster->
IsAvailable()))
126 if (hitSum13 > hitSum12)
127 return STATUS_CODE_NOT_FOUND;
131 if (hitSum23 > hitSum12)
132 return STATUS_CODE_NOT_FOUND;
136 overlapResult =
TwoViewDeltaRayOverlapResult(xOverlapObject, commonMuonPfoList, pBestMatchedCluster, matchedClusterList, reducedChiSquared);
138 return STATUS_CODE_SUCCESS;
145 ClusterList consideredClusters1, consideredClusters2;
146 PfoList nearbyMuonPfos1, nearbyMuonPfos2;
150 if (nearbyMuonPfos1.empty())
155 if (nearbyMuonPfos2.empty())
162 if (pNearbyMuon1 == pNearbyMuon2)
163 commonMuonPfoList.push_back(pNearbyMuon1);
176 if (!pInputClusterList || pInputClusterList->empty())
179 for (
const Cluster *
const pCluster : *pInputClusterList)
186 float reducedChiSquared(0.f);
193 matchedClusters.push_back(pCluster);
200 const PfoList &commonMuonPfoList,
const ClusterList &matchedClusters,
float &reducedChiSquared)
const
202 const Cluster *pBestMatchedCluster(
nullptr);
204 if (matchedClusters.empty())
205 return pBestMatchedCluster;
213 unsigned int highestNHits(0);
215 for (
const Cluster *
const pMatchedCluster : matchedClusters)
217 if (!pMatchedCluster->IsAvailable())
219 if (std::find(muonClusterList.begin(), muonClusterList.end(), pMatchedCluster) == muonClusterList.end())
223 if (pMatchedCluster->GetNCaloHits() > highestNHits)
225 highestNHits = pMatchedCluster->GetNCaloHits();
226 pBestMatchedCluster = pMatchedCluster;
230 if (!pBestMatchedCluster)
231 return pBestMatchedCluster;
233 if (this->
PerformThreeViewMatching(pCluster1, pCluster2, pBestMatchedCluster, reducedChiSquared) == STATUS_CODE_NOT_FOUND)
236 return pBestMatchedCluster;
245 protoParticle.
m_clusterList.push_back(protoParticleElement.GetCluster1());
246 protoParticle.
m_clusterList.push_back(protoParticleElement.GetCluster2());
248 const Cluster *
const pBestMatchedCluster(protoParticleElement.GetOverlapResult().GetBestMatchedCluster());
250 if (pBestMatchedCluster)
255 return (this->
CreatePfos(protoParticleVector));
262 const PfoList &commonMuonPfoList(element.GetOverlapResult().GetCommonMuonPfoList());
263 const Cluster *
const pBestMatchedCluster(element.GetOverlapResult().GetBestMatchedCluster());
272 if (std::find(muonClusterList.begin(), muonClusterList.end(), pBestMatchedCluster) != muonClusterList.end())
273 pMatchedMuonPfo = pMuonPfo;
276 const Cluster *pThirdViewCluster(pMatchedMuonPfo ?
nullptr : pBestMatchedCluster);
290 pThirdViewCluster = element.GetOverlapResult().GetBestMatchedAvailableCluster();
294 if (!pThirdViewCluster)
308 element.GetCluster1()->GetOrderedCaloHitList().FillCaloHitList(caloHitList1);
309 element.GetCluster2()->GetOrderedCaloHitList().FillCaloHitList(caloHitList2);
312 ClusterList matchedClusters(element.GetOverlapResult().GetMatchedClusterList());
316 if (std::find(matchedClusters.begin(), matchedClusters.end(), pSeedCluster) != matchedClusters.end())
317 checkedClusters.insert(pSeedCluster);
319 while (checkedClusters.size() != matchedClusters.size())
321 const Cluster *pClusterToDelete(
nullptr);
322 unsigned int highestHit(0);
324 for (
const Cluster *
const pMatchedCluster : matchedClusters)
326 if (checkedClusters.count(pMatchedCluster))
329 if (pMatchedCluster->GetNCaloHits() > highestHit)
331 pClusterToDelete = pMatchedCluster;
336 if (!pClusterToDelete)
339 checkedClusters.insert(pClusterToDelete);
348 float reducedChiSquared(std::numeric_limits<float>::max());
351 if (status == STATUS_CODE_NOT_FOUND)
371 for (
auto [pCluster1, overlapList] : theMatrix)
373 for (
auto [pCluster2, overlapResult] : overlapList)
375 ClusterList matchedClusters(overlapResult.GetMatchedClusterList());
377 auto matchedClustersIter(std::find(matchedClusters.begin(), matchedClusters.end(), pModifiedCluster));
379 if (matchedClustersIter == matchedClusters.end())
382 float tempReducedChiSquared(std::numeric_limits<float>::max());
388 matchedClusters.erase(matchedClustersIter);
390 float reducedChiSquared(std::numeric_limits<float>::max());
391 const Cluster *
const pBestMatchedCluster =
392 this->
GetBestMatchedCluster(pCluster1, pCluster2, overlapResult.GetCommonMuonPfoList(), matchedClusters, reducedChiSquared);
395 overlapResult.GetXOverlap(), overlapResult.GetCommonMuonPfoList(), pBestMatchedCluster, matchedClusters, reducedChiSquared);
396 theMatrix.ReplaceOverlapResult(pCluster1, pCluster2, newOverlapResult);
406 unsigned int repeatCounter(0);
411 const bool repeatTools(pTool->
Run(
this, this->GetMatchingControl().GetOverlapMatrix()));
414 repeatCounter = repeatTools ? repeatCounter + 1 : repeatCounter;
432 for (
auto algorithmTool : algorithmToolVector)
436 if (!pDeltaRayMatrixTool)
437 return STATUS_CODE_INVALID_PARAMETER;
Header file for the cluster helper class.
Header file for the muon leading helper class.
Header file for the pfo helper class.
Header file for the lar two dimensional sliding fit result class.
#define PANDORA_THROW_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
static pandora::StatusCode ReplaceCurrentList(const pandora::Algorithm &algorithm, const std::string &newListName)
Replace the current list with a pre-saved list; use this new list as a permanent replacement for the ...
static pandora::StatusCode MergeAndDeleteClusters(const pandora::Algorithm &algorithm, const pandora::Cluster *const pClusterToEnlarge, const pandora::Cluster *const pClusterToDelete)
Merge two clusters in the current list, enlarging one cluster and deleting the second.
static pandora::StatusCode GetList(const pandora::Algorithm &algorithm, const std::string &listName, const T *&pT)
Get a named list.
DeltaRayTensorTool class.
virtual bool Run(TwoViewDeltaRayMatchingAlgorithm *const pAlgorithm, MatrixType &matrixTensor)=0
Run the algorithm tool.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static float GetClosestDistance(const pandora::Cluster *const pCluster, const pandora::CartesianPointVector &cartesianPointVector)
Get closest distance between a specified cluster and list of positions.
static void GetClusters(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::ClusterList &clusterList)
Get a list of clusters of a particular hit type from a list of pfos.
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 GetNearbyMuonPfos(const pandora::Cluster *const pCluster, pandora::ClusterList &consideredClusters, pandora::PfoList &nearbyMuonPfos) const
Use the cluster proximity map to travel along paths of nearby clusters finding the cosmic ray cluster...
pandora::StatusCode PerformThreeViewMatching(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3, float &reducedChiSquared) const
To determine how well three clusters (one in each view) map onto one another expressing this in terms...
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 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.
bool CreatePfos(ProtoParticleVector &protoParticleVector)
Create delta ray pfos maxmising completeness by searching for and merging in any stray clusters.
std::vector< pandora::HitType > HitTypeVector
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
MatchingType & GetMatchingControl()
Get the matching control.
void ExamineOverlapContainer()
Examine contents of overlap container, collect together best-matching 2D particles and modify cluster...
void CalculateOverlapResult(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3)
Calculate cluster overlap result and store in container.
void CollectThirdViewClusters(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::CartesianPointVector &projectedPositions, pandora::ClusterList &matchedClusters) const
Collect the available and unavailable third view clusters that lie close to the projected delta ray h...
TwoViewDeltaRayMatchingAlgorithm()
Default constructor.
bool CreatePfo(const MatrixType::Element &element)
Create delta ray pfos out of a given element, merging the third view clusters together and adding in ...
float m_minDistanceFromMuon
The minimum distance of a hit from the cosmic ray track required for removal.
MatrixToolVector m_algorithmToolVector
The algorithm tool vector.
const pandora::Cluster * GetCluster(const MatrixType::Element &element, const pandora::HitType hitType)
Get the address of the given hit type cluster.
float m_maxDistanceFromPrediction
The maximum distance of a matched cluster from the third view projection points.
unsigned int m_minClusterCaloHits
The threshold number of hits for a cluster to be considered.
HitTypeVector GetHitTypeVector()
Obtain the HitTypeVector of input views.
void UpdateForThirdViewClusterModification(const pandora::Cluster *const pModifiedCluster, const bool isMuon)
Update the matrix after a third view cluster modification - remove delta ray clusters and reassess th...
const std::string & GetThirdViewClusterListName() const
Get the name of the third view clusters.
void FindCommonMuonParents(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, pandora::PfoList &commonMuonPfoList) const
Find the cosmic ray pfos that, in each view, lie close to the clusters of the matrix element.
float m_maxDistanceToCollected
The maximim distance of a hit from the projected delta ray hits required for removal.
const pandora::Cluster * GetBestMatchedCluster(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::PfoList &commonMuonPfoList, const pandora::ClusterList &matchedClusters, float &reducedChiSquared) const
Determine the best matched third view cluster and calculate the reduced chi-squared value of the thre...
void FormThirdViewCluster(const MatrixType::Element &element, ProtoParticle &protoParticle)
Form the third view cluster by removing hits from cosmic ray clusters and merging the matched cluster...
virtual bool DoesClusterPassTensorThreshold(const pandora::Cluster *const pCluster) const
To check whether a given cluster meets the requirements to be added into the matching container (tens...
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
float m_maxGoodMatchReducedChiSquared
The maximum reduced chi squared value of a good 1:1:1 match.
unsigned int m_nMaxMatrixToolRepeats
The maximum number of repeat loops over matrix tools.
std::string m_reclusteringAlgorithmName
The name of the clustering algorithm to be used to recluster created delta ray remnants.
std::string m_inputClusterListName
The name of the cluster list in the view in which to project into.
void MergeThirdView(const MatrixType::Element &element, const pandora::Cluster *const pSeedCluster)
Starting with an input seed cluster, sequentially merge in matched clusters that retain a good reduce...
TwoViewDeltaRayOverlapResult class.
bool IsInitialized() const
Whether the track overlap result has been initialized.
bool IsAvailable() const
Whether the cluster is available to be added to a particle flow object.
unsigned int GetNCaloHits() const
Get the number of calo hits in the cluster.
const OrderedCaloHitList & GetOrderedCaloHitList() const
Get the ordered calo hit list.
void GetClusterSpanX(float &xmin, float &xmax) const
Get minimum and maximum X positions of the calo hits in this cluster.
void FillCaloHitList(CaloHitList &caloHitList) const
Fill a provided calo hit list with all the calo hits in the ordered calo hit list.
ParticleFlowObject class.
StatusCodeException class.
static StatusCode ProcessAlgorithm(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &description, std::string &algorithmName)
Process an algorithm described in an xml element with a matching "description = .....
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
static StatusCode ProcessAlgorithmToolList(const Algorithm &algorithm, const TiXmlHandle &xmlHandle, const std::string &listName, AlgorithmToolVector &algorithmToolVector)
Process a list of algorithms tools in an xml file.
std::vector< ProtoParticle > ProtoParticleVector
pandora::ClusterList m_clusterList
List of 2D clusters in a 3D proto particle.
HitType
Calorimeter hit type enum.
MANAGED_CONTAINER< const Cluster * > ClusterList
std::vector< CartesianVector > CartesianPointVector
std::vector< AlgorithmTool * > AlgorithmToolVector
std::unordered_set< const Cluster * > ClusterSet
MANAGED_CONTAINER< const CaloHit * > CaloHitList
StatusCode
The StatusCode enum.
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList