LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PCAxis.cxx
Go to the documentation of this file.
1 //
3 // \file PCAxis.cxx
4 // \brief Definition of Principal Components Axis object for LArSoft
5 //
6 // \author usher@slac.stanford.edu
7 //
8 // \see PCAxis.h
9 //
11 
13 
14 #include <iomanip>
15 #include <ostream>
16 
17 namespace recob {
18 
19  //----------------------------------------------------------------------
21 
22  //----------------------------------------------------------------------
23  PCAxis::PCAxis(bool ok,
24  int nHits,
25  const double* eigenValues,
26  const recob::PCAxis::EigenVectors& eigenVecs,
27  const double* avePos,
28  const double aveHitDoca,
29  size_t id)
30  : fSvdOK(ok), fNumHitsUsed(nHits), fEigenVectors(eigenVecs), fAveHitDoca(aveHitDoca), fID(id)
31  {
32  fEigenValues[0] = eigenValues[0];
33  fEigenValues[1] = eigenValues[1];
34  fEigenValues[2] = eigenValues[2];
35  fAvePosition[0] = avePos[0];
36  fAvePosition[1] = avePos[1];
37  fAvePosition[2] = avePos[2];
38  }
39 
40  //----------------------------------------------------------------------
41  // ostream operator.
42  //
43  std::ostream& operator<<(std::ostream& o, const PCAxis& a)
44  {
45  if (a.fSvdOK) {
46  o << std::setiosflags(std::ios::fixed) << std::setprecision(2);
47  o << " PCAxis ID " << a.fID << " run with " << a.fNumHitsUsed << " space points" << std::endl;
48  o << " - center position: " << std::setw(6) << a.fAvePosition[0] << ", "
49  << a.fAvePosition[1] << ", " << a.fAvePosition[2] << std::endl;
50  o << " - eigen values: " << std::setw(8) << std::right << a.fEigenValues[0] << ", "
51  << a.fEigenValues[1] << ", " << a.fEigenValues[2] << std::endl;
52  o << " - average doca: " << a.fAveHitDoca << std::endl;
53  o << " - Principle axis: " << std::setw(7) << std::setprecision(4) << a.fEigenVectors[0][0]
54  << ", " << a.fEigenVectors[0][1] << ", " << a.fEigenVectors[0][2] << std::endl;
55  o << " - second axis: " << std::setw(7) << std::setprecision(4) << a.fEigenVectors[1][0]
56  << ", " << a.fEigenVectors[1][1] << ", " << a.fEigenVectors[1][2] << std::endl;
57  o << " - third axis: " << std::setw(7) << std::setprecision(4) << a.fEigenVectors[2][0]
58  << ", " << a.fEigenVectors[2][1] << ", " << a.fEigenVectors[2][2] << std::endl;
59  }
60  else
61  o << " Principal Components Axis is not valid" << std::endl;
62 
63  return o;
64  }
65 
66  //----------------------------------------------------------------------------
67  // comparison operator
68  //
69  bool operator<(const PCAxis& a, const PCAxis& b)
70  {
71  if (a.getID() != b.getID()) return a.getID() < b.getID();
72 
73  return false; //They are equal
74  }
75 
76 } // End of namespace
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
bool fSvdOK
SVD Decomposition was successful.
Definition: PCAxis.h:31
Reconstruction base classes.
friend bool operator<(const PCAxis &a, const PCAxis &b)
Definition: PCAxis.cxx:69
double fEigenValues[3]
Eigen values from SVD decomposition.
Definition: PCAxis.h:33
size_t getID() const
Definition: PCAxis.h:86
friend std::ostream & operator<<(std::ostream &o, const PCAxis &a)
Definition: PCAxis.cxx:43
size_t fID
axis ID
Definition: PCAxis.h:37
EigenVectors fEigenVectors
The three principle axes.
Definition: PCAxis.h:34
int fNumHitsUsed
Number of hits in the decomposition.
Definition: PCAxis.h:32
double fAveHitDoca
Average doca of hits used in PCA.
Definition: PCAxis.h:36
double fAvePosition[3]
Average position of hits fed to PCA.
Definition: PCAxis.h:35
std::vector< std::vector< double > > EigenVectors
Definition: PCAxis.h:26