Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:55:10

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Utilities/BinUtility.hpp"
0010 #include "Acts/Utilities/Logger.hpp"
0011 #include "ActsTests/CommonHelpers/BenchmarkTools.hpp"
0012 
0013 #include <algorithm>
0014 #include <vector>
0015 
0016 #include <boost/program_options.hpp>
0017 
0018 namespace po = boost::program_options;
0019 using namespace Acts;
0020 using namespace ActsTests;
0021 
0022 int main(int argc, char* argv[]) {
0023   unsigned int lvl = Acts::Logging::INFO;
0024   unsigned int toys = 1;
0025 
0026   try {
0027     po::options_description desc("Allowed options");
0028     // clang-format off
0029   desc.add_options()
0030       ("help", "produce help message")
0031       ("toys",po::value<unsigned int>(&toys)->default_value(100000000),"number searches to be done")
0032       ("verbose",po::value<unsigned int>(&lvl)->default_value(Acts::Logging::INFO),"logging level");
0033     // clang-format on
0034     po::variables_map vm;
0035     po::store(po::parse_command_line(argc, argv, desc), vm);
0036     po::notify(vm);
0037 
0038     if (vm.contains("help")) {
0039       std::cout << desc << std::endl;
0040       return 0;
0041     }
0042   } catch (std::exception& e) {
0043     std::cerr << "error: " << e.what() << std::endl;
0044     return 1;
0045   }
0046 
0047   ACTS_LOCAL_LOGGER(getDefaultLogger("BinUtility", Acts::Logging::Level(lvl)));
0048 
0049   std::vector<float> fewBins;
0050   fewBins.reserve(6);
0051   for (unsigned int ib = 0; ib < 6; ++ib) {
0052     fewBins.push_back(ib * 6. / 5.);
0053   }
0054   Acts::BinUtility small(fewBins, Acts::open, Acts::AxisDirection::AxisX);
0055 
0056   std::vector<float> mediumBins;
0057   mediumBins.reserve(21);
0058   for (unsigned int ib = 0; ib < 21; ++ib) {
0059     mediumBins.push_back(ib * 6. / 20.);
0060   }
0061   Acts::BinUtility medium(mediumBins, Acts::open, Acts::AxisDirection::AxisX);
0062 
0063   std::vector<float> manyBins;
0064   manyBins.reserve(101);
0065   for (unsigned int ib = 0; ib < 101; ++ib) {
0066     manyBins.push_back(ib * 6. / 100.);
0067   }
0068 
0069   Acts::BinUtility many(manyBins, Acts::open, Acts::AxisDirection::AxisX);
0070 
0071   Acts::Vector3 low = Acts::Vector3(1.5, 0., 0.);
0072   Acts::Vector3 high = Acts::Vector3(4.5, 0., 0.);
0073 
0074   std::size_t st = 0;
0075   std::size_t gt = 0;
0076   std::size_t num_iters = 0;
0077   const auto bin_utility_benchmark_small = microBenchmark(
0078       [&] {
0079         auto bin = (num_iters % 2) != 0u ? small.bin(low) : small.bin(high);
0080         if (bin < 3) {
0081           ++st;
0082         } else {
0083           ++gt;
0084         }
0085         ++num_iters;
0086       },
0087       1, toys);
0088 
0089   ACTS_INFO("Execution stats small: " << bin_utility_benchmark_small);
0090   ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0091 
0092   st = 0;
0093   gt = 0;
0094   num_iters = 0;
0095   const auto bin_utility_benchmark_medium = microBenchmark(
0096       [&] {
0097         auto bin = (num_iters % 2) != 0u ? medium.bin(low) : medium.bin(high);
0098         if (bin < 10) {
0099           ++st;
0100         } else {
0101           ++gt;
0102         }
0103         ++num_iters;
0104       },
0105       1, toys);
0106 
0107   ACTS_INFO("Execution stats medium: " << bin_utility_benchmark_medium);
0108   ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0109 
0110   st = 0;
0111   gt = 0;
0112   num_iters = 0;
0113   const auto bin_utility_benchmark_many = microBenchmark(
0114       [&] {
0115         auto bin = (num_iters % 2) != 0u ? many.bin(low) : many.bin(high);
0116         if (bin < 49) {
0117           ++st;
0118         } else {
0119           ++gt;
0120         }
0121         ++num_iters;
0122       },
0123       1, toys);
0124 
0125   ACTS_INFO("Execution stats many: " << bin_utility_benchmark_many);
0126   ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0127 
0128   Acts::BinUtility equidistant(100, 0., 6., Acts::open,
0129                                Acts::AxisDirection::AxisX);
0130   st = 0;
0131   gt = 0;
0132   num_iters = 0;
0133   const auto bin_utility_benchmark_eq = microBenchmark(
0134       [&] {
0135         auto bin = (num_iters % 2) != 0u ? equidistant.bin(low)
0136                                          : equidistant.bin(high);
0137         if (bin < 49) {
0138           ++st;
0139         } else {
0140           ++gt;
0141         }
0142         ++num_iters;
0143       },
0144       1, toys);
0145 
0146   ACTS_INFO("Execution stats equidistant: " << bin_utility_benchmark_eq);
0147   ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0148 
0149   return 0;
0150 }