ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackStateTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackStateTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 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/optional/optional_io.hpp>
10 #include <boost/test/unit_test.hpp>
11 
12 #include <random>
21 
22 namespace Acts {
23 namespace Test {
24 
25 // Create a test context
27 
28 using SourceLink = MinimalSourceLink;
29 
30 template <ParID_t... params>
31 using MeasurementType = Measurement<SourceLink, params...>;
32 using FittableMeasurement = FittableMeasurement<SourceLink>;
37 BOOST_AUTO_TEST_CASE(track_state_initialization) {
38  std::default_random_engine generator(42);
39 
40  // The plane surface
41  auto plane = Surface::makeShared<PlaneSurface>(Vector3D{0., 0., 0.},
42  Vector3D{1., 0., 0.});
43 
44  // Construct the 1D measurement
46  cov1D << 0.04;
47 
49  MeasurementType<ParDef::eLOC_0>(plane, {}, std::move(cov1D), 0.02));
50 
51  // Construct the 2D measurement
53  cov2D << 0.04, 0., 0.09, 0.;
54 
56  plane, {}, std::move(cov2D), 0.02, 0.03));
57 
58  // The 1D track state from the measurement
59  BoundTrackState mts1D(SourceLink{&m1D});
60 
61  auto calibrate = [](auto& trackstate) {
62  // double ref: optional, MinimalSourceLink
63  trackstate.measurement.calibrated = **trackstate.measurement.uncalibrated;
64  };
65 
66  // "calibrate" the measurement
67  calibrate(mts1D);
68 
69  BOOST_CHECK_EQUAL(*mts1D.size(), 1u);
70 
71  // Test the copy construtor
72  BoundTrackState mts1DCopy(mts1D);
73 
74  // Test the copy move constructor
75  BoundTrackState mts1DCopyMoved(std::move(mts1DCopy));
76 
77  // Test the copy assignment operator
78  BoundTrackState mts1DCopyAssigned = mts1DCopyMoved;
79 
80  // Test the comovepy assignment operator
81  BoundTrackState mts1DMoveAssigned = std::move(mts1DCopyAssigned);
82 
83  // Swap the measurements
84  std::swap(mts1DMoveAssigned, mts1D);
85 
86  // The 2D track state from the measurement
87  BoundTrackState mts2D(SourceLink{&m2D});
88  calibrate(mts2D);
89 
90  BOOST_CHECK_EQUAL(*mts2D.size(), 2u);
91 
92  // Construct the parameter
93  std::array<double, 6> pars_array = {
94  {-0.1234, 9.8765, 0.45, 0.888, 0.001, 0.}};
95  BoundVector pars;
96  pars << pars_array[0], pars_array[1], pars_array[2], pars_array[3],
97  pars_array[4], pars_array[5];
98 
99  // constructor from parameter vector: predicted filtered, smoothed
100  BoundParameters ataPlane(tgContext, std::nullopt, pars, plane);
101 
102  // The parameter track state from the parameters
103  BoundTrackState pts(std::move(ataPlane));
104 
105  // Test the copy constructor for a parameter state
106  BoundTrackState ptsCopy(pts);
107 
108  // Test the copy move constructor for a parameter state
109  BoundTrackState ptsCopyMove(std::move(ptsCopy));
110 
111  // Test the copy assignment for a parameter state
112  BoundTrackState ptsCopyAssigned = ptsCopyMove;
113 
114  // Test the move assignment for a parameter state
115  BoundTrackState ptsMoveAssigned = std::move(ptsCopyAssigned);
116 
117  std::vector<BoundTrackState> trackStates = {std::move(mts1DMoveAssigned),
118  std::move(mts2D), std::move(pts)};
119 
120  BOOST_CHECK_EQUAL(trackStates.size(), 3u);
121 
122  // Test is we can shuffle the track states
123  // Test to extract the surface of these guys
124  for (auto& ts : trackStates) {
125  const Surface* sf = &ts.referenceSurface();
126  BOOST_CHECK_EQUAL(sf, plane.get());
127  }
128 
129  // Create predicted, filtered and smoothed parameters
130  BoundParameters ataPlaneUpdt(tgContext, std::nullopt, pars, plane);
131  BoundParameters ataPlanePred(tgContext, std::nullopt, pars, plane);
132  BoundParameters ataPlaneSmth(tgContext, std::nullopt, pars, plane);
133 
134  // Get the predicted parameters back from the trackState
135  auto& ptsfList = trackStates[2];
136  auto& ataPlanefListPred = ptsfList.parameter.predicted;
137  BOOST_CHECK(ataPlanefListPred);
138 
139  // Check that the other parameters are empty
140  auto& ataPlanefListUpdt = ptsfList.parameter.filtered;
141  BOOST_CHECK(!ataPlanefListUpdt);
142 
143  auto& ataPlanefListSmthd = ptsfList.parameter.smoothed;
144  BOOST_CHECK(!ataPlanefListSmthd);
145 
146  // Get the track States from the list
147  auto& m2DfList = trackStates[1];
148 
149  m2DfList.parameter.filtered = std::move(ataPlaneUpdt);
150  auto& ataPlanefListUpdtM2D = m2DfList.parameter.filtered;
151  BOOST_CHECK(ataPlanefListUpdtM2D);
152 
153  m2DfList.parameter.predicted = std::move(ataPlanePred);
154  auto& ataPlanefListPred2D = m2DfList.parameter.predicted;
155  BOOST_CHECK(ataPlanefListPred2D);
156 
157  // Test the sorting helper
158  BoundParameters ataPlaneAt1(tgContext, std::nullopt, pars, plane);
159  BoundTrackState ataPlaneState1(std::move(ataPlaneAt1));
160  ataPlaneState1.parameter.pathLength = 1.;
161 
162  BoundParameters ataPlaneAt2(tgContext, std::nullopt, pars, plane);
163  BoundTrackState ataPlaneState2(std::move(ataPlaneAt2));
164  ataPlaneState2.parameter.pathLength = 2.;
165 
166  std::vector<BoundTrackState> unorderedStates = {std::move(ataPlaneState2),
167  std::move(ataPlaneState1)};
168 
169  // Sort the variant track state
171  std::sort(unorderedStates.begin(), unorderedStates.end(), plSorter);
172 
173  auto firstOrdered = unorderedStates[0];
174  BOOST_CHECK_EQUAL(firstOrdered.parameter.pathLength, 1.);
175 
176  auto secondOrdered = unorderedStates[1];
177  BOOST_CHECK_EQUAL(secondOrdered.parameter.pathLength, 2.);
178 
179  auto& pState = firstOrdered.parameter;
180 
181  BOOST_CHECK_EQUAL(pState.pathLength, 1.);
182 
183  std::shuffle(unorderedStates.begin(), unorderedStates.end(), generator);
184 
185  // Copy the TrackStates into a new vector
186  std::vector<BoundTrackState> copiedStates = {unorderedStates[0],
187  unorderedStates[1]};
188 
189  // Shuffle
190  std::shuffle(copiedStates.begin(), copiedStates.end(), generator);
191  // And sort again
192  std::sort(copiedStates.begin(), copiedStates.end(), plSorter);
193 }
194 
195 } // namespace Test
196 } // namespace Acts