9 #include "Pandora/AlgorithmHeaders.h" 21 DeltaRayParentAlgorithm::DeltaRayParentAlgorithm() :
22 m_distanceForMatching(5.
f)
30 const PfoList *pMuonPfoList(
nullptr);
31 PANDORA_THROW_RESULT_IF_AND_IF(
32 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_muonPfoListName, pMuonPfoList));
34 if (!pMuonPfoList || pMuonPfoList->empty())
35 return STATUS_CODE_SUCCESS;
37 const PfoList *pDeltaRayPfoList(
nullptr);
38 PANDORA_THROW_RESULT_IF_AND_IF(
39 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_deltaRayPfoListName, pDeltaRayPfoList));
41 if (!pDeltaRayPfoList || pDeltaRayPfoList->empty())
42 return STATUS_CODE_SUCCESS;
47 PfoVector deltaRayPfoVector(pDeltaRayPfoList->begin(), pDeltaRayPfoList->end());
50 for (
const ParticleFlowObject *
const pPfo : deltaRayPfoVector)
52 if (!pPfo->GetParentPfoList().empty())
55 const ParticleFlowObject *pParentPfo(
nullptr);
61 this->
AssignToParentPfo(pMuonPfoList, pDeltaRayPfoList, pPfo, pParentPfo, pfoLengthMap);
64 return STATUS_CODE_SUCCESS;
71 for (
const ParticleFlowObject *
const pPfo : *muonPfoList)
74 for (
const ParticleFlowObject *
const pPfo : *deltaRayPfoList)
84 if (currentIter == pfoLengthMap.end())
85 throw StatusCodeException(STATUS_CODE_FAILURE);
87 PfoVector allPfoVector;
89 for (
auto &entry : pfoLengthMap)
90 allPfoVector.push_back(entry.first);
92 const float lengthSquared(currentIter->second);
95 for (
const ParticleFlowObject *
const pTestParent : allPfoVector)
97 if (pTestParent == pPfo)
102 if (testIter == pfoLengthMap.end())
103 throw StatusCodeException(STATUS_CODE_FAILURE);
105 if (testIter->second < lengthSquared)
108 float distance(std::numeric_limits<float>::max());
110 if (this->
GetTwoDSeparation(pPfo, pTestParent, distance) == STATUS_CODE_NOT_FOUND)
113 if (distance < bestDistance)
115 pParentPfo = pTestParent;
116 bestDistance = distance;
125 ClusterList clusterListU1, clusterListV1, clusterListW1;
126 ClusterList clusterListU2, clusterListV2, clusterListW2;
136 float numViews(0.
f), distance(0.
f);
138 if (!clusterListU1.empty() && !clusterListU2.empty())
144 if (!clusterListV1.empty() && !clusterListV2.empty())
150 if (!clusterListW1.empty() && !clusterListW2.empty())
156 if (numViews < std::numeric_limits<float>::epsilon())
157 return STATUS_CODE_NOT_FOUND;
159 separation = distance / numViews;
161 return STATUS_CODE_SUCCESS;
167 const ParticleFlowObject *
const pPfo,
const ParticleFlowObject *
const pParentPfo,
PfoLengthMap &pfoLengthMap)
const 169 if (std::find(pMuonPfoList->begin(), pMuonPfoList->end(), pParentPfo) != pMuonPfoList->end())
170 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SetPfoParentDaughterRelationship(*
this, pParentPfo, pPfo));
172 if (std::find(pDeltaRayPfoList->begin(), pDeltaRayPfoList->end(), pParentPfo) != pDeltaRayPfoList->end())
174 ClusterList pfoClusters;
177 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete(*
this, pPfo,
m_deltaRayPfoListName));
179 for (
const Cluster *
const pCluster : pfoClusters)
180 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*
this, pParentPfo, pCluster));
190 for (
const ParticleFlowObject *
const pPfoToRemove : pfosToRemove)
194 if (iter == pfoLengthMap.end())
195 throw StatusCodeException(STATUS_CODE_FAILURE);
197 pfoLengthMap.erase(iter);
207 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"MuonPfoListName",
m_muonPfoListName));
209 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"DeltaRayPfoListName",
m_deltaRayPfoListName));
211 PANDORA_RETURN_RESULT_IF_AND_IF(
212 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"DistanceForMatching",
m_distanceForMatching));
214 return STATUS_CODE_SUCCESS;
static bool SortByNHits(const pandora::ParticleFlowObject *const pLhs, const pandora::ParticleFlowObject *const pRhs)
Sort pfos by number of constituent hits.
Header file for the pfo helper class.
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.
static void GetTwoDClusterList(const pandora::ParticleFlowObject *const pPfo, pandora::ClusterList &clusterList)
Get the list of 2D clusters from an input pfo.
pandora::StatusCode GetTwoDSeparation(const pandora::ParticleFlowObject *const pPfo1, const pandora::ParticleFlowObject *const pPfo2, float &separation) const
Get distance between two Pfos using 2D clusters.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
pandora::StatusCode Run()
static float GetTwoDLengthSquared(const pandora::ParticleFlowObject *const pPfo)
Calculate length of Pfo using 2D clusters.
Header file for the cluster helper class.
std::string m_muonPfoListName
The list of reconstructed muon pfos.
float m_distanceForMatching
The maximum separation of a delta ray pfo from its parent.
void AssignToParentPfo(const pandora::PfoList *const muonPfoList, const pandora::PfoList *const deltaRayPfoList, const pandora::ParticleFlowObject *const pPfo, const pandora::ParticleFlowObject *const pParentPfo, PfoLengthMap &pfoLengthMap) const
Apply parent-child link (if parent is a cosmic ray create parent-child link else merge the delta ray ...
void UpdatePfoLengthMap(const pandora::PfoList &pfosToRemove, const pandora::ParticleFlowObject *const pPfoToAdd, PfoLengthMap &pfoLengthMap) const
Update the pfo length map after a parent-child delta ray merge.
void FindParentPfo(const PfoLengthMap &pfoLengthMap, const pandora::ParticleFlowObject *const pPfo, const pandora::ParticleFlowObject *&pParentPfo) const
Identify the parent pfo of a given delta ray pfo (can be either a cosmic ray or delta ray pfo) ...
std::map< const pandora::ParticleFlowObject *, float > PfoLengthMap
void InitialisePfoLengthMap(const pandora::PfoList *const muonPfoList, const pandora::PfoList *const deltaRayPfoList, PfoLengthMap &pfoLengthMap) const
Initialise the delta ray pfo length map.
std::string m_deltaRayPfoListName
The list of reconstructed delta ray pfos.
Header file for the delta ray parent class.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.