ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KalmanVertexTrackUpdaterTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KalmanVertexTrackUpdaterTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
19 #include "Acts/Utilities/Units.hpp"
24 
25 namespace bdata = boost::unit_test::data;
26 using namespace Acts::UnitLiterals;
27 
28 namespace Acts {
29 namespace Test {
30 
32 using Propagator = Propagator<EigenStepper<ConstantBField>>;
33 using Linearizer = HelicalTrackLinearizer<Propagator>;
34 
35 // Create a test context
38 
39 // Vertex x/y position distribution
40 std::uniform_real_distribution<> vXYDist(-0.1_mm, 0.1_mm);
41 // Vertex z position distribution
42 std::uniform_real_distribution<> vZDist(-20_mm, 20_mm);
43 // Track d0 distribution
44 std::uniform_real_distribution<> d0Dist(-0.01_mm, 0.01_mm);
45 // Track z0 distribution
46 std::uniform_real_distribution<> z0Dist(-0.2_mm, 0.2_mm);
47 // Track pT distribution
48 std::uniform_real_distribution<> pTDist(0.4_GeV, 10_GeV);
49 // Track phi distribution
50 std::uniform_real_distribution<> phiDist(-M_PI, M_PI);
51 // Track theta distribution
52 std::uniform_real_distribution<> thetaDist(1.0, M_PI - 1.0);
53 // Track charge helper distribution
54 std::uniform_real_distribution<> qDist(-1, 1);
55 // Track IP resolution distribution
56 std::uniform_real_distribution<> resIPDist(0., 100_um);
57 // Track angular distribution
58 std::uniform_real_distribution<> resAngDist(0., 0.1);
59 // Track q/p resolution distribution
60 std::uniform_real_distribution<> resQoPDist(-0.01, 0.01);
61 
65 BOOST_AUTO_TEST_CASE(Kalman_Vertex_TrackUpdater) {
66  bool debug = true;
67 
68  // Number of tests
69  unsigned int nTests = 10;
70 
71  // Set up RNG
72  int mySeed = 31415;
73  std::mt19937 gen(mySeed);
74 
75  // Set up constant B-Field
76  ConstantBField bField(0.0, 0.0, 1_T);
77 
78  // Set up Eigenstepper
80 
81  // Set up propagator with void navigator
82  auto propagator = std::make_shared<Propagator>(stepper);
83 
84  // Set up ImpactPointEstimator, used for comparisons later
86  bField, propagator);
87 
89 
90  // Set up HelicalTrackLinearizer, needed for linearizing the tracks
91  // Linearizer for BoundParameters type test
92  Linearizer::Config ltConfig(bField, propagator);
93  Linearizer linearizer(ltConfig);
94 
95  // Create perigee surface at origin
96  std::shared_ptr<PerigeeSurface> perigeeSurface =
97  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
98 
99  // Create random tracks around origin and a random vertex.
100  // Update tracks with the assumption that they originate from
101  // the vertex position and check if they are closer to the
102  // vertex after the update process
103  for (unsigned int i = 0; i < nTests; ++i) {
104  // Construct positive or negative charge randomly
105  double q = qDist(gen) < 0 ? -1. : 1.;
106 
107  // Construct random track parameters
109 
110  paramVec << d0Dist(gen), z0Dist(gen), phiDist(gen), thetaDist(gen),
111  q / pTDist(gen), 0.;
112 
113  if (debug) {
114  std::cout << "Creating track parameters: " << paramVec << std::endl;
115  }
116 
117  // Fill vector of track objects with simple covariance matrix
118  Covariance covMat;
119 
120  // Resolutions
121  double res_d0 = resIPDist(gen);
122  double res_z0 = resIPDist(gen);
123  double res_ph = resAngDist(gen);
124  double res_th = resAngDist(gen);
125  double res_qp = resQoPDist(gen);
126 
127  covMat << res_d0 * res_d0, 0., 0., 0., 0., 0., 0., res_z0 * res_z0, 0., 0.,
128  0., 0., 0., 0., res_ph * res_ph, 0., 0., 0., 0., 0., 0.,
129  res_th * res_th, 0., 0., 0., 0., 0., 0., res_qp * res_qp, 0., 0., 0.,
130  0., 0., 0., 1.;
131  BoundParameters params(geoContext, std::move(covMat), paramVec,
132  perigeeSurface);
133 
134  // Linearized state of the track
135  LinearizedTrack linTrack =
136  linearizer
137  .linearizeTrack(params, SpacePointVector::Zero(), geoContext,
139  .value();
140 
141  // Create TrackAtVertex
142  TrackAtVertex<BoundParameters> trkAtVtx(0., params, &params);
143 
144  // Set linearized state of trackAtVertex
145  trkAtVtx.linearizedState = linTrack;
146 
147  // Copy parameters for later comparison of old and new version
148  auto fittedParamsCopy = trkAtVtx.fittedParams;
149 
150  // Create a vertex
151  Vector3D vtxPos(vXYDist(gen), vXYDist(gen), vZDist(gen));
152  Vertex<BoundParameters> vtx(vtxPos);
153 
154  // Update trkAtVertex with assumption of originating from vtx
155  KalmanVertexTrackUpdater::update<BoundParameters>(geoContext, trkAtVtx,
156  vtx);
157 
158  // The old distance
159  double oldDistance =
160  ip3dEst.calculate3dDistance(geoContext, fittedParamsCopy, vtxPos)
161  .value();
162 
163  // The new distance after update
164  double newDistance =
165  ip3dEst.calculate3dDistance(geoContext, trkAtVtx.fittedParams, vtxPos)
166  .value();
167  if (debug) {
168  std::cout << "Old distance: " << oldDistance << std::endl;
169  std::cout << "New distance: " << newDistance << std::endl;
170  }
171 
172  // Parameters should have changed
173  BOOST_CHECK_NE(fittedParamsCopy, trkAtVtx.fittedParams);
174 
175  // After update, track should be closer to the vertex
176  BOOST_CHECK(newDistance < oldDistance);
177 
178  } // end for loop
179 
180 } // end test case
181 
182 } // namespace Test
183 } // namespace Acts