Back to home page

EIC code displayed by LXR

 
 

    


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

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/definitions/pdg_particle.hpp"
0011 #include "detray/definitions/units.hpp"
0012 #include "detray/navigation/caching_navigator.hpp"
0013 #include "detray/propagator/actors.hpp"
0014 #include "detray/propagator/propagator.hpp"
0015 #include "detray/propagator/rk_stepper.hpp"
0016 #include "detray/tracks/tracks.hpp"
0017 #include "detray/utils/logging.hpp"
0018 
0019 // Detray test include(s)
0020 #include "detray/test/common/bfield.hpp"
0021 #include "detray/test/common/build_toy_detector.hpp"
0022 #include "detray/test/common/track_generators.hpp"
0023 
0024 // Example linear algebra plugin: std::array
0025 #include "detray/tutorial/types.hpp"
0026 
0027 // Vecmem include(s)
0028 #include <vecmem/memory/host_memory_resource.hpp>
0029 
0030 // System include(s)
0031 #include <sstream>
0032 
0033 /// Run the host-propagation
0034 int main() {
0035   // Toy detector
0036   using metadata_t = detray::tutorial::toy_metadata;
0037   using toy_detector_t = detray::detector<metadata_t>;
0038 
0039   using algebra_t = metadata_t::algebra_type;
0040   using scalar = detray::tutorial::scalar;
0041 
0042   // Navigation
0043   using navigator_t = detray::caching_navigator<toy_detector_t>;
0044   // Runge-Kutta-Nystrom stepper (field integration)
0045   using bfield_t = covfie::field<detray::bfield::const_bknd_t<scalar>>;
0046   using stepper_t = detray::rk_stepper<bfield_t::view_t, algebra_t>;
0047 
0048   // Actors
0049   using actor_chain_t = detray::actor_chain<
0050       detray::actor::pathlimit_aborter<scalar>,
0051       detray::actor::parameter_updater<
0052           algebra_t, detray::actor::pointwise_material_interactor<algebra_t>>>;
0053 
0054   // Propagator with empty actor chain
0055   using propagator_t =
0056       detray::propagator<stepper_t, navigator_t, actor_chain_t>;
0057 
0058   vecmem::host_memory_resource host_mr;
0059 
0060   std::clog << "Propagation Tutorial\n====================\n\n";
0061   std::clog << "Building toy detector:\n" << std::endl;
0062 
0063   const auto [det, _] = detray::build_toy_detector<algebra_t>(host_mr);
0064 
0065   typename toy_detector_t::geometry_context gctx{};
0066 
0067   // Create the bfield
0068   detray::tutorial::vector3 B{0.f, 0.f, 2.f * detray::unit<scalar>::T};
0069   const bfield_t bfield = detray::create_const_field<scalar>(B);
0070   const bfield_t::view_t bfield_view(bfield);
0071 
0072   // Build the propagator
0073   detray::propagation::config prop_cfg{};
0074   // Particle hypothesis (default: muon)
0075   constexpr auto ptc = detray::muon<scalar>{};
0076 
0077   propagator_t prop{prop_cfg};
0078 
0079   // Track generation config
0080   using track_t = detray::free_track_parameters<algebra_t>;
0081   using track_generator_t = detray::random_track_generator<track_t>;
0082 
0083   track_generator_t::configuration trck_cfg{};
0084   trck_cfg.n_tracks(1000);
0085   trck_cfg.eta_range(-3.f, 3.f);
0086   trck_cfg.pT_range(1.f * detray::unit<scalar>::GeV,
0087                     100.f * detray::unit<scalar>::GeV);
0088 
0089   std::clog << prop_cfg;
0090   std::clog << trck_cfg << std::endl;
0091 
0092   // Iterate through uniformly distributed momentum directions
0093   bool success{true};
0094   prop_cfg.context = gctx;
0095   for (auto track : track_generator_t{trck_cfg}) {
0096     propagator_t::state propagation(track, bfield_view, det, prop_cfg.context);
0097 
0098     propagation.set_particle(detray::update_particle_hypothesis(ptc, track));
0099 
0100     // Prepare actor states
0101     detray::actor::pathlimit_aborter<scalar>::state aborter_state{
0102         5.f * detray::unit<scalar>::m};
0103     detray::actor::parameter_updater_state<algebra_t> updater_state{prop_cfg};
0104     detray::actor::pointwise_material_interactor<algebra_t>::state
0105         interactor_state{};
0106 
0107     auto actor_states =
0108         detray::tie(aborter_state, updater_state, interactor_state);
0109 
0110     // Run the actual propagation
0111     prop.propagate(propagation, actor_states);
0112     success = success && prop.finished(propagation);
0113   }
0114 
0115   if (success) {
0116     DETRAY_INFO_HOST("Successfully propagated " << trck_cfg.n_tracks()
0117                                                 << " tracks!");
0118   } else {
0119     DETRAY_ERROR_HOST("Propagation did not complete successfully!");
0120   }
0121 }