ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KalmanVertexUpdaterTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KalmanVertexUpdaterTests.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"
23 
24 namespace bdata = boost::unit_test::data;
25 using namespace Acts::UnitLiterals;
26 
27 namespace Acts {
28 namespace Test {
29 
31 using Propagator = Propagator<EigenStepper<ConstantBField>>;
32 using Linearizer = HelicalTrackLinearizer<Propagator>;
33 
34 // Create a test context
37 
38 // Vertex x/y position distribution
39 std::uniform_real_distribution<> vXYDist(-0.1_mm, 0.1_mm);
40 // Vertex z position distribution
41 std::uniform_real_distribution<> vZDist(-20_mm, 20_mm);
42 // Track d0 distribution
43 std::uniform_real_distribution<> d0Dist(-0.01_mm, 0.01_mm);
44 // Track z0 distribution
45 std::uniform_real_distribution<> z0Dist(-0.2_mm, 0.2_mm);
46 // Track pT distribution
47 std::uniform_real_distribution<> pTDist(0.4_GeV, 10_GeV);
48 // Track phi distribution
49 std::uniform_real_distribution<> phiDist(-M_PI, M_PI);
50 // Track theta distribution
51 std::uniform_real_distribution<> thetaDist(1.0, M_PI - 1.0);
52 // Track charge helper distribution
53 std::uniform_real_distribution<> qDist(-1, 1);
54 // Track IP resolution distribution
55 std::uniform_real_distribution<> resIPDist(0., 100_um);
56 // Track angular distribution
57 std::uniform_real_distribution<> resAngDist(0., 0.1);
58 // Track q/p resolution distribution
59 std::uniform_real_distribution<> resQoPDist(-0.01, 0.01);
60 // Number of vertices per test event distribution
61 
65 BOOST_AUTO_TEST_CASE(Kalman_Vertex_Updater) {
66  bool debug = false;
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  // Linearizer for BoundParameters type test
85  Linearizer::Config ltConfig(bField, propagator);
86  Linearizer linearizer(ltConfig);
87 
88  // Create perigee surface at origin
89  std::shared_ptr<PerigeeSurface> perigeeSurface =
90  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
91 
92  // Creates a random tracks around origin and a random vertex.
93  // VertexUpdater adds track to vertex and updates the position
94  // which should afterwards be closer to the origin/track
95  for (unsigned int i = 0; i < nTests; ++i) {
96  if (debug) {
97  std::cout << "Test " << i + 1 << std::endl;
98  }
99  // Construct positive or negative charge randomly
100  double q = qDist(gen) < 0 ? -1. : 1.;
101 
102  // Construct random track parameters around origin
104 
105  paramVec << d0Dist(gen), z0Dist(gen), phiDist(gen), thetaDist(gen),
106  q / pTDist(gen), 0.;
107 
108  if (debug) {
109  std::cout << "Creating track parameters: " << paramVec << std::endl;
110  }
111 
112  // Fill vector of track objects with simple covariance matrix
113  Covariance covMat;
114 
115  // Resolutions
116  double res_d0 = resIPDist(gen);
117  double res_z0 = resIPDist(gen);
118  double res_ph = resAngDist(gen);
119  double res_th = resAngDist(gen);
120  double res_qp = resQoPDist(gen);
121 
122  covMat << res_d0 * res_d0, 0., 0., 0., 0., 0., 0., res_z0 * res_z0, 0., 0.,
123  0., 0., 0., 0., res_ph * res_ph, 0., 0., 0., 0., 0., 0.,
124  res_th * res_th, 0., 0., 0., 0., 0., 0., res_qp * res_qp, 0., 0., 0.,
125  0., 0., 0., 1.;
126  BoundParameters params(geoContext, std::move(covMat), paramVec,
127  perigeeSurface);
128 
129  // Linearized state of the track
130  LinearizedTrack linTrack =
131  linearizer
132  .linearizeTrack(params, SpacePointVector::Zero(), geoContext,
134  .value();
135 
136  // Create TrackAtVertex
137  TrackAtVertex<BoundParameters> trkAtVtx(0., params, &params);
138 
139  // Set linearized state of trackAtVertex
140  trkAtVtx.linearizedState = linTrack;
141 
142  // Create a vertex
143  Vector3D vtxPos(vXYDist(gen), vXYDist(gen), vZDist(gen));
144  Vertex<BoundParameters> vtx(vtxPos);
145  vtx.setFullCovariance(SpacePointSymMatrix::Identity() * 0.01);
146 
147  // Update trkAtVertex with assumption of originating from vtx
148  KalmanVertexUpdater::updateVertexWithTrack<BoundParameters>(vtx, trkAtVtx);
149 
150  if (debug) {
151  std::cout << "Old vertex position: " << vtxPos << std::endl;
152  std::cout << "New vertex position: " << vtx.position() << std::endl;
153  }
154 
155  double oldDistance = vtxPos.norm();
156  double newDistance = vtx.position().norm();
157 
158  if (debug) {
159  std::cout << "Old distance: " << oldDistance << std::endl;
160  std::cout << "New distance: " << newDistance << std::endl;
161  }
162 
163  // After update, vertex should be closer to the track
164  BOOST_CHECK(newDistance < oldDistance);
165 
166  // Note: KalmanVertexUpdater updates the vertex w.r.t. the
167  // newly given track, but does NOT add the track to the
168  // TrackAtVertex list. Has to be done manually after calling
169  // the update method.
170  BOOST_CHECK(vtx.tracks().size() == 0);
171 
172  } // end for loop
173 
174 } // end test case
175 
176 } // namespace Test
177 } // namespace Acts