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/trackingUtilities/eventdata/tracks/CDCTrack.h>
15#include <tracking/trackingUtilities/eventdata/tracks/CDCSegmentPair.h>
17#include <tracking/trackingUtilities/eventdata/segments/CDCSegment3D.h>
18#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
20#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
21#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
23#include <tracking/trackingUtilities/geometry/SZParameters.h>
25#include <tracking/trackingUtilities/numerics/EigenView.h>
27#include <framework/logging/Logger.h>
34using namespace TrackFindingCDC;
35using namespace TrackingUtilities;
47 Eigen::Matrix<double, 2, 2> sumMatrixWS = sumMatrixWSZ.block<2, 2>(0, 0);
48 Eigen::Matrix<double, 2, 1> sumVectorZOverWS = sumMatrixWSZ.block<2, 1>(0, 2);
49 Eigen::Matrix<double, 2, 1> nZOverWS = sumMatrixWS.llt().solve(sumVectorZOverWS);
50 double chi2 = sumMatrixWSZ(2, 2) - nZOverWS.transpose() * sumVectorZOverWS;
53 SZParameters szParameters;
54 szParameters(c_TanL) = nZOverWS(1);
55 szParameters(c_Z0) = nZOverWS(0);
57 SZPrecision szPrecision;
58 szPrecision(c_TanL, c_TanL) = sumMatrixWS(1, 1);
59 szPrecision(c_Z0, c_TanL) = sumMatrixWS(0, 1);
60 szPrecision(c_TanL, c_Z0) = sumMatrixWS(1, 0);
61 szPrecision(c_Z0, c_Z0) = sumMatrixWS(0, 0);
63 SZCovariance szCovariance = SZUtil::covarianceFromFullPrecision(szPrecision);
68 UncertainSZLine fitSZ(
const Eigen::Matrix<double, 3, 3>& sumMatrixWSZ) __attribute__((__unused__));
75 Eigen::Matrix<double, 3, 3> averageMatrixWSZ = sumMatrixWSZ / sumMatrixWSZ(0);
78 Eigen::Matrix<double, 3, 1> meansWSZ = averageMatrixWSZ.row(0);
81 Eigen::Matrix<double, 3, 3> covMatrixWSZ = averageMatrixWSZ - meansWSZ * meansWSZ.transpose();
83 Eigen::Matrix<double, 2, 2> covMatrixSZ = covMatrixWSZ.block<2, 2>(1, 1);
84 Eigen::Matrix<double, 2, 1> meansSZ = meansWSZ.segment<2>(1);
86 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 2, 2>> eigensolver(covMatrixSZ);
87 if (eigensolver.info() != Eigen::Success) {
89 "SelfAdjointEigenSolver could not compute the eigen values of the observation matrix");
95 Eigen::Matrix<double, 2, 1> nSZ = eigensolver.eigenvectors().col(0);
96 B2INFO(
"nSZ " << nSZ);
97 nSZ /= std::copysign(nSZ.norm(), -nSZ(1));
98 Eigen::Matrix<double, 3, 1> nWSZ;
100 nWSZ << -meansSZ.transpose() * nSZ, nSZ;
101 B2INFO(
"nWSZ " << nWSZ);
103 double chi2 = nWSZ.transpose() * sumMatrixWSZ * nWSZ;
105 Eigen::Matrix<double, 3, 3> precN = sumMatrixWSZ;
108 SZParameters szParameters;
109 szParameters(c_TanL) = -nWSZ(1) / nWSZ(2);
110 szParameters(c_Z0) = -nWSZ(0) / nWSZ(2);
112 Eigen::Matrix<double, 3, 2> ambiguitySZToN = Eigen::Matrix<double, 3, 2>::Zero();
113 ambiguitySZToN(0, c_Z0) = -nWSZ(2);
114 ambiguitySZToN(0, c_TanL) = -nWSZ(1) * nWSZ(0);
115 ambiguitySZToN(1, c_TanL) = -nWSZ(2) * nWSZ(2) * nWSZ(2);
116 ambiguitySZToN(2, c_TanL) = nWSZ(1) * nWSZ(2) * nWSZ(2);
118 SZPrecision szPrecision;
119 mapToEigen(szPrecision) = ambiguitySZToN.transpose() * precN * ambiguitySZToN;
121 SZCovariance szCovariance = SZUtil::covarianceFromFullPrecision(szPrecision);
128 const bool onlyStereo =
true;
131 if (observationsSZ.
size() > 3) {
133 update(szTrajectory, observationsSZ);
143 B2ASSERT(
"Expected stereo segment", not stereoSegment.
isAxial());
146 update(trajectorySZ, stereoSegment, axialTrajectory2D);
154 return fit(std::move(observationsSZ));
160 update(trajectorySZ, observationsSZ);
169 assert(ptrStereoSegment);
170 assert(ptrAxialSegment);
177 update(trajectorySZ, stereoSegment, axialTrajectory2D);
186 for (
size_t i = 0; i < observations2D.
size(); ++i) {
187 const double s = observations2D.
getX(i);
188 const double z = observations2D.
getY(i);
189 szObservations.
fill(s, z);
191 return fit(std::move(szObservations));
198 B2ASSERT(
"Expected stereo segment", not stereoSegment.
isAxial());
204 observationsSZ.
append(recoHit3D);
207 update(trajectorySZ, observationsSZ);
212 trajectorySZ.
clear();
213 if (observationsSZ.
size() < 3) {
218 size_t ndf = observationsSZ.
size() - 2;
221 Eigen::Matrix<double, 3, 3> sumMatrixWSZ = getWSZSumMatrix(observationsSZ);
224 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 implementing the z coordinate over travel distance line fit.
TrackingUtilities::CDCTrajectorySZ fitWithStereoHits(const TrackingUtilities::CDCTrack &track) const
Returns the fitted sz trajectory of the track with the z-information of all stereo hits of the number...
TrackingUtilities::CDCTrajectorySZ fit(const TrackingUtilities::CDCSegment2D &stereoSegment, const TrackingUtilities::CDCTrajectory2D &axialTrajectory2D) const
Returns a fitted trajectory.
static const CDCSZFitter & getFitter()
Getter for a standard sz line fitter instance.
void update(const TrackingUtilities::CDCSegmentPair &segmentPair) const
Updates the trajectory of the axial stereo segment pair inplace.
Class serving as a storage of observed sz positions to present to the sz line fitters.
std::size_t append(const TrackingUtilities::CDCRecoHit3D &recoHit3D)
Appends the observed position.
std::size_t fill(double s, double z, double weight=1.0)
Appends the observed position.
std::size_t appendRange(const std::vector< TrackingUtilities::CDCRecoHit3D > &recoHit3Ds)
Appends all reconstructed hits from the three dimensional track.
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.
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.