8#include <tracking/trackFindingCDC/fitting/CDCSZFitter.h>
10#include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
11#include <tracking/trackFindingCDC/fitting/CDCKarimakiFitter.h>
12#include <tracking/trackFindingCDC/fitting/CDCFitter2D.icc.h>
13#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
14#include <tracking/trackFindingCDC/fitting/CDCSZObservations.h>
16#include <tracking/trackFindingCDC/fitting/ExtendedRiemannsMethod.h>
17#include <tracking/trackFindingCDC/fitting/RiemannsMethod.h>
19#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
20#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
22#include <tracking/trackFindingCDC/geometry/UncertainSZLine.h>
23#include <tracking/trackFindingCDC/geometry/UncertainPerigeeCircle.h>
24#include <tracking/trackFindingCDC/geometry/PerigeeParameters.h>
25#include <tracking/trackFindingCDC/geometry/Circle2D.h>
26#include <tracking/trackFindingCDC/geometry/Vector2D.h>
28#include <framework/logging/Logger.h>
30#include <gtest/gtest.h>
33using namespace TrackFindingCDC;
36 const Vector2D generalCenter(6.0, 0);
37 const double generalRadius = 5.0;
39 const Circle2D generalCircle(generalCenter, generalRadius);
41 std::vector<Vector2D> createGeneralCircleObservationCenters()
43 std::vector<Vector2D> observationCenters;
45 for (
int iObservation = 11; iObservation > -12; --iObservation) {
46 double y = iObservation / 2.0;
48 observationCenters.emplace_back(x, y);
50 return observationCenters;
55 std::vector<Vector2D> observationCenters = createGeneralCircleObservationCenters();
58 if (withDriftLength) {
59 for (
const Vector2D& observationCenter : observationCenters) {
60 double distance = generalCircle.distance(observationCenter);
61 observations2D.
fill(observationCenter, distance);
64 for (
const Vector2D& observationCenter : observationCenters) {
65 Vector2D onCircle = generalCircle.closest(observationCenter);
66 observations2D.
fill(onCircle, 0.0);
69 return observations2D;
72 template<
class AFitter>
73 CDCTrajectory2D testGeneralCircleFitter(
const AFitter& fitter,
const bool withDriftLenght)
76 CDCObservations2D observations2D = createGeneralCircleObservations(withDriftLenght);
78 fitter.update(trajectory2D, observations2D);
83 EXPECT_NEAR(generalCircle.perigee().x(), fittedCircle->
perigee().
x(), 10e-7) <<
84 "AFitter " <<
typeid(fitter).name() <<
" failed.";
85 EXPECT_NEAR(generalCircle.perigee().y(), fittedCircle->
perigee().
y(), 10e-7) <<
86 "AFitter " <<
typeid(fitter).name() <<
" failed.";
87 EXPECT_NEAR(generalCircle.radius(), fittedCircle->
radius(), 10e-7) <<
88 "AFitter " <<
typeid(fitter).name() <<
" failed.";
89 EXPECT_NEAR(generalCircle.tangentialPhi(), fittedCircle->
phi0(), 10e-7) <<
90 "AFitter " <<
typeid(fitter).name() <<
" failed.";
91 EXPECT_NEAR(0.0, fittedCircle.
chi2(), 10e-7) <<
"AFitter " <<
typeid(fitter).name() <<
" failed.";
93 const double curv = fittedCircle->
curvature();
94 const double I = fittedCircle->
impact();
95 const double phi = fittedCircle->
phi0();
97 const double chi2 = fittedCircle.
chi2();
99 B2INFO(
"Curvature " << curv);
100 B2INFO(
"Tangential phi " << phi);
101 B2INFO(
"Impact " << I);
102 B2INFO(
"Chi2 " << chi2);
104 B2INFO(
"Covariance matrix:");
111 Line2D line(-0.5, 0.0, -1.0);
113 template<
class AFitter>
124 fitter.update(trajectory2D, observations2D);
129 EXPECT_EQ(0.0, fittedCircle->
curvature()) <<
"AFitter " <<
typeid(fitter).name() <<
" failed.";
132 EXPECT_NEAR(0.0, perigee.
x(), 10e-7);
133 EXPECT_NEAR(-0.5, perigee.
y(), 10e-7);
142TEST(TrackFindingCDCTest, fitting_ExtendedRiemannsMethod_GeneralCircleFit_NoDriftLength)
151 EXPECT_NEAR(0.0003644, perigeeCovariance(0, 0), 10e-7);
152 EXPECT_NEAR(3.028e-20, perigeeCovariance(0, 1), 10e-7);
153 EXPECT_NEAR(-0.002235, perigeeCovariance(0, 2), 10e-7);
155 EXPECT_NEAR(3.028e-20, perigeeCovariance(1, 0), 10e-7);
156 EXPECT_NEAR(0.002525, perigeeCovariance(1, 1), 10e-7);
157 EXPECT_NEAR(-1.265e-19, perigeeCovariance(1, 2), 10e-7);
159 EXPECT_NEAR(-0.002235, perigeeCovariance(2, 0), 10e-7);
160 EXPECT_NEAR(-1.265e-19, perigeeCovariance(2, 1), 10e-7);
161 EXPECT_NEAR(0.09703616, perigeeCovariance(2, 2), 10e-7);
166TEST(TrackFindingCDCTest, fitting_ExtendedRiemannsMethod_GeneralCircleFit_WithDriftLengths)
169 testGeneralCircleFitter(fitter,
true);
173TEST(TrackFindingCDCTest, fitting_RiemannsMethod_GeneralCircleFit_WithDriftLengths)
176 testGeneralCircleFitter(fitter,
true);
181TEST(TrackFindingCDCTest, fitting_CDCRiemannFitter_CircleFit_NoDriftLength)
184 testGeneralCircleFitter(fitter,
false);
189TEST(TrackFindingCDCTest, fitting_CDCKarimakiFitter_CircleFit_NoDriftLength)
192 fitter.useOnlyPosition();
193 testGeneralCircleFitter(fitter,
false);
198TEST(TrackFindingCDCTest, fitting_CDCRiemannFitter_LineFit_WithDriftLength)
201 testLineFitter(fitter);
204TEST(TrackFindingCDCTest, fitting_CDCSZFitter)
209 szObservations.
fill(0, 0);
210 szObservations.
fill(5, 3);
211 szObservations.
fill(10, 0);
216 EXPECT_NEAR(0.0, fittedSZLine->
slope(), 10e-10);
217 EXPECT_NEAR(1.0, fittedSZLine->
intercept(), 10e-10);
Class implementing a fit for two dimensional trajectory circle using a generic fitting backend.
Class implementing the fitter using Karimakis method.
static const CDCKarimakiFitter & getFitter()
Static getter for a general fitter instance with Karimakis method.
Class serving as a storage of observed drift circles to present to the Riemann fitter.
std::size_t fill(double x, double y, double signedRadius=0.0, double weight=1.0)
Appends the observed position.
Class implementing the Riemann fit for two dimensional trajectory circle.
static const CDCRiemannFitter & getLineFitter()
Static getter for a line fitter.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Class implementing the z coordinate over travel distance line fit.
Class serving as a storage of observed sz positions to present to the sz line fitters.
std::size_t fill(double s, double z, double weight=1.0)
Appends the observed position.
Particle trajectory as it is seen in xy projection represented as a circle.
double setLocalOrigin(const Vector2D &localOrigin)
Setter for the origin of the local coordinate system.
const UncertainPerigeeCircle & getLocalCircle() const
Getter for the circle in local coordinates.
Vector2D getGlobalPerigee() const
Getter for the closest approach on the trajectory to the global origin.
Linear trajectory in sz space.
const UncertainSZLine & getSZLine() const
Getter for the line in sz space.
A two dimensional circle in its natural representation using center and radius as parameters.
A two dimensional normal line.
Vector2D perigee() const
Getter for the perigee point.
double phi0() const
Getter for the azimuth angle of the direction of flight at the perigee.
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
double impact() const
Getter for the signed distance of the origin to the circle.
double curvature() const
Getter for the signed curvature.
A matrix implementation to be used as an interface typ through out the track finder.
double slope() const
Getter for the slope in the sz space which is equivalent to tan lambda.
double intercept() const
Getter for the intercept in the sz space which is equivalent to z0.
Adds an uncertainty matrix to the circle in perigee parameterisation.
double chi2() const
Getter for the chi square value of the circle fit.
const PerigeeCovariance & perigeeCovariance() const
Getter for the whole covariance matrix of the perigee parameters.
A line in sz where s is the transverse travel distance as seen in the xy projection with uncertaintie...
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
double x() const
Getter for the x coordinate.
double y() const
Getter for the y coordinate.
Abstract base class for different kinds of events.