LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::SimplePCAThreeDClusteringTool Class Reference

#include "SimplePCAThreeDClusteringTool.h"

Inheritance diagram for lar_content::SimplePCAThreeDClusteringTool:
lar_content::ClusteringTool

Public Member Functions

 SimplePCAThreeDClusteringTool ()
 

Private Member Functions

bool Run (const pandora::CaloHitList &inputCaloHitList, std::vector< pandora::CaloHitList > &outputCaloHitListsVector)
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle)
 

Detailed Description

Definition at line 18 of file SimplePCAThreeDClusteringTool.h.

Constructor & Destructor Documentation

lar_content::SimplePCAThreeDClusteringTool::SimplePCAThreeDClusteringTool ( )

Definition at line 20 of file SimplePCAThreeDClusteringTool.cc.

21 {
22 }

Member Function Documentation

StatusCode lar_content::SimplePCAThreeDClusteringTool::ReadSettings ( const pandora::TiXmlHandle  )
private

Definition at line 111 of file SimplePCAThreeDClusteringTool.cc.

112 {
113  return STATUS_CODE_SUCCESS;
114 }
bool lar_content::SimplePCAThreeDClusteringTool::Run ( const pandora::CaloHitList &  inputCaloHitList,
std::vector< pandora::CaloHitList > &  outputCaloHitListsVector 
)
privatevirtual

Implements lar_content::ClusteringTool.

Definition at line 26 of file SimplePCAThreeDClusteringTool.cc.

References f, and GetIntersection().

27 {
28  // Begin with a PCA
29  CartesianVector centroid(0.f, 0.f, 0.f);
31  LArPcaHelper::EigenValues eigenValues(0.f, 0.f, 0.f);
32  LArPcaHelper::RunPca(inputCaloHitList, centroid, eigenValues, eigenVecs);
33 
34  // By convention, the primary axis has a positive z-component - define ortho directions
35  const CartesianVector orthoDirection1(eigenVecs.at(1).GetZ() > 0.f ? eigenVecs.at(1) : eigenVecs.at(1) * -1.f);
36 
37  //Lists for hits that have a positive and negative projection on the secondary axis
38  CaloHitList posCaloHitList, negCaloHitList;
39 
40  for (const CaloHit *const pCaloHit3D : inputCaloHitList)
41  {
42  const CartesianVector pCaloHit3DPosition{pCaloHit3D->GetPositionVector()};
43 
44  if ((pCaloHit3DPosition - centroid).GetDotProduct(orthoDirection1) < 0)
45  {
46  negCaloHitList.push_back(pCaloHit3D);
47  }
48  else
49  {
50  posCaloHitList.push_back(pCaloHit3D);
51  }
52  }
53 
54  outputCaloHitListsVector.push_back(posCaloHitList);
55  outputCaloHitListsVector.push_back(negCaloHitList);
56 
57  //Now, run PCA independently on pos and neg hit lists, to refine split
58 
59  //Get pos list PCA
60  CartesianVector centroidPos(0.f, 0.f, 0.f);
61  LArPcaHelper::EigenVectors eigenVecsPos;
62  LArPcaHelper::EigenValues eigenValuesPos(0.f, 0.f, 0.f);
63  LArPcaHelper::RunPca(posCaloHitList, centroidPos, eigenValuesPos, eigenVecsPos);
64 
65  // By convention, the primary axis has a positive z-component.
66  const CartesianVector axisDirectionPos(eigenVecsPos.at(0).GetZ() > 0.f ? eigenVecsPos.at(0) : eigenVecsPos.at(0) * -1.f);
67 
68  //Get neg list PCA
69  CartesianVector centroidNeg(0.f, 0.f, 0.f);
70  LArPcaHelper::EigenVectors eigenVecsNeg;
71  LArPcaHelper::EigenValues eigenValuesNeg(0.f, 0.f, 0.f);
72  LArPcaHelper::RunPca(negCaloHitList, centroidNeg, eigenValuesNeg, eigenVecsNeg);
73 
74  // By convention, the primary axis has a positive z-component.
75  const CartesianVector axisDirectionNeg(eigenVecsNeg.at(0).GetZ() > 0.f ? eigenVecsNeg.at(0) : eigenVecsNeg.at(0) * -1.f);
76 
77  //Get intersection point of the two new principal axes
78  CartesianVector intersectionPoint(0.f, 0.f, 0.f);
79  float displacementPos(0.f), displacementNeg(0.f);
80 
81  try
82  {
84  centroidPos, axisDirectionPos, centroidNeg, axisDirectionNeg, intersectionPoint, displacementPos, displacementNeg);
85  }
86  catch (const StatusCodeException &)
87  {
88  std::cout << "Exception caught! Cannot get intersection between positive and negative hit lists primary PCA axes!" << std::endl;
89  }
90 
91  //Clear pos and neg lists
92  posCaloHitList.clear();
93  negCaloHitList.clear();
94 
95  //Loop over original hit list, check whether it is within smaller cone of pos or neg axis, attach to relevant list
96  for (const CaloHit *const pCaloHit3D : inputCaloHitList)
97  {
98  const float cosConeAxisPos = axisDirectionPos.GetCosOpeningAngle(pCaloHit3D->GetPositionVector() - intersectionPoint);
99  const float cosConeAxisNeg = axisDirectionNeg.GetCosOpeningAngle(pCaloHit3D->GetPositionVector() - intersectionPoint);
100  if (cosConeAxisPos > cosConeAxisNeg)
101  posCaloHitList.push_back(pCaloHit3D);
102  else
103  negCaloHitList.push_back(pCaloHit3D);
104  }
105 
106  return true;
107 }
static void GetIntersection(const LArPointingCluster::Vertex &firstVertex, const LArPointingCluster::Vertex &secondVertex, pandora::CartesianVector &intersectPosition, float &firstDisplacement, float &secondDisplacement)
Get intersection of two vertices.
pandora::CartesianVector EigenValues
Definition: LArPcaHelper.h:24
TFile f
Definition: plotHisto.C:6
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

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