LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
BranchAssociatedPfosTool.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
13 
16 
18 
19 using namespace pandora;
20 
21 namespace lar_content
22 {
23 
26 
27 BranchAssociatedPfosTool::BranchAssociatedPfosTool() :
28  m_minNeutrinoVertexDistance(5.f),
29  m_trackBranchAdditionFraction(0.4f),
30  m_maxParentClusterDistance(3.5f)
31 {
32 }
33 
34 //------------------------------------------------------------------------------------------------------------------------------------------
35 
36 void BranchAssociatedPfosTool::Run(NeutrinoHierarchyAlgorithm *const pAlgorithm, const Vertex *const pNeutrinoVertex, PfoInfoMap &pfoInfoMap)
37 {
38  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
39  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
40 
41  bool associationsMade(true);
42 
43  while (associationsMade)
44  {
45  associationsMade = false;
46  PfoVector assignedPfos, unassignedPfos;
47  pAlgorithm->SeparatePfos(pfoInfoMap, assignedPfos, unassignedPfos);
48 
49  if (unassignedPfos.empty())
50  break;
51 
52  // ATTN May want to reconsider precise association mechanics for complex situations
53  PfoSet recentlyAssigned;
54 
55  for (const ParticleFlowObject *const pParentPfo : assignedPfos)
56  {
57  PfoInfo *const pParentPfoInfo(pfoInfoMap.at(pParentPfo));
58  const Cluster *const pParentCluster3D(pParentPfoInfo->GetCluster3D());
59 
60  const bool parentIsTrack(LArPfoHelper::IsTrack(pParentPfo));
61  const ThreeDSlidingFitResult &parentFitResult(*(pParentPfoInfo->GetSlidingFitResult3D()));
62 
63  const float parentLength3D((parentFitResult.GetGlobalMinLayerPosition() - parentFitResult.GetGlobalMaxLayerPosition()).GetMagnitude());
64  const CartesianVector &parentVertexPosition(pParentPfoInfo->IsInnerLayerAssociated() ? parentFitResult.GetGlobalMinLayerPosition() :
65  parentFitResult.GetGlobalMaxLayerPosition());
66 
67  for (const ParticleFlowObject *const pPfo : unassignedPfos)
68  {
69  if (recentlyAssigned.count(pPfo))
70  continue;
71 
72  PfoInfo *const pPfoInfo(pfoInfoMap.at(pPfo));
73  const LArPointingCluster pointingCluster(*(pPfoInfo->GetSlidingFitResult3D()));
74 
75  const float dNeutrinoVertex(std::min((pointingCluster.GetInnerVertex().GetPosition() - pNeutrinoVertex->GetPosition()).GetMagnitude(),
76  (pointingCluster.GetOuterVertex().GetPosition() - pNeutrinoVertex->GetPosition()).GetMagnitude()));
77 
78  if (dNeutrinoVertex < m_minNeutrinoVertexDistance)
79  continue;
80 
81  const float dParentVertex(std::min((pointingCluster.GetInnerVertex().GetPosition() - parentVertexPosition).GetMagnitude(),
82  (pointingCluster.GetOuterVertex().GetPosition() - parentVertexPosition).GetMagnitude()));
83 
84  if (parentIsTrack && (dParentVertex < m_trackBranchAdditionFraction * parentLength3D))
85  continue;
86 
87  const float dInnerVertex(LArClusterHelper::GetClosestDistance(pointingCluster.GetInnerVertex().GetPosition(), pParentCluster3D));
88  const float dOuterVertex(LArClusterHelper::GetClosestDistance(pointingCluster.GetOuterVertex().GetPosition(), pParentCluster3D));
89 
90  if ((dInnerVertex < m_maxParentClusterDistance) || (dOuterVertex < m_maxParentClusterDistance))
91  {
92  associationsMade = true;
93  pParentPfoInfo->AddDaughterPfo(pPfoInfo->GetThisPfo());
94  pPfoInfo->SetParentPfo(pParentPfoInfo->GetThisPfo());
95  pPfoInfo->SetInnerLayerAssociation(dInnerVertex < dOuterVertex);
96  recentlyAssigned.insert(pPfoInfo->GetThisPfo());
97  }
98  }
99  }
100  }
101 }
102 
103 //------------------------------------------------------------------------------------------------------------------------------------------
104 
105 StatusCode BranchAssociatedPfosTool::ReadSettings(const TiXmlHandle xmlHandle)
106 {
107  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
108  "MinNeutrinoVertexDistance", m_minNeutrinoVertexDistance));
109 
110  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
111  "TrackBranchAdditionFraction", m_trackBranchAdditionFraction));
112 
113  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
114  "MaxParentClusterDistance", m_maxParentClusterDistance));
115 
116  return STATUS_CODE_SUCCESS;
117 }
118 
119 } // namespace lar_content
Header file for the pfo helper class.
std::unordered_map< const pandora::ParticleFlowObject *, PfoInfo * > PfoInfoMap
Header file for the lar pointing cluster class.
NeutrinoHierarchyAlgorithm::PfoInfoMap PfoInfoMap
float m_maxParentClusterDistance
Branch association: max distance from branch vertex to a hit in parent 3D cluster.
Header file for the branch associated pfos tool class.
void Run(NeutrinoHierarchyAlgorithm *const pAlgorithm, const pandora::Vertex *const pNeutrinoVertex, NeutrinoHierarchyAlgorithm::PfoInfoMap &pfoInfoMap)
Run the algorithm tool.
void SeparatePfos(const NeutrinoHierarchyAlgorithm::PfoInfoMap &pfoInfoMap, pandora::PfoVector &assignedPfos, pandora::PfoVector &unassignedPfos) const
Query the pfo info map and separate/extract pfos currently either acting as parents or associated wit...
LArPointingCluster class.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
float m_minNeutrinoVertexDistance
Branch association: min distance from branch vertex to neutrino vertex.
TFile f
Definition: plotHisto.C:6
Header file for the cluster helper class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
const pandora::CartesianVector & GetGlobalMaxLayerPosition() const
Get global position corresponding to the fit result in maximum fit layer.
Header file for the lar three dimensional sliding fit result class.
Int_t min
Definition: plot.C:26
float m_trackBranchAdditionFraction
Branch association: min fraction of length along parent track before association allowed.
NeutrinoHierarchyAlgorithm::PfoInfo PfoInfo
const pandora::CartesianVector & GetGlobalMinLayerPosition() const
Get global position corresponding to the fit result in minimum fit layer.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.