EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ZScanVertexFinderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ZScanVertexFinderTests.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 
20 #include "Acts/Utilities/Units.hpp"
27 
28 namespace bdata = boost::unit_test::data;
29 using namespace Acts::UnitLiterals;
30 
31 namespace Acts {
32 namespace Test {
33 
35 using Propagator = Propagator<EigenStepper<ConstantBField>>;
37 
38 // Create a test context
41 
42 // Vertex x/y position distribution
43 std::uniform_real_distribution<> vXYDist(-0.1_mm, 0.1_mm);
44 // Vertex z position distribution
45 std::uniform_real_distribution<> vZDist(-20_mm, 20_mm);
46 // Track d0 distribution
47 std::uniform_real_distribution<> d0Dist(-0.01_mm, 0.01_mm);
48 // Track z0 distribution
49 std::uniform_real_distribution<> z0Dist(-0.2_mm, 0.2_mm);
50 // Track pT distribution
51 std::uniform_real_distribution<> pTDist(0.4_GeV, 10_GeV);
52 // Track phi distribution
53 std::uniform_real_distribution<> phiDist(-M_PI, M_PI);
54 // Track theta distribution
55 std::uniform_real_distribution<> thetaDist(1.0, M_PI - 1.0);
56 // Track charge helper distribution
57 std::uniform_real_distribution<> qDist(-1, 1);
58 // Track IP resolution distribution
59 std::uniform_real_distribution<> resIPDist(0., 100_um);
60 // Track angular distribution
61 std::uniform_real_distribution<> resAngDist(0., 0.1);
62 // Track q/p resolution distribution
63 std::uniform_real_distribution<> resQoPDist(-0.01, 0.01);
64 
68 BOOST_AUTO_TEST_CASE(zscan_finder_test) {
69  unsigned int nTests = 50;
70 
71  for (unsigned int iTest = 0; iTest < nTests; ++iTest) {
72  // Number of tracks
73  unsigned int nTracks = 30;
74 
75  // Set up RNG
76  int mySeed = 31415;
77  std::mt19937 gen(mySeed);
78 
79  // Set up constant B-Field
80  ConstantBField bField(0.0, 0.0, 1_T);
81 
82  // Set up Eigenstepper
84 
85  // Set up propagator with void navigator
86  auto propagator = std::make_shared<Propagator>(stepper);
87 
89  BilloirFitter;
90 
91  // Create perigee surface
92  std::shared_ptr<PerigeeSurface> perigeeSurface =
93  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
94 
95  // Create position of vertex and perigee surface
96  double x = vXYDist(gen);
97  double y = vXYDist(gen);
98  double z = vZDist(gen);
99 
100  // Calculate d0 and z0 corresponding to vertex position
101  double d0_v = sqrt(x * x + y * y);
102  double z0_v = z;
103 
104  // Start constructing nTracks tracks in the following
105  std::vector<BoundTrackParameters> tracks;
106 
107  // Construct random track emerging from vicinity of vertex position
108  // Vector to store track objects used for vertex fit
109  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
110  // Construct positive or negative charge randomly
111  double q = qDist(gen) < 0 ? -1. : 1.;
112 
113  // Construct random track parameters
114  BoundVector paramVec = BoundVector::Zero();
115  paramVec[eBoundLoc0] = d0_v + d0Dist(gen);
116  paramVec[eBoundLoc1] = z0_v + z0Dist(gen);
117  paramVec[eBoundPhi] = phiDist(gen);
118  paramVec[eBoundTheta] = thetaDist(gen);
119  paramVec[eBoundQOverP] = q / pTDist(gen);
120 
121  // Resolutions
122  double resD0 = resIPDist(gen);
123  double resZ0 = resIPDist(gen);
124  double resPh = resAngDist(gen);
125  double resTh = resAngDist(gen);
126  double resQp = resQoPDist(gen);
127 
128  // Fill vector of track objects with simple covariance matrix
129  Covariance covMat;
130 
131  covMat << resD0 * resD0, 0., 0., 0., 0., 0., 0., resZ0 * resZ0, 0., 0.,
132  0., 0., 0., 0., resPh * resPh, 0., 0., 0., 0., 0., 0., resTh * resTh,
133  0., 0., 0., 0., 0., 0., resQp * resQp, 0., 0., 0., 0., 0., 0., 1.;
134 
135  tracks.emplace_back(perigeeSurface, paramVec, std::move(covMat));
136  }
137 
138  std::vector<const BoundTrackParameters*> tracksPtr;
139  for (const auto& trk : tracks) {
140  tracksPtr.push_back(&trk);
141  }
142 
144 
145  static_assert(VertexFinderConcept<VertexFinder>,
146  "Vertex finder does not fulfill vertex finder concept.");
147 
148  // Impact point estimator
150 
151  IPEstimator::Config ipEstimatorCfg(bField, propagator);
152  IPEstimator ipEstimator(ipEstimatorCfg);
153 
154  VertexFinder::Config cfg(ipEstimator);
155 
156  VertexFinder finder(cfg);
157 
160 
161  VertexFinder::State state;
162  auto res = finder.find(tracksPtr, vertexingOptions, state);
163 
164  BOOST_CHECK(res.ok());
165 
166  if (!res.ok()) {
167  std::cout << res.error().message() << std::endl;
168  }
169 
170  if (res.ok()) {
171  BOOST_CHECK(!(*res).empty());
172  Vector3D result = (*res).back().position();
173  CHECK_CLOSE_ABS(result[eZ], z, 1_mm);
174  }
175  }
176 }
177 
178 // Dummy user-defined InputTrack type
179 struct InputTrack {
180  InputTrack(const BoundTrackParameters& params) : m_parameters(params) {}
181 
182  const BoundTrackParameters& parameters() const { return m_parameters; }
183 
184  // store e.g. link to original objects here
185 
186  private:
187  BoundTrackParameters m_parameters;
188 };
189 
193 BOOST_AUTO_TEST_CASE(zscan_finder_usertrack_test) {
194  unsigned int nTests = 50;
195 
196  for (unsigned int iTest = 0; iTest < nTests; ++iTest) {
197  // Number of tracks
198  unsigned int nTracks = 30;
199 
200  // Set up RNG
201  int mySeed = 31415;
202  std::mt19937 gen(mySeed);
203 
204  // Set up constant B-Field
205  ConstantBField bField(0.0, 0.0, 1_T);
206 
207  // Set up Eigenstepper
209 
210  // Set up propagator with void navigator
211  auto propagator = std::make_shared<Propagator>(stepper);
212 
214 
215  // Create perigee surface
216  std::shared_ptr<PerigeeSurface> perigeeSurface =
217  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
218 
219  // Create position of vertex and perigee surface
220  double x = vXYDist(gen);
221  double y = vXYDist(gen);
222  double z = vZDist(gen);
223 
224  // Calculate d0 and z0 corresponding to vertex position
225  double d0_v = sqrt(x * x + y * y);
226  double z0_v = z;
227 
228  // Start constructing nTracks tracks in the following
229  std::vector<InputTrack> tracks;
230 
231  // Construct random track emerging from vicinity of vertex position
232  // Vector to store track objects used for vertex fit
233  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
234  // Construct positive or negative charge randomly
235  double q = qDist(gen) < 0 ? -1. : 1.;
236 
237  // Construct random track parameters
238  BoundVector paramVec;
239  double z0track = z0_v + z0Dist(gen);
240  paramVec << d0_v + d0Dist(gen), z0track, phiDist(gen), thetaDist(gen),
241  q / pTDist(gen), 0.;
242 
243  // Resolutions
244  double resD0 = resIPDist(gen);
245  double resZ0 = resIPDist(gen);
246  double resPh = resAngDist(gen);
247  double resTh = resAngDist(gen);
248  double resQp = resQoPDist(gen);
249 
250  // Fill vector of track objects with simple covariance matrix
251  Covariance covMat;
252 
253  covMat << resD0 * resD0, 0., 0., 0., 0., 0., 0., resZ0 * resZ0, 0., 0.,
254  0., 0., 0., 0., resPh * resPh, 0., 0., 0., 0., 0., 0., resTh * resTh,
255  0., 0., 0., 0., 0., 0., resQp * resQp, 0., 0., 0., 0., 0., 0., 1.;
256 
257  tracks.emplace_back(
258  BoundTrackParameters(perigeeSurface, paramVec, std::move(covMat)));
259  }
260 
261  std::vector<const InputTrack*> tracksPtr;
262  for (const auto& trk : tracks) {
263  tracksPtr.push_back(&trk);
264  }
265 
267 
268  static_assert(VertexFinderConcept<VertexFinder>,
269  "Vertex finder does not fulfill vertex finder concept.");
270 
271  // Impact point estimator
273 
274  IPEstimator::Config ipEstimatorCfg(bField, propagator);
275  IPEstimator ipEstimator(ipEstimatorCfg);
276 
277  VertexFinder::Config cfg(ipEstimator);
278 
279  // Create a custom std::function to extract BoundTrackParameters from
280  // user-defined InputTrack
281  std::function<BoundTrackParameters(InputTrack)> extractParameters =
282  [](InputTrack params) { return params.parameters(); };
283 
284  VertexFinder finder(cfg, extractParameters);
285  VertexFinder::State state;
286 
288 
289  auto res = finder.find(tracksPtr, vertexingOptions, state);
290 
291  BOOST_CHECK(res.ok());
292 
293  if (!res.ok()) {
294  std::cout << res.error().message() << std::endl;
295  }
296 
297  if (res.ok()) {
298  BOOST_CHECK(!(*res).empty());
299  Vector3D result = (*res).back().position();
300  CHECK_CLOSE_ABS(result[eZ], z, 1_mm);
301  }
302  }
303 }
304 
305 } // namespace Test
306 } // namespace Acts