LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ThreeViewDeltaRayMatchingAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
13 using namespace pandora;
14 
15 namespace lar_content
16 {
17 
18 ThreeViewDeltaRayMatchingAlgorithm::ThreeViewDeltaRayMatchingAlgorithm() :
19  m_minClusterCaloHits(5),
20  m_nMaxTensorToolRepeats(10)
21 {
22 }
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
27 {
28  return (pCluster->GetNCaloHits() >= m_minClusterCaloHits);
29 }
30 
31 //------------------------------------------------------------------------------------------------------------------------------------------
32 
33 void ThreeViewDeltaRayMatchingAlgorithm::CalculateOverlapResult(const Cluster *const pClusterU, const Cluster *const pClusterV, const Cluster *const pClusterW)
34 {
35  DeltaRayOverlapResult overlapResult;
36  PANDORA_THROW_RESULT_IF_AND_IF(
37  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, this->CalculateOverlapResult(pClusterU, pClusterV, pClusterW, overlapResult));
38 
39  if (overlapResult.IsInitialized())
40  this->GetMatchingControl().GetOverlapTensor().SetOverlapResult(pClusterU, pClusterV, pClusterW, overlapResult);
41 }
42 
43 //------------------------------------------------------------------------------------------------------------------------------------------
44 
45 StatusCode ThreeViewDeltaRayMatchingAlgorithm::CalculateOverlapResult(const Cluster *const pClusterU, const Cluster *const pClusterV,
46  const Cluster *const pClusterW, DeltaRayOverlapResult &overlapResult) const
47 {
48  float chiSquaredSum(0.f);
49  unsigned int nSamplingPoints(0), nMatchedSamplingPoints(0);
50  XOverlap xOverlapObject(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
51 
52  StatusCode statusCode(
53  this->PerformThreeViewMatching(pClusterU, pClusterV, pClusterW, chiSquaredSum, nSamplingPoints, nMatchedSamplingPoints, xOverlapObject));
54 
55  if (statusCode != STATUS_CODE_SUCCESS)
56  return statusCode;
57 
58  PfoList commonMuonPfoList;
59  this->FindCommonMuonParents(pClusterU, pClusterV, pClusterW, commonMuonPfoList);
60 
61  if (commonMuonPfoList.empty())
62  return STATUS_CODE_NOT_FOUND;
63 
64  overlapResult = DeltaRayOverlapResult(nMatchedSamplingPoints, nSamplingPoints, chiSquaredSum, xOverlapObject, commonMuonPfoList);
65 
66  return STATUS_CODE_SUCCESS;
67 }
68 
69 //------------------------------------------------------------------------------------------------------------------------------------------
70 
72  const Cluster *const pClusterU, const Cluster *const pClusterV, const Cluster *const pClusterW, PfoList &commonMuonPfoList) const
73 {
74  ClusterList consideredClustersU, consideredClustersV, consideredClustersW;
75  PfoList nearbyMuonPfosU, nearbyMuonPfosV, nearbyMuonPfosW;
76 
77  this->GetNearbyMuonPfos(pClusterU, consideredClustersU, nearbyMuonPfosU);
78 
79  if (nearbyMuonPfosU.empty())
80  return;
81 
82  this->GetNearbyMuonPfos(pClusterV, consideredClustersV, nearbyMuonPfosV);
83 
84  if (nearbyMuonPfosV.empty())
85  return;
86 
87  this->GetNearbyMuonPfos(pClusterW, consideredClustersW, nearbyMuonPfosW);
88 
89  if (nearbyMuonPfosW.empty())
90  return;
91 
92  for (const ParticleFlowObject *const pNearbyMuonU : nearbyMuonPfosU)
93  {
94  for (const ParticleFlowObject *const pNearbyMuonV : nearbyMuonPfosV)
95  {
96  if (pNearbyMuonV != pNearbyMuonU)
97  continue;
98 
99  for (const ParticleFlowObject *const pNearbyMuonW : nearbyMuonPfosW)
100  {
101  if (pNearbyMuonW == pNearbyMuonV)
102  commonMuonPfoList.emplace_back(pNearbyMuonU);
103  }
104  }
105  }
106 }
107 
108 //------------------------------------------------------------------------------------------------------------------------------------------
109 
111 {
112  // Apply tools sequentially restarting if a change is made and ending if the tools finish or the restart limit is reached
113  unsigned int repeatCounter(0);
114 
115  for (auto toolIter = m_algorithmToolVector.begin(); toolIter != m_algorithmToolVector.end();)
116  {
117  DeltaRayTensorTool *const pTool(*toolIter);
118  const bool repeatTools(pTool->Run(this, this->GetMatchingControl().GetOverlapTensor()));
119 
120  toolIter = repeatTools ? m_algorithmToolVector.begin() : toolIter + 1;
121  repeatCounter = repeatTools ? repeatCounter + 1 : repeatCounter;
122 
123  if (repeatCounter > m_nMaxTensorToolRepeats)
124  break;
125  }
126 }
127 
128 //------------------------------------------------------------------------------------------------------------------------------------------
129 
130 StatusCode ThreeViewDeltaRayMatchingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
131 {
132  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "MuonPfoListName", m_muonPfoListName));
133 
134  AlgorithmToolVector algorithmToolVector;
135  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithmToolList(*this, xmlHandle, "DeltaRayTools", algorithmToolVector));
136 
137  for (auto algorithmTool : algorithmToolVector)
138  {
139  DeltaRayTensorTool *const pDeltaRayTensorTool(dynamic_cast<DeltaRayTensorTool *>(algorithmTool));
140 
141  if (!pDeltaRayTensorTool)
142  return STATUS_CODE_INVALID_PARAMETER;
143 
144  m_algorithmToolVector.push_back(pDeltaRayTensorTool);
145  }
146 
147  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ProcessAlgorithm(*this, xmlHandle, "ClusterRebuilding", m_reclusteringAlgorithmName));
148 
149  PANDORA_RETURN_RESULT_IF_AND_IF(
150  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinClusterCaloHits", m_minClusterCaloHits));
151 
152  PANDORA_RETURN_RESULT_IF_AND_IF(
153  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "NMaxTensorToolRepeats", m_nMaxTensorToolRepeats));
154 
155  return BaseAlgorithm::ReadSettings(xmlHandle);
156 }
157 
158 } // namespace lar_content
TensorType & GetOverlapTensor()
Get the overlap tensor.
bool IsInitialized() const
Whether the track overlap result has been initialized.
void ExamineOverlapContainer()
Examine contents of overlap container, collect together best-matching 2D particles and modify cluster...
unsigned int m_nMaxTensorToolRepeats
The maximum number of repeat loops over tensor tools.
std::string m_reclusteringAlgorithmName
The name of the clustering algorithm to be used to recluster created delta ray remnants.
TensorToolVector m_algorithmToolVector
The algorithm tool vector.
TFile f
Definition: plotHisto.C:6
pandora::StatusCode PerformThreeViewMatching(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, const pandora::Cluster *const pCluster3, float &reducedChiSquared) const
To determine how well three clusters (one in each view) map onto one another expressing this in terms...
void SetOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, const OverlapResult &overlapResult)
Set overlap result.
virtual bool DoesClusterPassTensorThreshold(const pandora::Cluster *const pCluster) const
To check whether a given cluster meets the requirements to be added into the matching container (tens...
void FindCommonMuonParents(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW, pandora::PfoList &commonMuonPfoList) const
Find the cosmic ray pfos that, in each view, lie close to the clusters of the tensor element...
unsigned int m_minClusterCaloHits
The threshold number of hits for a cluster to be considered.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
virtual bool Run(ThreeViewDeltaRayMatchingAlgorithm *const pAlgorithm, TensorType &overlapTensor)=0
Run the algorithm tool.
DeltaRayOverlapResult class.
void GetNearbyMuonPfos(const pandora::Cluster *const pCluster, pandora::ClusterList &consideredClusters, pandora::PfoList &nearbyMuonPfos) const
Use the cluster proximity map to travel along paths of nearby clusters finding the cosmic ray cluster...
void CalculateOverlapResult(const pandora::Cluster *const pClusterU, const pandora::Cluster *const pClusterV, const pandora::Cluster *const pClusterW)
Calculate cluster overlap result and store in container.
XOverlap class.
Definition: LArXOverlap.h:17