LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MatchingBaseAlgorithm.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 MatchingBaseAlgorithm::MatchingBaseAlgorithm()
21 {
22 }
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
26 MatchingBaseAlgorithm::~MatchingBaseAlgorithm()
27 {
28 }
29 
30 //------------------------------------------------------------------------------------------------------------------------------------------
31 
32 void MatchingBaseAlgorithm::SelectInputClusters(const ClusterList *const pInputClusterList, ClusterList &selectedClusterList) const
33 {
34  if (!pInputClusterList)
35  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
36 
37  selectedClusterList = *pInputClusterList;
38 }
39 
40 //------------------------------------------------------------------------------------------------------------------------------------------
41 
42 void MatchingBaseAlgorithm::PrepareInputClusters(ClusterList & /*preparedClusterList*/)
43 {
44 }
45 
46 //------------------------------------------------------------------------------------------------------------------------------------------
47 
48 bool MatchingBaseAlgorithm::MakeClusterMerges(const ClusterMergeMap &clusterMergeMap)
49 {
50  ClusterSet deletedClusters;
51 
52  ClusterList parentClusters;
53  for (const auto &mapEntry : clusterMergeMap)
54  parentClusters.push_back(mapEntry.first);
55  parentClusters.sort(LArClusterHelper::SortByNHits);
56 
57  for (const Cluster *const pParentCluster : parentClusters)
58  {
59  const HitType hitType(LArClusterHelper::GetClusterHitType(pParentCluster));
60  const std::string &clusterListName(this->GetClusterListName(hitType));
61 
62  if (!((TPC_VIEW_U == hitType) || (TPC_VIEW_V == hitType) || (TPC_VIEW_W == hitType)))
63  throw StatusCodeException(STATUS_CODE_FAILURE);
64 
65  ClusterList daughterClusters(clusterMergeMap.at(pParentCluster));
66  daughterClusters.sort(LArClusterHelper::SortByNHits);
67 
68  for (const Cluster *const pDaughterCluster : daughterClusters)
69  {
70  if (deletedClusters.count(pParentCluster) || deletedClusters.count(pDaughterCluster))
71  throw StatusCodeException(STATUS_CODE_FAILURE);
72 
73  this->UpdateUponDeletion(pDaughterCluster);
74  this->UpdateUponDeletion(pParentCluster);
75  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
76  PandoraContentApi::MergeAndDeleteClusters(*this, pParentCluster, pDaughterCluster, clusterListName, clusterListName));
77 
78  this->UpdateForNewCluster(pParentCluster);
79  deletedClusters.insert(pDaughterCluster);
80  }
81  }
82 
83  return !(deletedClusters.empty());
84 }
85 
86 //------------------------------------------------------------------------------------------------------------------------------------------
87 
88 bool MatchingBaseAlgorithm::CreateThreeDParticles(const ProtoParticleVector &protoParticleVector)
89 {
90  bool particlesMade(false);
91  const PfoList *pPfoList(nullptr);
92  std::string pfoListName;
93  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pPfoList, pfoListName));
94 
95  for (const ProtoParticle &protoParticle : protoParticleVector)
96  {
97  PandoraContentApi::ParticleFlowObject::Parameters pfoParameters;
98  this->SetPfoParameters(protoParticle, pfoParameters);
99 
100  const ParticleFlowObject *pPfo(nullptr);
101  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pPfo));
102  particlesMade = true;
103  }
104 
105  if (!pPfoList->empty())
106  {
107  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Pfo>(*this, m_outputPfoListName));
108  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Pfo>(*this, m_outputPfoListName));
109  }
110 
111  return particlesMade;
112 }
113 
114 //------------------------------------------------------------------------------------------------------------------------------------------
115 
116 void MatchingBaseAlgorithm::SetPfoParameters(const ProtoParticle &protoParticle, PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
117 {
118  this->SetPfoParticleId(pfoParameters);
119  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
120  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
121  pfoParameters.m_energy = 0.f;
122  pfoParameters.m_momentum = CartesianVector(0.f, 0.f, 0.f);
123  pfoParameters.m_clusterList = protoParticle.m_clusterList;
124 }
125 
126 //------------------------------------------------------------------------------------------------------------------------------------------
127 
128 void MatchingBaseAlgorithm::SetPfoParticleId(PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
129 {
130  pfoParameters.m_particleId = E_MINUS; // Shower
131 }
132 
133 //------------------------------------------------------------------------------------------------------------------------------------------
134 
135 StatusCode MatchingBaseAlgorithm::Run()
136 {
137  try
138  {
139  this->SelectAllInputClusters();
140  this->PrepareAllInputClusters();
141  this->PerformMainLoop();
142  this->ExamineOverlapContainer();
143  this->TidyUp();
144  }
145  catch (StatusCodeException &statusCodeException)
146  {
147  this->TidyUp();
148 
149  if (STATUS_CODE_SUCCESS != statusCodeException.GetStatusCode())
150  throw statusCodeException;
151  }
152 
153  return STATUS_CODE_SUCCESS;
154 }
155 
156 //------------------------------------------------------------------------------------------------------------------------------------------
157 
158 StatusCode MatchingBaseAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
159 {
160  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputPfoListName", m_outputPfoListName));
161 
162  return STATUS_CODE_SUCCESS;
163 }
164 
165 } // namespace lar_content
std::vector< ProtoParticle > ProtoParticleVector
TFile f
Definition: plotHisto.C:6
Header file for the cluster helper class.
pandora::ClusterList m_clusterList
List of 2D clusters in a 3D proto particle.
HitType
Definition: HitType.h:12
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
Header file for the three dimension algorithm base class.