Skip to content

Commit

Permalink
fix: Solenoid B field benchmark goes out of bounds (#853)
Browse files Browse the repository at this point in the history
The solenoid B field benchmark goes out of bounds when subsequent positions along a straight line are tested. This fixes this by precomputing the positions only until they leave the interpolation volume, and running on these inputs.

This also revealed a bug that since the benchmark tools run the benchmark a number of times (500 here, I believe), but the starting position was not reset, the steps continued further and further outward. This should be fixed now as well.

The timing results do not seem to change substantially.
  • Loading branch information
paulgessinger committed Jun 24, 2021
1 parent 54dcb61 commit 7ff587b
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions Tests/Benchmarks/SolenoidFieldBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Acts/MagneticField/InterpolatedBFieldMap.hpp"
#include "Acts/MagneticField/SolenoidBField.hpp"
#include "Acts/Tests/CommonHelpers/BenchmarkTools.hpp"
#include "Acts/Utilities/Helpers.hpp"

#include <chrono>
#include <fstream>
Expand Down Expand Up @@ -152,35 +153,33 @@ int main(int argc, char* argv[]) {
Acts::Vector3 dir{};
dir.setRandom();
double h = 1e-3;
std::vector<Acts::Vector3> steps;
steps.reserve(iters_map);
for (size_t i = 0; i < iters_map; i++) {
pos += dir * h;
double z = pos[Acts::eFreePos2];
if (Acts::VectorHelpers::perp(pos) > rMax || z >= zMax || z < zMin) {
break;
}
steps.push_back(pos);
}
const auto map_adv_result = Acts::Test::microBenchmark(
[&] {
pos += dir * h;
return bFieldMap.getField(pos);
},
iters_map);
[&](const auto& s) { return bFieldMap.getField(s); }, steps);
std::cout << map_adv_result << std::endl;
csv("interp_nocache_adv", map_adv_result);
}

// - This variation of the fourth benchmark advances in a straight line, but
// also uses the cache infrastructure. As subsequent positions are close to
// one another, the cache will be valid for a certain number of points,
// before becoming invalid. This means we expect performance to improve over
// the uncached straight line advance.
{
// - This variation of the fourth benchmark advances in a straight line, but
// also uses the cache infrastructure. As subsequent positions are close
// to one another, the cache will be valid for a certain number of points,
// before becoming invalid. This means we expect performance to improve
// over the uncached straight line advance.

std::cout << "Benchmarking cached advancing interpolated field lookup: "
<< std::flush;
auto cache = bFieldMap.makeCache(mctx);
Acts::Vector3 pos{0, 0, 0};
Acts::Vector3 dir{};
dir.setRandom();
double h = 1e-3;
const auto map_adv_result_cache = Acts::Test::microBenchmark(
[&] {
pos += dir * h;
return bFieldMap.getField(pos, cache).value();
},
iters_map);
[&](const auto& s) { return bFieldMap.getField(s, cache).value(); },
steps);
std::cout << map_adv_result_cache << std::endl;
csv("interp_cache_adv", map_adv_result_cache);
}
Expand Down

0 comments on commit 7ff587b

Please sign in to comment.