All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransverseMatrixVisualizationTool.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArMonitoring/TransverseMatrixVisualizationTool.cc
3  *
4  * @brief Implementation of the transverse matrix visualization 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 TransverseMatrixVisualizationTool::TransverseMatrixVisualizationTool() :
19  m_minClusterConnections(1),
20  m_ignoreUnavailableClusters(true),
21  m_showEachIndividualElement(false),
22  m_showOnlyTrueMatchIndividualElements(false)
23 {
24 }
25 
26 //------------------------------------------------------------------------------------------------------------------------------------------
27 
29 {
30  if (PandoraContentApi::GetSettings(*pAlgorithm)->ShouldDisplayAlgorithmInfo())
31  std::cout << "----> Running Algorithm Tool: " << this->GetInstanceName() << ", " << this->GetType() << std::endl;
32 
33  ClusterSet usedKeyClusters;
34  ClusterVector sortedKeyClusters;
35  overlapMatrix.GetSortedKeyClusters(sortedKeyClusters);
36 
37  for (const Cluster *const pKeyCluster : sortedKeyClusters)
38  {
39  if (m_ignoreUnavailableClusters && !pKeyCluster->IsAvailable())
40  continue;
41 
42  if (usedKeyClusters.count(pKeyCluster))
43  continue;
44 
45  unsigned int n1(0), n2(0);
46  MatrixType::ElementList elementList;
47  overlapMatrix.GetConnectedElements(pKeyCluster, m_ignoreUnavailableClusters, elementList, n1, n2);
48 
50  continue;
51 
52  if (n1 * n2 == 0)
53  continue;
54 
55  int counter(0);
56  ClusterList allClusterList1, allClusterList2;
57  std::cout << " Connections: n1 " << n1 << ", n2 " << n2 << ", nElements " << elementList.size() << std::endl;
58 
59  for (MatrixType::ElementList::const_iterator eIter = elementList.begin(); eIter != elementList.end(); ++eIter)
60  {
61  if (allClusterList1.end() == std::find(allClusterList1.begin(), allClusterList1.end(), eIter->GetCluster1()))
62  allClusterList1.push_back(eIter->GetCluster1());
63  if (allClusterList2.end() == std::find(allClusterList2.begin(), allClusterList2.end(), eIter->GetCluster2()))
64  allClusterList2.push_back(eIter->GetCluster2());
65  usedKeyClusters.insert(eIter->GetCluster1());
66  }
67 
68  for (MatrixType::ElementList::const_iterator eIter = elementList.begin(); eIter != elementList.end(); ++eIter)
69  {
70  int pdg0(0);
71  int pdg1(0);
72  bool isPrimary0(false);
73  bool isPrimary1(false);
74  bool sameParticle(false);
75  try
76  {
77  const MCParticle *particle0(MCParticleHelper::GetMainMCParticle(eIter->GetCluster1()));
78  const MCParticle *particle1(MCParticleHelper::GetMainMCParticle(eIter->GetCluster2()));
79  pdg0 = (particle0->GetParticleId());
80  isPrimary0 = (particle0->IsRootParticle());
81  pdg1 = (particle1->GetParticleId());
82  isPrimary1 = (particle1->IsRootParticle());
83  sameParticle = (particle0->GetUid() == particle1->GetUid());
84  }
85  catch (const StatusCodeException &)
86  {
87  };
88 
89  if (m_showOnlyTrueMatchIndividualElements && !sameParticle)
90  continue;
91 
92  std::cout << " Element " << counter++ << std::endl;
93  std::cout << " ---True PDG 0: " << pdg0 << std::endl;
94  std::cout << " ---True PDG 1: " << pdg1 << std::endl;
95  std::cout << " ---True is primary 0: " << isPrimary0 << std::endl;
96  std::cout << " ---True is primary 1: " << isPrimary1 << std::endl;
97  std::cout << " ---True is same particle: " << sameParticle << std::endl;
98  std::cout << " ---Is cluster 0 available: " << eIter->GetCluster1()->IsAvailable() << std::endl;
99  std::cout << " ---Is cluster 1 available: " << eIter->GetCluster2()->IsAvailable() << std::endl;
100  std::cout << " ---XOverlap: " << eIter->GetOverlapResult().GetTwoViewXOverlap().GetTwoViewXOverlapSpan() << std::endl;
101  std::cout << " ---XOverlap fraction view0: " << eIter->GetOverlapResult().GetTwoViewXOverlap().GetXOverlapFraction0() << std::endl;
102  std::cout << " ---XOverlap fraction view1: " << eIter->GetOverlapResult().GetTwoViewXOverlap().GetXOverlapFraction1() << std::endl;
103  std::cout << " ---Matching score: " << eIter->GetOverlapResult().GetMatchingScore() << std::endl;
104  std::cout << " ---N. sampling points: " << eIter->GetOverlapResult().GetNSamplingPoints() << std::endl;
105  std::cout << " ---N. matched sampling points: " << eIter->GetOverlapResult().GetNMatchedSamplingPoints() << std::endl;
106  std::cout << " ---N. (re-)upsampled sampling points: " << eIter->GetOverlapResult().GetNReUpsampledSamplingPoints() << std::endl;
107  std::cout << " ---N. (re-)upsampled matched sampling points: " << eIter->GetOverlapResult().GetNMatchedReUpsampledSamplingPoints()
108  << std::endl;
109  std::cout << " ---Correlation coeff.: " << eIter->GetOverlapResult().GetCorrelationCoefficient() << std::endl;
110  std::cout << " ---Locally matched fraction: " << eIter->GetOverlapResult().GetLocallyMatchedFraction() << std::endl;
111 
113  {
114  const ClusterList clusterList1(1, eIter->GetCluster1()), clusterList2(1, eIter->GetCluster2());
115  PANDORA_MONITORING_API(SetEveDisplayParameters(this->GetPandora(), false, DETECTOR_VIEW_XZ, -1.f, -1.f, 1.f));
116  PANDORA_MONITORING_API(VisualizeClusters(this->GetPandora(), &allClusterList1, "AllClusters1", LIGHTORANGE));
117  PANDORA_MONITORING_API(VisualizeClusters(this->GetPandora(), &allClusterList2, "AllClusters2", LIGHTYELLOW));
118  PANDORA_MONITORING_API(VisualizeClusters(this->GetPandora(), &clusterList1, "Cluster1", RED));
119  PANDORA_MONITORING_API(VisualizeClusters(this->GetPandora(), &clusterList2, "Cluster2", GREEN));
120  PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
121  }
122  }
123 
124  std::cout << " All Connected Clusters " << std::endl;
125  PANDORA_MONITORING_API(SetEveDisplayParameters(this->GetPandora(), false, DETECTOR_VIEW_XZ, -1.f, -1.f, 1.f));
126  PANDORA_MONITORING_API(VisualizeClusters(this->GetPandora(), &allClusterList1, "AllClusters1", RED));
127  PANDORA_MONITORING_API(VisualizeClusters(this->GetPandora(), &allClusterList2, "AllClusters2", GREEN));
128 
129  PANDORA_MONITORING_API(ViewEvent(this->GetPandora()));
130  }
131 
132  return false;
133 }
134 
135 //------------------------------------------------------------------------------------------------------------------------------------------
136 
137 StatusCode TransverseMatrixVisualizationTool::ReadSettings(const TiXmlHandle xmlHandle)
138 {
139  PANDORA_RETURN_RESULT_IF_AND_IF(
140  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinClusterConnections", m_minClusterConnections));
141 
142  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
143  XmlHelper::ReadValue(xmlHandle, "IgnoreUnavailableClusters", m_ignoreUnavailableClusters));
144 
145  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
146  XmlHelper::ReadValue(xmlHandle, "ShowEachIndividualElement", m_showEachIndividualElement));
147 
148  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
149  XmlHelper::ReadValue(xmlHandle, "ShowOnlyTrueMatchIndividualElements", m_showOnlyTrueMatchIndividualElements));
150 
151  return STATUS_CODE_SUCCESS;
152 }
153 
154 } // namespace lar_content
bool m_ignoreUnavailableClusters
Whether to ignore (skip-over) unavailable clusters in the matrix.
unsigned int m_minClusterConnections
The minimum number of cluster connections for display.
Header file for the transverse matrix visualization tool class.
bool m_showOnlyTrueMatchIndividualElements
Whether to draw only truly matching individual matrix elements.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void GetSortedKeyClusters(pandora::ClusterVector &sortedKeyClusters) const
Get a sorted vector of key clusters (view 1 clusters with current implementation) ...
bool Run(TwoViewTransverseTracksAlgorithm *const pAlgorithm, MatrixType &overlapMatrix)
Run the algorithm tool.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
bool m_showEachIndividualElement
Whether to draw each individual matrix element.
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 don t mess with this pandoraTrackGausCryoW true
BEGIN_PROLOG could also be cout