Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:11

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 // TODO: Remove this when gcc fixes their false positives.
0010 #if defined(__GNUC__) && !defined(__clang__)
0011 #pragma GCC diagnostic warning "-Wmaybe-uninitialized"
0012 #endif
0013 
0014 // Detray core include(s).
0015 #include "detray/definitions/indexing.hpp"
0016 #include "detray/geometry/mask.hpp"
0017 #include "detray/geometry/shapes.hpp"
0018 #include "detray/navigation/intersection/intersection.hpp"
0019 #include "detray/utils/logging.hpp"
0020 
0021 // Detray benchmark include(s)
0022 #include "detray/benchmarks/types.hpp"
0023 
0024 // Google benchmark include(s).
0025 #include <benchmark/benchmark.h>
0026 
0027 // System include(s).
0028 #include <iostream>
0029 
0030 // Use the detray:: namespace implicitly.
0031 using namespace detray;
0032 
0033 using bench_algebra = benchmarks::algebra;
0034 using point3 = benchmarks::point3;
0035 using scalar = benchmarks::scalar;
0036 
0037 static constexpr unsigned int steps_x3{1000u};
0038 static constexpr unsigned int steps_y3{1000u};
0039 static constexpr unsigned int steps_z3{1000u};
0040 
0041 static const benchmarks::transform3 trf{};
0042 
0043 // Tolerance applied to the mask
0044 static constexpr scalar tol{0.f};
0045 
0046 // This runs a benchmark on a rectangle2D mask
0047 void BM_MASK_CUBOID_3D(benchmark::State &state) {
0048   using mask_type = mask<cuboid3D, bench_algebra>;
0049   constexpr mask_type cb(0u, 0.f, 0.f, 0.f, 3.f, 4.f, 1.f);
0050 
0051   constexpr scalar world{10.f};
0052 
0053   constexpr scalar sx{world / steps_x3};
0054   constexpr scalar sy{world / steps_y3};
0055   constexpr scalar sz{world / steps_z3};
0056 
0057   unsigned long inside = 0u;
0058   unsigned long outside = 0u;
0059 
0060   for (auto _ : state) {
0061     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0062       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0063       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0064         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0065         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0066           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0067 
0068           benchmark::DoNotOptimize(inside);
0069           benchmark::DoNotOptimize(outside);
0070           if (cb.is_inside(trf, point3{x, y, z}, tol)) {
0071             ++inside;
0072           } else {
0073             ++outside;
0074           }
0075         }
0076       }
0077     }
0078   }
0079 
0080 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0081   constexpr scalar volume{cb[3] * cb[4] * cb[5]};
0082   constexpr scalar rest{world * world * world - volume};
0083   DETRAY_INFO_HOST("Cuboid : Inside/outside ... "
0084                    << inside << " / " << outside << " = "
0085                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0086                    << " (theoretical = " << volume / rest << ") ");
0087 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0088 }
0089 
0090 BENCHMARK(BM_MASK_CUBOID_3D)
0091 #ifdef DETRAY_BENCHMARK_MULTITHREAD
0092     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0093 #endif
0094     ->Unit(benchmark::kMillisecond);
0095 
0096 // This runs a benchmark on a rectangle2D mask
0097 void BM_MASK_RECTANGLE_2D(benchmark::State &state) {
0098   using mask_type = mask<rectangle2D, bench_algebra>;
0099   constexpr mask_type r(0u, 3.f, 4.f);
0100 
0101   constexpr scalar world{10.f};
0102 
0103   constexpr scalar sx{world / steps_x3};
0104   constexpr scalar sy{world / steps_y3};
0105   constexpr scalar sz{world / steps_z3};
0106 
0107   unsigned long inside = 0u;
0108   unsigned long outside = 0u;
0109 
0110   for (auto _ : state) {
0111     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0112       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0113       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0114         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0115         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0116           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0117 
0118           benchmark::DoNotOptimize(inside);
0119           benchmark::DoNotOptimize(outside);
0120           if (r.is_inside(trf, point3{x, y, z}, tol)) {
0121             ++inside;
0122           } else {
0123             ++outside;
0124           }
0125         }
0126       }
0127     }
0128   }
0129 
0130 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0131   constexpr scalar area{4.f * r[0] * r[1]};
0132   constexpr scalar rest{world * world - area};
0133   DETRAY_INFO_HOST("Rectangle : Inside/outside ... "
0134                    << inside << " / " << outside << " = "
0135                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0136                    << " (theoretical = " << area / rest << ") ");
0137 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0138 }
0139 
0140 BENCHMARK(BM_MASK_RECTANGLE_2D)
0141 #ifdef DETRAY_BENCHMARK_MULTITHREAD
0142     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0143 #endif
0144     ->Unit(benchmark::kMillisecond);
0145 
0146 // This runs a benchmark on a trapezoid2D mask
0147 void BM_MASK_TRAPEZOID_2D(benchmark::State &state) {
0148   using mask_type = mask<trapezoid2D, bench_algebra>;
0149   constexpr mask_type t{0u, 2.f, 3.f, 4.f, 1.f / (2.f * 4.f)};
0150 
0151   constexpr scalar world{10.f};
0152 
0153   constexpr scalar sx{world / steps_x3};
0154   constexpr scalar sy{world / steps_y3};
0155   constexpr scalar sz{world / steps_z3};
0156 
0157   unsigned long inside = 0u;
0158   unsigned long outside = 0u;
0159 
0160   for (auto _ : state) {
0161     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0162       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0163       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0164         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0165         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0166           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0167 
0168           benchmark::DoNotOptimize(inside);
0169           benchmark::DoNotOptimize(outside);
0170           if (t.is_inside(trf, point3{x, y, z}, tol)) {
0171             ++inside;
0172           } else {
0173             ++outside;
0174           }
0175         }
0176       }
0177     }
0178   }
0179 
0180 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0181   constexpr scalar area{2.f * (t[0] + t[1]) * t[2]};
0182   constexpr scalar rest{world * world - area};
0183   DETRAY_INFO_HOST("Trapezoid : Inside/outside ..."
0184                    << inside << " / " << outside << " = "
0185                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0186                    << " (theoretical = " << area / rest << ") ");
0187 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0188 }
0189 
0190 BENCHMARK(BM_MASK_TRAPEZOID_2D)
0191 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0192     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0193 #endif
0194     ->Unit(benchmark::kMillisecond);
0195 
0196 // This runs a benchmark on a ring2D mask (as disc)
0197 void BM_MASK_DISC_2D(benchmark::State &state) {
0198   using mask_type = mask<ring2D, bench_algebra>;
0199   constexpr mask_type r{0u, 0.f, 5.f};
0200 
0201   constexpr scalar world{10.f};
0202 
0203   constexpr scalar sx{world / steps_x3};
0204   constexpr scalar sy{world / steps_y3};
0205   constexpr scalar sz{world / steps_z3};
0206 
0207   unsigned long inside = 0u;
0208   unsigned long outside = 0u;
0209 
0210   for (auto _ : state) {
0211     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0212       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0213       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0214         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0215         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0216           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0217 
0218           benchmark::DoNotOptimize(inside);
0219           benchmark::DoNotOptimize(outside);
0220           if (r.is_inside(trf, point3{x, y, z}, tol)) {
0221             ++inside;
0222           } else {
0223             ++outside;
0224           }
0225         }
0226       }
0227     }
0228   }
0229 
0230 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0231   constexpr scalar area{r[1] * r[1] * constant<scalar>::pi};
0232   constexpr scalar rest{world * world - area};
0233   DETRAY_INFO_HOST("Disc : Inside/outside ..."
0234                    << inside << " / " << outside << " = "
0235                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0236                    << " (theoretical = " << area / rest << ") ");
0237 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0238 }
0239 
0240 BENCHMARK(BM_MASK_DISC_2D)
0241 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0242     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0243 #endif
0244     ->Unit(benchmark::kMillisecond);
0245 
0246 // This runs a benchmark on a ring2D mask
0247 void BM_MASK_RING_2D(benchmark::State &state) {
0248   using mask_type = mask<ring2D, bench_algebra>;
0249   constexpr mask_type r{0u, 2.f, 5.f};
0250 
0251   constexpr scalar world{10.f};
0252 
0253   constexpr scalar sx{world / steps_x3};
0254   constexpr scalar sy{world / steps_y3};
0255   constexpr scalar sz{world / steps_z3};
0256 
0257   unsigned long inside = 0u;
0258   unsigned long outside = 0u;
0259 
0260   for (auto _ : state) {
0261     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0262       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0263       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0264         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0265         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0266           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0267 
0268           benchmark::DoNotOptimize(inside);
0269           benchmark::DoNotOptimize(outside);
0270           if (r.is_inside(trf, point3{x, y, z}, tol)) {
0271             ++inside;
0272           } else {
0273             ++outside;
0274           }
0275         }
0276       }
0277     }
0278   }
0279 
0280 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0281   constexpr scalar area{(r[1] * r[1] - r[0] * r[0]) * constant<scalar>::pi};
0282   constexpr scalar rest{world * world - area};
0283   DETRAY_INFO_HOST("Ring : Inside/outside ..."
0284                    << inside << " / " << outside << " = "
0285                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0286                    << " (theoretical = " << area / rest << ") ");
0287 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0288 }
0289 
0290 BENCHMARK(BM_MASK_RING_2D)
0291 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0292     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0293 #endif
0294     ->Unit(benchmark::kMillisecond);
0295 
0296 // This runs a benchmark on a cylinder2D mask
0297 void BM_MASK_CYLINDER_3D(benchmark::State &state) {
0298   using mask_type = mask<cylinder3D, bench_algebra>;
0299   constexpr mask_type c{
0300       0u, 1.f, -constant<scalar>::pi, 0.f, 3.f, constant<scalar>::pi, 5.f};
0301 
0302   constexpr scalar world{10.f};
0303 
0304   constexpr scalar sx{world / steps_x3};
0305   constexpr scalar sy{world / steps_y3};
0306   constexpr scalar sz{world / steps_z3};
0307 
0308   unsigned long inside = 0u;
0309   unsigned long outside = 0u;
0310 
0311   for (auto _ : state) {
0312     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0313       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0314       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0315         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0316         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0317           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0318 
0319           benchmark::DoNotOptimize(inside);
0320           benchmark::DoNotOptimize(outside);
0321           if (c.is_inside(trf, point3{x, y, z}, tol)) {
0322             ++inside;
0323           } else {
0324             ++outside;
0325           }
0326         }
0327       }
0328     }
0329   }
0330 
0331 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0332   constexpr scalar volume{constant<scalar>::pi * (c[5] - c[2]) *
0333                           (c[3] * c[3] - c[0] * c[0])};
0334   constexpr scalar rest{world * world * world - volume};
0335   DETRAY_INFO_HOST("Cylinder 3D : Inside/outside ... "
0336                    << inside << " / " << outside << " = "
0337                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0338                    << " (theoretical = " << volume / rest << ") ");
0339 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0340 }
0341 
0342 BENCHMARK(BM_MASK_CYLINDER_3D)
0343 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0344     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0345 #endif
0346     ->Unit(benchmark::kMillisecond);
0347 
0348 // This runs a benchmark on a cylinder2D mask
0349 void BM_MASK_CYLINDER_2D(benchmark::State &state) {
0350   using mask_type = mask<cylinder2D, bench_algebra>;
0351   constexpr mask_type c{0u, 3.f, 0.f, 5.f};
0352 
0353   constexpr scalar world{10.f};
0354 
0355   constexpr scalar sx{world / steps_x3};
0356   constexpr scalar sy{world / steps_y3};
0357   constexpr scalar sz{world / steps_z3};
0358 
0359   unsigned long inside = 0u;
0360   unsigned long outside = 0u;
0361 
0362   for (auto _ : state) {
0363     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0364       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0365       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0366         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0367         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0368           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0369 
0370           benchmark::DoNotOptimize(inside);
0371           benchmark::DoNotOptimize(outside);
0372           if (c.is_inside(trf, point3{x, y, z}, tol)) {
0373             ++inside;
0374           } else {
0375             ++outside;
0376           }
0377         }
0378       }
0379     }
0380   }
0381 
0382 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0383   DETRAY_INFO_HOST("Cylinder 2D : Inside/outside ..."
0384                    << inside << " / " << outside << " = "
0385                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0386                    << " (theoretical = " << 1.f << ") ");
0387 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0388 }
0389 
0390 BENCHMARK(BM_MASK_CYLINDER_2D)
0391 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0392     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0393 #endif
0394     ->Unit(benchmark::kMillisecond);
0395 
0396 // This runs a benchmark on a cylinder2D mask
0397 void BM_MASK_CONCENTRIC_CYLINDER_2D(benchmark::State &state) {
0398   using mask_type = mask<concentric_cylinder2D, bench_algebra>;
0399   constexpr mask_type c{0u, 3.f, 0.f, 5.f};
0400 
0401   constexpr scalar world{10.f};
0402 
0403   constexpr scalar sx{world / steps_x3};
0404   constexpr scalar sy{world / steps_y3};
0405   constexpr scalar sz{world / steps_z3};
0406 
0407   unsigned long inside = 0u;
0408   unsigned long outside = 0u;
0409 
0410   for (auto _ : state) {
0411     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0412       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0413       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0414         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0415         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0416           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0417 
0418           benchmark::DoNotOptimize(inside);
0419           benchmark::DoNotOptimize(outside);
0420           if (c.is_inside(trf, point3{x, y, z}, tol)) {
0421             ++inside;
0422           } else {
0423             ++outside;
0424           }
0425         }
0426       }
0427     }
0428   }
0429 
0430 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0431   DETRAY_INFO_HOST("Concnetric Cylinder : Inside/outside ..."
0432                    << inside << " / " << outside << " = "
0433                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0434                    << " (theoretical = " << 1.f << ") ");
0435 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0436 }
0437 
0438 BENCHMARK(BM_MASK_CONCENTRIC_CYLINDER_2D)
0439 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0440     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0441 #endif
0442     ->Unit(benchmark::kMillisecond);
0443 
0444 // This runs a benchmark on an annulus2D mask
0445 void BM_MASK_ANNULUS_2D(benchmark::State &state) {
0446   using mask_type = mask<annulus2D, bench_algebra>;
0447   constexpr mask_type ann{0u, 2.5f, 5.f, -0.64299f, 4.13173f, 1.f, 0.5f, 0.f};
0448 
0449   constexpr scalar world{10.f};
0450 
0451   constexpr scalar sx{world / steps_x3};
0452   constexpr scalar sy{world / steps_y3};
0453   constexpr scalar sz{world / steps_z3};
0454 
0455   unsigned long inside = 0u;
0456   unsigned long outside = 0u;
0457 
0458   for (auto _ : state) {
0459     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0460       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0461       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0462         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0463         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0464           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0465 
0466           benchmark::DoNotOptimize(inside);
0467           benchmark::DoNotOptimize(outside);
0468           if (ann.is_inside(trf, point3{x, y, z}, tol)) {
0469             ++inside;
0470           } else {
0471             ++outside;
0472           }
0473         }
0474       }
0475     }
0476   }
0477 
0478 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0479   DETRAY_INFO_HOST("Annulus : Inside/outside ..."
0480                    << inside << " / " << outside << " = "
0481                    << static_cast<scalar>(inside) /
0482                           static_cast<scalar>(outside));
0483 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0484 }
0485 
0486 BENCHMARK(BM_MASK_ANNULUS_2D)
0487 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0488     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0489 #endif
0490     ->Unit(benchmark::kMillisecond);
0491 
0492 // This runs a benchmark on a straw tube mask
0493 void BM_MASK_LINE_CIRCULAR(benchmark::State &state) {
0494   using mask_type = mask<line_circular, bench_algebra>;
0495   constexpr mask_type st{0u, 3.f, 5.f};
0496 
0497   constexpr scalar world{10.f};
0498 
0499   constexpr scalar sx{world / steps_x3};
0500   constexpr scalar sy{world / steps_y3};
0501   constexpr scalar sz{world / steps_z3};
0502 
0503   unsigned long inside = 0u;
0504   unsigned long outside = 0u;
0505 
0506   for (auto _ : state) {
0507     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0508       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0509       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0510         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0511         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0512           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0513 
0514           benchmark::DoNotOptimize(inside);
0515           benchmark::DoNotOptimize(outside);
0516           if (st.is_inside(trf, point3{x, y, z}, tol)) {
0517             ++inside;
0518           } else {
0519             ++outside;
0520           }
0521         }
0522       }
0523     }
0524   }
0525 
0526 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0527   constexpr scalar volume{constant<scalar>::pi * 2.f * st[1] * st[0] * st[0]};
0528   constexpr scalar rest{world * world * world - volume};
0529   DETRAY_INFO_HOST("Straw Tube : Inside/outside ... "
0530                    << inside << " / " << outside << " = "
0531                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0532                    << " (theoretical = " << volume / rest << ") ");
0533 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0534 }
0535 
0536 BENCHMARK(BM_MASK_LINE_CIRCULAR)
0537 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0538     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0539 #endif
0540     ->Unit(benchmark::kMillisecond);
0541 
0542 // This runs a benchmark on a wire cell mask
0543 void BM_MASK_LINE_SQUARE(benchmark::State &state) {
0544   using mask_type = mask<line_square, bench_algebra>;
0545   constexpr mask_type dcl{0u, 3.f, 5.f};
0546 
0547   constexpr scalar world{10.f};
0548 
0549   constexpr scalar sx{world / steps_x3};
0550   constexpr scalar sy{world / steps_y3};
0551   constexpr scalar sz{world / steps_z3};
0552 
0553   unsigned long inside = 0u;
0554   unsigned long outside = 0u;
0555 
0556   for (auto _ : state) {
0557     for (unsigned int ix = 0u; ix < steps_x3; ++ix) {
0558       scalar x{-0.5f * world + static_cast<scalar>(ix) * sx};
0559       for (unsigned int iy = 0u; iy < steps_y3; ++iy) {
0560         scalar y{-0.5f * world + static_cast<scalar>(iy) * sy};
0561         for (unsigned int iz = 0u; iz < steps_z3; ++iz) {
0562           scalar z{-0.5f * world + static_cast<scalar>(iz) * sz};
0563 
0564           benchmark::DoNotOptimize(inside);
0565           benchmark::DoNotOptimize(outside);
0566           if (dcl.is_inside(trf, point3{x, y, z}, tol)) {
0567             ++inside;
0568           } else {
0569             ++outside;
0570           }
0571         }
0572       }
0573     }
0574   }
0575 
0576 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0577   constexpr scalar volume{8.f * dcl[1] * dcl[0] * dcl[0]};
0578   constexpr scalar rest{world * world * world - volume};
0579   DETRAY_INFO_HOST("Drift Chamber Cell : Inside/outside ... "
0580                    << inside << " / " << outside << " = "
0581                    << static_cast<scalar>(inside) / static_cast<scalar>(outside)
0582                    << " (theoretical = " << volume / rest << ") ");
0583 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0584 }
0585 
0586 BENCHMARK(BM_MASK_LINE_SQUARE)
0587 #ifdef DETRAY_BENCHMARKS_MULTITHREAD
0588     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0589 #endif
0590     ->Unit(benchmark::kMillisecond);