22 #include <boost/program_options.hpp>
23 #include <boost/progress.hpp>
32 namespace po = boost::program_options;
37 template <
typename field_t,
typename field_context_t>
39 size_t events,
size_t theta_steps,
double theta_0,
40 double theta_step,
size_t phi_steps,
double phi_0,
41 double phi_step,
size_t access_steps,
double access_step) {
42 std::cout <<
"[>>>] Start: step-wise access pattern ... " << std::endl;
43 size_t mismatched = 0;
45 typename field_t::Cache bCache(bFieldContext);
47 size_t totalSteps = events * theta_steps * phi_steps * access_steps;
48 boost::progress_display show_progress(totalSteps);
51 for (
size_t ievt = 0; ievt < events; ++ievt) {
52 for (
size_t itheta = 0; itheta < theta_steps; ++itheta) {
53 double theta = theta_0 + itheta * theta_step;
54 for (
size_t iphi = 0; iphi < phi_steps; ++iphi) {
55 double phi = phi_0 + iphi * phi_step;
60 double currentStep = 0.;
62 for (
size_t istep = 0; istep < access_steps; ++istep) {
65 auto field_direct = bField.getField(position);
67 auto field_from_cache = bField.getField(position, bCache);
69 if (!field_direct.isApprox(field_from_cache)) {
73 currentStep += access_step;
79 std::cout <<
"[<<<] End result : " << mismatched <<
"/" << totalSteps
80 <<
" mismatches" << std::endl;
84 template <
typename field_t,
typename field_context_t>
86 size_t totalSteps,
double radius) {
87 std::cout <<
"[>>>] Start: random access pattern ... " << std::endl;
88 size_t mismatched = 0;
95 typename field_t::Cache bCache(bFieldContext);
96 boost::progress_display show_progress(totalSteps);
100 for (
size_t istep = 0; istep < totalSteps; ++istep) {
103 auto field_direct = bField.getField(position);
105 auto field_from_cache = bField.getField(position, bCache);
107 if (!field_direct.isApprox(field_from_cache)) {
113 std::cout <<
"[<<<] End result : " << mismatched <<
"/" << totalSteps
114 <<
" mismatches" << std::endl;
121 int main(
int argc,
char* argv[]) {
126 desc.add_options()(
"bf-phi-range",
127 po::value<read_range>()->default_value({-
M_PI,
M_PI}),
128 "range in which the phi parameter is generated.")(
129 "bf-theta-range", po::value<read_range>()->default_value({0.,
M_PI}),
130 "range in which the eta parameter is generated.")(
131 "bf-phisteps", po::value<size_t>()->default_value(1000),
132 "number of steps for the phi parameter.")(
133 "bf-thetasteps", po::value<size_t>()->default_value(100),
134 "number of steps for the eta parameter.")(
135 "bf-accesssteps", po::value<size_t>()->default_value(100),
136 "number of steps for magnetic field access.")(
137 "bf-tracklength", po::value<double>()->default_value(100.),
138 "track length in [mm] magnetic field access.");
155 auto phir = vm[
"bf-phi-range"].as<
read_range>();
156 auto thetar = vm[
"bf-theta-range"].as<
read_range>();
158 size_t phi_steps = vm[
"bf-phisteps"].as<
size_t>();
159 size_t theta_steps = vm[
"bf-thetasteps"].as<
size_t>();
161 size_t access_steps = vm[
"bf-accesssteps"].as<
size_t>();
162 double track_length =
165 std::sort(phir.begin(), phir.end());
166 std::sort(thetar.begin(), thetar.end());
167 double phi_span =
std::abs(phir[1] - phir[0]);
168 double phi_step = phi_span / phi_steps;
169 double theta_span =
std::abs(thetar[1] - thetar[0]);
170 double theta_step = theta_span / theta_steps;
171 double access_step = track_length / access_steps;
174 [&](
auto&
bField) ->
int {
176 typename std::decay_t<decltype(bField)>::element_type;
177 if constexpr (!std::is_same_v<field_type, InterpolatedBFieldMap2D> &&
178 !std::is_same_v<field_type, InterpolatedBFieldMap3D>) {
179 std::cout <<
"Bfield map could not be read. Exiting." << std::endl;
184 thetar[0], theta_step, phi_steps, phir[0], phi_step,
185 access_steps, access_step);
188 nEvents * theta_steps * phi_steps * access_steps,