MopUpRemnantsTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/ShowerFragments/MopUpRemnantsTool.cc
3  *
4  * @brief Implementation of the mop-up remnants tool class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 MopUpRemnantsTool::MopUpRemnantsTool()
19 {
20 }
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
24 bool MopUpRemnantsTool::Run(ThreeViewRemnantsAlgorithm *const pAlgorithm, TensorType &overlapTensor)
25 {
26  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
27  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
28 
29  ProtoParticleVector protoParticleVector;
30  this->FindBestShowers(overlapTensor, protoParticleVector);
31 
32  const bool particlesMade(pAlgorithm->CreateThreeDParticles(protoParticleVector));
33  return particlesMade;
34 }
35 
36 //------------------------------------------------------------------------------------------------------------------------------------------
37 
38 void MopUpRemnantsTool::FindBestShowers(const TensorType &overlapTensor, ProtoParticleVector &protoParticleVector) const
39 {
40  ClusterSet usedClusters;
41  ClusterVector sortedKeyClusters;
42  overlapTensor.GetSortedKeyClusters(sortedKeyClusters);
43 
44  for (const Cluster *const pKeyCluster : sortedKeyClusters)
45  {
46  if (!pKeyCluster->IsAvailable())
47  continue;
48 
49  TensorType::ElementList connectedElements;
50  overlapTensor.GetConnectedElements(pKeyCluster, true, connectedElements);
51 
52  TensorType::ElementList::const_iterator eIter = connectedElements.end();
53  this->SelectBestElement(connectedElements, usedClusters, eIter);
54  this->GetUsedClusters(connectedElements, usedClusters);
55 
56  if (connectedElements.end() == eIter)
57  continue;
58 
59  ProtoParticle protoParticle;
60  protoParticle.m_clusterList.push_back(eIter->GetClusterU());
61  protoParticle.m_clusterList.push_back(eIter->GetClusterV());
62  protoParticle.m_clusterList.push_back(eIter->GetClusterW());
63  protoParticleVector.push_back(protoParticle);
64  }
65 }
66 
67 //------------------------------------------------------------------------------------------------------------------------------------------
68 
69 void MopUpRemnantsTool::GetUsedClusters(const TensorType::ElementList &elementList, ClusterSet &usedClusters) const
70 {
71  for (TensorType::ElementList::const_iterator eIter = elementList.begin(); eIter != elementList.end(); ++eIter)
72  {
73  usedClusters.insert(eIter->GetClusterU());
74  usedClusters.insert(eIter->GetClusterV());
75  usedClusters.insert(eIter->GetClusterW());
76  }
77 }
78 
79 //------------------------------------------------------------------------------------------------------------------------------------------
80 
81 void MopUpRemnantsTool::SelectBestElement(
82  const TensorType::ElementList &elementList, const ClusterSet &usedClusters, TensorType::ElementList::const_iterator &bestIter) const
83 {
84  float bestFigureOfMerit(0.f);
85 
86  for (TensorType::ElementList::const_iterator eIter = elementList.begin(); eIter != elementList.end(); ++eIter)
87  {
88  const Cluster *const pClusterU = eIter->GetClusterU();
89  const Cluster *const pClusterV = eIter->GetClusterV();
90  const Cluster *const pClusterW = eIter->GetClusterW();
91 
92  if (usedClusters.count(pClusterU) || usedClusters.count(pClusterV) || usedClusters.count(pClusterW))
93  continue;
94 
95  const float figureOfMerit(pClusterU->GetHadronicEnergy() + pClusterV->GetHadronicEnergy() + pClusterW->GetHadronicEnergy());
96 
97  if (figureOfMerit > bestFigureOfMerit)
98  {
99  bestFigureOfMerit = figureOfMerit;
100  bestIter = eIter;
101  }
102  }
103 }
104 
105 //------------------------------------------------------------------------------------------------------------------------------------------
106 
107 StatusCode MopUpRemnantsTool::ReadSettings(const TiXmlHandle /*xmlHandle*/)
108 {
109  return STATUS_CODE_SUCCESS;
110 }
111 
112 } // namespace lar_content
std::vector< ProtoParticle > ProtoParticleVector
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
Header file for the mop-up remnants tool class.
std::vector< Element > ElementList
pandora::ClusterList m_clusterList
List of 2D clusters in a 3D proto particle.
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (U clusters with current implementation)
virtual bool CreateThreeDParticles(const ProtoParticleVector &protoParticleVector)
Create particles using findings from recent algorithm processing.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
TheTensor::const_iterator const_iterator
QTextStream & endl(QTextStream &s)