Belle II Software  release-08-01-10
EigenObservationMatrix.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/trackFindingCDC/fitting/EigenObservationMatrix.h>
9 
10 #include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
11 #include <tracking/trackFindingCDC/fitting/CDCSZObservations.h>
12 
13 #include <cassert>
14 
15 using namespace Belle2;
16 using namespace TrackFindingCDC;
17 
18 TrackFindingCDC::EigenObservationMatrix
19 TrackFindingCDC::getEigenObservationMatrix(CDCObservations2D* observations2D)
20 {
21  std::size_t nObservations = observations2D->size();
22  double* rawObservations = observations2D->data();
23  EigenObservationMatrix eigenObservations(rawObservations, nObservations, 4);
24  return eigenObservations;
25 }
26 
27 TrackFindingCDC::EigenObservationMatrix
28 TrackFindingCDC::getEigenObservationMatrix(CDCSZObservations* szObservations)
29 {
30  std::size_t nObservations = szObservations->size();
31  double* rawObservations = szObservations->data();
32  EigenObservationMatrix eigenObservations(rawObservations, nObservations, 3);
33  return eigenObservations;
34 }
35 
36 Eigen::Matrix<double, 5, 5> TrackFindingCDC::getWXYRLSumMatrix(CDCObservations2D& observations2D)
37 {
38  EigenObservationMatrix eigenObservations = getEigenObservationMatrix(&observations2D);
39  assert(eigenObservations.cols() == 4);
40  std::size_t nObservations = eigenObservations.rows();
41 
42  // B2INFO("Matrix of observations: " << endl << eigenObservations);
43 
44  Eigen::Matrix<double, Eigen::Dynamic, 5> projectedPoints(nObservations, 5);
45 
46  const std::size_t iW = 0;
47  const std::size_t iX = 1;
48  const std::size_t iY = 2;
49  const std::size_t iR2 = 3;
50  const std::size_t iL = 4;
51 
52  projectedPoints.col(iW) =
53  Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0); // Offset column
54  projectedPoints.col(iX) = eigenObservations.col(0);
55  projectedPoints.col(iY) = eigenObservations.col(1);
56  projectedPoints.col(iR2) = eigenObservations.leftCols<2>().rowwise().squaredNorm() -
57  eigenObservations.col(2).rowwise().squaredNorm();
58  projectedPoints.col(iL) = eigenObservations.col(2);
59 
60  Eigen::Array<double, Eigen::Dynamic, 1> weights = eigenObservations.col(3);
61  Eigen::Matrix<double, Eigen::Dynamic, 5> weightedProjectedPoints =
62  projectedPoints.array().colwise() * weights;
63  Eigen::Matrix<double, 5, 5> sumMatrix = weightedProjectedPoints.transpose() * projectedPoints;
64 
65  // B2INFO("Matrix of sums: " << endl << sumMatrix);
66 
67  return sumMatrix;
68 }
69 
70 Eigen::Matrix<double, 4, 4> TrackFindingCDC::getWXYLSumMatrix(CDCObservations2D& observations2D)
71 {
72  EigenObservationMatrix eigenObservations = getEigenObservationMatrix(&observations2D);
73  assert(eigenObservations.cols() == 4);
74  std::size_t nObservations = eigenObservations.rows();
75 
76  Eigen::Matrix<double, Eigen::Dynamic, 4> projectedPoints(nObservations, 4);
77 
78  const std::size_t iW = 0;
79  const std::size_t iX = 1;
80  const std::size_t iY = 2;
81  const std::size_t iL = 3;
82 
83  projectedPoints.col(iW) =
84  Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0); // Offset column
85  projectedPoints.col(iX) = eigenObservations.col(0);
86  projectedPoints.col(iY) = eigenObservations.col(1);
87  projectedPoints.col(iL) = eigenObservations.col(2);
88 
89  Eigen::Array<double, Eigen::Dynamic, 1> weights = eigenObservations.col(3);
90  Eigen::Matrix<double, Eigen::Dynamic, 4> weightedProjectedPoints =
91  projectedPoints.array().colwise() * weights;
92  Eigen::Matrix<double, 4, 4> sumMatrix = weightedProjectedPoints.transpose() * projectedPoints;
93 
94  return sumMatrix;
95 }
96 
97 Eigen::Matrix<double, 4, 4> TrackFindingCDC::getWXYRSumMatrix(CDCObservations2D& observations2D)
98 {
99  EigenObservationMatrix eigenObservations = getEigenObservationMatrix(&observations2D);
100  assert(eigenObservations.cols() == 4);
101  std::size_t nObservations = eigenObservations.rows();
102 
103  Eigen::Matrix<double, Eigen::Dynamic, 4> projectedPoints(nObservations, 4);
104 
105  const std::size_t iW = 0;
106  const std::size_t iX = 1;
107  const std::size_t iY = 2;
108  const std::size_t iR2 = 3;
109 
110  projectedPoints.col(iW) =
111  Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0); // Offset column
112  projectedPoints.col(iX) = eigenObservations.col(0);
113  projectedPoints.col(iY) = eigenObservations.col(1);
114  projectedPoints.col(iR2) = eigenObservations.leftCols<2>().rowwise().squaredNorm() -
115  eigenObservations.col(2).rowwise().squaredNorm();
116 
117  Eigen::Array<double, Eigen::Dynamic, 1> weights = eigenObservations.col(3);
118  Eigen::Matrix<double, Eigen::Dynamic, 4> weightedProjectedPoints =
119  projectedPoints.array().colwise() * weights;
120  Eigen::Matrix<double, 4, 4> sumMatrix = weightedProjectedPoints.transpose() * projectedPoints;
121  return sumMatrix;
122 }
123 
124 Eigen::Matrix<double, 3, 3> TrackFindingCDC::getWXYSumMatrix(CDCObservations2D& observations2D)
125 {
126  EigenObservationMatrix eigenObservations = getEigenObservationMatrix(&observations2D);
127  assert(eigenObservations.cols() == 4);
128  std::size_t nObservations = eigenObservations.rows();
129 
130  Eigen::Matrix<double, Eigen::Dynamic, 3> projectedPoints(nObservations, 3);
131 
132  const std::size_t iW = 0;
133  const std::size_t iX = 1;
134  const std::size_t iY = 2;
135 
136  projectedPoints.col(iW) =
137  Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0); // Offset column
138  projectedPoints.col(iX) = eigenObservations.col(0);
139  projectedPoints.col(iY) = eigenObservations.col(1);
140 
141  Eigen::Array<double, Eigen::Dynamic, 1> weights = eigenObservations.col(3);
142  Eigen::Matrix<double, Eigen::Dynamic, 3> weightedProjectedPoints =
143  projectedPoints.array().colwise() * weights;
144  Eigen::Matrix<double, 3, 3> sumMatrix = weightedProjectedPoints.transpose() * projectedPoints;
145 
146  return sumMatrix;
147 }
148 
149 Eigen::Matrix<double, 3, 3> TrackFindingCDC::getWSZSumMatrix(CDCSZObservations& szObservations)
150 {
151  EigenObservationMatrix eigenObservations = getEigenObservationMatrix(&szObservations);
152  assert(eigenObservations.cols() == 3);
153  std::size_t nObservations = eigenObservations.rows();
154 
155  Eigen::Matrix<double, Eigen::Dynamic, 3> projectedPoints(nObservations, 3);
156 
157  const std::size_t iW = 0;
158  const std::size_t iS = 1;
159  const std::size_t iZ = 2;
160 
161  projectedPoints.col(iW) = Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0); // Offset column
162  projectedPoints.col(iS) = eigenObservations.col(0);
163  projectedPoints.col(iZ) = eigenObservations.col(1);
164 
165  Eigen::Array<double, Eigen::Dynamic, 1> weights = eigenObservations.col(2);
166  Eigen::Matrix<double, Eigen::Dynamic, 3> weightedProjectedPoints = projectedPoints.array().colwise() * weights;
167  Eigen::Matrix<double, 3, 3> sumMatrix = weightedProjectedPoints.transpose() * projectedPoints;
168 
169  return sumMatrix;
170 }
Class serving as a storage of observed drift circles to present to the Riemann fitter.
double * data()
Return the pointer to the number buffer.
std::size_t size() const
Returns the number of observations stored.
Class serving as a storage of observed sz positions to present to the sz line fitters.
double * data()
Return the pointer to the number buffer.
std::size_t size() const
Returns the number of observations stored.
Abstract base class for different kinds of events.