9 #include "Pandora/AlgorithmHeaders.h" 21 DeltaRayParentAlgorithm::DeltaRayParentAlgorithm() : m_distanceForMatching(5.
f)
29 const PfoList *pMuonPfoList(
nullptr);
30 PANDORA_THROW_RESULT_IF_AND_IF(
31 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_muonPfoListName, pMuonPfoList));
33 if (!pMuonPfoList || pMuonPfoList->empty())
34 return STATUS_CODE_SUCCESS;
36 const PfoList *pDeltaRayPfoList(
nullptr);
37 PANDORA_THROW_RESULT_IF_AND_IF(
38 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_deltaRayPfoListName, pDeltaRayPfoList));
40 if (!pDeltaRayPfoList || pDeltaRayPfoList->empty())
41 return STATUS_CODE_SUCCESS;
46 PfoVector deltaRayPfoVector(pDeltaRayPfoList->begin(), pDeltaRayPfoList->end());
49 for (
const ParticleFlowObject *
const pPfo : deltaRayPfoVector)
51 if (!pPfo->GetParentPfoList().empty())
54 const ParticleFlowObject *pParentPfo(
nullptr);
60 this->
AssignToParentPfo(pMuonPfoList, pDeltaRayPfoList, pPfo, pParentPfo, pfoLengthMap);
63 return STATUS_CODE_SUCCESS;
70 for (
const ParticleFlowObject *
const pPfo : *muonPfoList)
73 for (
const ParticleFlowObject *
const pPfo : *deltaRayPfoList)
83 if (currentIter == pfoLengthMap.end())
84 throw StatusCodeException(STATUS_CODE_FAILURE);
86 PfoVector allPfoVector;
88 for (
auto &
entry : pfoLengthMap)
91 const float lengthSquared(currentIter->second);
94 for (
const ParticleFlowObject *
const pTestParent : allPfoVector)
96 if (pTestParent == pPfo)
101 if (testIter == pfoLengthMap.end())
102 throw StatusCodeException(STATUS_CODE_FAILURE);
104 if (testIter->second < lengthSquared)
109 if (this->
GetTwoDSeparation(pPfo, pTestParent, distance) == STATUS_CODE_NOT_FOUND)
112 if (distance < bestDistance)
114 pParentPfo = pTestParent;
124 ClusterList clusterListU1, clusterListV1, clusterListW1;
125 ClusterList clusterListU2, clusterListV2, clusterListW2;
137 if (!clusterListU1.empty() && !clusterListU2.empty())
143 if (!clusterListV1.empty() && !clusterListV2.empty())
149 if (!clusterListW1.empty() && !clusterListW2.empty())
155 if (numViews < std::numeric_limits<float>::epsilon())
156 return STATUS_CODE_NOT_FOUND;
158 separation = distance / numViews;
160 return STATUS_CODE_SUCCESS;
166 const ParticleFlowObject *
const pPfo,
const ParticleFlowObject *
const pParentPfo,
PfoLengthMap &pfoLengthMap)
const 168 if (std::find(pMuonPfoList->begin(), pMuonPfoList->end(), pParentPfo) != pMuonPfoList->end())
169 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SetPfoParentDaughterRelationship(*
this, pParentPfo, pPfo));
171 if (std::find(pDeltaRayPfoList->begin(), pDeltaRayPfoList->end(), pParentPfo) != pDeltaRayPfoList->end())
173 ClusterList pfoClusters;
176 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete(*
this, pPfo,
m_deltaRayPfoListName));
178 for (
const Cluster *
const pCluster : pfoClusters)
179 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*
this, pParentPfo, pCluster));
189 for (
const ParticleFlowObject *
const pPfoToRemove : pfosToRemove)
193 if (iter == pfoLengthMap.end())
194 throw StatusCodeException(STATUS_CODE_FAILURE);
196 pfoLengthMap.erase(iter);
206 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"MuonPfoListName",
m_muonPfoListName));
208 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"DeltaRayPfoListName",
m_deltaRayPfoListName));
210 PANDORA_RETURN_RESULT_IF_AND_IF(
211 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"DistanceForMatching",
m_distanceForMatching));
213 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.
QCollection::Item first()
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.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
static int max(int a, int b)
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.