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;
65 pointMean << 0.0, 0.0;
68 pointMean = points.colwise().mean();
70 points = points.rowwise() - pointMean;
72 Eigen::Matrix<double, 2, 2> covarianceMatrix = points.transpose() * points;
74 Eigen::SelfAdjointEigenSolver< Eigen::Matrix<double, 2, 2> > eigensolver(covarianceMatrix);
76 if (eigensolver.info() != Eigen::Success)
77 B2WARNING(
"SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
82 Eigen::Matrix<double, 2, 1> normalToLine = eigensolver.eigenvectors().col(0);
84 double offset = -pointMean * normalToLine;
93 Eigen::Matrix<double, Eigen::Dynamic, 3> projectedPoints(nObservations, 3);
95 projectedPoints.col(0) = eigenObservation.col(0);
96 projectedPoints.col(1) = eigenObservation.col(1);
97 projectedPoints.col(2) = eigenObservation.leftCols<2>().rowwise().squaredNorm();
100 Eigen::Matrix<double, 1, 3> pointMean;
102 pointMean << 0.0, 0.0, 0.0;
105 pointMean = projectedPoints.colwise().mean();
107 projectedPoints = projectedPoints.rowwise() - pointMean;
110 Eigen::Matrix<double, 3, 3> covarianceMatrix = projectedPoints.transpose() * projectedPoints;
112 Eigen::SelfAdjointEigenSolver< Eigen::Matrix<double, 3, 3> > eigensolver(covarianceMatrix);
114 if (eigensolver.info() != Eigen::Success)
115 B2WARNING(
"Eigen::SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
120 Eigen::Matrix<double, 3, 1> normalToPlane = eigensolver.eigenvectors().col(0);
122 double offset = -pointMean * normalToPlane;
131 const ROOT::Math::XYVector& directionAtCenter = trajectory2D.
getFlightDirection2D(ROOT::Math::XYVector(0.0, 0.0));
134 size_t voteForChangeSign = 0;
135 for (
size_t iPoint = 0; iPoint < nObservations; ++iPoint) {
136 double pointInSameDirection = eigenObservation(iPoint, 0) * directionAtCenter.x() +
137 eigenObservation(iPoint, 1) * directionAtCenter.y();
138 if (pointInSameDirection < 0) ++voteForChangeSign;
141 if (voteForChangeSign > nObservations / 2.0) trajectory2D.
reverse();
149 EigenObservationMatrix eigenObservation = getEigenObservationMatrix(&observations2D);
150 assert(eigenObservation.cols() == 4);
151 size_t nObservations = observations2D.
size();
161 Eigen::Matrix< double, Eigen::Dynamic, 1 > distances = eigenObservation.col(2);
168 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 2);
172 projectedPoints.col(0) = eigenObservation.col(0);
173 projectedPoints.col(1) = eigenObservation.col(1);
176 Eigen::Matrix<double, 2, 1> parameters =
177 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
184 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 3);
188 projectedPoints.col(0) = eigenObservation.col(0);
189 projectedPoints.col(1) = eigenObservation.col(1);
190 projectedPoints.col(2) = eigenObservation.leftCols<2>().rowwise().squaredNorm() - distances.rowwise().squaredNorm();
192 Eigen::Matrix<double, 3, 1> parameters =
193 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
200 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 3);
203 projectedPoints.col(0) = Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0);
204 projectedPoints.col(1) = eigenObservation.col(0);
205 projectedPoints.col(2) = eigenObservation.col(1);
208 Eigen::Matrix<double, 3, 1> parameters =
209 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);
218 Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > projectedPoints(nObservations, 4);
221 projectedPoints.col(0) = Eigen::Matrix<double, Eigen::Dynamic, 1>::Constant(nObservations, 1.0);
222 projectedPoints.col(1) = eigenObservation.col(0);
223 projectedPoints.col(2) = eigenObservation.col(1);
224 projectedPoints.col(3) = eigenObservation.leftCols<2>().rowwise().squaredNorm() - distances.rowwise().squaredNorm();
228 Eigen::Matrix<double, 4, 1> parameters =
229 projectedPoints.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(distances);