ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AdaptiveMultiVertexFinderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AdaptiveMultiVertexFinderTests.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 
14 
20 #include "Acts/Utilities/Units.hpp"
26 
27 #include "AMVFTestData.ipp"
28 
29 namespace Acts {
30 namespace Test {
31 
32 using namespace Acts::UnitLiterals;
33 
37 
38 // Create a test context
41 
42 BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_test) {
43  // Set debug mode
44  bool debugMode = false;
45  // Set up constant B-Field
46  ConstantBField bField(Vector3D(0., 0., 2_T));
47 
48  // Set up EigenStepper
49  // EigenStepper<ConstantBField> stepper(bField);
51 
52  // Set up propagator with void navigator
53  auto propagator = std::make_shared<Propagator>(stepper);
54 
55  // IP 3D Estimator
57 
58  IPEstimator::Config ipEstimatorCfg(bField, propagator);
59  IPEstimator ipEstimator(ipEstimatorCfg);
60 
61  std::vector<double> temperatures{8.0, 4.0, 2.0, 1.4142136, 1.2247449, 1.0};
62  AnnealingUtility::Config annealingConfig(temperatures);
63  AnnealingUtility annealingUtility(annealingConfig);
64 
66 
67  Fitter::Config fitterCfg(ipEstimator);
68 
69  fitterCfg.annealingTool = annealingUtility;
70 
71  // Linearizer for BoundParameters type test
72  Linearizer::Config ltConfig(bField, propagator);
73  Linearizer linearizer(ltConfig);
74 
75  // Test smoothing
76  fitterCfg.doSmoothing = true;
77 
78  Fitter fitter(fitterCfg);
79 
81 
82  SeedFinder seedFinder;
83 
85 
86  Finder::Config finderConfig(std::move(fitter), seedFinder, ipEstimator,
87  linearizer);
88 
89  // TODO: test this as well!
90  // finderConfig.useBeamSpotConstraint = false;
91 
92  Finder finder(finderConfig);
93 
94  auto tracks = getAthenaTracks();
95 
96  if (debugMode) {
97  std::cout << "Number of tracks in event: " << tracks.size() << std::endl;
98  int maxCout = 10;
99  int count = 0;
100  for (const auto& trk : tracks) {
101  std::cout << count << ". track: " << std::endl;
102  std::cout << "params: " << trk << std::endl;
103  count++;
104  if (count == maxCout) {
105  break;
106  }
107  }
108  }
109 
110  std::vector<const BoundParameters*> tracksPtr;
111  for (const auto& trk : tracks) {
112  tracksPtr.push_back(&trk);
113  }
114 
117 
118  Vector3D constraintPos{0._mm, 0._mm, 0_mm};
119  ActsSymMatrixD<3> constraintCov;
120  constraintCov << 0.000196000008145347238, 0, 0, 0, 0.000196000008145347238, 0,
121  0, 0, 2809;
122 
123  Vertex<BoundParameters> constraintVtx;
124  constraintVtx.setPosition(constraintPos);
125  constraintVtx.setCovariance(constraintCov);
126 
127  vertexingOptions.vertexConstraint = constraintVtx;
128 
129  auto findResult = finder.find(tracksPtr, vertexingOptions);
130 
131  if (!findResult.ok()) {
132  std::cout << findResult.error().message() << std::endl;
133  }
134 
135  BOOST_CHECK(findResult.ok());
136 
137  std::vector<Vertex<BoundParameters>> allVertices = *findResult;
138 
139  if (debugMode) {
140  std::cout << "Number of vertices reconstructed: " << allVertices.size()
141  << std::endl;
142 
143  int count = 0;
144  for (const auto& vtx : allVertices) {
145  count++;
146  std::cout << count << ". Vertex at position: " << vtx.position()[0]
147  << ", " << vtx.position()[1] << ", " << vtx.position()[2]
148  << std::endl;
149  std::cout << count << ". Vertex with cov: " << vtx.covariance()
150  << std::endl;
151  std::cout << "\t with n tracks: " << vtx.tracks().size() << std::endl;
152  }
153  }
154 
155  // Test expected outcomes from athena implementation
156  // Number of reconstructed vertices
157  const int expNRecoVertices = 15;
158 
159  // First vertex
160  const Vector3D expVtx1Pos(-0.0067_mm, 0.0060_mm, -6.0709_mm);
161  ActsSymMatrixD<3> expVtx1Cov;
162  expVtx1Cov << 0.000, 1.e-05, -8.e-05, 1.e-05, 0.000, -8.e-05, -8.e-05,
163  -8.e-05, 0.002;
164  std::vector<double> expVtx1TrkWeights{0.9796, 0.0334, 0.9884, 0.9697};
165  std::vector<double> expVtx1TrkComp{1.2542, 15.7317, 0.1144, 2.067};
166  std::vector<double> expVtx1TrkChi2{0, 0, 0, 0};
167 
168  // Last vertex
169  const Vector3D expVtx15Pos(0.00264_mm, -0.0072_mm, -39.8197_mm);
170  ActsSymMatrixD<3> expVtx15Cov;
171  expVtx15Cov << 0.000, 1.e-06, 0.000, 1.e-06, 0.000, -6.e-05, 0.000, -6.e-05,
172  0.014;
173  std::vector<double> expVtx15TrkWeights{0.0048, 0.0005, 0.0236, 0.8481,
174  0.8924};
175  std::vector<double> expVtx15TrkComp{19.6561, 24.1389, 16.4425, 5.5604,
176  4.7683};
177  std::vector<double> expVtx15TrkChi2{0, 0, 0, 0};
178 
179  // Vertex z positions of all found vertices
180  const std::vector<double> expAllVtxZPos{
181  -6.070_mm, -12.0605_mm, -15.1093_mm, -27.6569_mm, -22.1054_mm,
182  -45.7010_mm, -5.0622_mm, -26.5496_mm, -28.9597_mm, -37.7430_mm,
183  5.4828_mm, -47.8939_mm, 2.5777_mm, -0.2656_mm, -39.8197_mm};
184 
185  // Number of tracks of all vertices
186  const std::vector<int> expAllNTracks{4, 2, 3, 14, 5, 9, 8, 17,
187  7, 2, 2, 4, 2, 7, 5};
188 
189  BOOST_CHECK_EQUAL(allVertices.size(), expNRecoVertices);
190 
191  int count = 0;
192  for (const auto& vtx : allVertices) {
193  // Check vertex z positions
194  CHECK_CLOSE_ABS(vtx.position()[2], expAllVtxZPos[count], 0.003_mm);
195  // Check number of tracks
196  BOOST_CHECK_EQUAL(vtx.tracks().size(), expAllNTracks[count]);
197 
198  // Check vertex 1 thoroughly
199  if (count == 0) {
200  CHECK_CLOSE_ABS(vtx.position(), expVtx1Pos, 0.001_mm);
201  CHECK_CLOSE_ABS(vtx.covariance(), expVtx1Cov, 0.001_mm);
202  int trkCount = 0;
203  for (const auto& trk : vtx.tracks()) {
204  CHECK_CLOSE_ABS(trk.trackWeight, expVtx1TrkWeights[trkCount], 0.01);
205  CHECK_CLOSE_ABS(trk.vertexCompatibility, expVtx1TrkComp[trkCount],
206  0.15);
207  // CHECK_CLOSE_ABS(trk.chi2Track, expVtx1TrkChi2[trkCount], 0.001);
208  trkCount++;
209  }
210  }
211 
212  // Check vertex 15 thoroughly
213  if (count == 14) {
214  CHECK_CLOSE_ABS(vtx.position(), expVtx15Pos, 0.001_mm);
215  CHECK_CLOSE_ABS(vtx.covariance(), expVtx15Cov, 0.001_mm);
216  int trkCount = 0;
217  for (const auto& trk : vtx.tracks()) {
218  CHECK_CLOSE_ABS(trk.trackWeight, expVtx15TrkWeights[trkCount], 0.01);
219  CHECK_CLOSE_ABS(trk.vertexCompatibility, expVtx15TrkComp[trkCount],
220  0.15);
221  // CHECK_CLOSE_ABS(trk.chi2Track, expVtx15TrkChi2[trkCount], 0.001);
222  trkCount++;
223  }
224  }
225 
226  count++;
227  }
228 }
229 
230 // Dummy user-defined InputTrack type
231 struct InputTrack {
232  InputTrack(const BoundParameters& params, int id)
233  : m_parameters(params), m_id(id) {}
234 
235  const BoundParameters& parameters() const { return m_parameters; }
236  // store e.g. link to original objects here
237 
238  int id() const { return m_id; }
239 
240  private:
242 
243  // Some test track ID
244  int m_id;
245 };
246 
247 BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_finder_usertype_test) {
248  // Set debug mode
249  bool debugMode = false;
250  // Set up constant B-Field
251  ConstantBField bField(Vector3D(0., 0., 2_T));
252 
253  // Set up EigenStepper
254  // EigenStepper<ConstantBField> stepper(bField);
256 
257  // Set up propagator with void navigator
258  auto propagator = std::make_shared<Propagator>(stepper);
259 
260  // Create a custom std::function to extract BoundParameters from
261  // user-defined InputTrack
262  std::function<BoundParameters(InputTrack)> extractParameters =
263  [](InputTrack params) { return params.parameters(); };
264 
265  // IP 3D Estimator
267 
268  IPEstimator::Config ipEstimatorCfg(bField, propagator);
269  IPEstimator ipEstimator(ipEstimatorCfg);
270 
271  std::vector<double> temperatures{8.0, 4.0, 2.0, 1.4142136, 1.2247449, 1.0};
272  AnnealingUtility::Config annealingConfig(temperatures);
273  AnnealingUtility annealingUtility(annealingConfig);
274 
276 
277  Fitter::Config fitterCfg(ipEstimator);
278 
279  fitterCfg.annealingTool = annealingUtility;
280 
281  // Linearizer
282  Linearizer::Config ltConfig(bField, propagator);
283  Linearizer linearizer(ltConfig);
284 
285  // Test smoothing
286  fitterCfg.doSmoothing = true;
287 
288  Fitter fitter(fitterCfg, extractParameters);
289 
291 
292  SeedFinder seedFinder(extractParameters);
293 
295 
296  Finder::Config finderConfig(std::move(fitter), seedFinder, ipEstimator,
297  linearizer);
298 
299  Finder finder(finderConfig, extractParameters);
300 
301  auto tracks = getAthenaTracks();
302 
303  std::vector<InputTrack> userTracks;
304  int idCount = 0;
305  for (const auto& trk : tracks) {
306  userTracks.push_back(InputTrack(trk, idCount));
307  idCount++;
308  }
309 
310  if (debugMode) {
311  std::cout << "Number of tracks in event: " << tracks.size() << std::endl;
312  int maxCout = 10;
313  int count = 0;
314  for (const auto& trk : tracks) {
315  std::cout << count << ". track: " << std::endl;
316  std::cout << "params: " << trk << std::endl;
317  count++;
318  if (count == maxCout) {
319  break;
320  }
321  }
322  }
323 
324  std::vector<const InputTrack*> userTracksPtr;
325  for (const auto& trk : userTracks) {
326  userTracksPtr.push_back(&trk);
327  }
328 
330 
331  Vector3D constraintPos{0._mm, 0._mm, 0_mm};
332  ActsSymMatrixD<3> constraintCov;
333  constraintCov << 0.000196000008145347238, 0, 0, 0, 0.000196000008145347238, 0,
334  0, 0, 2809;
335 
336  Vertex<InputTrack> constraintVtx;
337  constraintVtx.setPosition(constraintPos);
338  constraintVtx.setCovariance(constraintCov);
339 
340  vertexingOptions.vertexConstraint = constraintVtx;
341 
342  auto findResult = finder.find(userTracksPtr, vertexingOptions);
343 
344  if (!findResult.ok()) {
345  std::cout << findResult.error().message() << std::endl;
346  }
347 
348  BOOST_CHECK(findResult.ok());
349 
350  std::vector<Vertex<InputTrack>> allVertices = *findResult;
351 
352  if (debugMode) {
353  std::cout << "Number of vertices reconstructed: " << allVertices.size()
354  << std::endl;
355 
356  int count = 0;
357  for (const auto& vtx : allVertices) {
358  count++;
359  std::cout << count << ". Vertex at position: " << vtx.position()[0]
360  << ", " << vtx.position()[1] << ", " << vtx.position()[2]
361  << std::endl;
362  std::cout << count << ". Vertex with cov: " << vtx.covariance()
363  << std::endl;
364  std::cout << "\t with n tracks: " << vtx.tracks().size() << std::endl;
365  }
366  for (auto& trk : allVertices[0].tracks()) {
367  std::cout << "Track ID at first vertex: " << trk.originalParams->id()
368  << std::endl;
369  }
370  }
371 
372  // Test expected outcomes from athena implementation
373  // Number of reconstructed vertices
374  const int expNRecoVertices = 15;
375 
376  // First vertex
377  const Vector3D expVtx1Pos(-0.0067_mm, 0.0060_mm, -6.0709_mm);
378  ActsSymMatrixD<3> expVtx1Cov;
379  expVtx1Cov << 0.000, 1.e-05, -8.e-05, 1.e-05, 0.000, -8.e-05, -8.e-05,
380  -8.e-05, 0.002;
381  std::vector<double> expVtx1TrkWeights{0.9796, 0.0334, 0.9884, 0.9697};
382  std::vector<double> expVtx1TrkComp{1.2542, 15.7317, 0.1144, 2.067};
383  std::vector<double> expVtx1TrkChi2{0, 0, 0, 0};
384 
385  // Last vertex
386  const Vector3D expVtx15Pos(0.00264_mm, -0.0072_mm, -39.8197_mm);
387  ActsSymMatrixD<3> expVtx15Cov;
388  expVtx15Cov << 0.000, 1.e-06, 0.000, 1.e-06, 0.000, -6.e-05, 0.000, -6.e-05,
389  0.014;
390  std::vector<double> expVtx15TrkWeights{0.0048, 0.0005, 0.0236, 0.8481,
391  0.8924};
392  std::vector<double> expVtx15TrkComp{19.6561, 24.1389, 16.4425, 5.5604,
393  4.7683};
394  std::vector<double> expVtx15TrkChi2{0, 0, 0, 0};
395 
396  // Vertex z positions of all found vertices
397  const std::vector<double> expAllVtxZPos{
398  -6.070_mm, -12.0605_mm, -15.1093_mm, -27.6569_mm, -22.1054_mm,
399  -45.7010_mm, -5.0622_mm, -26.5496_mm, -28.9597_mm, -37.7430_mm,
400  5.4828_mm, -47.8939_mm, 2.5777_mm, -0.2656_mm, -39.8197_mm};
401 
402  // Number of tracks of all vertices
403  const std::vector<int> expAllNTracks{4, 2, 3, 14, 5, 9, 8, 17,
404  7, 2, 2, 4, 2, 7, 5};
405 
406  const std::vector<int> expTracksIDs{29, 51, 89, 132};
407 
408  BOOST_CHECK_EQUAL(allVertices.size(), expNRecoVertices);
409 
410  int count = 0;
411  for (const auto& vtx : allVertices) {
412  // Check vertex z positions
413  CHECK_CLOSE_ABS(vtx.position()[2], expAllVtxZPos[count], 0.003_mm);
414  // Check number of tracks
415  BOOST_CHECK_EQUAL(vtx.tracks().size(), expAllNTracks[count]);
416 
417  // Check vertex 1 thoroughly
418  if (count == 0) {
419  CHECK_CLOSE_ABS(vtx.position(), expVtx1Pos, 0.001_mm);
420  CHECK_CLOSE_ABS(vtx.covariance(), expVtx1Cov, 0.001_mm);
421  int trkCount = 0;
422  for (const auto& trk : vtx.tracks()) {
423  CHECK_CLOSE_ABS(trk.trackWeight, expVtx1TrkWeights[trkCount], 0.01);
424  CHECK_CLOSE_ABS(trk.vertexCompatibility, expVtx1TrkComp[trkCount],
425  0.15);
426  BOOST_CHECK_EQUAL(trk.originalParams->id(), expTracksIDs[trkCount]);
427  // CHECK_CLOSE_ABS(trk.chi2Track, expVtx1TrkChi2[trkCount], 0.001);
428  trkCount++;
429  }
430  }
431 
432  // Check vertex 15 thoroughly
433  if (count == 14) {
434  CHECK_CLOSE_ABS(vtx.position(), expVtx15Pos, 0.001_mm);
435  CHECK_CLOSE_ABS(vtx.covariance(), expVtx15Cov, 0.001_mm);
436  int trkCount = 0;
437  for (const auto& trk : vtx.tracks()) {
438  CHECK_CLOSE_ABS(trk.trackWeight, expVtx15TrkWeights[trkCount], 0.01);
439  CHECK_CLOSE_ABS(trk.vertexCompatibility, expVtx15TrkComp[trkCount],
440  0.15);
441  // CHECK_CLOSE_ABS(trk.chi2Track, expVtx15TrkChi2[trkCount], 0.001);
442  trkCount++;
443  }
444  }
445 
446  count++;
447  }
448 }
449 
450 } // namespace Test
451 } // namespace Acts