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 BoundTrackParameters type test
85  Linearizer::Config ltConfig(bField, propagator);
86  Linearizer linearizer(ltConfig);
88 
89  // Create perigee surface at origin
90  std::shared_ptr<PerigeeSurface> perigeeSurface =
91  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
92 
93  // Creates a random tracks around origin and a random vertex.
94  // VertexUpdater adds track to vertex and updates the position
95  // which should afterwards be closer to the origin/track
96  for (unsigned int i = 0; i < nTests; ++i) {
97  if (debug) {
98  std::cout << "Test " << i + 1 << std::endl;
99  }
100  // Construct positive or negative charge randomly
101  double q = qDist(gen) < 0 ? -1. : 1.;
102 
103  // Construct random track parameters around origin
105 
106  paramVec << d0Dist(gen), z0Dist(gen), phiDist(gen), thetaDist(gen),
107  q / pTDist(gen), 0.;
108 
109  if (debug) {
110  std::cout << "Creating track parameters: " << paramVec << std::endl;
111  }
112 
113  // Fill vector of track objects with simple covariance matrix
114  Covariance covMat;
115 
116  // Resolutions
117  double res_d0 = resIPDist(gen);
118  double res_z0 = resIPDist(gen);
119  double res_ph = resAngDist(gen);
120  double res_th = resAngDist(gen);
121  double res_qp = resQoPDist(gen);
122 
123  covMat << res_d0 * res_d0, 0., 0., 0., 0., 0., 0., res_z0 * res_z0, 0., 0.,
124  0., 0., 0., 0., res_ph * res_ph, 0., 0., 0., 0., 0., 0.,
125  res_th * res_th, 0., 0., 0., 0., 0., 0., res_qp * res_qp, 0., 0., 0.,
126  0., 0., 0., 1.;
127  BoundTrackParameters params(perigeeSurface, paramVec, std::move(covMat));
128 
129  // Linearized state of the track
130  LinearizedTrack linTrack =
131  linearizer
132  .linearizeTrack(params, Vector4D::Zero(), geoContext,
133  magFieldContext, state)
134  .value();
135 
136  // Create TrackAtVertex
137  TrackAtVertex<BoundTrackParameters> 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));
145  vtx.setFullCovariance(SymMatrix4D::Identity() * 0.01);
146 
147  // Update trkAtVertex with assumption of originating from vtx
148  KalmanVertexUpdater::updateVertexWithTrack<BoundTrackParameters>(vtx,
149  trkAtVtx);
150 
151  if (debug) {
152  std::cout << "Old vertex position: " << vtxPos << std::endl;
153  std::cout << "New vertex position: " << vtx.position() << std::endl;
154  }
155 
156  double oldDistance = vtxPos.norm();
157  double newDistance = vtx.position().norm();
158 
159  if (debug) {
160  std::cout << "Old distance: " << oldDistance << std::endl;
161  std::cout << "New distance: " << newDistance << std::endl;
162  }
163 
164  // After update, vertex should be closer to the track
165  BOOST_CHECK(newDistance < oldDistance);
166 
167  // Note: KalmanVertexUpdater updates the vertex w.r.t. the
168  // newly given track, but does NOT add the track to the
169  // TrackAtVertex list. Has to be done manually after calling
170  // the update method.
171  BOOST_CHECK(vtx.tracks().size() == 0);
172 
173  } // end for loop
174 
175 } // end test case
176 
177 } // namespace Test
178 } // namespace Acts