Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestTrackState.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TestTrackState.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 #pragma once
10 
16 
17 #include <random>
18 
19 namespace Acts::Test {
20 
22  std::shared_ptr<Surface> surface;
28  double chi2;
29  double pathLength;
30 
31  // Generate a random TestTrackState.
32  //
33  // @param rng Random number generator
34  // @param size_t nMeasurement either 1 or 2
35  template <typename rng_t>
36  TestTrackState(rng_t& rng, size_t measdim)
37  : surface(Surface::makeShared<PlaneSurface>(Vector3::Zero(),
38  Vector3::UnitZ())),
39  // set bogus parameters first since they are not default-constructible
40  predicted(surface, BoundVector::Zero(), std::nullopt,
42  filtered(surface, BoundVector::Zero(), std::nullopt,
44  smoothed(surface, BoundVector::Zero(), std::nullopt,
47  chi2(std::chi_squared_distribution<double>(measdim)(rng)),
48  pathLength(std::uniform_real_distribution<ActsScalar>(
49  1 * Acts::UnitConstants::mm, 10 * Acts::UnitConstants::mm)(rng)) {
50  // set a random geometry identifier to uniquely identify each surface
51  auto geoId =
52  std::uniform_int_distribution<GeometryIdentifier::Value>()(rng);
53  surface->assignGeometryId(geoId);
54 
55  // create source link w/ inline 1d or 2d measurement data
56  if (measdim == 1u) {
57  auto [par, cov] = generateParametersCovariance<ActsScalar, 1u>(rng);
58  sourceLink = TestSourceLink(eBoundLoc0, par[0], cov(0, 0), geoId);
59  } else if (measdim == 2u) {
60  auto [par, cov] = generateParametersCovariance<ActsScalar, 2u>(rng);
62  } else {
63  throw std::runtime_error("invalid number of measurement dimensions");
64  }
65 
66  // create track parameters
67  auto [trkPar, trkCov] = generateBoundParametersCovariance(rng);
68  // trkPar[eBoundPhi] = 45_degree;
69  // trkPar[eBoundTheta] = 90_degree;
70  // trkPar[eBoundQOverP] = 5.;
71  // predicted
72  predicted = BoundTrackParameters(surface, trkPar, trkCov,
74  // filtered, modified q/p, reduced covariance
75  // trkPar[eBoundQOverP] = 10.;
76  filtered = BoundTrackParameters(surface, trkPar, 0.75 * trkCov,
78  // smoothed, modified q/p, further reduced covariance
79  // trkPar[eBoundQOverP] = 15.;
80  smoothed = BoundTrackParameters(surface, trkPar, 0.5 * trkCov,
82 
83  // propagation jacobian is identity + corrections
84  for (Eigen::Index c = 0; c < jacobian.cols(); ++c) {
85  for (Eigen::Index r = 0; r < jacobian.rows(); ++r) {
86  jacobian(c, r) +=
87  std::uniform_real_distribution<ActsScalar>(-0.125, 0.125)(rng);
88  }
89  }
90  }
91 };
92 
93 // Fill a TrackStateProxy with values from a TestTrackState.
94 //
95 // @param[in] pc TestTrackState with the input values
96 // @param[in] mask Specifies which components are used/filled
97 // @param[out] ts TrackStateProxy which is filled
98 // @param [in] measdim Dimension of the measurement
99 template <typename trajectory_t, typename track_state_t>
101  track_state_t& ts) {
102  // always set the reference surface
103  ts.setReferenceSurface(pc.predicted.referenceSurface().getSharedPtr());
104 
105  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
106  ts.predicted() = pc.predicted.parameters();
107  assert(pc.predicted.covariance().has_value());
108  ts.predictedCovariance() = *(pc.predicted.covariance());
109  }
110  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
111  ts.filtered() = pc.filtered.parameters();
112  assert(pc.filtered.covariance().has_value());
113  ts.filteredCovariance() = *(pc.filtered.covariance());
114  }
115  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
116  ts.smoothed() = pc.smoothed.parameters();
117  assert(pc.smoothed.covariance().has_value());
118  ts.smoothedCovariance() = *(pc.smoothed.covariance());
119  }
121  ts.jacobian() = pc.jacobian;
122  }
123  ts.chi2() = pc.chi2;
124  ts.pathLength() = pc.pathLength;
125  // source link defines the uncalibrated measurement
126  // create calibrated measurements from source link
127  if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
128  testSourceLinkCalibrator<trajectory_t>(Acts::GeometryContext{},
130  SourceLink{pc.sourceLink}, ts);
131  assert(ts.hasUncalibratedSourceLink());
132  }
133 }
134 
135 } // namespace Acts::Test