LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ClusterSplittingAlgorithm.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 ClusterSplittingAlgorithm::Run()
21 {
22  if (m_inputClusterListNames.empty())
23  return this->RunUsingCurrentList();
24 
25  std::string originalListName;
26  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentListName<Cluster>(*this, originalListName));
27 
28  for (const std::string &clusterListName : m_inputClusterListNames)
29  {
30  const StatusCode listChangeStatusCode(PandoraContentApi::ReplaceCurrentList<Cluster>(*this, clusterListName));
31 
32  if (STATUS_CODE_NOT_FOUND == listChangeStatusCode)
33  {
34  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
35  std::cout << "ClusterSplittingAlgorithm: cluster list not found " << clusterListName << std::endl;
36 
37  continue;
38  }
39 
40  if (STATUS_CODE_SUCCESS != listChangeStatusCode)
41  return listChangeStatusCode;
42 
43  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->RunUsingCurrentList());
44  }
45 
46  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Cluster>(*this, originalListName));
47  return STATUS_CODE_SUCCESS;
48 }
49 
50 //------------------------------------------------------------------------------------------------------------------------------------------
51 
52 StatusCode ClusterSplittingAlgorithm::RunUsingCurrentList() const
53 {
54  const ClusterList *pClusterList = NULL;
55  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pClusterList));
56 
57  ClusterList internalClusterList(pClusterList->begin(), pClusterList->end());
58  internalClusterList.sort(LArClusterHelper::SortByNHits);
59 
60  for (ClusterList::iterator iter = internalClusterList.begin(); iter != internalClusterList.end(); ++iter)
61  {
62  const Cluster *const pCluster = *iter;
63  ClusterList clusterSplittingList;
64 
65  if (STATUS_CODE_SUCCESS != this->SplitCluster(pCluster, clusterSplittingList))
66  continue;
67 
68  internalClusterList.splice(internalClusterList.end(), clusterSplittingList);
69  *iter = NULL;
70  }
71 
72  return STATUS_CODE_SUCCESS;
73 }
74 
75 //------------------------------------------------------------------------------------------------------------------------------------------
76 
77 StatusCode ClusterSplittingAlgorithm::SplitCluster(const Cluster *const pCluster, ClusterList &clusterSplittingList) const
78 {
79  // Split cluster into two CaloHit lists
80  PandoraContentApi::Cluster::Parameters firstParameters, secondParameters;
81 
82  if (STATUS_CODE_SUCCESS != this->DivideCaloHits(pCluster, firstParameters.m_caloHitList, secondParameters.m_caloHitList))
83  return STATUS_CODE_NOT_FOUND;
84 
85  if (firstParameters.m_caloHitList.empty() || secondParameters.m_caloHitList.empty())
86  return STATUS_CODE_NOT_ALLOWED;
87 
88  // Begin cluster fragmentation operations
89  const ClusterList clusterList(1, pCluster);
90  std::string clusterListToSaveName, clusterListToDeleteName;
91 
92  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=,
93  PandoraContentApi::InitializeFragmentation(*this, clusterList, clusterListToDeleteName, clusterListToSaveName));
94 
95  // Create new clusters
96  const Cluster *pFirstCluster(NULL), *pSecondCluster(NULL);
97  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, firstParameters, pFirstCluster));
98  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*this, secondParameters, pSecondCluster));
99 
100  clusterSplittingList.push_back(pFirstCluster);
101  clusterSplittingList.push_back(pSecondCluster);
102 
103  // End cluster fragmentation operations
104  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::EndFragmentation(*this, clusterListToSaveName, clusterListToDeleteName));
105 
106  return STATUS_CODE_SUCCESS;
107 }
108 
109 //------------------------------------------------------------------------------------------------------------------------------------------
110 
111 StatusCode ClusterSplittingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
112 {
113  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
114  XmlHelper::ReadVectorOfValues(xmlHandle, "InputClusterListNames", m_inputClusterListNames));
115 
116  return STATUS_CODE_SUCCESS;
117 }
118 
119 } // namespace lar_content
Header file for the cluster splitting algorithm class.
intermediate_table::iterator iterator
Header file for the cluster helper class.