Belle II Software  release-08-01-10
fitting.test.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/trackFindingCDC/fitting/CDCSZFitter.h>
9 
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>
15 
16 #include <tracking/trackFindingCDC/fitting/ExtendedRiemannsMethod.h>
17 #include <tracking/trackFindingCDC/fitting/RiemannsMethod.h>
18 
19 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
20 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
21 
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>
27 
28 #include <framework/logging/Logger.h>
29 
30 #include <gtest/gtest.h>
31 
32 using namespace Belle2;
33 using namespace TrackFindingCDC;
34 
35 namespace {
36  const Vector2D generalCenter(6.0, 0);
37  const double generalRadius = 5.0;
38 
39  const Circle2D generalCircle(generalCenter, generalRadius);
40 
41  std::vector<Vector2D> createGeneralCircleObservationCenters()
42  {
43  std::vector<Vector2D> observationCenters;
44  // Setting up a trajectory traveling clockwise
45  for (int iObservation = 11; iObservation > -12; --iObservation) {
46  double y = iObservation / 2.0;
47  double x = fabs(y);
48  observationCenters.emplace_back(x, y);
49  }
50  return observationCenters;
51  }
52 
53  CDCObservations2D createGeneralCircleObservations(bool withDriftLength = true)
54  {
55  std::vector<Vector2D> observationCenters = createGeneralCircleObservationCenters();
56 
57  CDCObservations2D observations2D;
58  if (withDriftLength) {
59  for (const Vector2D& observationCenter : observationCenters) {
60  double distance = generalCircle.distance(observationCenter);
61  observations2D.fill(observationCenter, distance);
62  }
63  } else {
64  for (const Vector2D& observationCenter : observationCenters) {
65  Vector2D onCircle = generalCircle.closest(observationCenter);
66  observations2D.fill(onCircle, 0.0);
67  }
68  }
69  return observations2D;
70  }
71 
72  template<class AFitter>
73  CDCTrajectory2D testGeneralCircleFitter(const AFitter& fitter, const bool withDriftLenght)
74  {
75  // Setup a test circle
76  CDCObservations2D observations2D = createGeneralCircleObservations(withDriftLenght);
77  CDCTrajectory2D trajectory2D;
78  fitter.update(trajectory2D, observations2D);
79 
80  trajectory2D.setLocalOrigin(Vector2D(0.0, 0.0));
81  const UncertainPerigeeCircle& fittedCircle = trajectory2D.getLocalCircle();
82 
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.";
92 
93  const double curv = fittedCircle->curvature();
94  const double I = fittedCircle->impact();
95  const double phi = fittedCircle->phi0();
96 
97  const double chi2 = fittedCircle.chi2();
98 
99  B2INFO("Curvature " << curv);
100  B2INFO("Tangential phi " << phi);
101  B2INFO("Impact " << I);
102  B2INFO("Chi2 " << chi2);
103 
104  B2INFO("Covariance matrix:");
105  B2INFO(fittedCircle.perigeeCovariance());
106  return trajectory2D;
107  }
108 
109 
110 
111  Line2D line(-0.5, 0.0, -1.0);
112 
113  template<class AFitter>
114  CDCTrajectory2D testLineFitter(const AFitter& fitter)
115  {
116 
117  CDCObservations2D observations2D;
118  observations2D.fill(Vector2D(0, 0), 0.5);
119  observations2D.fill(Vector2D(1, -1), -0.5);
120  observations2D.fill(Vector2D(2, 0), 0.5);
121 
122  CDCTrajectory2D trajectory2D;
123 
124  fitter.update(trajectory2D, observations2D);
125 
126  trajectory2D.setLocalOrigin(Vector2D(0.0, 0.0));
127  const UncertainPerigeeCircle& fittedCircle = trajectory2D.getLocalCircle();
128 
129  EXPECT_EQ(0.0, fittedCircle->curvature()) << "AFitter " << typeid(fitter).name() << " failed.";
130 
131  Vector2D perigee = trajectory2D.getGlobalPerigee();
132  EXPECT_NEAR(0.0, perigee.x(), 10e-7);
133  EXPECT_NEAR(-0.5, perigee.y(), 10e-7);
134 
135  return trajectory2D;
136  }
137 
138 }
139 
140 
141 
142 TEST(TrackFindingCDCTest, fitting_ExtendedRiemannsMethod_GeneralCircleFit_NoDriftLength)
143 {
145  CDCTrajectory2D trajectory2D = testGeneralCircleFitter(fitter, false);
146 
147  trajectory2D.setLocalOrigin(Vector2D(0.0, 0.0));
148  const UncertainPerigeeCircle& perigeeCircle = trajectory2D.getLocalCircle();
149  PerigeeCovariance perigeeCovariance = perigeeCircle.perigeeCovariance();
150 
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);
154 
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);
158 
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);
162 }
163 
164 
165 
166 TEST(TrackFindingCDCTest, fitting_ExtendedRiemannsMethod_GeneralCircleFit_WithDriftLengths)
167 {
169  testGeneralCircleFitter(fitter, true);
170 }
171 
172 
173 TEST(TrackFindingCDCTest, fitting_RiemannsMethod_GeneralCircleFit_WithDriftLengths)
174 {
175  const CDCFitter2D<RiemannsMethod> fitter;
176  testGeneralCircleFitter(fitter, true);
177 }
178 
179 
180 
181 TEST(TrackFindingCDCTest, fitting_CDCRiemannFitter_CircleFit_NoDriftLength)
182 {
184  testGeneralCircleFitter(fitter, false);
185 }
186 
187 
188 
189 TEST(TrackFindingCDCTest, fitting_CDCKarimakiFitter_CircleFit_NoDriftLength)
190 {
192  fitter.useOnlyPosition();
193  testGeneralCircleFitter(fitter, false);
194 }
195 
196 
197 
198 TEST(TrackFindingCDCTest, fitting_CDCRiemannFitter_LineFit_WithDriftLength)
199 {
201  testLineFitter(fitter);
202 }
203 
204 TEST(TrackFindingCDCTest, fitting_CDCSZFitter)
205 {
206  CDCSZFitter fitter;
207  CDCSZObservations szObservations;
208 
209  szObservations.fill(0, 0);
210  szObservations.fill(5, 3);
211  szObservations.fill(10, 0);
212 
213  CDCTrajectorySZ trajectorySZ = fitter.fit(szObservations);
214  const UncertainSZLine& fittedSZLine = trajectorySZ.getSZLine();
215 
216  EXPECT_NEAR(0.0, fittedSZLine->slope(), 10e-10);
217  EXPECT_NEAR(1.0, fittedSZLine->intercept(), 10e-10);
218 }
Class implementing a fit for two dimensional trajectory circle using a generic fitting backend.
Definition: CDCFitter2D.h:33
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.
Definition: CDCSZFitter.h:27
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 cirlce 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.
Definition: Circle2D.h:26
A two dimensional normal line.
Definition: Line2D.h:37
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.
Definition: PlainMatrix.h:40
double slope() const
Getter for the slope in the sz space which is equivalent to tan lambda.
Definition: SZLine.h:58
double intercept() const
Getter for the intercept in the sz space which is equivalent to z0.
Definition: SZLine.h:88
Adds an uncertainty matrix to the circle in perigee parameterisation.
const PerigeeCovariance & perigeeCovariance() const
Getter for the whole covariance matrix of the perigee parameters.
double chi2() const
Getter for the chi square value of the circle fit.
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 handeling of orientation relat...
Definition: Vector2D.h:35
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:607
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:617
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.