Public Member Functions | Private Member Functions | Private Attributes | List of all members
lar_content::VertexRefinementAlgorithm Class Reference

VertexRefinementAlgorithm class. More...

#include <VertexRefinementAlgorithm.h>

Inheritance diagram for lar_content::VertexRefinementAlgorithm:

Public Member Functions

 VertexRefinementAlgorithm ()
 Default constructor. More...
 

Private Member Functions

pandora::StatusCode Run ()
 
void GetClusterLists (const pandora::StringVector &inputClusterListNames, pandora::ClusterList &clusterListU, pandora::ClusterList &clusterListV, pandora::ClusterList &clusterListW) const
 Get the input cluster lists. More...
 
void RefineVertices (const pandora::VertexList *const pVertexList, const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV, const pandora::ClusterList &clusterListW) const
 Perform the refinement proceduce on a list of vertices. More...
 
pandora::CartesianVector RefineVertexTwoD (const pandora::ClusterList &clusterList, const pandora::CartesianVector &originalVtxPos) const
 Refine the position of a two dimensional projection of a vertex using the clusters in that view. More...
 
void GetBestFitPoint (const pandora::CartesianPointVector &intercepts, const pandora::CartesianPointVector &directions, const pandora::FloatVector &weights, pandora::CartesianVector &bestFitPoint) const
 Calculate the best fit point of a set of lines using a matrix equation. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

pandora::StringVector m_inputClusterListNames
 The list of input cluster list names. More...
 
std::string m_inputVertexListName
 The initial vertex list. More...
 
std::string m_outputVertexListName
 The refined vertex list to be outputted. More...
 
float m_chiSquaredCut
 The maximum chi2 value a refined vertex can have to be kept. More...
 
float m_distanceCut
 The maximum distance a refined vertex can be from the original position to be kept. More...
 
unsigned int m_minimumHitsCut
 The minimum size of a cluster to be used in refinement. More...
 
float m_twoDDistanceCut
 The maximum distance a cluster can be from the original position to be used in refinement. More...
 

Detailed Description

VertexRefinementAlgorithm class.

Definition at line 19 of file VertexRefinementAlgorithm.h.

Constructor & Destructor Documentation

lar_content::VertexRefinementAlgorithm::VertexRefinementAlgorithm ( )

Default constructor.

Definition at line 24 of file VertexRefinementAlgorithm.cc.

24  :
25  m_chiSquaredCut(2.f),
26  m_distanceCut(5.f),
29 {
30 }
float m_chiSquaredCut
The maximum chi2 value a refined vertex can have to be kept.
unsigned int m_minimumHitsCut
The minimum size of a cluster to be used in refinement.
float m_twoDDistanceCut
The maximum distance a cluster can be from the original position to be used in refinement.
float m_distanceCut
The maximum distance a refined vertex can be from the original position to be kept.

Member Function Documentation

void lar_content::VertexRefinementAlgorithm::GetBestFitPoint ( const pandora::CartesianPointVector &  intercepts,
const pandora::CartesianPointVector &  directions,
const pandora::FloatVector weights,
pandora::CartesianVector &  bestFitPoint 
) const
private

Calculate the best fit point of a set of lines using a matrix equation.

Parameters
interceptsthe vector of the defining points of the lines
directionsthe vector of line directions
weightsthe vector of weights for each line
bestFitPointthe resulting best fit point

Definition at line 195 of file VertexRefinementAlgorithm.cc.

197 {
198  const int n(intercepts.size());
199 
200  Eigen::VectorXd d = Eigen::VectorXd::Zero(3 * n);
201  Eigen::MatrixXd G = Eigen::MatrixXd::Zero(3 * n, n + 3);
202 
203  for (int i = 0; i < n; ++i)
204  {
205  d(3 * i) = intercepts[i].GetX() * weights[i];
206  d(3 * i + 1) = intercepts[i].GetY() * weights[i];
207  d(3 * i + 2) = intercepts[i].GetZ() * weights[i];
208 
209  G(3 * i, 0) = weights[i];
210  G(3 * i + 1, 1) = weights[i];
211  G(3 * i + 2, 2) = weights[i];
212 
213  G(3 * i, i + 3) = -directions[i].GetX();
214  G(3 * i + 1, i + 3) = -directions[i].GetY();
215  G(3 * i + 2, i + 3) = -directions[i].GetZ();
216  }
217 
218  if ((G.transpose() * G).determinant() < std::numeric_limits<float>::epsilon())
219  {
221  return;
222  }
223 
224  Eigen::VectorXd m = (G.transpose() * G).inverse() * G.transpose() * d;
225 
226  bestFitPoint = CartesianVector(m[0], m[1], m[2]);
227 }
std::void_t< T > n
static int max(int a, int b)
void lar_content::VertexRefinementAlgorithm::GetClusterLists ( const pandora::StringVector inputClusterListNames,
pandora::ClusterList &  clusterListU,
pandora::ClusterList &  clusterListV,
pandora::ClusterList &  clusterListW 
) const
private

Get the input cluster lists.

Parameters
inputClusterListNamesthe input cluster list names
clusterListUthe U-view cluster list to populate
clusterListVthe V-view cluster list to populate
clusterListWthe W-view cluster list to populate

Definition at line 67 of file VertexRefinementAlgorithm.cc.

69 {
70  for (const std::string &clusterListName : inputClusterListNames)
71  {
72  const ClusterList *pClusterList(nullptr);
73  PANDORA_THROW_RESULT_IF_AND_IF(
74  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*this, clusterListName, pClusterList));
75 
76  if (!pClusterList || pClusterList->empty())
77  {
78  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
79  std::cout << "VertexRefinementAlgorithm: unable to find cluster list " << clusterListName << std::endl;
80 
81  continue;
82  }
83 
84  const HitType hitType(LArClusterHelper::GetClusterHitType(pClusterList->front()));
85 
86  if ((TPC_VIEW_U != hitType) && (TPC_VIEW_V != hitType) && (TPC_VIEW_W != hitType))
87  throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
88 
89  ClusterList &outputClusterList((TPC_VIEW_U == hitType) ? clusterListU : (TPC_VIEW_V == hitType) ? clusterListV : clusterListW);
90  outputClusterList.insert(outputClusterList.end(), pClusterList->begin(), pClusterList->end());
91  }
92 }
enum cvn::HType HitType
std::string string
Definition: nybbler.cc:12
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
QTextStream & endl(QTextStream &s)
StatusCode lar_content::VertexRefinementAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 231 of file VertexRefinementAlgorithm.cc.

232 {
233  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "InputClusterListNames", m_inputClusterListNames));
234 
235  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "InputVertexListName", m_inputVertexListName));
236 
237  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputVertexListName", m_outputVertexListName));
238 
239  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "ChiSquaredCut", m_chiSquaredCut));
240 
241  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "DistanceCut", m_distanceCut));
242 
243  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "MinimumHitsCut", m_minimumHitsCut));
244 
245  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "TwoDDistanceCut", m_twoDDistanceCut));
246 
247  return STATUS_CODE_SUCCESS;
248 }
float m_chiSquaredCut
The maximum chi2 value a refined vertex can have to be kept.
unsigned int m_minimumHitsCut
The minimum size of a cluster to be used in refinement.
std::string m_outputVertexListName
The refined vertex list to be outputted.
float m_twoDDistanceCut
The maximum distance a cluster can be from the original position to be used in refinement.
float m_distanceCut
The maximum distance a refined vertex can be from the original position to be kept.
std::string m_inputVertexListName
The initial vertex list.
pandora::StringVector m_inputClusterListNames
The list of input cluster list names.
CartesianVector lar_content::VertexRefinementAlgorithm::RefineVertexTwoD ( const pandora::ClusterList &  clusterList,
const pandora::CartesianVector &  originalVtxPos 
) const
private

Refine the position of a two dimensional projection of a vertex using the clusters in that view.

Parameters
clusterListthe list of two dimensional clusters
originalVtxPosthe original vertex position projected into two dimensions
Returns
the new refined position

Definition at line 157 of file VertexRefinementAlgorithm.cc.

158 {
159  CartesianPointVector intercepts, directions;
160  FloatVector weights;
161 
162  for (const Cluster *const pCluster : clusterList)
163  {
164  if (LArClusterHelper::GetClosestDistance(originalVtxPos, pCluster) > 10)
165  continue;
166 
167  if (pCluster->GetNCaloHits() < m_minimumHitsCut)
168  continue;
169 
170  CartesianVector centroid(0.f, 0.f, 0.f);
171  LArPcaHelper::EigenValues eigenValues(0.f, 0.f, 0.f);
172  LArPcaHelper::EigenVectors eigenVectors;
173  CartesianPointVector pointVector;
174 
175  LArClusterHelper::GetCoordinateVector(pCluster, pointVector);
176  LArPcaHelper::RunPca(pointVector, centroid, eigenValues, eigenVectors);
177 
178  intercepts.push_back(LArClusterHelper::GetClosestPosition(originalVtxPos, pCluster));
179  directions.push_back(eigenVectors.at(0).GetUnitVector());
180  weights.push_back(1.f / ((LArClusterHelper::GetClosestPosition(originalVtxPos, pCluster) - originalVtxPos).GetMagnitudeSquared() + 1));
181  }
182 
183  CartesianVector newVtxPos(originalVtxPos);
184  if (intercepts.size() > 1)
185  GetBestFitPoint(intercepts, directions, weights, newVtxPos);
186 
187  if ((newVtxPos - originalVtxPos).GetMagnitude() > m_twoDDistanceCut)
188  return originalVtxPos;
189 
190  return newVtxPos;
191 }
pandora::CartesianVector EigenValues
Definition: LArPcaHelper.h:24
unsigned int m_minimumHitsCut
The minimum size of a cluster to be used in refinement.
float m_twoDDistanceCut
The maximum distance a cluster can be from the original position to be used in refinement.
void GetBestFitPoint(const pandora::CartesianPointVector &intercepts, const pandora::CartesianPointVector &directions, const pandora::FloatVector &weights, pandora::CartesianVector &bestFitPoint) const
Calculate the best fit point of a set of lines using a matrix equation.
static void RunPca(const T &t, pandora::CartesianVector &centroid, EigenValues &outputEigenValues, EigenVectors &outputEigenVectors)
Run principal component analysis using input calo hits (TPC_VIEW_U,V,W or TPC_3D; all treated as 3D p...
std::vector< pandora::CartesianVector > EigenVectors
Definition: LArPcaHelper.h:25
static void GetCoordinateVector(const pandora::Cluster *const pCluster, pandora::CartesianPointVector &coordinateVector)
Get vector of hit coordinates from an input cluster.
Dft::FloatVector FloatVector
static pandora::CartesianVector GetClosestPosition(const pandora::CartesianVector &position, const pandora::ClusterList &clusterList)
Get closest position in a list of clusters to a specified input position vector.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.
void lar_content::VertexRefinementAlgorithm::RefineVertices ( const pandora::VertexList *const  pVertexList,
const pandora::ClusterList &  clusterListU,
const pandora::ClusterList &  clusterListV,
const pandora::ClusterList &  clusterListW 
) const
private

Perform the refinement proceduce on a list of vertices.

Parameters
pVertexListaddress of the vertex list
clusterListUthe list of U-view clusters
clusterListVthe list of V-view clusters
clusterListWthe list of W-view clusters

Definition at line 96 of file VertexRefinementAlgorithm.cc.

98 {
99  for (const Vertex *const pVertex : *pVertexList)
100  {
101  const CartesianVector originalPosition(pVertex->GetPosition());
102 
103  const CartesianVector vtxU(
104  this->RefineVertexTwoD(clusterListU, LArGeometryHelper::ProjectPosition(this->GetPandora(), originalPosition, TPC_VIEW_U)));
105  const CartesianVector vtxV(
106  this->RefineVertexTwoD(clusterListV, LArGeometryHelper::ProjectPosition(this->GetPandora(), originalPosition, TPC_VIEW_V)));
107  const CartesianVector vtxW(
108  this->RefineVertexTwoD(clusterListW, LArGeometryHelper::ProjectPosition(this->GetPandora(), originalPosition, TPC_VIEW_W)));
109 
110  CartesianVector vtxUV(0.f, 0.f, 0.f), vtxUW(0.f, 0.f, 0.f), vtxVW(0.f, 0.f, 0.f), vtx3D(0.f, 0.f, 0.f), position3D(0.f, 0.f, 0.f);
111  float chi2UV(0.f), chi2UW(0.f), chi2VW(0.f), chi23D(0.f), chi2(0.f);
112 
113  LArGeometryHelper::MergeTwoPositions3D(this->GetPandora(), TPC_VIEW_U, TPC_VIEW_V, vtxU, vtxV, vtxUV, chi2UV);
114  LArGeometryHelper::MergeTwoPositions3D(this->GetPandora(), TPC_VIEW_U, TPC_VIEW_W, vtxU, vtxW, vtxUW, chi2UW);
115  LArGeometryHelper::MergeTwoPositions3D(this->GetPandora(), TPC_VIEW_V, TPC_VIEW_W, vtxV, vtxW, vtxVW, chi2VW);
116  LArGeometryHelper::MergeThreePositions3D(this->GetPandora(), TPC_VIEW_U, TPC_VIEW_V, TPC_VIEW_W, vtxU, vtxV, vtxW, vtx3D, chi23D);
117 
118  if (chi2UV < chi2UW && chi2UV < chi2VW && chi2UV < chi23D)
119  {
120  position3D = vtxUV;
121  chi2 = chi2UV;
122  }
123  else if (chi2UW < chi2VW && chi2UW < chi23D)
124  {
125  position3D = vtxUW;
126  chi2 = chi2UW;
127  }
128  else if (chi2VW < chi23D)
129  {
130  position3D = vtxVW;
131  chi2 = chi2VW;
132  }
133  else
134  {
135  position3D = vtx3D;
136  chi2 = chi23D;
137  }
138 
139  if (chi2 > m_chiSquaredCut)
140  position3D = originalPosition;
141 
142  if ((position3D - originalPosition).GetMagnitude() > m_distanceCut)
143  position3D = originalPosition;
144 
145  PandoraContentApi::Vertex::Parameters parameters;
146  parameters.m_position = position3D;
147  parameters.m_vertexLabel = VERTEX_INTERACTION;
148  parameters.m_vertexType = VERTEX_3D;
149 
150  const Vertex *pNewVertex(NULL);
151  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, parameters, pNewVertex));
152  }
153 }
float m_chiSquaredCut
The maximum chi2 value a refined vertex can have to be kept.
static void MergeTwoPositions3D(const pandora::Pandora &pandora, const pandora::HitType view1, const pandora::HitType view2, const pandora::CartesianVector &position1, const pandora::CartesianVector &position2, pandora::CartesianVector &position3D, float &chiSquared)
Merge 2D positions from two views to give unified 3D position.
static pandora::CartesianVector ProjectPosition(const pandora::Pandora &pandora, const pandora::CartesianVector &position3D, const pandora::HitType view)
Project 3D position into a given 2D view.
pandora::CartesianVector RefineVertexTwoD(const pandora::ClusterList &clusterList, const pandora::CartesianVector &originalVtxPos) const
Refine the position of a two dimensional projection of a vertex using the clusters in that view...
static void MergeThreePositions3D(const pandora::Pandora &pandora, const pandora::HitType view1, const pandora::HitType view2, const pandora::HitType view3, const pandora::CartesianVector &position1, const pandora::CartesianVector &position2, const pandora::CartesianVector &position3, pandora::CartesianVector &position3D, float &chiSquared)
Merge 2D positions from three views to give unified 3D position.
float m_distanceCut
The maximum distance a refined vertex can be from the original position to be kept.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
StatusCode lar_content::VertexRefinementAlgorithm::Run ( )
private

Definition at line 34 of file VertexRefinementAlgorithm.cc.

35 {
36  const VertexList *pInputVertexList(nullptr);
37  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pInputVertexList));
38 
39  if (!pInputVertexList || pInputVertexList->empty())
40  {
41  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
42  std::cout << "VertexRefinementAlgorithm: unable to find current vertex list " << std::endl;
43 
44  return STATUS_CODE_SUCCESS;
45  }
46 
47  const VertexList *pOutputVertexList(NULL);
48  std::string temporaryListName;
49  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pOutputVertexList, temporaryListName));
50 
51  ClusterList clusterListU, clusterListV, clusterListW;
52  this->GetClusterLists(m_inputClusterListNames, clusterListU, clusterListV, clusterListW);
53 
54  this->RefineVertices(pInputVertexList, clusterListU, clusterListV, clusterListW);
55 
56  if (!pOutputVertexList->empty())
57  {
58  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*this, m_outputVertexListName));
59  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Vertex>(*this, m_outputVertexListName));
60  }
61 
62  return STATUS_CODE_SUCCESS;
63 }
std::string string
Definition: nybbler.cc:12
std::string m_outputVertexListName
The refined vertex list to be outputted.
void GetClusterLists(const pandora::StringVector &inputClusterListNames, pandora::ClusterList &clusterListU, pandora::ClusterList &clusterListV, pandora::ClusterList &clusterListW) const
Get the input cluster lists.
void RefineVertices(const pandora::VertexList *const pVertexList, const pandora::ClusterList &clusterListU, const pandora::ClusterList &clusterListV, const pandora::ClusterList &clusterListW) const
Perform the refinement proceduce on a list of vertices.
pandora::StringVector m_inputClusterListNames
The list of input cluster list names.
std::list< Vertex > VertexList
Definition: DCEL.h:182
QTextStream & endl(QTextStream &s)

Member Data Documentation

float lar_content::VertexRefinementAlgorithm::m_chiSquaredCut
private

The maximum chi2 value a refined vertex can have to be kept.

Definition at line 79 of file VertexRefinementAlgorithm.h.

float lar_content::VertexRefinementAlgorithm::m_distanceCut
private

The maximum distance a refined vertex can be from the original position to be kept.

Definition at line 80 of file VertexRefinementAlgorithm.h.

pandora::StringVector lar_content::VertexRefinementAlgorithm::m_inputClusterListNames
private

The list of input cluster list names.

Definition at line 75 of file VertexRefinementAlgorithm.h.

std::string lar_content::VertexRefinementAlgorithm::m_inputVertexListName
private

The initial vertex list.

Definition at line 76 of file VertexRefinementAlgorithm.h.

unsigned int lar_content::VertexRefinementAlgorithm::m_minimumHitsCut
private

The minimum size of a cluster to be used in refinement.

Definition at line 81 of file VertexRefinementAlgorithm.h.

std::string lar_content::VertexRefinementAlgorithm::m_outputVertexListName
private

The refined vertex list to be outputted.

Definition at line 77 of file VertexRefinementAlgorithm.h.

float lar_content::VertexRefinementAlgorithm::m_twoDDistanceCut
private

The maximum distance a cluster can be from the original position to be used in refinement.

Definition at line 82 of file VertexRefinementAlgorithm.h.


The documentation for this class was generated from the following files: