EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackDensityVertexFinderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackDensityVertexFinderTests.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 
18 #include "Acts/Utilities/Units.hpp"
23 
24 namespace bdata = boost::unit_test::data;
25 using namespace Acts::UnitLiterals;
27 
28 namespace Acts {
29 namespace Test {
30 
32 
33 // Create a test context
36 
42 BOOST_AUTO_TEST_CASE(track_density_finder_test) {
43  // Define some track parameter properties
44  Vector3D pos0{0, 0, 0};
45  Vector3D pos1a{2_mm, 1_mm, -10_mm};
46  Vector3D mom1a{400_MeV, 600_MeV, 200_MeV};
47  Vector3D pos1b{1_mm, 2_mm, -3_mm};
48  Vector3D mom1b{600_MeV, 400_MeV, -200_MeV};
49  Vector3D pos1c{1.2_mm, 1.3_mm, -7_mm};
50  Vector3D mom1c{300_MeV, 1000_MeV, 100_MeV};
51 
54  using Finder =
57  Finder finder;
58  Finder::State state;
59 
60  // Start creating some track parameters
61  Covariance covMat = Covariance::Identity();
62  std::shared_ptr<PerigeeSurface> perigeeSurface =
63  Surface::makeShared<PerigeeSurface>(pos0);
64 
65  // Test finder for some fixed track parameter values
66  BoundTrackParameters params1a(perigeeSurface, geoContext,
67  makeVector4(pos1a, 0), mom1a, mom1a.norm(), 1,
68  covMat);
69  BoundTrackParameters params1b(perigeeSurface, geoContext,
70  makeVector4(pos1b, 0), mom1b, mom1b.norm(), -1,
71  covMat);
72  BoundTrackParameters params1c(perigeeSurface, geoContext,
73  makeVector4(pos1c, 0), mom1c, mom1c.norm(), -1,
74  covMat);
75 
76  // Vectors of track parameters in different orders
77  std::vector<const BoundTrackParameters*> vec1 = {&params1a, &params1b,
78  &params1c};
79  std::vector<const BoundTrackParameters*> vec2 = {&params1c, &params1a,
80  &params1b};
81 
82  auto res1 = finder.find(vec1, vertexingOptions, state);
83  auto res2 = finder.find(vec2, vertexingOptions, state);
84 
85  if (!res1.ok()) {
86  std::cout << res1.error().message() << std::endl;
87  }
88 
89  if (!res2.ok()) {
90  std::cout << res2.error().message() << std::endl;
91  }
92 
93  if (res1.ok() and res2.ok()) {
94  BOOST_CHECK(!(*res1).empty());
95  BOOST_CHECK(!(*res2).empty());
96  Vector3D result1 = (*res1).back().position();
97  Vector3D result2 = (*res2).back().position();
98  BOOST_CHECK(result1 == result2);
99  }
100 }
101 
106 BOOST_AUTO_TEST_CASE(track_density_finder_constr_test) {
107  // Define some track parameter properties
108  Vector3D pos0{0, 0, 0};
109  Vector3D pos1a{2_mm, 1_mm, -10_mm};
110  Vector3D mom1a{400_MeV, 600_MeV, 200_MeV};
111  Vector3D pos1b{1_mm, 2_mm, -3_mm};
112  Vector3D mom1b{600_MeV, 400_MeV, -200_MeV};
113  Vector3D pos1c{1.2_mm, 1.3_mm, -7_mm};
114  Vector3D mom1c{300_MeV, 1000_MeV, 100_MeV};
115 
116  // From Athena VertexSeedFinderTestAlg
117  double const expectedZResult = -13.013;
118 
119  // Finder options
122 
123  // Create constraint for seed finding
124  Vector3D constraintPos{1.7_mm, 1.3_mm, -6_mm};
126 
127  Vertex<BoundTrackParameters> vertexConstraint(constraintPos);
128  vertexConstraint.setCovariance(constrCov);
129 
130  vertexingOptions.vertexConstraint = vertexConstraint;
131  using Finder =
134  Finder finder;
135  Finder::State state;
136 
137  // Start creating some track parameters
138  Covariance covMat = Covariance::Identity();
139  std::shared_ptr<PerigeeSurface> perigeeSurface =
140  Surface::makeShared<PerigeeSurface>(pos0);
141 
142  // Test finder for some fixed track parameter values
143  BoundTrackParameters params1a(perigeeSurface, geoContext,
144  makeVector4(pos1a, 0), mom1a, mom1a.norm(), 1,
145  covMat);
146  BoundTrackParameters params1b(perigeeSurface, geoContext,
147  makeVector4(pos1b, 0), mom1b, mom1b.norm(), -1,
148  covMat);
149  BoundTrackParameters params1c(perigeeSurface, geoContext,
150  makeVector4(pos1c, 0), mom1c, mom1c.norm(), -1,
151  covMat);
152 
153  // Vector of track parameters
154  std::vector<const BoundTrackParameters*> vec1 = {&params1a, &params1b,
155  &params1c};
156 
157  auto res = finder.find(vec1, vertexingOptions, state);
158 
159  if (!res.ok()) {
160  std::cout << res.error().message() << std::endl;
161  }
162 
163  if (res.ok()) {
164  BOOST_CHECK(!(*res).empty());
165  Vector3D result = (*res).back().position();
166 
167  BOOST_CHECK(result[eX] == constraintPos[eX]);
168  BOOST_CHECK(result[eY] == constraintPos[eY]);
169  CHECK_CLOSE_ABS(result[eZ], expectedZResult, 0.001_mm);
170  }
171 }
172 
173 const double zVertexPos = 12.;
174 // x position
175 std::normal_distribution<double> xdist(1_mm, 0.1_mm);
176 // y position
177 std::normal_distribution<double> ydist(-0.7_mm, 0.1_mm);
178 // z1 position
179 std::normal_distribution<double> z1dist(zVertexPos * 1_mm, 1_mm);
180 // z2 position
181 std::normal_distribution<double> z2dist(-3_mm, 0.5_mm);
182 // Track pT distribution
183 std::uniform_real_distribution<double> pTDist(0.1_GeV, 100_GeV);
184 // Track phi distribution
185 std::uniform_real_distribution<double> phiDist(-M_PI, M_PI);
186 // Track eta distribution
187 std::uniform_real_distribution<double> etaDist(-4., 4.);
188 
193 BOOST_AUTO_TEST_CASE(track_density_finder_random_test) {
194  Covariance covMat = Covariance::Identity();
195 
196  // Perigee surface for track parameters
197  Vector3D pos0{0, 0, 0};
198  std::shared_ptr<PerigeeSurface> perigeeSurface =
199  Surface::makeShared<PerigeeSurface>(pos0);
200 
203  using Finder =
206  Finder finder;
207  Finder::State state;
208 
209  int mySeed = 31415;
210  std::mt19937 gen(mySeed);
211  unsigned int nTracks = 200;
212 
213  std::vector<BoundTrackParameters> trackVec;
214  trackVec.reserve(nTracks);
215 
216  // Create nTracks tracks for test case
217  for (unsigned int i = 0; i < nTracks; i++) {
218  double x = xdist(gen);
219  double y = ydist(gen);
220  // Produce most of the tracks at near z1 position,
221  // some near z2. Highest track density then expected at z1
222  double z = ((i % 4) == 0) ? z2dist(gen) : z1dist(gen);
223  double pt = pTDist(gen);
224  double phi = phiDist(gen);
225  double eta = etaDist(gen);
226  double charge = etaDist(gen) > 0 ? 1 : -1;
227  trackVec.push_back(BoundTrackParameters(
228  perigeeSurface, geoContext, Vector4D(x, y, z, 0),
229  makeDirectionUnitFromPhiEta(phi, eta), pt, charge, covMat));
230  }
231 
232  std::vector<const BoundTrackParameters*> trackPtrVec;
233  for (const auto& trk : trackVec) {
234  trackPtrVec.push_back(&trk);
235  }
236 
237  auto res3 = finder.find(trackPtrVec, vertexingOptions, state);
238  if (!res3.ok()) {
239  std::cout << res3.error().message() << std::endl;
240  }
241 
242  if (res3.ok()) {
243  BOOST_CHECK(!(*res3).empty());
244  Vector3D result = (*res3).back().position();
245  CHECK_CLOSE_ABS(result[eZ], zVertexPos, 1_mm);
246  }
247 }
248 
249 // Dummy user-defined InputTrack type
250 struct InputTrack {
251  InputTrack(const BoundTrackParameters& params) : m_parameters(params) {}
252 
253  const BoundTrackParameters& parameters() const { return m_parameters; }
254 
255  // store e.g. link to original objects here
256 
257  private:
258  BoundTrackParameters m_parameters;
259 };
260 
265 BOOST_AUTO_TEST_CASE(track_density_finder_usertrack_test) {
266  // Define some track parameter properties
267  Vector3D pos0{0, 0, 0};
268  Vector3D pos1a{2_mm, 1_mm, -10_mm};
269  Vector3D mom1a{400_MeV, 600_MeV, 200_MeV};
270  Vector3D pos1b{1_mm, 2_mm, -3_mm};
271  Vector3D mom1b{600_MeV, 400_MeV, -200_MeV};
272  Vector3D pos1c{1.2_mm, 1.3_mm, -7_mm};
273  Vector3D mom1c{300_MeV, 1000_MeV, 100_MeV};
274 
275  // From Athena VertexSeedFinderTestAlg
276  double const expectedZResult = -13.013;
277 
278  // Finder options
280 
281  // Create constraint for seed finding
282  Vector3D constraintPos{1.7_mm, 1.3_mm, -6_mm};
284 
285  Vertex<InputTrack> vertexConstraint(constraintPos);
286  vertexConstraint.setCovariance(constrCov);
287 
288  vertexingOptions.vertexConstraint = vertexConstraint;
289 
290  std::function<BoundTrackParameters(InputTrack)> extractParameters =
291  [](InputTrack params) { return params.parameters(); };
292 
295 
296  Finder finder(extractParameters);
297  Finder::State state;
298 
299  // Start creating some track parameters
300  Covariance covMat = Covariance::Identity();
301  std::shared_ptr<PerigeeSurface> perigeeSurface =
302  Surface::makeShared<PerigeeSurface>(pos0);
303 
304  // Test finder for some fixed track parameter values
305  InputTrack params1a(BoundTrackParameters(perigeeSurface, geoContext,
306  makeVector4(pos1a, 0), mom1a,
307  mom1a.norm(), 1, covMat));
308  InputTrack params1b(BoundTrackParameters(perigeeSurface, geoContext,
309  makeVector4(pos1b, 0), mom1b,
310  mom1b.norm(), -1, covMat));
311  InputTrack params1c(BoundTrackParameters(perigeeSurface, geoContext,
312  makeVector4(pos1c, 0), mom1c,
313  mom1c.norm(), -1, covMat));
314 
315  // Vector of track parameters
316  std::vector<const InputTrack*> vec1 = {&params1a, &params1b, &params1c};
317 
318  auto res = finder.find(vec1, vertexingOptions, state);
319 
320  if (!res.ok()) {
321  std::cout << res.error().message() << std::endl;
322  }
323 
324  if (res.ok()) {
325  BOOST_CHECK(!(*res).empty());
326  Vector3D result = (*res).back().position();
327 
328  BOOST_CHECK(result[eX] == constraintPos[eX]);
329  BOOST_CHECK(result[eY] == constraintPos[eY]);
330  CHECK_CLOSE_ABS(result[eZ], expectedZResult, 0.001_mm);
331  }
332 }
333 
334 } // namespace Test
335 } // namespace Acts