Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinUtilityBenchmark.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinUtilityBenchmark.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 
12 
13 #include <algorithm>
14 #include <vector>
15 
16 #include <boost/program_options.hpp>
17 
18 namespace po = boost::program_options;
19 using namespace Acts;
20 
21 int main(int argc, char* argv[]) {
22  unsigned int lvl = Acts::Logging::INFO;
23  unsigned int toys = 1;
24 
25  try {
26  po::options_description desc("Allowed options");
27  // clang-format off
28  desc.add_options()
29  ("help", "produce help message")
30  ("toys",po::value<unsigned int>(&toys)->default_value(100000000),"number searches to be done")
31  ("verbose",po::value<unsigned int>(&lvl)->default_value(Acts::Logging::INFO),"logging level");
32  // clang-format on
33  po::variables_map vm;
34  po::store(po::parse_command_line(argc, argv, desc), vm);
35  po::notify(vm);
36 
37  if (vm.count("help") != 0u) {
38  std::cout << desc << std::endl;
39  return 0;
40  }
41  } catch (std::exception& e) {
42  std::cerr << "error: " << e.what() << std::endl;
43  return 1;
44  }
45 
47 
48  std::vector<float> fewBins;
49  fewBins.reserve(6);
50  for (unsigned int ib = 0; ib < 6; ++ib) {
51  fewBins.push_back(ib * 6. / 5.);
52  }
54 
55  std::vector<float> mediumBins;
56  mediumBins.reserve(21);
57  for (unsigned int ib = 0; ib < 21; ++ib) {
58  mediumBins.push_back(ib * 6. / 20.);
59  }
60  Acts::BinUtility medium(mediumBins, Acts::open, Acts::binX);
61 
62  std::vector<float> manyBins;
63  manyBins.reserve(101);
64  for (unsigned int ib = 0; ib < 101; ++ib) {
65  manyBins.push_back(ib * 6. / 100.);
66  }
67 
68  Acts::BinUtility many(manyBins, Acts::open, Acts::binX);
69 
70  Acts::Vector3 low = Acts::Vector3(1.5, 0., 0.);
71  Acts::Vector3 high = Acts::Vector3(4.5, 0., 0.);
72 
73  size_t st = 0;
74  size_t gt = 0;
75  size_t num_iters = 0;
76  const auto bin_utility_benchmark_small = Acts::Test::microBenchmark(
77  [&] {
78  auto bin = (num_iters % 2) != 0u ? small.bin(low) : small.bin(high);
79  if (bin < 3) {
80  ++st;
81  } else {
82  ++gt;
83  }
84  ++num_iters;
85  },
86  1, toys);
87 
88  ACTS_INFO("Execution stats small: " << bin_utility_benchmark_small);
89  ACTS_INFO("Fraction is: " << st << " vs. " << gt);
90 
91  st = 0;
92  gt = 0;
93  num_iters = 0;
94  const auto bin_utility_benchmark_medium = Acts::Test::microBenchmark(
95  [&] {
96  auto bin = (num_iters % 2) != 0u ? medium.bin(low) : medium.bin(high);
97  if (bin < 10) {
98  ++st;
99  } else {
100  ++gt;
101  }
102  ++num_iters;
103  },
104  1, toys);
105 
106  ACTS_INFO("Execution stats medium: " << bin_utility_benchmark_medium);
107  ACTS_INFO("Fraction is: " << st << " vs. " << gt);
108 
109  st = 0;
110  gt = 0;
111  num_iters = 0;
112  const auto bin_utility_benchmark_many = Acts::Test::microBenchmark(
113  [&] {
114  auto bin = (num_iters % 2) != 0u ? many.bin(low) : many.bin(high);
115  if (bin < 49) {
116  ++st;
117  } else {
118  ++gt;
119  }
120  ++num_iters;
121  },
122  1, toys);
123 
124  ACTS_INFO("Execution stats many: " << bin_utility_benchmark_many);
125  ACTS_INFO("Fraction is: " << st << " vs. " << gt);
126 
128  st = 0;
129  gt = 0;
130  num_iters = 0;
131  const auto bin_utility_benchmark_eq = Acts::Test::microBenchmark(
132  [&] {
133  auto bin = (num_iters % 2) != 0u ? equidistant.bin(low)
134  : equidistant.bin(high);
135  if (bin < 49) {
136  ++st;
137  } else {
138  ++gt;
139  }
140  ++num_iters;
141  },
142  1, toys);
143 
144  ACTS_INFO("Execution stats equidistant: " << bin_utility_benchmark_eq);
145  ACTS_INFO("Fraction is: " << st << " vs. " << gt);
146 
147  return 0;
148 }