9 #include <boost/program_options.hpp>
10 #include <boost/progress.hpp>
31 namespace po = boost::program_options;
36 template <
typename field_t,
typename field_context_t>
38 size_t events,
size_t theta_steps,
double theta_0,
39 double theta_step,
size_t phi_steps,
double phi_0,
40 double phi_step,
size_t access_steps,
double access_step) {
41 std::cout <<
"[>>>] Start: step-wise access pattern ... " << std::endl;
42 size_t mismatched = 0;
44 typename field_t::Cache bCache(bFieldContext);
46 size_t totalSteps = events * theta_steps * phi_steps * access_steps;
47 boost::progress_display show_progress(totalSteps);
50 for (
size_t ievt = 0; ievt < events; ++ievt) {
51 for (
size_t itheta = 0; itheta < theta_steps; ++itheta) {
52 double theta = theta_0 + itheta * theta_step;
53 for (
size_t iphi = 0; iphi < phi_steps; ++iphi) {
54 double phi = phi_0 + iphi * phi_step;
59 double currentStep = 0.;
61 for (
size_t istep = 0; istep < access_steps; ++istep) {
64 auto field_direct = bField.getField(position);
66 auto field_from_cache = bField.getField(position, bCache);
68 if (!field_direct.isApprox(field_from_cache)) {
72 currentStep += access_step;
78 std::cout <<
"[<<<] End result : " << mismatched <<
"/" << totalSteps
79 <<
" mismatches" << std::endl;
83 template <
typename field_t,
typename field_context_t>
85 size_t totalSteps,
double radius) {
86 std::cout <<
"[>>>] Start: random access pattern ... " << std::endl;
87 size_t mismatched = 0;
94 typename field_t::Cache bCache(bFieldContext);
95 boost::progress_display show_progress(totalSteps);
99 for (
size_t istep = 0; istep < totalSteps; ++istep) {
102 auto field_direct = bField.getField(position);
104 auto field_from_cache = bField.getField(position, bCache);
106 if (!field_direct.isApprox(field_from_cache)) {
112 std::cout <<
"[<<<] End result : " << mismatched <<
"/" << totalSteps
113 <<
" mismatches" << std::endl;
120 int main(
int argc,
char* argv[]) {
125 desc.add_options()(
"bf-phi-range",
126 po::value<read_range>()->default_value({-
M_PI,
M_PI}),
127 "range in which the phi parameter is generated.")(
128 "bf-theta-range", po::value<read_range>()->default_value({0.,
M_PI}),
129 "range in which the eta parameter is generated.")(
130 "bf-phisteps", po::value<size_t>()->default_value(1000),
131 "number of steps for the phi parameter.")(
132 "bf-thetasteps", po::value<size_t>()->default_value(100),
133 "number of steps for the eta parameter.")(
134 "bf-accesssteps", po::value<size_t>()->default_value(100),
135 "number of steps for magnetic field access.")(
136 "bf-tracklength", po::value<double>()->default_value(100.),
137 "track length in [mm] magnetic field access.");
154 auto phir = vm[
"bf-phi-range"].as<
read_range>();
155 auto thetar = vm[
"bf-theta-range"].as<
read_range>();
157 size_t phi_steps = vm[
"bf-phisteps"].as<
size_t>();
158 size_t theta_steps = vm[
"bf-thetasteps"].as<
size_t>();
160 size_t access_steps = vm[
"bf-accesssteps"].as<
size_t>();
163 std::sort(phir.begin(), phir.end());
164 std::sort(thetar.begin(), thetar.end());
165 double phi_span =
std::abs(phir[1] - phir[0]);
166 double phi_step = phi_span / phi_steps;
167 double theta_span =
std::abs(thetar[1] - thetar[0]);
168 double theta_step = theta_span / theta_steps;
169 double access_step = track_length / access_steps;
172 [&](
auto&
bField) ->
int {
174 typename std::decay_t<decltype(bField)>::element_type;
175 if constexpr (!std::is_same_v<field_type, InterpolatedBFieldMap2D> &&
176 !std::is_same_v<field_type, InterpolatedBFieldMap3D>) {
177 std::cout <<
"Bfield map could not be read. Exiting." << std::endl;
182 thetar[0], theta_step, phi_steps, phir[0], phi_step,
183 access_steps, access_step);
186 nEvents * theta_steps * phi_steps * access_steps,