All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleShowersTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArShowerMatching/SimpleShowersTool.cc
3  *
4  * @brief Implementation of the clear showers 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 SimpleShowersTool::SimpleShowersTool() : m_minMatchedFraction(0.2f), m_minMatchedSamplingPoints(40), m_minXOverlapFraction(0.5f)
19 {
20 }
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
24 bool SimpleShowersTool::Run(ThreeViewShowersAlgorithm *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->FindBestShower(overlapTensor, protoParticleVector);
31 
32  const bool particlesMade(pAlgorithm->CreateThreeDParticles(protoParticleVector));
33  return particlesMade;
34 }
35 
36 //------------------------------------------------------------------------------------------------------------------------------------------
37 
38 void SimpleShowersTool::FindBestShower(const TensorType &overlapTensor, ProtoParticleVector &protoParticleVector) const
39 {
40  ClusterVector sortedKeyClusters;
41  overlapTensor.GetSortedKeyClusters(sortedKeyClusters);
42 
43  for (const Cluster *const pKeyCluster : sortedKeyClusters)
44  {
45  if (!pKeyCluster->IsAvailable())
46  continue;
47 
48  unsigned int nU(0), nV(0), nW(0);
49  TensorType::ElementList elementList;
50  overlapTensor.GetConnectedElements(pKeyCluster, true, elementList, nU, nV, nW);
51 
52  if (elementList.empty())
53  continue;
54 
55  TensorType::Element bestElement(elementList.back());
56 
57  if (!bestElement.GetOverlapResult().IsInitialized())
58  continue;
59 
60  if ((NULL == bestElement.GetClusterU()) || (NULL == bestElement.GetClusterV()) || (NULL == bestElement.GetClusterW()))
61  continue;
62 
63  ProtoParticle protoParticle;
64  protoParticle.m_clusterList.push_back(bestElement.GetClusterU());
65  protoParticle.m_clusterList.push_back(bestElement.GetClusterV());
66  protoParticle.m_clusterList.push_back(bestElement.GetClusterW());
67  protoParticleVector.push_back(protoParticle);
68 
69  return;
70  }
71 }
72 
73 //------------------------------------------------------------------------------------------------------------------------------------------
74 
76 {
77  if (eIter->GetOverlapResult().GetMatchedFraction() < m_minMatchedFraction)
78  return false;
79 
80  if (eIter->GetOverlapResult().GetNMatchedSamplingPoints() < m_minMatchedSamplingPoints)
81  return false;
82 
83  const XOverlap &xOverlap(eIter->GetOverlapResult().GetXOverlap());
84 
85  if ((xOverlap.GetXSpanU() > std::numeric_limits<float>::epsilon()) && (xOverlap.GetXOverlapSpan() / xOverlap.GetXSpanU() > m_minXOverlapFraction) &&
86  (xOverlap.GetXSpanV() > std::numeric_limits<float>::epsilon()) && (xOverlap.GetXOverlapSpan() / xOverlap.GetXSpanV() > m_minXOverlapFraction) &&
87  (xOverlap.GetXSpanW() > std::numeric_limits<float>::epsilon()) && (xOverlap.GetXOverlapSpan() / xOverlap.GetXSpanW() > m_minXOverlapFraction))
88  {
89  return true;
90  }
91 
92  return false;
93 }
94 
95 //------------------------------------------------------------------------------------------------------------------------------------------
96 
97 StatusCode SimpleShowersTool::ReadSettings(const TiXmlHandle xmlHandle)
98 {
99  PANDORA_RETURN_RESULT_IF_AND_IF(
100  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinMatchedFraction", m_minMatchedFraction));
101 
102  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
103  XmlHelper::ReadValue(xmlHandle, "MinMatchedSamplingPoints", m_minMatchedSamplingPoints));
104 
105  PANDORA_RETURN_RESULT_IF_AND_IF(
106  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinXOverlapFraction", m_minXOverlapFraction));
107 
108  return STATUS_CODE_SUCCESS;
109 }
110 
111 } // namespace lar_content
std::vector< ProtoParticle > ProtoParticleVector
void FindBestShower(const TensorType &overlapTensor, ProtoParticleVector &protoParticleVector) const
Find best shower match as a simple way to (try to) resolve ambiguities in the tensor.
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
bool Run(ThreeViewShowersAlgorithm *const pAlgorithm, TensorType &overlapTensor)
Run the algorithm tool.
float m_minMatchedFraction
The min matched sampling point fraction for particle creation.
pandora::ClusterList m_clusterList
List of 2D clusters in a 3D proto particle.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (U clusters with current implementation)
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
Header file for the simple showers tool class.
virtual bool CreateThreeDParticles(const ProtoParticleVector &protoParticleVector)
Create particles using findings from recent algorithm processing.
unsigned int m_minMatchedSamplingPoints
The min number of matched sampling points for particle creation.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
float m_minXOverlapFraction
The min x overlap fraction (in each view) for particle creation.
bool PassesElementCuts(TensorType::ElementList::const_iterator eIter) const
Whether a provided (iterator to a) tensor element passes the selection cuts for particle creation...
XOverlap class.
Definition: LArXOverlap.h:17
BEGIN_PROLOG could also be cout