Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:22

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2019 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Definitions/Units.hpp"
0010 #include "Acts/EventData/ParticleHypothesis.hpp"
0011 #include "Acts/EventData/TrackParameters.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0014 #include "Acts/Propagator/Propagator.hpp"
0015 #include "Acts/Propagator/StraightLineStepper.hpp"
0016 #include "Acts/Tests/CommonHelpers/BenchmarkTools.hpp"
0017 #include "Acts/Utilities/Logger.hpp"
0018 
0019 #include <iostream>
0020 
0021 #include <boost/program_options.hpp>
0022 
0023 namespace po = boost::program_options;
0024 using namespace Acts;
0025 using namespace Acts::UnitLiterals;
0026 
0027 int main(int argc, char* argv[]) {
0028   unsigned int toys = 1;
0029   double ptInGeV = 1;
0030   double BzInT = 1;
0031   double maxPathInM = 1;
0032   unsigned int lvl = Acts::Logging::INFO;
0033   bool withCov = true;
0034 
0035   // Create a test context
0036   GeometryContext tgContext = GeometryContext();
0037   MagneticFieldContext mfContext = MagneticFieldContext();
0038 
0039   try {
0040     po::options_description desc("Allowed options");
0041     // clang-format off
0042   desc.add_options()
0043       ("help", "produce help message")
0044       ("toys",po::value<unsigned int>(&toys)->default_value(20000),"number of tracks to propagate")
0045       ("pT",po::value<double>(&ptInGeV)->default_value(1),"transverse momentum in GeV")
0046       ("path",po::value<double>(&maxPathInM)->default_value(5),"maximum path length in m")
0047       ("cov",po::value<bool>(&withCov)->default_value(true),"propagation with covariance matrix")
0048       ("verbose",po::value<unsigned int>(&lvl)->default_value(Acts::Logging::INFO),"logging level");
0049     // clang-format on
0050     po::variables_map vm;
0051     po::store(po::parse_command_line(argc, argv, desc), vm);
0052     po::notify(vm);
0053 
0054     if (vm.count("help") != 0u) {
0055       std::cout << desc << std::endl;
0056       return 0;
0057     }
0058   } catch (std::exception& e) {
0059     std::cerr << "error: " << e.what() << std::endl;
0060     return 1;
0061   }
0062 
0063   ACTS_LOCAL_LOGGER(
0064       getDefaultLogger("ATLAS_Stepper", Acts::Logging::Level(lvl)));
0065 
0066   // print information about profiling setup
0067   ACTS_INFO("propagating " << toys << " tracks with pT = " << ptInGeV
0068                            << "GeV in a " << BzInT << "T B-field");
0069 
0070   using Stepper = StraightLineStepper;
0071   using Propagator = Propagator<Stepper>;
0072   using Covariance = BoundSquareMatrix;
0073 
0074   Stepper stepper;
0075   Propagator propagator(stepper);
0076 
0077   PropagatorOptions<> options(tgContext, mfContext);
0078   options.pathLimit = maxPathInM * UnitConstants::m;
0079 
0080   Vector4 pos4(0, 0, 0, 0);
0081   Vector3 dir(1, 0, 0);
0082   Covariance cov;
0083   // clang-format off
0084   cov << 10_mm, 0, 0, 0, 0, 0,
0085          0, 10_mm, 0, 0, 0, 0,
0086          0, 0, 1, 0, 0, 0,
0087          0, 0, 0, 1, 0, 0,
0088          0, 0, 0, 0, 1_e / 10_GeV, 0,
0089          0, 0, 0, 0, 0, 0;
0090   // clang-format on
0091 
0092   std::optional<Covariance> covOpt = std::nullopt;
0093   if (withCov) {
0094     covOpt = cov;
0095   }
0096   CurvilinearTrackParameters pars(pos4, dir, +1 / ptInGeV, covOpt,
0097                                   ParticleHypothesis::pion());
0098 
0099   double totalPathLength = 0;
0100   std::size_t numSteps = 0;
0101   std::size_t numIters = 0;
0102   const auto propagationBenchResult = Acts::Test::microBenchmark(
0103       [&] {
0104         auto r = propagator.propagate(pars, options).value();
0105         if (totalPathLength == 0.) {
0106           ACTS_DEBUG("reached position "
0107                      << r.endParameters->position(tgContext).transpose()
0108                      << " in " << r.steps << " steps");
0109         }
0110         totalPathLength += r.pathLength;
0111         numSteps += r.steps;
0112         ++numIters;
0113         return r;
0114       },
0115       1, toys);
0116 
0117   ACTS_INFO("Execution stats: " << propagationBenchResult);
0118   ACTS_INFO("average path length = " << totalPathLength / numIters / 1_mm
0119                                      << "mm");
0120   ACTS_INFO("average number of steps = " << 1.0 * numSteps / numIters);
0121 
0122   return 0;
0123 }