LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ShowerHierarchyMopUpAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 StatusCode ShowerHierarchyMopUpAlgorithm::Run()
21 {
22  const PfoList *pLeadingPfoList(nullptr);
23  PANDORA_RETURN_RESULT_IF_AND_IF(
24  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, m_leadingPfoListName, pLeadingPfoList));
25 
26  if (!pLeadingPfoList || pLeadingPfoList->empty())
27  {
28  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
29  std::cout << "ShowerHierarchyMopUpAlgorithm: unable to find pfos in provided list, " << m_leadingPfoListName << std::endl;
30 
31  return STATUS_CODE_SUCCESS;
32  }
33 
34  PfoList parentShowerPfos;
35  this->FindParentShowerPfos(pLeadingPfoList, parentShowerPfos);
36  this->PerformPfoMerges(parentShowerPfos);
37 
38  return STATUS_CODE_SUCCESS;
39 }
40 
41 //------------------------------------------------------------------------------------------------------------------------------------------
42 
43 void ShowerHierarchyMopUpAlgorithm::FindParentShowerPfos(const PfoList *const pLeadingPfoList, PfoList &parentShowerPfos) const
44 {
45  for (const Pfo *const pLeadingPfo : *pLeadingPfoList)
46  {
47  this->FindParentShowerPfos(pLeadingPfo, parentShowerPfos);
48  }
49 }
50 
51 //------------------------------------------------------------------------------------------------------------------------------------------
52 
53 void ShowerHierarchyMopUpAlgorithm::FindParentShowerPfos(const Pfo *const pPfo, PfoList &parentShowerPfos) const
54 {
55  if (LArPfoHelper::IsShower(pPfo))
56  {
57  if (pPfo->GetDaughterPfoList().empty())
58  return;
59 
60  if (parentShowerPfos.end() != std::find(parentShowerPfos.begin(), parentShowerPfos.end(), pPfo))
61  throw StatusCodeException(STATUS_CODE_ALREADY_PRESENT);
62 
63  parentShowerPfos.push_back(pPfo);
64  }
65  else
66  {
67  for (const Pfo *const pDaughterPfo : pPfo->GetDaughterPfoList())
68  this->FindParentShowerPfos(pDaughterPfo, parentShowerPfos);
69  }
70 }
71 
72 //------------------------------------------------------------------------------------------------------------------------------------------
73 
74 void ShowerHierarchyMopUpAlgorithm::PerformPfoMerges(const PfoList &parentShowerPfos) const
75 {
76  for (const Pfo *const pParentShowerPfo : parentShowerPfos)
77  {
78  PfoList downstreamPfos;
79  LArPfoHelper::GetAllDownstreamPfos(pParentShowerPfo, downstreamPfos);
80 
81  for (const Pfo *const pDownstreamPfo : downstreamPfos)
82  {
83  if (pDownstreamPfo != pParentShowerPfo)
84  this->MergeAndDeletePfos(pParentShowerPfo, pDownstreamPfo);
85  }
86  }
87 }
88 
89 //------------------------------------------------------------------------------------------------------------------------------------------
90 
91 StatusCode ShowerHierarchyMopUpAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
92 {
93  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "LeadingPfoListName", m_leadingPfoListName));
94 
95  return PfoMopUpBaseAlgorithm::ReadSettings(xmlHandle);
96 }
97 
98 } // namespace lar_content
Header file for the pfo helper class.
Header file for the shower hierarchy mop up algorithm class.