File indexing completed on 2026-04-17 07:47:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Surfaces/PlaneSurface.hpp"
0010 #include "Acts/TrackFitting/GsfMixtureReduction.hpp"
0011
0012 #include <boost/program_options.hpp>
0013
0014 #include "StepperBenchmarkCommons.hpp"
0015
0016 namespace po = boost::program_options;
0017 using namespace Acts;
0018 using namespace ActsTests;
0019
0020 constexpr std::size_t nComponents = 72;
0021
0022 template <typename Fun>
0023 void test(const std::vector<std::vector<GsfComponent>> &inputData,
0024 const Acts::Surface &surface, Fun &&fun) {
0025 auto num_runs = 1000;
0026 auto res = microBenchmark(
0027 [&](const std::vector<GsfComponent> &input) {
0028
0029 static std::vector<GsfComponent> inputCopy(nComponents);
0030 inputCopy = input;
0031 fun(inputCopy, 12, surface);
0032 assumeRead(inputCopy);
0033 },
0034 inputData, num_runs);
0035
0036 std::cout << res << std::endl;
0037 }
0038
0039 int main(int argc, char *argv[]) {
0040 bool weight = true;
0041 bool kl_optimized = true;
0042 bool kl_naive = true;
0043
0044 try {
0045 po::options_description desc("Allowed options");
0046 desc.add_options()("help", "produce help message")(
0047 "weight", po::value<bool>(&weight)->default_value(true),
0048 "run weight-based reduction (reduceMixtureLargestWeights)")(
0049 "kl-optimized", po::value<bool>(&kl_optimized)->default_value(true),
0050 "run optimized KL distance reduction (reduceMixtureWithKLDistance)")(
0051 "kl-naive", po::value<bool>(&kl_naive)->default_value(true),
0052 "run naive KL distance reduction (reduceMixtureWithKLDistanceNaive)");
0053
0054 po::variables_map vm;
0055 po::store(po::parse_command_line(argc, argv, desc), vm);
0056 po::notify(vm);
0057
0058 if (vm.contains("help")) {
0059 std::cout << desc << std::endl;
0060 return 0;
0061 }
0062 } catch (std::exception &e) {
0063 std::cerr << "error: " << e.what() << std::endl;
0064 return 1;
0065 }
0066
0067 std::vector<std::vector<GsfComponent>> data(100);
0068
0069 auto surface = Acts::Surface::makeShared<Acts::PlaneSurface>(
0070 Acts::Transform3::Identity());
0071
0072 for (auto &sample : data) {
0073 sample.reserve(nComponents);
0074 for (auto i = 0ul; i < nComponents; ++i) {
0075 double weight_val = 1.0 / nComponents;
0076 auto cov = Acts::BoundMatrix::Identity();
0077 auto pars = Acts::BoundVector::Random();
0078 sample.push_back({weight_val, pars, cov});
0079 }
0080 }
0081
0082 if (weight) {
0083 std::cout << "reduceMixtureLargestWeights" << std::endl;
0084 test(data, *surface, reduceMixtureLargestWeights);
0085 std::cout << std::endl;
0086 }
0087
0088 if (kl_optimized) {
0089 std::cout << "reduceMixtureWithKLDistance (optimized)" << std::endl;
0090 test(data, *surface, reduceMixtureWithKLDistance);
0091 std::cout << std::endl;
0092 }
0093
0094 if (kl_naive) {
0095 std::cout << "reduceMixtureWithKLDistanceNaive (baseline)" << std::endl;
0096 test(data, *surface, reduceMixtureWithKLDistanceNaive);
0097 std::cout << std::endl;
0098 }
0099 }