LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
LArEigenHelper.cc
Go to the documentation of this file.
1 
12 
13 #include <Eigen/Dense>
14 
15 #define _USE_MATH_DEFINES
16 #include <cmath>
17 
18 using namespace pandora;
19 
20 namespace lar_content
21 {
22 
23 //------------------------------------------------------------------------------------------------------------------------------------------
24 
25 template <class T>
26 void LArEigenHelper::Vectorize(const T &caloHitContainer, Eigen::MatrixXf &hitMatrix)
27 {
28  int i{0};
29  for (const CaloHit *const pCaloHit : caloHitContainer)
30  {
31  const CartesianVector &pos{pCaloHit->GetPositionVector()};
32  hitMatrix(i, 0) = pos.GetX();
33  hitMatrix(i, 1) = pos.GetZ();
34  ++i;
35  }
36 }
37 
38 //------------------------------------------------------------------------------------------------------------------------------------------
39 
40 template <class T>
41 void LArEigenHelper::Vectorize(const T &caloHitContainer, Eigen::MatrixXf &centre, Eigen::MatrixXf &low, Eigen::MatrixXf &high)
42 {
43  LArEigenHelper::Vectorize(caloHitContainer, centre);
44  int i{0};
45  for (const CaloHit *const pCaloHit : caloHitContainer)
46  {
47  const CartesianVector &pos{pCaloHit->GetPositionVector()};
48  low(i, 0) = pos.GetX() - pCaloHit->GetCellSize1() * 0.5f;
49  low(i, 1) = pos.GetZ();
50  high(i, 0) = pos.GetX() + pCaloHit->GetCellSize1() * 0.5f;
51  high(i, 1) = pos.GetZ();
52  ++i;
53  }
54 }
55 
56 //------------------------------------------------------------------------------------------------------------------------------------------
57 
58 void LArEigenHelper::GetAngles(const Eigen::MatrixXf &hitMatrix, const Eigen::RowVectorXf &origin, Eigen::RowVectorXf &phis)
59 {
60  const float pi{static_cast<float>(M_PI)};
61  Eigen::RowVectorXf piVec{Eigen::RowVectorXf::Constant(hitMatrix.rows(), pi)};
62  Eigen::RowVectorXf zeroVec{Eigen::RowVectorXf::Zero(hitMatrix.rows())};
63  Eigen::MatrixXf deltas(hitMatrix.rowwise() - origin);
64  for (int i = 0; i < deltas.rows(); ++i)
65  phis(i) = std::atan2(deltas(i, 1), deltas(i, 0));
66  // Move from [-pi, +pi] to [0, 2pi)
67  phis = (phis.array() < 0).select(piVec * 2 + phis, phis);
68  phis = (phis.array() < 2 * pi).select(phis, zeroVec);
69 }
70 
71 //------------------------------------------------------------------------------------------------------------------------------------------
72 
73 template void LArEigenHelper::Vectorize(const CaloHitList &, Eigen::MatrixXf &);
74 template void LArEigenHelper::Vectorize(const CaloHitVector &, Eigen::MatrixXf &);
75 template void LArEigenHelper::Vectorize(const CaloHitList &, Eigen::MatrixXf &, Eigen::MatrixXf &, Eigen::MatrixXf &);
76 template void LArEigenHelper::Vectorize(const CaloHitVector &, Eigen::MatrixXf &, Eigen::MatrixXf &, Eigen::MatrixXf &);
77 
78 } // namespace lar_content
Header file for the principal curve analysis helper class.
Header file for the object helper class.
Header file for the cluster helper class.
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:229