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 // Project include(s)
0010 #include "detray/core/detector.hpp"
0011 #include "detray/definitions/units.hpp"
0012 #include "detray/geometry/surface.hpp"
0013 #include "detray/navigation/detail/intersection_kernel.hpp"
0014 #include "detray/navigation/intersection/intersection_config.hpp"
0015 #include "detray/navigation/intersection/ray_intersector.hpp"
0016 #include "detray/tracks/ray.hpp"
0017 #include "detray/tracks/tracks.hpp"
0018 #include "detray/utils/logging.hpp"
0019 #include "detray/utils/ranges.hpp"
0020 
0021 // Detray test include(s)
0022 #include "detray/test/common/build_toy_detector.hpp"
0023 #include "detray/test/common/track_generators.hpp"
0024 
0025 // Detray benchmark include(s)
0026 #include "detray/benchmarks/types.hpp"
0027 
0028 // Vecmem include(s)
0029 #include <vecmem/memory/host_memory_resource.hpp>
0030 
0031 // Google Benchmark include(s)
0032 #include <benchmark/benchmark.h>
0033 
0034 // System include(s)
0035 #include <iostream>
0036 #include <map>
0037 #include <string>
0038 
0039 // Use the detray:: namespace implicitly.
0040 using namespace detray;
0041 
0042 using bench_algebra = benchmarks::algebra;
0043 
0044 using trk_generator_t =
0045     uniform_track_generator<free_track_parameters<bench_algebra>>;
0046 
0047 constexpr unsigned int theta_steps{100u};
0048 constexpr unsigned int phi_steps{100u};
0049 
0050 // This test runs intersection with all surfaces of the TrackML detector
0051 void BM_INTERSECT_ALL(benchmark::State &state) {
0052   // Detector configuration
0053   vecmem::host_memory_resource host_mr;
0054   toy_det_config<benchmarks::scalar> toy_cfg{};
0055   toy_cfg.n_edc_layers(7u);
0056   auto [d, names] = build_toy_detector<bench_algebra>(host_mr, toy_cfg);
0057 
0058   using detector_t = decltype(d);
0059   using scalar_t = dscalar<bench_algebra>;
0060   using sf_desc_t = typename detector_t::surface_type;
0061 
0062   detector_t::geometry_context geo_context;
0063 
0064   const auto &transforms = d.transform_store(geo_context);
0065 
0066   std::size_t hits{0u};
0067   std::size_t missed{0u};
0068   std::size_t n_surfaces{0u};
0069   benchmarks::point3 origin{0.f, 0.f, 0.f};
0070   std::vector<intersection2D<sf_desc_t, bench_algebra>> intersections{};
0071 
0072   // Iterate through uniformly distributed momentum directions
0073   auto trk_generator = trk_generator_t{};
0074   trk_generator.config()
0075       .theta_steps(theta_steps)
0076       .phi_steps(phi_steps)
0077       .origin(origin);
0078 
0079   // Intersector configuration
0080   intersection::config intr_cfg{.min_mask_tolerance = 1.f * unit<float>::um,
0081                                 .max_mask_tolerance = 1.f * unit<float>::mm};
0082   constexpr const scalar_t external_mask_tol{0.f};
0083 
0084   for (auto _ : state) {
0085     for (const auto track : trk_generator) {
0086       // Loop over all surfaces in detector
0087       for (const sf_desc_t &sf_desc : d.surfaces()) {
0088         const auto sf = geometry::surface{d, sf_desc};
0089         sf.template visit_mask<
0090             detail::intersection_initialize<ray_intersector>>(
0091             intersections, detail::ray(track), sf_desc, transforms, geo_context,
0092             intr_cfg, external_mask_tol);
0093 
0094         ++n_surfaces;
0095       }
0096       benchmark::DoNotOptimize(hits);
0097       benchmark::DoNotOptimize(missed);
0098 
0099       hits += intersections.size();
0100       missed += n_surfaces - intersections.size();
0101 
0102       n_surfaces = 0u;
0103       intersections.clear();
0104     }
0105   }
0106 
0107 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0108   DETRAY_INFO_HOST("[detray] hits / missed / total = "
0109                    << hits << " / " << missed << " / " << hits + missed);
0110 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0111 }
0112 
0113 BENCHMARK(BM_INTERSECT_ALL)
0114 #ifdef DETRAY_BENCHMARK_MULTITHREAD
0115     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0116 #endif
0117     ->Unit(benchmark::kMillisecond);