Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CovarianceTransportBenchmark.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CovarianceTransportBenchmark.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 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 
16 
17 #include <random>
18 
19 int main(int argc, char* argv[]) {
20  using namespace Acts;
21 
22  size_t iterations = 3;
23  size_t runs = 1000;
24  if (argc >= 2) {
25  iterations = std::stoi(argv[1]);
26  }
27  if (argc >= 3) {
28  runs = std::stoi(argv[2]);
29  }
30 
31  // Create a test context
33 
34  Vector3 position{1., 2., 3.};
35  ActsScalar time = 4.;
36  ActsScalar qop = 0.125;
37  Vector3 direction = Vector3(5., 6., 7.).normalized();
38  auto planeSurface = Surface::makeShared<PlaneSurface>(position, direction);
39  auto otherSurface = Surface::makeShared<PlaneSurface>(
40  position, Vector3(6., 7., 8.).normalized());
41 
42  // Free & bound parameters
43  FreeVector freeParameters;
44  freeParameters << position[0], position[1], position[2], time, direction[0],
45  direction[1], direction[2], qop;
46 
47  BoundVector boundParameters;
48  boundParameters << 0., 0., VectorHelpers::phi(direction),
49  VectorHelpers::theta(direction), qop, time;
50 
51  std::minstd_rand rng;
52  std::uniform_real_distribution<> uniform(0.5, 0.95);
53 
54  unsigned int sillyCounter = 0;
55 
57  getDefaultLogger("CovarianceTransport", Acts::Logging::Level(0)));
58 
59  const auto cov_transport_bound_bound = Acts::Test::microBenchmark(
60  [&] {
61  BoundSquareMatrix boundCovariance =
62  uniform(rng) * BoundSquareMatrix::Identity();
63  boundCovariance(eBoundLoc0, eBoundPhi) = 0.076;
64  boundCovariance(eBoundPhi, eBoundLoc0) = 0.076;
65  boundCovariance(eBoundLoc0, eBoundQOverP) = -0.022;
66  boundCovariance(eBoundQOverP, eBoundLoc0) = -0.022;
67  boundCovariance(eBoundLoc1, eBoundTheta) = -0.007;
68  boundCovariance(eBoundTheta, eBoundLoc1) = -0.007;
69 
70  CovarianceCache covCache(tgContext, *planeSurface, position,
71  boundParameters, boundCovariance);
72 
73  // Transport bound to another bound surface
74  auto covJacAtBound = transportCovarianceToBound(
75  tgContext, *otherSurface, freeParameters, covCache);
76 
77  // Mimic access to the result
78  const auto& variantCovariance = std::get<0>(covJacAtBound);
79  const auto& variantJacobian = std::get<1>(covJacAtBound);
80 
81  const auto& covariance = std::get<BoundSquareMatrix>(variantCovariance);
82  const auto& jacobian = std::get<BoundMatrix>(variantJacobian);
83 
84  if (covariance(eBoundLoc0, eBoundLoc0) > 0 and
85  jacobian(eBoundLoc0, eBoundLoc1) > 0.) {
86  ++sillyCounter;
87  }
88  },
89  iterations, runs);
90 
91  ACTS_INFO("Execution stats: " << cov_transport_bound_bound);
92 }