8#include <tracking/trackFindingCDC/fitting/CDCSZFitter.h>
10#include <tracking/trackFindingCDC/fitting/EigenObservationMatrix.h>
11#include <tracking/trackFindingCDC/fitting/CDCSZObservations.h>
12#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
14#include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
15#include <tracking/trackFindingCDC/eventdata/tracks/CDCSegmentPair.h>
17#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment3D.h>
18#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
20#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
21#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
23#include <tracking/trackFindingCDC/geometry/SZParameters.h>
25#include <tracking/trackFindingCDC/numerics/EigenView.h>
27#include <framework/logging/Logger.h>
34using namespace TrackFindingCDC;
46 Eigen::Matrix<double, 2, 2> sumMatrixWS = sumMatrixWSZ.block<2, 2>(0, 0);
47 Eigen::Matrix<double, 2, 1> sumVectorZOverWS = sumMatrixWSZ.block<2, 1>(0, 2);
48 Eigen::Matrix<double, 2, 1> nZOverWS = sumMatrixWS.llt().solve(sumVectorZOverWS);
49 double chi2 = sumMatrixWSZ(2, 2) - nZOverWS.transpose() * sumVectorZOverWS;
52 SZParameters szParameters;
53 szParameters(c_TanL) = nZOverWS(1);
54 szParameters(c_Z0) = nZOverWS(0);
56 SZPrecision szPrecision;
57 szPrecision(c_TanL, c_TanL) = sumMatrixWS(1, 1);
58 szPrecision(c_Z0, c_TanL) = sumMatrixWS(0, 1);
59 szPrecision(c_TanL, c_Z0) = sumMatrixWS(1, 0);
60 szPrecision(c_Z0, c_Z0) = sumMatrixWS(0, 0);
67 UncertainSZLine fitSZ(
const Eigen::Matrix<double, 3, 3>& sumMatrixWSZ) __attribute__((__unused__));
74 Eigen::Matrix<double, 3, 3> averageMatrixWSZ = sumMatrixWSZ / sumMatrixWSZ(0);
77 Eigen::Matrix<double, 3, 1> meansWSZ = averageMatrixWSZ.row(0);
80 Eigen::Matrix<double, 3, 3> covMatrixWSZ = averageMatrixWSZ - meansWSZ * meansWSZ.transpose();
82 Eigen::Matrix<double, 2, 2> covMatrixSZ = covMatrixWSZ.block<2, 2>(1, 1);
83 Eigen::Matrix<double, 2, 1> meansSZ = meansWSZ.segment<2>(1);
85 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 2, 2>> eigensolver(covMatrixSZ);
86 if (eigensolver.info() != Eigen::Success) {
88 "SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
94 Eigen::Matrix<double, 2, 1> nSZ = eigensolver.eigenvectors().col(0);
95 B2INFO(
"nSZ " << nSZ);
96 nSZ /= std::copysign(nSZ.norm(), -nSZ(1));
97 Eigen::Matrix<double, 3, 1> nWSZ;
99 nWSZ << -meansSZ.transpose() * nSZ, nSZ;
100 B2INFO(
"nWSZ " << nWSZ);
102 double chi2 = nWSZ.transpose() * sumMatrixWSZ * nWSZ;
104 Eigen::Matrix<double, 3, 3> precN = sumMatrixWSZ;
107 SZParameters szParameters;
108 szParameters(c_TanL) = -nWSZ(1) / nWSZ(2);
109 szParameters(c_Z0) = -nWSZ(0) / nWSZ(2);
111 Eigen::Matrix<double, 3, 2> ambiguitySZToN = Eigen::Matrix<double, 3, 2>::Zero();
112 ambiguitySZToN(0, c_Z0) = -nWSZ(2);
113 ambiguitySZToN(0, c_TanL) = -nWSZ(1) * nWSZ(0);
114 ambiguitySZToN(1, c_TanL) = -nWSZ(2) * nWSZ(2) * nWSZ(2);
115 ambiguitySZToN(2, c_TanL) = nWSZ(1) * nWSZ(2) * nWSZ(2);
117 SZPrecision szPrecision;
118 mapToEigen(szPrecision) = ambiguitySZToN.transpose() * precN * ambiguitySZToN;
127 const bool onlyStereo =
true;
130 if (observationsSZ.
size() > 3) {
132 update(szTrajectory, observationsSZ);
142 B2ASSERT(
"Expected stereo segment", not stereoSegment.
isAxial());
145 update(trajectorySZ, stereoSegment, axialTrajectory2D);
153 return fit(std::move(observationsSZ));
159 update(trajectorySZ, observationsSZ);
168 assert(ptrStereoSegment);
169 assert(ptrAxialSegment);
176 update(trajectorySZ, stereoSegment, axialTrajectory2D);
185 for (
size_t i = 0; i < observations2D.
size(); ++i) {
186 const double s = observations2D.
getX(i);
187 const double z = observations2D.
getY(i);
188 szObservations.
fill(s, z);
190 return fit(std::move(szObservations));
197 B2ASSERT(
"Expected stereo segment", not stereoSegment.
isAxial());
203 observationsSZ.
append(recoHit3D);
206 update(trajectorySZ, observationsSZ);
211 trajectorySZ.
clear();
212 if (observationsSZ.
size() < 3) {
217 size_t ndf = observationsSZ.
size() - 2;
220 Eigen::Matrix<double, 3, 3> sumMatrixWSZ = getWSZSumMatrix(observationsSZ);
223 uncertainSZLine.
setNDF(ndf);
Class serving as a storage of observed drift circles to present to the Riemann fitter.
double getX(int iObservation) const
Getter for the x value of the observation at the given index.
double getY(int iObservation) const
Getter for the y value of the observation at the given index.
std::size_t size() const
Returns the number of observations stored.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Class representing a three dimensional reconstructed hit.
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
Class implementing the z coordinate over travel distance line fit.
void update(const CDCSegmentPair &segmentPair) const
Updates the trajectory of the axial stereo segment pair inplace.
static const CDCSZFitter & getFitter()
Getter for a standard sz line fitter instance.
CDCTrajectorySZ fitWithStereoHits(const CDCTrack &track) const
Returns the fitted sz trajectory of the track with the z-information of all stereo hits of the number...
CDCTrajectorySZ fit(const CDCSegment2D &stereoSegment, const CDCTrajectory2D &axialTrajectory2D) const
Returns a fitted trajectory.
Class serving as a storage of observed sz positions to present to the sz line fitters.
std::size_t appendRange(const std::vector< CDCRecoHit3D > &recoHit3Ds)
Appends all reconstructed hits from the three dimensional track.
std::size_t fill(double s, double z, double weight=1.0)
Appends the observed position.
std::size_t append(const CDCRecoHit3D &recoHit3D)
Appends the observed position.
std::size_t size() const
Returns the number of observations stored.
A reconstructed sequence of two dimensional hits in one super layer.
A segment consisting of three dimensional reconstructed hits.
Class representing a pair of one reconstructed axial segment and one stereo segment in adjacent super...
const CDCSegment2D * getAxialSegment() const
Getter for the axial segment.
void setTrajectory3D(const CDCTrajectory3D &trajectory3D) const
Setter for the three dimensional trajectory.
const CDCSegment2D * getStereoSegment() const
Getter for the stereo segment.
bool isAxial() const
Indicator if the underlying wires are axial.
CDCTrajectory2D & getTrajectory2D() const
Getter for the two dimensional trajectory fitted to the segment.
Class representing a sequence of three dimensional reconstructed hits.
Particle trajectory as it is seen in xy projection represented as a circle.
Particle full three dimensional trajectory.
Linear trajectory in sz space.
static CDCTrajectorySZ basicAssumption()
Constructs a basic assumption, what the z0 start position and the sz slope are, including some broad ...
void setSZLine(const UncertainSZLine &szLine)
Setter for the line in sz space.
void clear()
Clears all information from this trajectory line.
A line in sz where s is the transverse travel distance as seen in the xy projection with uncertaintie...
void setNDF(std::size_t ndf)
Setter for the number of degrees of freediom used in the line fit.
Namespace to hide the contained enum constants.
Abstract base class for different kinds of events.
static CovarianceMatrix covarianceFromFullPrecision(const PrecisionMatrix &prec)