ECCE @ 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 
17 #include "Acts/Utilities/Units.hpp"
22 
23 namespace bdata = boost::unit_test::data;
24 using namespace Acts::UnitLiterals;
25 
26 namespace Acts {
27 namespace Test {
28 
30 
31 // Create a test context
34 
40 BOOST_AUTO_TEST_CASE(track_density_finder_test) {
41  // Define some track parameter properties
42  Vector3D pos0{0, 0, 0};
43  Vector3D pos1a{2_mm, 1_mm, -10_mm};
44  Vector3D mom1a{400_MeV, 600_MeV, 200_MeV};
45  Vector3D pos1b{1_mm, 2_mm, -3_mm};
46  Vector3D mom1b{600_MeV, 400_MeV, -200_MeV};
47  Vector3D pos1c{1.2_mm, 1.3_mm, -7_mm};
48  Vector3D mom1c{300_MeV, 1000_MeV, 100_MeV};
49 
52 
54 
55  // Start creating some track parameters
56  Covariance covMat = Covariance::Identity();
57  std::shared_ptr<PerigeeSurface> perigeeSurface =
58  Surface::makeShared<PerigeeSurface>(pos0);
59 
60  // Test finder for some fixed track parameter values
61  BoundParameters params1a(geoContext, covMat, pos1a, mom1a, 1, 0,
62  perigeeSurface);
63  BoundParameters params1b(geoContext, covMat, pos1b, mom1b, -1, 0,
64  perigeeSurface);
65  BoundParameters params1c(geoContext, covMat, pos1c, mom1c, -1, 0,
66  perigeeSurface);
67 
68  // Vectors of track parameters in different orders
69  std::vector<const BoundParameters*> vec1 = {&params1a, &params1b, &params1c};
70  std::vector<const BoundParameters*> vec2 = {&params1c, &params1a, &params1b};
71 
72  auto res1 = finder.find(vec1, vertexingOptions);
73  auto res2 = finder.find(vec2, vertexingOptions);
74 
75  if (!res1.ok()) {
76  std::cout << res1.error().message() << std::endl;
77  }
78 
79  if (!res2.ok()) {
80  std::cout << res2.error().message() << std::endl;
81  }
82 
83  if (res1.ok() and res2.ok()) {
84  BOOST_CHECK(!(*res1).empty());
85  BOOST_CHECK(!(*res2).empty());
86  Vector3D result1 = (*res1).back().position();
87  Vector3D result2 = (*res2).back().position();
88  BOOST_CHECK(result1 == result2);
89  }
90 }
91 
96 BOOST_AUTO_TEST_CASE(track_density_finder_constr_test) {
97  // Define some track parameter properties
98  Vector3D pos0{0, 0, 0};
99  Vector3D pos1a{2_mm, 1_mm, -10_mm};
100  Vector3D mom1a{400_MeV, 600_MeV, 200_MeV};
101  Vector3D pos1b{1_mm, 2_mm, -3_mm};
102  Vector3D mom1b{600_MeV, 400_MeV, -200_MeV};
103  Vector3D pos1c{1.2_mm, 1.3_mm, -7_mm};
104  Vector3D mom1c{300_MeV, 1000_MeV, 100_MeV};
105 
106  // From Athena VertexSeedFinderTestAlg
107  double const expectedZResult = -13.013;
108 
109  // Finder options
112 
113  // Create constraint for seed finding
114  Vector3D constraintPos{1.7_mm, 1.3_mm, -6_mm};
116 
117  Vertex<BoundParameters> vertexConstraint(constraintPos);
118  vertexConstraint.setCovariance(constrCov);
119 
120  vertexingOptions.vertexConstraint = vertexConstraint;
121 
123 
124  // Start creating some track parameters
125  Covariance covMat = Covariance::Identity();
126  std::shared_ptr<PerigeeSurface> perigeeSurface =
127  Surface::makeShared<PerigeeSurface>(pos0);
128 
129  // Test finder for some fixed track parameter values
130  BoundParameters params1a(geoContext, covMat, pos1a, mom1a, 1, 0,
131  perigeeSurface);
132  BoundParameters params1b(geoContext, covMat, pos1b, mom1b, -1, 0,
133  perigeeSurface);
134  BoundParameters params1c(geoContext, covMat, pos1c, mom1c, -1, 0,
135  perigeeSurface);
136 
137  // Vector of track parameters
138  std::vector<const BoundParameters*> vec1 = {&params1a, &params1b, &params1c};
139 
140  auto res = finder.find(vec1, vertexingOptions);
141 
142  if (!res.ok()) {
143  std::cout << res.error().message() << std::endl;
144  }
145 
146  if (res.ok()) {
147  BOOST_CHECK(!(*res).empty());
148  Vector3D result = (*res).back().position();
149 
150  BOOST_CHECK(result[eX] == constraintPos[eX]);
151  BOOST_CHECK(result[eY] == constraintPos[eY]);
152  CHECK_CLOSE_ABS(result[eZ], expectedZResult, 0.001_mm);
153  }
154 }
155 
156 const double zVertexPos = 12.;
157 // x position
158 std::normal_distribution<double> xdist(1_mm, 0.1_mm);
159 // y position
160 std::normal_distribution<double> ydist(-0.7_mm, 0.1_mm);
161 // z1 position
162 std::normal_distribution<double> z1dist(zVertexPos * 1_mm, 1_mm);
163 // z2 position
164 std::normal_distribution<double> z2dist(-3_mm, 0.5_mm);
165 // Track pT distribution
166 std::uniform_real_distribution<double> pTDist(0.1_GeV, 100_GeV);
167 // Track phi distribution
168 std::uniform_real_distribution<double> phiDist(-M_PI, M_PI);
169 // Track eta distribution
170 std::uniform_real_distribution<double> etaDist(-4., 4.);
171 
176 BOOST_AUTO_TEST_CASE(track_density_finder_random_test) {
177  Covariance covMat = Covariance::Identity();
178 
179  // Perigee surface for track parameters
180  Vector3D pos0{0, 0, 0};
181  std::shared_ptr<PerigeeSurface> perigeeSurface =
182  Surface::makeShared<PerigeeSurface>(pos0);
183 
186 
188 
189  int mySeed = 31415;
190  std::mt19937 gen(mySeed);
191  unsigned int nTracks = 200;
192 
193  std::vector<BoundParameters> trackVec;
194  trackVec.reserve(nTracks);
195 
196  // Create nTracks tracks for test case
197  for (unsigned int i = 0; i < nTracks; i++) {
198  // The position of the particle
199  Vector3D pos(xdist(gen), ydist(gen), 0);
200  // Produce most of the tracks at near z1 position,
201  // some near z2. Highest track density then expected at z1
202  if ((i % 4) == 0) {
203  pos[eZ] = z2dist(gen);
204  } else {
205  pos[eZ] = z1dist(gen);
206  }
207 
208  // Create momentum and charge of track
209  double pt = pTDist(gen);
210  double phi = phiDist(gen);
211  double eta = etaDist(gen);
212  Vector3D mom(pt * std::cos(phi), pt * std::sin(phi), pt * std::sinh(eta));
213  double charge = etaDist(gen) > 0 ? 1 : -1;
214 
215  trackVec.push_back(BoundParameters(geoContext, covMat, pos, mom, charge, 0,
216  perigeeSurface));
217  }
218 
219  std::vector<const BoundParameters*> trackPtrVec;
220  for (const auto& trk : trackVec) {
221  trackPtrVec.push_back(&trk);
222  }
223 
224  auto res3 = finder.find(trackPtrVec, vertexingOptions);
225  if (!res3.ok()) {
226  std::cout << res3.error().message() << std::endl;
227  }
228 
229  if (res3.ok()) {
230  BOOST_CHECK(!(*res3).empty());
231  Vector3D result = (*res3).back().position();
232  CHECK_CLOSE_ABS(result[eZ], zVertexPos, 1_mm);
233  }
234 }
235 
236 // Dummy user-defined InputTrack type
237 struct InputTrack {
238  InputTrack(const BoundParameters& params) : m_parameters(params) {}
239 
240  const BoundParameters& parameters() const { return m_parameters; }
241 
242  // store e.g. link to original objects here
243 
244  private:
245  BoundParameters m_parameters;
246 };
247 
252 BOOST_AUTO_TEST_CASE(track_density_finder_usertrack_test) {
253  // Define some track parameter properties
254  Vector3D pos0{0, 0, 0};
255  Vector3D pos1a{2_mm, 1_mm, -10_mm};
256  Vector3D mom1a{400_MeV, 600_MeV, 200_MeV};
257  Vector3D pos1b{1_mm, 2_mm, -3_mm};
258  Vector3D mom1b{600_MeV, 400_MeV, -200_MeV};
259  Vector3D pos1c{1.2_mm, 1.3_mm, -7_mm};
260  Vector3D mom1c{300_MeV, 1000_MeV, 100_MeV};
261 
262  // From Athena VertexSeedFinderTestAlg
263  double const expectedZResult = -13.013;
264 
265  // Finder options
267 
268  // Create constraint for seed finding
269  Vector3D constraintPos{1.7_mm, 1.3_mm, -6_mm};
271 
272  Vertex<InputTrack> vertexConstraint(constraintPos);
273  vertexConstraint.setCovariance(constrCov);
274 
275  vertexingOptions.vertexConstraint = vertexConstraint;
276 
277  std::function<BoundParameters(InputTrack)> extractParameters =
278  [](InputTrack params) { return params.parameters(); };
279 
281  finder(extractParameters);
282 
283  // Start creating some track parameters
284  Covariance covMat = Covariance::Identity();
285  std::shared_ptr<PerigeeSurface> perigeeSurface =
286  Surface::makeShared<PerigeeSurface>(pos0);
287 
288  // Test finder for some fixed track parameter values
289  InputTrack params1a(
290  BoundParameters(geoContext, covMat, pos1a, mom1a, 1, 0, perigeeSurface));
291  InputTrack params1b(
292  BoundParameters(geoContext, covMat, pos1b, mom1b, -1, 0, perigeeSurface));
293  InputTrack params1c(
294  BoundParameters(geoContext, covMat, pos1c, mom1c, -1, 0, perigeeSurface));
295 
296  // Vector of track parameters
297  std::vector<const InputTrack*> vec1 = {&params1a, &params1b, &params1c};
298 
299  auto res = finder.find(vec1, vertexingOptions);
300 
301  if (!res.ok()) {
302  std::cout << res.error().message() << std::endl;
303  }
304 
305  if (res.ok()) {
306  BOOST_CHECK(!(*res).empty());
307  Vector3D result = (*res).back().position();
308 
309  BOOST_CHECK(result[eX] == constraintPos[eX]);
310  BOOST_CHECK(result[eY] == constraintPos[eY]);
311  CHECK_CLOSE_ABS(result[eZ], expectedZResult, 0.001_mm);
312  }
313 }
314 
315 } // namespace Test
316 } // namespace Acts