ECCE @ 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<BoundParameters> 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.push_back(BoundParameters(geoContext, std::move(covMat), paramVec,
123  perigeeSurface));
124  }
125 
126  Linearizer::Config ltConfig(bField, propagator);
127  Linearizer linFactory(ltConfig);
128 
129  BoundVector vecBoundZero = BoundVector::Zero();
130  BoundSymMatrix matBoundZero = BoundSymMatrix::Zero();
131  SpacePointVector vecSPZero = SpacePointVector::Zero();
132  SpacePointToBoundMatrix matBound2SPZero = SpacePointToBoundMatrix::Zero();
133  ActsMatrixD<eBoundParametersSize, 3> matBound2MomZero =
135 
136  for (const BoundParameters& parameters : tracks) {
137  LinearizedTrack linTrack =
138  linFactory
139  .linearizeTrack(parameters, SpacePointVector::Zero(), geoContext,
141  .value();
142 
143  BOOST_CHECK_NE(linTrack.parametersAtPCA, vecBoundZero);
144  BOOST_CHECK_NE(linTrack.covarianceAtPCA, matBoundZero);
145  BOOST_CHECK_EQUAL(linTrack.linearizationPoint, vecSPZero);
146  BOOST_CHECK_NE(linTrack.positionJacobian, matBound2SPZero);
147  BOOST_CHECK_NE(linTrack.momentumJacobian, matBound2MomZero);
148  BOOST_CHECK_NE(linTrack.constantTerm, vecBoundZero);
149  }
150 }
151 
155 BOOST_AUTO_TEST_CASE(linearized_track_factory_straightline_test) {
156  using LinearizerStraightLine =
158  // Number of tracks
159  unsigned int nTracks = 100;
160 
161  // Set up RNG
162  int mySeed = 31415;
163  std::mt19937 gen(mySeed);
164 
165  // Set up stepper
167 
168  // Set up propagator with void navigator
169  auto propagator = std::make_shared<Propagator<StraightLineStepper>>(stepper);
170 
171  // Create perigee surface
172  std::shared_ptr<PerigeeSurface> perigeeSurface =
173  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
174 
175  // Create position of vertex and perigee surface
176  double x = vXYDist(gen);
177  double y = vXYDist(gen);
178  double z = vZDist(gen);
179 
180  // Calculate d0 and z0 corresponding to vertex position
181  double d0v = sqrt(x * x + y * y);
182  double z0v = z;
183 
184  // Start constructing nTracks tracks in the following
185  std::vector<BoundParameters> tracks;
186 
187  // Construct random track emerging from vicinity of vertex position
188  // Vector to store track objects used for vertex fit
189  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
190  // Construct positive or negative charge randomly
191  double q = qDist(gen) < 0 ? -1. : 1.;
192 
193  // Construct random track parameters
194  BoundVector paramVec;
195  paramVec << d0v + d0Dist(gen), z0v + z0Dist(gen), phiDist(gen),
196  thetaDist(gen), q / pTDist(gen), 0.;
197 
198  // Resolutions
199  double resD0 = resIPDist(gen);
200  double resZ0 = resIPDist(gen);
201  double resPh = resAngDist(gen);
202  double resTh = resAngDist(gen);
203  double resQp = resQoPDist(gen);
204 
205  // Fill vector of track objects with simple covariance matrix
206  Covariance covMat;
207 
208  covMat << resD0 * resD0, 0., 0., 0., 0., 0., 0., resZ0 * resZ0, 0., 0., 0.,
209  0., 0., 0., resPh * resPh, 0., 0., 0., 0., 0., 0., resTh * resTh, 0.,
210  0., 0., 0., 0., 0., resQp * resQp, 0., 0., 0., 0., 0., 0., 1.;
211  tracks.push_back(BoundParameters(geoContext, std::move(covMat), paramVec,
212  perigeeSurface));
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 
220  BoundVector vecBoundZero = BoundVector::Zero();
221  BoundSymMatrix matBoundZero = BoundSymMatrix::Zero();
222  SpacePointVector vecSPZero = SpacePointVector::Zero();
223  SpacePointToBoundMatrix matBound2SPZero = SpacePointToBoundMatrix::Zero();
224  ActsMatrixD<eBoundParametersSize, 3> matBound2MomZero =
226 
227  for (const BoundParameters& parameters : tracks) {
228  LinearizedTrack linTrack =
229  linFactory
230  .linearizeTrack(parameters, SpacePointVector::Zero(), geoContext,
232  .value();
233 
234  BOOST_CHECK_NE(linTrack.parametersAtPCA, vecBoundZero);
235  BOOST_CHECK_NE(linTrack.covarianceAtPCA, matBoundZero);
236  BOOST_CHECK_EQUAL(linTrack.linearizationPoint, vecSPZero);
237  BOOST_CHECK_NE(linTrack.positionJacobian, matBound2SPZero);
238  BOOST_CHECK_NE(linTrack.momentumJacobian, matBound2MomZero);
239  BOOST_CHECK_NE(linTrack.constantTerm, vecBoundZero);
240  }
241 }
242 
243 } // namespace Test
244 } // namespace Acts