SlicingAlgorithm.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArControlFlow/SlicingAlgorithm.cc
3  *
4  * @brief Implementation of the slicing algorithm class.
5  *
6  * $Log: $
7  */
8 
9 #include "Api/PandoraApi.h"
10 
11 #include "Pandora/AlgorithmHeaders.h"
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 SlicingAlgorithm::SlicingAlgorithm() : m_pEventSlicingTool(nullptr)
21 {
22 }
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
27 {
28  SliceList sliceList;
30  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RunDaughterAlgorithm(*this, m_slicingListDeletionAlgorithm));
31 
32  if (sliceList.empty())
33  return STATUS_CODE_SUCCESS;
34 
35  std::string clusterListName;
36  const ClusterList *pClusterList(nullptr);
37  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pClusterList, clusterListName));
38 
39  std::string pfoListName;
40  const PfoList *pPfoList(nullptr);
41  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pPfoList, pfoListName));
42 
43  for (const Slice &slice : sliceList)
44  {
45  const Cluster *pClusterU(nullptr), *pClusterV(nullptr), *pClusterW(nullptr);
46  PandoraContentApi::Cluster::Parameters clusterParametersU, clusterParametersV, clusterParametersW;
47  clusterParametersU.m_caloHitList = slice.m_caloHitListU;
48  clusterParametersV.m_caloHitList = slice.m_caloHitListV;
49  clusterParametersW.m_caloHitList = slice.m_caloHitListW;
50  if (!clusterParametersU.m_caloHitList.empty())
51  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, clusterParametersU, pClusterU));
52  if (!clusterParametersV.m_caloHitList.empty())
53  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, clusterParametersV, pClusterV));
54  if (!clusterParametersW.m_caloHitList.empty())
55  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, clusterParametersW, pClusterW));
56 
57  if (!pClusterU && !pClusterV && !pClusterW)
58  throw StatusCodeException(STATUS_CODE_FAILURE);
59 
60  const Pfo *pSlicePfo(nullptr);
61  PandoraContentApi::ParticleFlowObject::Parameters pfoParameters;
62  if (pClusterU)
63  pfoParameters.m_clusterList.push_back(pClusterU);
64  if (pClusterV)
65  pfoParameters.m_clusterList.push_back(pClusterV);
66  if (pClusterW)
67  pfoParameters.m_clusterList.push_back(pClusterW);
68  pfoParameters.m_charge = 0;
69  pfoParameters.m_energy = 0.f;
70  pfoParameters.m_mass = 0.f;
71  pfoParameters.m_momentum = CartesianVector(0.f, 0.f, 0.f);
72  pfoParameters.m_particleId = 0;
73  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pSlicePfo));
74  }
75 
76  if (!pClusterList->empty())
77  {
78  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Cluster>(*this, m_sliceClusterListName));
79  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Cluster>(*this, m_sliceClusterListName));
80  }
81 
82  if (!pPfoList->empty())
83  {
84  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<ParticleFlowObject>(*this, m_slicePfoListName));
85  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<ParticleFlowObject>(*this, m_slicePfoListName));
86  }
87 
88  return STATUS_CODE_SUCCESS;
89 }
90 
91 //------------------------------------------------------------------------------------------------------------------------------------------
92 
93 StatusCode SlicingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
94 {
95  AlgorithmTool *pAlgorithmTool(nullptr);
96  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithmTool(*this, xmlHandle, "SliceCreation", pAlgorithmTool));
97  m_pEventSlicingTool = dynamic_cast<EventSlicingBaseTool *>(pAlgorithmTool);
98 
100  return STATUS_CODE_INVALID_PARAMETER;
101 
102  PANDORA_RETURN_RESULT_IF(
103  STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithm(*this, xmlHandle, "SlicingListDeletion", m_slicingListDeletionAlgorithm));
104 
105  std::string caloHitListNameU, caloHitListNameV, caloHitListNameW;
106  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputCaloHitListNameU", caloHitListNameU));
107  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputCaloHitListNameV", caloHitListNameV));
108  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputCaloHitListNameW", caloHitListNameW));
109  m_caloHitListNames[TPC_VIEW_U] = caloHitListNameU;
110  m_caloHitListNames[TPC_VIEW_V] = caloHitListNameV;
111  m_caloHitListNames[TPC_VIEW_W] = caloHitListNameW;
112 
113  std::string clusterListNameU, clusterListNameV, clusterListNameW;
114  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListNameU", clusterListNameU));
115  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListNameV", clusterListNameV));
116  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputClusterListNameW", clusterListNameW));
117  m_clusterListNames[TPC_VIEW_U] = clusterListNameU;
118  m_clusterListNames[TPC_VIEW_V] = clusterListNameV;
119  m_clusterListNames[TPC_VIEW_W] = clusterListNameW;
120 
121  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputClusterListName", m_sliceClusterListName));
122  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputPfoListName", m_slicePfoListName));
123 
124  return STATUS_CODE_SUCCESS;
125 }
126 
127 } // namespace lar_content
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::string string
Definition: nybbler.cc:12
HitTypeToNameMap m_caloHitListNames
The hit type to calo hit list name map.
EventSlicingBaseTool class.
std::string m_slicingListDeletionAlgorithm
The name of the slicing list deletion algorithm.
virtual void RunSlicing(const pandora::Algorithm *const pAlgorithm, const SlicingAlgorithm::HitTypeToNameMap &caloHitListNames, const SlicingAlgorithm::HitTypeToNameMap &clusterListNames, SlicingAlgorithm::SliceList &sliceList)=0
Run the slicing tool.
std::string m_sliceClusterListName
The name of the output slice cluster list.
HitTypeToNameMap m_clusterListNames
The hit type to cluster list name map.
std::vector< Slice > SliceList
std::string m_slicePfoListName
The name of the output slice pfo list.
Header file for the master algorithm class.
EventSlicingBaseTool * m_pEventSlicingTool
The address of the event slicing tool.