All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TwoViewAmbiguousDeltaRayTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArThreeDReco/LArCosmicRay/TwoViewAmbiguousDeltaRayTool.cc
3  *
4  * @brief Implementation of the two view amgiuous delta ray 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 TwoViewAmbiguousDeltaRayTool::TwoViewAmbiguousDeltaRayTool()
19 {
20 }
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
24 bool TwoViewAmbiguousDeltaRayTool::Run(TwoViewDeltaRayMatchingAlgorithm *const pAlgorithm, MatrixType &overlapMatrix)
25 {
26  m_pParentAlgorithm = pAlgorithm;
27 
28  if (PandoraContentApi::GetSettings(*m_pParentAlgorithm)->ShouldDisplayAlgorithmInfo())
29  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
30 
31  this->ExamineConnectedElements(overlapMatrix);
32 
33  // ATTN: Prevent tensor tool loop running again
34  return false;
35 }
36 
37 //------------------------------------------------------------------------------------------------------------------------------------------
38 
39 void TwoViewAmbiguousDeltaRayTool::ExamineConnectedElements(MatrixType &overlapMatrix) const
40 {
41  bool particleCreated(false);
42 
43  do
44  {
45  particleCreated = false;
46 
47  ClusterVector sortedKeyClusters;
48  overlapMatrix.GetSortedKeyClusters(sortedKeyClusters);
49 
50  ClusterSet usedKeyClusters;
51 
52  for (const Cluster *const pKeyCluster : sortedKeyClusters)
53  {
54  if (usedKeyClusters.count(pKeyCluster))
55  continue;
56 
57  MatrixType::ElementList elementList;
58  overlapMatrix.GetConnectedElements(pKeyCluster, true, elementList);
59 
60  for (const MatrixType::Element &element : elementList)
61  usedKeyClusters.insert(element.GetCluster1());
62 
63  if (this->PickOutGoodMatches(elementList))
64  {
65  particleCreated = true;
66  break;
67  }
68  }
69  } while (particleCreated);
70 }
71 
72 //------------------------------------------------------------------------------------------------------------------------------------------
73 
74 bool TwoViewAmbiguousDeltaRayTool::PickOutGoodMatches(const MatrixType::ElementList &elementList) const
75 {
76  unsigned int highestHitCount(0);
77  float bestChiSquared(std::numeric_limits<float>::max());
78  auto bestElementIter(elementList.end());
79 
80  for (auto iter = elementList.begin(); iter != elementList.end(); ++iter)
81  {
82  const MatrixType::Element &element(*iter);
83  const float chiSquared(element.GetOverlapResult().GetReducedChiSquared());
84  const Cluster *const pCluster1(element.GetCluster1()), *const pCluster2(element.GetCluster2());
85  const unsigned int hitSum(pCluster1->GetNCaloHits() + pCluster2->GetNCaloHits());
86 
87  if ((hitSum > highestHitCount) || ((hitSum == highestHitCount) && (chiSquared < bestChiSquared)))
88  {
89  bestChiSquared = chiSquared;
90  highestHitCount = hitSum;
91  bestElementIter = iter;
92  }
93  }
94 
95  if (bestElementIter != elementList.end())
96  {
97  m_pParentAlgorithm->CreatePfo(*bestElementIter);
98  return true;
99  }
100 
101  return false;
102 }
103 
104 //------------------------------------------------------------------------------------------------------------------------------------------
105 
106 StatusCode TwoViewAmbiguousDeltaRayTool::ReadSettings(const TiXmlHandle /*xmlHandle*/)
107 {
108  return STATUS_CODE_SUCCESS;
109 }
110 
111 } // namespace lar_content
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (view 1 clusters with current implementation) ...
Header file for the two view delta ray merge tool class.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
void GetConnectedElements(const pandora::Cluster *const pCluster, const bool ignoreUnavailable, ElementList &elementList) const
Get a list of elements connected to a specified cluster.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
BEGIN_PROLOG could also be cout