EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EigenStepperBenchmark.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EigenStepperBenchmark.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
17 #include "Acts/Utilities/Units.hpp"
18 
19 #include <iostream>
20 
21 #include <boost/program_options.hpp>
22 
23 namespace po = boost::program_options;
24 using namespace Acts;
25 using namespace Acts::UnitLiterals;
26 
27 int main(int argc, char* argv[]) {
28  unsigned int toys = 1;
29  double ptInGeV = 1;
30  double BzInT = 1;
31  double maxPathInM = 1;
32  unsigned int lvl = Acts::Logging::INFO;
33  bool withCov = true;
34 
35  // Create a test context
38 
39  try {
40  po::options_description desc("Allowed options");
41  // clang-format off
42  desc.add_options()
43  ("help", "produce help message")
44  ("toys",po::value<unsigned int>(&toys)->default_value(20000),"number of tracks to propagate")
45  ("pT",po::value<double>(&ptInGeV)->default_value(1),"transverse momentum in GeV")
46  ("B",po::value<double>(&BzInT)->default_value(2),"z-component of B-field in T")
47  ("path",po::value<double>(&maxPathInM)->default_value(5),"maximum path length in m")
48  ("cov",po::value<bool>(&withCov)->default_value(true),"propagation with covariance matrix")
49  ("verbose",po::value<unsigned int>(&lvl)->default_value(Acts::Logging::INFO),"logging level");
50  // clang-format on
51  po::variables_map vm;
52  po::store(po::parse_command_line(argc, argv, desc), vm);
53  po::notify(vm);
54 
55  if (vm.count("help") != 0u) {
56  std::cout << desc << std::endl;
57  return 0;
58  }
59  } catch (std::exception& e) {
60  std::cerr << "error: " << e.what() << std::endl;
61  return 1;
62  }
63 
65  getDefaultLogger("Eigen_Stepper", Acts::Logging::Level(lvl)));
66 
67  // print information about profiling setup
68  ACTS_INFO("propagating " << toys << " tracks with pT = " << ptInGeV
69  << "GeV in a " << BzInT << "T B-field");
70 
71  using BField_type = ConstantBField;
72  using Stepper_type = EigenStepper<BField_type>;
73  using Propagator_type = Propagator<Stepper_type>;
74  using Covariance = BoundSymMatrix;
75 
76  BField_type bField(0, 0, BzInT * UnitConstants::T);
77  Stepper_type atlas_stepper(std::move(bField));
78  Propagator_type propagator(std::move(atlas_stepper));
79 
80  PropagatorOptions<> options(tgContext, mfContext, getDummyLogger());
81  options.pathLimit = maxPathInM * UnitConstants::m;
82 
83  Vector4D pos4(0, 0, 0, 0);
84  Vector3D dir(1, 0, 0);
86  // clang-format off
87  cov << 10_mm, 0, 0, 0, 0, 0,
88  0, 10_mm, 0, 0, 0, 0,
89  0, 0, 1, 0, 0, 0,
90  0, 0, 0, 1, 0, 0,
91  0, 0, 0, 0, 1_e / 10_GeV, 0,
92  0, 0, 0, 0, 0, 0;
93  // clang-format on
94 
95  std::optional<Covariance> covOpt = std::nullopt;
96  if (withCov) {
97  covOpt = cov;
98  }
99  CurvilinearTrackParameters pars(pos4, dir, ptInGeV, +1, covOpt);
100 
101  double totalPathLength = 0;
102  size_t num_iters = 0;
103  const auto propagation_bench_result = Acts::Test::microBenchmark(
104  [&] {
105  auto r = propagator.propagate(pars, options).value();
106  if (totalPathLength == 0.) {
107  ACTS_DEBUG("reached position "
108  << r.endParameters->position(tgContext).transpose()
109  << " in " << r.steps << " steps");
110  }
111  totalPathLength += r.pathLength;
112  ++num_iters;
113  return r;
114  },
115  1, toys);
116 
117  ACTS_INFO("Execution stats: " << propagation_bench_result);
118  ACTS_INFO("average path length = " << totalPathLength / num_iters / 1_mm
119  << "mm");
120 
121  return 0;
122 }