EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LinearizedTrackFactoryTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LinearizedTrackFactoryTests.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 
21 #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 Linearizer =
32  HelicalTrackLinearizer<Propagator<EigenStepper<ConstantBField>>>;
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.1, 0.1);
60 
64 BOOST_AUTO_TEST_CASE(linearized_track_factory_test) {
65  // Number of tracks
66  unsigned int nTracks = 100;
67 
68  // Set up RNG
69  int mySeed = 31415;
70  std::mt19937 gen(mySeed);
71 
72  // Set up constant B-Field
73  ConstantBField bField(0.0, 0.0, 1_T);
74 
75  // Set up Eigenstepper
77 
78  // Set up propagator with void navigator
79  auto propagator =
80  std::make_shared<Propagator<EigenStepper<ConstantBField>>>(stepper);
81 
82  // Create perigee surface
83  std::shared_ptr<PerigeeSurface> perigeeSurface =
84  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
85 
86  // Create position of vertex and perigee surface
87  double x = vXYDist(gen);
88  double y = vXYDist(gen);
89  double z = vZDist(gen);
90 
91  // Calculate d0 and z0 corresponding to vertex position
92  double d0v = sqrt(x * x + y * y);
93  double z0v = z;
94 
95  // Start constructing nTracks tracks in the following
96  std::vector<BoundTrackParameters> tracks;
97 
98  // Construct random track emerging from vicinity of vertex position
99  // Vector to store track objects used for vertex fit
100  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
101  // Construct positive or negative charge randomly
102  double q = qDist(gen) < 0 ? -1. : 1.;
103 
104  // Construct random track parameters
105  BoundVector paramVec;
106  paramVec << d0v + d0Dist(gen), z0v + z0Dist(gen), phiDist(gen),
107  thetaDist(gen), q / pTDist(gen), 0.;
108 
109  // Resolutions
110  double resD0 = resIPDist(gen);
111  double resZ0 = resIPDist(gen);
112  double resPh = resAngDist(gen);
113  double resTh = resAngDist(gen);
114  double resQp = resQoPDist(gen);
115 
116  // Fill vector of track objects with simple covariance matrix
117  Covariance covMat;
118 
119  covMat << resD0 * resD0, 0., 0., 0., 0., 0., 0., resZ0 * resZ0, 0., 0., 0.,
120  0., 0., 0., resPh * resPh, 0., 0., 0., 0., 0., 0., resTh * resTh, 0.,
121  0., 0., 0., 0., 0., resQp * resQp, 0., 0., 0., 0., 0., 0., 1.;
122  tracks.emplace_back(perigeeSurface, paramVec, std::move(covMat));
123  }
124 
125  Linearizer::Config ltConfig(bField, propagator);
126  Linearizer linFactory(ltConfig);
128 
129  BoundVector vecBoundZero = BoundVector::Zero();
130  BoundSymMatrix matBoundZero = BoundSymMatrix::Zero();
131  Vector4D vecSPZero = Vector4D::Zero();
134  ActsMatrixD<eBoundSize, 3> matBound2MomZero =
136 
137  for (const BoundTrackParameters& parameters : tracks) {
138  LinearizedTrack linTrack =
139  linFactory
140  .linearizeTrack(parameters, Vector4D::Zero(), geoContext,
141  magFieldContext, state)
142  .value();
143 
144  BOOST_CHECK_NE(linTrack.parametersAtPCA, vecBoundZero);
145  BOOST_CHECK_NE(linTrack.covarianceAtPCA, matBoundZero);
146  BOOST_CHECK_EQUAL(linTrack.linearizationPoint, vecSPZero);
147  BOOST_CHECK_NE(linTrack.positionJacobian, matBound2SPZero);
148  BOOST_CHECK_NE(linTrack.momentumJacobian, matBound2MomZero);
149  BOOST_CHECK_NE(linTrack.constantTerm, vecBoundZero);
150  }
151 }
152 
156 BOOST_AUTO_TEST_CASE(linearized_track_factory_straightline_test) {
157  using LinearizerStraightLine =
159  // Number of tracks
160  unsigned int nTracks = 100;
161 
162  // Set up RNG
163  int mySeed = 31415;
164  std::mt19937 gen(mySeed);
165 
166  // Set up stepper
168 
169  // Set up propagator with void navigator
170  auto propagator = std::make_shared<Propagator<StraightLineStepper>>(stepper);
171 
172  // Create perigee surface
173  std::shared_ptr<PerigeeSurface> perigeeSurface =
174  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
175 
176  // Create position of vertex and perigee surface
177  double x = vXYDist(gen);
178  double y = vXYDist(gen);
179  double z = vZDist(gen);
180 
181  // Calculate d0 and z0 corresponding to vertex position
182  double d0v = sqrt(x * x + y * y);
183  double z0v = z;
184 
185  // Start constructing nTracks tracks in the following
186  std::vector<BoundTrackParameters> tracks;
187 
188  // Construct random track emerging from vicinity of vertex position
189  // Vector to store track objects used for vertex fit
190  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
191  // Construct positive or negative charge randomly
192  double q = qDist(gen) < 0 ? -1. : 1.;
193 
194  // Construct random track parameters
195  BoundVector paramVec;
196  paramVec << d0v + d0Dist(gen), z0v + z0Dist(gen), phiDist(gen),
197  thetaDist(gen), q / pTDist(gen), 0.;
198 
199  // Resolutions
200  double resD0 = resIPDist(gen);
201  double resZ0 = resIPDist(gen);
202  double resPh = resAngDist(gen);
203  double resTh = resAngDist(gen);
204  double resQp = resQoPDist(gen);
205 
206  // Fill vector of track objects with simple covariance matrix
207  Covariance covMat;
208 
209  covMat << resD0 * resD0, 0., 0., 0., 0., 0., 0., resZ0 * resZ0, 0., 0., 0.,
210  0., 0., 0., resPh * resPh, 0., 0., 0., 0., 0., 0., resTh * resTh, 0.,
211  0., 0., 0., 0., 0., resQp * resQp, 0., 0., 0., 0., 0., 0., 1.;
212  tracks.emplace_back(perigeeSurface, paramVec, std::move(covMat));
213  }
214 
215  // Set up helical track linearizer for the case of a non-existing
216  // magnetic field, which results in the extreme case of a straight line
217  LinearizerStraightLine::Config ltConfig(propagator);
218  LinearizerStraightLine linFactory(ltConfig);
219  LinearizerStraightLine::State state(magFieldContext);
220 
221  BoundVector vecBoundZero = BoundVector::Zero();
222  BoundSymMatrix matBoundZero = BoundSymMatrix::Zero();
223  Vector4D vecSPZero = Vector4D::Zero();
226  ActsMatrixD<eBoundSize, 3> matBound2MomZero =
228 
229  for (const BoundTrackParameters& parameters : tracks) {
230  LinearizedTrack linTrack =
231  linFactory
232  .linearizeTrack(parameters, Vector4D::Zero(), geoContext,
233  magFieldContext, state)
234  .value();
235 
236  BOOST_CHECK_NE(linTrack.parametersAtPCA, vecBoundZero);
237  BOOST_CHECK_NE(linTrack.covarianceAtPCA, matBoundZero);
238  BOOST_CHECK_EQUAL(linTrack.linearizationPoint, vecSPZero);
239  BOOST_CHECK_NE(linTrack.positionJacobian, matBound2SPZero);
240  BOOST_CHECK_NE(linTrack.momentumJacobian, matBound2MomZero);
241  BOOST_CHECK_NE(linTrack.constantTerm, vecBoundZero);
242  }
243 }
244 
245 } // namespace Test
246 } // namespace Acts