EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GridDensityVertexFinderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GridDensityVertexFinderTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 
19 #include "Acts/Utilities/Units.hpp"
22 
23 namespace bdata = boost::unit_test::data;
24 using namespace Acts::UnitLiterals;
26 
27 namespace Acts {
28 namespace Test {
29 
31 
32 // Create a test context
35 
36 const double zVertexPos1 = 12.;
37 const double zVertexPos2 = -3.;
38 // x position
39 std::normal_distribution<double> xdist(1_mm, 0.1_mm);
40 // y position
41 std::normal_distribution<double> ydist(-0.7_mm, 0.1_mm);
42 // z1 position
43 std::normal_distribution<double> z1dist(zVertexPos1 * 1_mm, 1_mm);
44 // z2 position
45 std::normal_distribution<double> z2dist(zVertexPos2 * 1_mm, 0.5_mm);
46 // Track pT distribution
47 std::uniform_real_distribution<double> pTDist(0.1_GeV, 100_GeV);
48 // Track phi distribution
49 std::uniform_real_distribution<double> phiDist(-M_PI, M_PI);
50 // Track eta distribution
51 std::uniform_real_distribution<double> etaDist(-4., 4.);
52 
57 BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_test) {
58  bool debugMode = true;
59 
60  const int mainGridSize = 3000;
61  const int trkGridSize = 35;
62 
63  Covariance covMat = Covariance::Identity();
64 
65  // Perigee surface for track parameters
66  Vector3D pos0{0, 0, 0};
67  std::shared_ptr<PerigeeSurface> perigeeSurface =
68  Surface::makeShared<PerigeeSurface>(pos0);
69 
72 
74  Finder::Config cfg;
75  cfg.cacheGridStateForTrackRemoval = false;
76  Finder finder(cfg);
77 
78  Finder::State state;
79 
80  int mySeed = 31415;
81  std::mt19937 gen(mySeed);
82  unsigned int nTracks = 200;
83 
84  std::vector<BoundTrackParameters> trackVec;
85  trackVec.reserve(nTracks);
86 
87  // Create nTracks tracks for test case
88  for (unsigned int i = 0; i < nTracks; i++) {
89  // The position of the particle
90  Vector3D pos(xdist(gen), ydist(gen), 0);
91  // Produce most of the tracks at near z1 position,
92  // some near z2. Highest track density then expected at z1
93  if ((i % 4) == 0) {
94  pos[eZ] = z2dist(gen);
95  } else {
96  pos[eZ] = z1dist(gen);
97  }
98 
99  // Create momentum and charge of track
100  double pt = pTDist(gen);
101  double phi = phiDist(gen);
102  double eta = etaDist(gen);
103  double charge = etaDist(gen) > 0 ? 1 : -1;
104 
105  trackVec.push_back(BoundTrackParameters(
106  perigeeSurface, geoContext, makeVector4(pos, 0),
107  makeDirectionUnitFromPhiEta(phi, eta), pt, charge, covMat));
108  }
109 
110  std::vector<const BoundTrackParameters*> trackPtrVec;
111  for (const auto& trk : trackVec) {
112  trackPtrVec.push_back(&trk);
113  }
114 
115  auto res = finder.find(trackPtrVec, vertexingOptions, state);
116  if (!res.ok()) {
117  std::cout << res.error().message() << std::endl;
118  }
119 
120  if (res.ok()) {
121  BOOST_CHECK(!(*res).empty());
122  Vector3D result = (*res).back().position();
123  if (debugMode) {
124  std::cout << "Vertex position result: " << result << std::endl;
125  }
126  CHECK_CLOSE_ABS(result[eZ], zVertexPos1, 1_mm);
127  }
128 }
129 
130 BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_track_caching_test) {
131  bool debugMode = true;
132 
133  const int mainGridSize = 3000;
134  const int trkGridSize = 35;
135 
136  Covariance covMat = Covariance::Identity();
137 
138  // Perigee surface for track parameters
139  Vector3D pos0{0, 0, 0};
140  std::shared_ptr<PerigeeSurface> perigeeSurface =
141  Surface::makeShared<PerigeeSurface>(pos0);
142 
145 
148 
149  // Use custom grid density here
150  GridDensity::Config densityConfig(100_mm);
151  densityConfig.useHighestSumZPosition = true;
152  GridDensity density(densityConfig);
153 
154  Finder::Config cfg(density);
155  cfg.cacheGridStateForTrackRemoval = true;
156  Finder finder(cfg);
157 
158  int mySeed = 31415;
159  std::mt19937 gen(mySeed);
160  unsigned int nTracks = 200;
161 
162  std::vector<BoundTrackParameters> trackVec;
163  trackVec.reserve(nTracks);
164 
165  // Create nTracks tracks for test case
166  for (unsigned int i = 0; i < nTracks; i++) {
167  double x = xdist(gen);
168  double y = ydist(gen);
169  // Produce most of the tracks at near z1 position,
170  // some near z2. Highest track density then expected at z1
171  double z = ((i % 4) == 0) ? z2dist(gen) : z1dist(gen);
172  double pt = pTDist(gen);
173  double phi = phiDist(gen);
174  double eta = etaDist(gen);
175  double charge = etaDist(gen) > 0 ? 1 : -1;
176  trackVec.push_back(BoundTrackParameters(
177  perigeeSurface, geoContext, Vector4D(x, y, z, 0),
178  makeDirectionUnitFromPhiEta(phi, eta), pt, charge, covMat));
179  }
180 
181  std::vector<const BoundTrackParameters*> trackPtrVec;
182  for (const auto& trk : trackVec) {
183  trackPtrVec.push_back(&trk);
184  }
185 
186  Finder::State state;
187 
188  auto res = finder.find(trackPtrVec, vertexingOptions, state);
189  if (!res.ok()) {
190  std::cout << res.error().message() << std::endl;
191  }
192  if (res.ok()) {
193  BOOST_CHECK(!(*res).empty());
194  Vector3D result = (*res).back().position();
195  if (debugMode) {
196  std::cout << "Vertex position after first fill: " << result << std::endl;
197  }
198  CHECK_CLOSE_ABS(result[eZ], zVertexPos1, 1_mm);
199  }
200 
201  int trkCount = 0;
202  std::vector<const BoundTrackParameters*> removedTracks;
203  for (const auto& trk : trackVec) {
204  if ((trkCount % 4) != 0) {
205  removedTracks.push_back(&trk);
206  }
207  trkCount++;
208  }
209 
210  state.tracksToRemove = removedTracks;
211 
212  auto res2 = finder.find(trackPtrVec, vertexingOptions, state);
213  if (!res2.ok()) {
214  std::cout << res2.error().message() << std::endl;
215  }
216  if (res2.ok()) {
217  BOOST_CHECK(!(*res2).empty());
218  Vector3D result = (*res2).back().position();
219  if (debugMode) {
220  std::cout
221  << "Vertex position after removing tracks near first density peak: "
222  << result << std::endl;
223  }
224  CHECK_CLOSE_ABS(result[eZ], zVertexPos2, 1_mm);
225  }
226 }
227 
231 BOOST_AUTO_TEST_CASE(grid_density_vertex_finder_seed_width_test) {
232  bool debugMode = true;
233 
234  const int mainGridSize = 3000;
235  const int trkGridSize = 35;
236 
237  Covariance covMat = Covariance::Identity();
238 
239  // Perigee surface for track parameters
240  Vector3D pos0{0, 0, 0};
241  std::shared_ptr<PerigeeSurface> perigeeSurface =
242  Surface::makeShared<PerigeeSurface>(pos0);
243 
246  Vertex<BoundTrackParameters> constraintVtx;
248  vertexingOptions.vertexConstraint = constraintVtx;
249 
251  Finder::Config cfg;
252  cfg.cacheGridStateForTrackRemoval = false;
253  cfg.estimateSeedWidth = true;
254  Finder finder(cfg);
255 
256  Finder::State state;
257 
258  int mySeed = 31415;
259  std::mt19937 gen(mySeed);
260  unsigned int nTracks = 20;
261 
262  std::vector<BoundTrackParameters> trackVec;
263  trackVec.reserve(nTracks);
264 
265  // Create nTracks tracks for test case
266  for (unsigned int i = 0; i < nTracks; i++) {
267  double x = xdist(gen);
268  double y = ydist(gen);
269  double z = z1dist(gen);
270  double pt = pTDist(gen);
271  double phi = phiDist(gen);
272  double eta = etaDist(gen);
273  double charge = etaDist(gen) > 0 ? 1 : -1;
274  trackVec.push_back(BoundTrackParameters(
275  perigeeSurface, geoContext, Vector4D(x, y, z, 0),
276  makeDirectionUnitFromPhiEta(phi, eta), pt, charge, covMat));
277  }
278 
279  std::vector<const BoundTrackParameters*> trackPtrVec;
280  for (const auto& trk : trackVec) {
281  trackPtrVec.push_back(&trk);
282  }
283 
284  auto res = finder.find(trackPtrVec, vertexingOptions, state);
285  if (!res.ok()) {
286  std::cout << res.error().message() << std::endl;
287  }
288 
289  if (res.ok()) {
290  BOOST_CHECK(!(*res).empty());
291  ActsSymMatrixD<3> cov = (*res).back().covariance();
292  BOOST_CHECK(constraintVtx.covariance() != cov);
293  BOOST_CHECK(cov(eZ, eZ) != 0.);
294  if (debugMode) {
295  std::cout << "Estimated z-seed width: " << cov(eZ, eZ) << std::endl;
296  }
297  }
298 }
299 
300 } // namespace Test
301 } // namespace Acts