53 EigenObservationMatrix eigenObservation = getEigenObservationMatrix(&observations2D);
54 assert(eigenObservation.cols() == 4);
55 size_t nObservations = observations2D.
size();
60 Eigen::Matrix<double, Eigen::Dynamic, 2> points = eigenObservation.leftCols<2>();
62 Eigen::Matrix<double, 1, 2> pointMean;
64 pointMean << 0.0, 0.0;
67 pointMean = points.colwise().mean();
69 points = points.rowwise() - pointMean;
71 Eigen::Matrix<double, 2, 2> covarianceMatrix = points.transpose() * points;
73 Eigen::SelfAdjointEigenSolver< Eigen::Matrix<double, 2, 2> > eigensolver(covarianceMatrix);
75 if (eigensolver.info() != Eigen::Success)
76 B2WARNING(
"SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
81 Eigen::Matrix<double, 2, 1> normalToLine = eigensolver.eigenvectors().col(0);
83 double offset = -pointMean * normalToLine;
92 Eigen::Matrix<double, Eigen::Dynamic, 3> projectedPoints(nObservations, 3);
94 projectedPoints.col(0) = eigenObservation.col(0);
95 projectedPoints.col(1) = eigenObservation.col(1);
96 projectedPoints.col(2) = eigenObservation.leftCols<2>().rowwise().squaredNorm();
99 Eigen::Matrix<double, 1, 3> pointMean;
100 pointMean << 0.0, 0.0, 0.0;
103 pointMean = projectedPoints.colwise().mean();
105 projectedPoints = projectedPoints.rowwise() - pointMean;
108 Eigen::Matrix<double, 3, 3> covarianceMatrix = projectedPoints.transpose() * projectedPoints;
110 Eigen::SelfAdjointEigenSolver< Eigen::Matrix<double, 3, 3> > eigensolver(covarianceMatrix);
112 if (eigensolver.info() != Eigen::Success)
113 B2WARNING(
"Eigen::SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
118 Eigen::Matrix<double, 3, 1> normalToPlane = eigensolver.eigenvectors().col(0);
120 double offset = -pointMean * normalToPlane;
129 const ROOT::Math::XYVector& directionAtCenter = trajectory2D.
getFlightDirection2D(ROOT::Math::XYVector(0.0, 0.0));
132 size_t voteForChangeSign = 0;
133 for (
size_t iPoint = 0; iPoint < nObservations; ++iPoint) {
134 double pointInSameDirection = eigenObservation(iPoint, 0) * directionAtCenter.x() +
135 eigenObservation(iPoint, 1) * directionAtCenter.y();
136 if (pointInSameDirection < 0) ++voteForChangeSign;
139 if (voteForChangeSign > nObservations / 2.0) trajectory2D.
reverse();
147 EigenObservationMatrix eigenObservation = getEigenObservationMatrix(&observations2D);
148 assert(eigenObservation.cols() == 4);
149 size_t nObservations = observations2D.
size();
159 Eigen::Matrix< double, Eigen::Dynamic, 1 > distances = eigenObservation.col(2);
166 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 2);
170 projectedPoints.col(0) = eigenObservation.col(0);
171 projectedPoints.col(1) = eigenObservation.col(1);
174 Eigen::Matrix<double, 2, 1> parameters =
175 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
182 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 3);
186 projectedPoints.col(0) = eigenObservation.col(0);
187 projectedPoints.col(1) = eigenObservation.col(1);
188 projectedPoints.col(2) = eigenObservation.leftCols<2>().rowwise().squaredNorm() - distances.rowwise().squaredNorm();
190 Eigen::Matrix<double, 3, 1> parameters =
191 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
198 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 3);
201 projectedPoints.col(0) = Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0);
202 projectedPoints.col(1) = eigenObservation.col(0);
203 projectedPoints.col(2) = eigenObservation.col(1);
206 Eigen::Matrix<double, 3, 1> parameters =
207 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
216 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 4);
219 projectedPoints.col(0) = Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0);
220 projectedPoints.col(1) = eigenObservation.col(0);
221 projectedPoints.col(2) = eigenObservation.col(1);
222 projectedPoints.col(3) = eigenObservation.leftCols<2>().rowwise().squaredNorm() - distances.rowwise().squaredNorm();
226 Eigen::Matrix<double, 4, 1> parameters =
227 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);