ECCE @ 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<BoundParameters> 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;
115  double z0track = z0_v + z0Dist(gen);
116  paramVec << d0_v + d0Dist(gen), z0track, phiDist(gen), thetaDist(gen),
117  q / pTDist(gen), 0.;
118 
119  // Resolutions
120  double resD0 = resIPDist(gen);
121  double resZ0 = resIPDist(gen);
122  double resPh = resAngDist(gen);
123  double resTh = resAngDist(gen);
124  double resQp = resQoPDist(gen);
125 
126  // Fill vector of track objects with simple covariance matrix
127  Covariance covMat;
128 
129  covMat << resD0 * resD0, 0., 0., 0., 0., 0., 0., resZ0 * resZ0, 0., 0.,
130  0., 0., 0., 0., resPh * resPh, 0., 0., 0., 0., 0., 0., resTh * resTh,
131  0., 0., 0., 0., 0., 0., resQp * resQp, 0., 0., 0., 0., 0., 0., 1.;
132 
133  tracks.push_back(BoundParameters(geoContext, std::move(covMat), paramVec,
134  perigeeSurface));
135  }
136 
137  std::vector<const BoundParameters*> tracksPtr;
138  for (const auto& trk : tracks) {
139  tracksPtr.push_back(&trk);
140  }
141 
143 
144  static_assert(VertexFinderConcept<VertexFinder>,
145  "Vertex finder does not fulfill vertex finder concept.");
146 
147  // Impact point estimator
149 
150  IPEstimator::Config ipEstimatorCfg(bField, propagator);
151  IPEstimator ipEstimator(ipEstimatorCfg);
152 
153  VertexFinder::Config cfg(ipEstimator);
154 
155  VertexFinder finder(cfg);
156 
159 
160  auto res = finder.find(tracksPtr, vertexingOptions);
161 
162  BOOST_CHECK(res.ok());
163 
164  if (!res.ok()) {
165  std::cout << res.error().message() << std::endl;
166  }
167 
168  if (res.ok()) {
169  BOOST_CHECK(!(*res).empty());
170  Vector3D result = (*res).back().position();
171  CHECK_CLOSE_ABS(result[eZ], z, 1_mm);
172  }
173  }
174 }
175 
176 // Dummy user-defined InputTrack type
177 struct InputTrack {
178  InputTrack(const BoundParameters& params) : m_parameters(params) {}
179 
180  const BoundParameters& parameters() const { return m_parameters; }
181 
182  // store e.g. link to original objects here
183 
184  private:
185  BoundParameters m_parameters;
186 };
187 
191 BOOST_AUTO_TEST_CASE(zscan_finder_usertrack_test) {
192  unsigned int nTests = 50;
193 
194  for (unsigned int iTest = 0; iTest < nTests; ++iTest) {
195  // Number of tracks
196  unsigned int nTracks = 30;
197 
198  // Set up RNG
199  int mySeed = 31415;
200  std::mt19937 gen(mySeed);
201 
202  // Set up constant B-Field
203  ConstantBField bField(0.0, 0.0, 1_T);
204 
205  // Set up Eigenstepper
207 
208  // Set up propagator with void navigator
209  auto propagator = std::make_shared<Propagator>(stepper);
210 
212 
213  // Create perigee surface
214  std::shared_ptr<PerigeeSurface> perigeeSurface =
215  Surface::makeShared<PerigeeSurface>(Vector3D(0., 0., 0.));
216 
217  // Create position of vertex and perigee surface
218  double x = vXYDist(gen);
219  double y = vXYDist(gen);
220  double z = vZDist(gen);
221 
222  // Calculate d0 and z0 corresponding to vertex position
223  double d0_v = sqrt(x * x + y * y);
224  double z0_v = z;
225 
226  // Start constructing nTracks tracks in the following
227  std::vector<InputTrack> tracks;
228 
229  // Construct random track emerging from vicinity of vertex position
230  // Vector to store track objects used for vertex fit
231  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
232  // Construct positive or negative charge randomly
233  double q = qDist(gen) < 0 ? -1. : 1.;
234 
235  // Construct random track parameters
236  BoundVector paramVec;
237  double z0track = z0_v + z0Dist(gen);
238  paramVec << d0_v + d0Dist(gen), z0track, phiDist(gen), thetaDist(gen),
239  q / pTDist(gen), 0.;
240 
241  // Resolutions
242  double resD0 = resIPDist(gen);
243  double resZ0 = resIPDist(gen);
244  double resPh = resAngDist(gen);
245  double resTh = resAngDist(gen);
246  double resQp = resQoPDist(gen);
247 
248  // Fill vector of track objects with simple covariance matrix
249  Covariance covMat;
250 
251  covMat << resD0 * resD0, 0., 0., 0., 0., 0., 0., resZ0 * resZ0, 0., 0.,
252  0., 0., 0., 0., resPh * resPh, 0., 0., 0., 0., 0., 0., resTh * resTh,
253  0., 0., 0., 0., 0., 0., resQp * resQp, 0., 0., 0., 0., 0., 0., 1.;
254 
255  tracks.push_back(InputTrack(BoundParameters(geoContext, std::move(covMat),
256  paramVec, perigeeSurface)));
257  }
258 
259  std::vector<const InputTrack*> tracksPtr;
260  for (const auto& trk : tracks) {
261  tracksPtr.push_back(&trk);
262  }
263 
265 
266  static_assert(VertexFinderConcept<VertexFinder>,
267  "Vertex finder does not fulfill vertex finder concept.");
268 
269  // Impact point estimator
271 
272  IPEstimator::Config ipEstimatorCfg(bField, propagator);
273  IPEstimator ipEstimator(ipEstimatorCfg);
274 
275  VertexFinder::Config cfg(ipEstimator);
276 
277  // Create a custom std::function to extract BoundParameters from
278  // user-defined InputTrack
279  std::function<BoundParameters(InputTrack)> extractParameters =
280  [](InputTrack params) { return params.parameters(); };
281 
282  VertexFinder finder(cfg, extractParameters);
283 
285 
286  auto res = finder.find(tracksPtr, vertexingOptions);
287 
288  BOOST_CHECK(res.ok());
289 
290  if (!res.ok()) {
291  std::cout << res.error().message() << std::endl;
292  }
293 
294  if (res.ok()) {
295  BOOST_CHECK(!(*res).empty());
296  Vector3D result = (*res).back().position();
297  CHECK_CLOSE_ABS(result[eZ], z, 1_mm);
298  }
299  }
300 }
301 
302 } // namespace Test
303 } // namespace Acts