diff --git a/core/include/traccc/finding/finding_algorithm.hpp b/core/include/traccc/finding/finding_algorithm.hpp index ab77b0d770..1633ec037b 100644 --- a/core/include/traccc/finding/finding_algorithm.hpp +++ b/core/include/traccc/finding/finding_algorithm.hpp @@ -39,6 +39,7 @@ template class finding_algorithm : public algorithm { @@ -72,6 +73,8 @@ class finding_algorithm using interactor_type = detray::pointwise_material_interactor; + using bfield_type = typename stepper_t::magnetic_field_type; + public: /// Configuration type using config_type = finding_config; @@ -91,7 +94,7 @@ class finding_algorithm /// @param measurements Input measurements /// @param seeds Input seeds track_candidate_container_types::host operator()( - const detector_type& det, + const detector_type& det, const bfield_type& field, const measurement_collection_types::host& measurements, const bound_track_parameters_collection_types::host& seeds) const; diff --git a/core/include/traccc/finding/finding_algorithm.ipp b/core/include/traccc/finding/finding_algorithm.ipp index 7759837c22..2401615e00 100644 --- a/core/include/traccc/finding/finding_algorithm.ipp +++ b/core/include/traccc/finding/finding_algorithm.ipp @@ -19,7 +19,7 @@ namespace traccc { template track_candidate_container_types::host finding_algorithm::operator()( - const detector_type& det, + const detector_type& det, const bfield_type& field, const measurement_collection_types::host& measurements, const bound_track_parameters_collection_types::host& seeds) const { @@ -207,7 +207,7 @@ finding_algorithm::operator()( // Create propagator state typename propagator_type::state propagation( - trk_state.filtered(), det.get_bfield(), det); + trk_state.filtered(), field, det); propagation._stepping.template set_constraint< detray::step::constraint::e_accuracy>( m_cfg.constrained_step_size); diff --git a/core/include/traccc/fitting/fitting_algorithm.hpp b/core/include/traccc/fitting/fitting_algorithm.hpp index 74a6c27c77..f206a03316 100644 --- a/core/include/traccc/fitting/fitting_algorithm.hpp +++ b/core/include/traccc/fitting/fitting_algorithm.hpp @@ -22,10 +22,12 @@ template class fitting_algorithm : public algorithm { public: using transform3_type = typename fitter_t::transform3_type; + using bfield_type = typename fitter_t::bfield_type; /// Configuration type using config_type = typename fitter_t::config_type; @@ -40,10 +42,11 @@ class fitting_algorithm /// @return the container of the fitted track parameters track_state_container_types::host operator()( const typename fitter_t::detector_type& det, + const typename fitter_t::bfield_type& field, const typename track_candidate_container_types::host& track_candidates) const override { - fitter_t fitter(det, m_cfg); + fitter_t fitter(det, field, m_cfg); track_state_container_types::host output_states; diff --git a/core/include/traccc/fitting/kalman_filter/kalman_fitter.hpp b/core/include/traccc/fitting/kalman_filter/kalman_fitter.hpp index be9cd14778..20ca93eb62 100644 --- a/core/include/traccc/fitting/kalman_filter/kalman_fitter.hpp +++ b/core/include/traccc/fitting/kalman_filter/kalman_fitter.hpp @@ -54,6 +54,9 @@ class kalman_fitter { // Detector type using detector_type = typename navigator_t::detector_type; + // Field type + using bfield_type = typename stepper_t::magnetic_field_type; + // Actor types using aborter = detray::pathlimit_aborter; using transporter = detray::parameter_transporter; @@ -73,8 +76,9 @@ class kalman_fitter { /// /// @param det the detector object TRACCC_HOST_DEVICE - kalman_fitter(const detector_type& det, const config_type& cfg) - : m_detector(det), m_cfg(cfg) {} + kalman_fitter(const detector_type& det, const bfield_type& field, + const config_type& cfg) + : m_detector(det), m_field(field), m_cfg(cfg) {} /// Kalman fitter state struct state { @@ -163,8 +167,7 @@ class kalman_fitter { // Create propagator state typename propagator_type::state propagation( - seed_params, m_detector.get_bfield(), m_detector, - std::move(nav_candidates)); + seed_params, m_field, m_detector, std::move(nav_candidates)); // @TODO: Should be removed once detray is fixed to set the // volume in the constructor @@ -244,6 +247,9 @@ class kalman_fitter { private: // Detector object const detector_type& m_detector; + // Field object + const bfield_type& m_field; + // Configuration object config_type m_cfg; }; diff --git a/core/include/traccc/utils/seed_generator.hpp b/core/include/traccc/utils/seed_generator.hpp index a2f7ef63a7..d89c9086a8 100644 --- a/core/include/traccc/utils/seed_generator.hpp +++ b/core/include/traccc/utils/seed_generator.hpp @@ -36,7 +36,7 @@ struct seed_generator { seed_generator(const detector_t& det, const std::array& stddevs, const std::size_t sd = 0) - : m_detector(std::make_unique(det)), m_stddevs(stddevs) { + : m_detector(det), m_stddevs(stddevs) { generator.seed(sd); } @@ -49,7 +49,7 @@ struct seed_generator { const free_track_parameters& free_param) { // Get bound parameter - const detray::surface sf{*m_detector, surface_link}; + const detray::surface sf{m_detector, surface_link}; const cxt_t ctx{}; auto bound_vec = sf.free_to_bound_vector(ctx, free_param.vector()); @@ -68,10 +68,10 @@ struct seed_generator { detray::pointwise_material_interactor; intersection_type sfi; - sfi.sf_desc = m_detector->surface(surface_link); + sfi.sf_desc = m_detector.surface(surface_link); sf.template visit_mask( detray::detail::ray(free_param.vector()), sfi, - m_detector->transform_store()); + m_detector.transform_store()); // Apply interactor typename interactor_type::state interactor_state; @@ -100,8 +100,8 @@ struct seed_generator { std::random_device rd{}; std::mt19937 generator{rd()}; - /// Detector objects - std::unique_ptr m_detector; + // Detector object + const detector_t& m_detector; /// Standard deviations for parameter smearing std::array m_stddevs; }; diff --git a/device/common/include/traccc/finding/device/impl/propagate_to_next_surface.ipp b/device/common/include/traccc/finding/device/impl/propagate_to_next_surface.ipp index aca9a48181..ee55ec62b3 100644 --- a/device/common/include/traccc/finding/device/impl/propagate_to_next_surface.ipp +++ b/device/common/include/traccc/finding/device/impl/propagate_to_next_surface.ipp @@ -9,10 +9,11 @@ namespace traccc::device { -template +template TRACCC_DEVICE inline void propagate_to_next_surface( std::size_t globalIndex, const config_t cfg, typename propagator_t::detector_type::view_type det_data, + bfield_t field_data, vecmem::data::jagged_vector_view nav_candidates_buffer, bound_track_parameters_collection_types::const_view in_params_view, @@ -60,8 +61,7 @@ TRACCC_DEVICE inline void propagate_to_next_surface( // Create propagator state typename propagator_t::state propagation( - in_par, det.get_bfield(), det, - std::move(nav_candidates.at(globalIndex))); + in_par, field_data, det, std::move(nav_candidates.at(globalIndex))); propagation._stepping .template set_constraint( cfg.constrained_step_size); diff --git a/device/common/include/traccc/finding/device/propagate_to_next_surface.hpp b/device/common/include/traccc/finding/device/propagate_to_next_surface.hpp index dfb53f49a4..7ce4b04b10 100644 --- a/device/common/include/traccc/finding/device/propagate_to_next_surface.hpp +++ b/device/common/include/traccc/finding/device/propagate_to_next_surface.hpp @@ -13,6 +13,9 @@ #include "traccc/edm/measurement.hpp" #include "traccc/edm/track_parameters.hpp" +// Covfie include(s). +#include + namespace traccc::device { /// Function for propagating the kalman-updated tracks to the next surface @@ -35,10 +38,11 @@ namespace traccc::device { /// @param[out] tips_view Tip link container for the current step /// @param[out] n_out_params The number of output parameters /// -template +template TRACCC_DEVICE inline void propagate_to_next_surface( std::size_t globalIndex, const config_t cfg, typename propagator_t::detector_type::view_type det_data, + bfield_t field_data, vecmem::data::jagged_vector_view nav_candidates_buffer, bound_track_parameters_collection_types::const_view in_params_view, diff --git a/device/common/include/traccc/fitting/device/fit.hpp b/device/common/include/traccc/fitting/device/fit.hpp index ad9572fe68..61dbfd6863 100644 --- a/device/common/include/traccc/fitting/device/fit.hpp +++ b/device/common/include/traccc/fitting/device/fit.hpp @@ -28,6 +28,7 @@ namespace traccc::device { template TRACCC_HOST_DEVICE inline void fit( std::size_t globalIndex, detector_view_t det_data, + const typename fitter_t::bfield_type field_data, const typename fitter_t::config_type cfg, vecmem::data::jagged_vector_view nav_candidates_buffer, diff --git a/device/common/include/traccc/fitting/device/impl/fit.ipp b/device/common/include/traccc/fitting/device/impl/fit.ipp index 34978a5ef3..3403e68ec3 100644 --- a/device/common/include/traccc/fitting/device/impl/fit.ipp +++ b/device/common/include/traccc/fitting/device/impl/fit.ipp @@ -12,6 +12,7 @@ namespace traccc::device { template TRACCC_HOST_DEVICE inline void fit( std::size_t globalIndex, detector_view_t det_data, + const typename fitter_t::bfield_type field_data, const typename fitter_t::config_type cfg, vecmem::data::jagged_vector_view nav_candidates_buffer, @@ -28,7 +29,7 @@ TRACCC_HOST_DEVICE inline void fit( track_state_container_types::device track_states(track_states_view); - fitter_t fitter(det, cfg); + fitter_t fitter(det, field_data, cfg); if (globalIndex >= track_states.size()) { return; diff --git a/device/cuda/include/traccc/cuda/finding/finding_algorithm.hpp b/device/cuda/include/traccc/cuda/finding/finding_algorithm.hpp index d130639797..f265ee2945 100644 --- a/device/cuda/include/traccc/cuda/finding/finding_algorithm.hpp +++ b/device/cuda/include/traccc/cuda/finding/finding_algorithm.hpp @@ -38,6 +38,7 @@ template class finding_algorithm : public algorithm&, const typename measurement_collection_types::view&, @@ -49,6 +50,9 @@ class finding_algorithm /// Detector type using detector_type = typename navigator_t::detector_type; + /// Field type + using bfield_type = typename stepper_t::magnetic_field_type; + /// Actor types using interactor = detray::pointwise_material_interactor; @@ -86,6 +90,7 @@ class finding_algorithm /// @param seeds Input seeds track_candidate_container_types::buffer operator()( const typename detector_type::view_type& det_view, + const bfield_type& field_view, const vecmem::data::jagged_vector_view< typename navigator_t::intersection_type>& navigation_buffer, const typename measurement_collection_types::view& measurements, diff --git a/device/cuda/include/traccc/cuda/fitting/fitting_algorithm.hpp b/device/cuda/include/traccc/cuda/fitting/fitting_algorithm.hpp index 841e2f7244..036433fd1a 100644 --- a/device/cuda/include/traccc/cuda/fitting/fitting_algorithm.hpp +++ b/device/cuda/include/traccc/cuda/fitting/fitting_algorithm.hpp @@ -28,6 +28,7 @@ template class fitting_algorithm : public algorithm&, const typename track_candidate_container_types::const_view&)> { @@ -46,6 +47,7 @@ class fitting_algorithm /// Run the algorithm track_state_container_types::buffer operator()( const typename fitter_t::detector_type::view_type& det_view, + const typename fitter_t::bfield_type& field_view, const vecmem::data::jagged_vector_view< typename fitter_t::intersection_type>& navigation_buffer, const typename track_candidate_container_types::const_view& diff --git a/device/cuda/src/finding/finding_algorithm.cu b/device/cuda/src/finding/finding_algorithm.cu index fcf0415c31..cc4cdfa03c 100644 --- a/device/cuda/src/finding/finding_algorithm.cu +++ b/device/cuda/src/finding/finding_algorithm.cu @@ -116,10 +116,11 @@ __global__ void find_tracks( } /// CUDA kernel for running @c traccc::device::propagate_to_next_surface -template +template __global__ void propagate_to_next_surface( const config_t cfg, typename propagator_t::detector_type::view_type det_data, + bfield_t field_data, vecmem::data::jagged_vector_view nav_candidates_buffer, bound_track_parameters_collection_types::const_view in_params_view, @@ -133,10 +134,10 @@ __global__ void propagate_to_next_surface( int gid = threadIdx.x + blockIdx.x * blockDim.x; - device::propagate_to_next_surface( - gid, cfg, det_data, nav_candidates_buffer, in_params_view, links_view, - step, n_candidates, out_params_view, param_to_link_view, tips_view, - n_out_params); + device::propagate_to_next_surface( + gid, cfg, det_data, field_data, nav_candidates_buffer, in_params_view, + links_view, step, n_candidates, out_params_view, param_to_link_view, + tips_view, n_out_params); } /// CUDA kernel for running @c traccc::device::build_tracks @@ -174,6 +175,7 @@ template track_candidate_container_types::buffer finding_algorithm::operator()( const typename detector_type::view_type& det_view, + const bfield_type& field_view, const vecmem::data::jagged_vector_view< typename navigator_t::intersection_type>& navigation_buffer, const typename measurement_collection_types::view& measurements, @@ -400,11 +402,13 @@ finding_algorithm::operator()( if (global_counter_host.n_candidates > 0) { nBlocks = (global_counter_host.n_candidates + nThreads - 1) / nThreads; - kernels::propagate_to_next_surface + kernels::propagate_to_next_surface <<>>( - m_cfg, det_view, navigation_buffer, updated_params_buffer, - link_map[step], step, (*global_counter_device).n_candidates, - out_params_buffer, param_to_link_map[step], tips_map[step], + m_cfg, det_view, field_view, navigation_buffer, + updated_params_buffer, link_map[step], step, + (*global_counter_device).n_candidates, out_params_buffer, + param_to_link_map[step], tips_map[step], (*global_counter_device).n_out_params); CUDA_ERROR_CHECK(cudaGetLastError()); CUDA_ERROR_CHECK(cudaDeviceSynchronize()); diff --git a/device/cuda/src/fitting/fitting_algorithm.cu b/device/cuda/src/fitting/fitting_algorithm.cu index 977c01ed55..0f8e85e07b 100644 --- a/device/cuda/src/fitting/fitting_algorithm.cu +++ b/device/cuda/src/fitting/fitting_algorithm.cu @@ -12,6 +12,7 @@ #include "traccc/fitting/kalman_filter/kalman_fitter.hpp" // detray include(s). +#include "detray/detectors/bfield.hpp" #include "detray/detectors/telescope_metadata.hpp" #include "detray/detectors/toy_metadata.hpp" #include "detray/masks/unbounded.hpp" @@ -26,7 +27,8 @@ namespace kernels { template __global__ void fit( - detector_view_t det_data, const typename fitter_t::config_type cfg, + detector_view_t det_data, const typename fitter_t::bfield_type field_data, + const typename fitter_t::config_type cfg, vecmem::data::jagged_vector_view nav_candidates_buffer, track_candidate_container_types::const_view track_candidates_view, @@ -34,7 +36,7 @@ __global__ void fit( int gid = threadIdx.x + blockIdx.x * blockDim.x; - device::fit(gid, det_data, cfg, nav_candidates_buffer, + device::fit(gid, det_data, field_data, cfg, nav_candidates_buffer, track_candidates_view, track_states_view); } @@ -56,6 +58,7 @@ fitting_algorithm::fitting_algorithm( template track_state_container_types::buffer fitting_algorithm::operator()( const typename fitter_t::detector_type::view_type& det_view, + const typename fitter_t::bfield_type& field_view, const vecmem::data::jagged_vector_view< typename fitter_t::intersection_type>& navigation_buffer, const typename track_candidate_container_types::const_view& @@ -86,9 +89,9 @@ track_state_container_types::buffer fitting_algorithm::operator()( const unsigned int nBlocks = (n_tracks + nThreads - 1) / nThreads; // Run the track fitting - kernels::fit - <<>>(det_view, m_cfg, navigation_buffer, - track_candidates_view, track_states_buffer); + kernels::fit<<>>( + det_view, field_view, m_cfg, navigation_buffer, + track_candidates_view, track_states_buffer); CUDA_ERROR_CHECK(cudaGetLastError()); CUDA_ERROR_CHECK(cudaDeviceSynchronize()); } @@ -97,21 +100,20 @@ track_state_container_types::buffer fitting_algorithm::operator()( // Explicit template instantiation using toy_detector_type = - detray::detector, covfie::field_view, - detray::device_container_types>; -using toy_stepper_type = detray::rk_stepper< - covfie::field::view_t, transform3, - detray::constrained_step<>>; + detray::detector; +using toy_stepper_type = + detray::rk_stepper, + transform3, detray::constrained_step<>>; using toy_navigator_type = detray::navigator; using toy_fitter_type = kalman_fitter; template class fitting_algorithm; using device_detector_type = detray::detector>, - covfie::field_view, detray::device_container_types>; -using rk_stepper_type = detray::rk_stepper< - covfie::field::view_t, - transform3, detray::constrained_step<>>; + detray::device_container_types>; +using rk_stepper_type = + detray::rk_stepper, + transform3, detray::constrained_step<>>; using device_navigator_type = detray::navigator; using device_fitter_type = kalman_fitter; diff --git a/examples/options/include/traccc/options/common_options.hpp b/examples/options/include/traccc/options/common_options.hpp index 362bec54d1..e53f5bb9d7 100644 --- a/examples/options/include/traccc/options/common_options.hpp +++ b/examples/options/include/traccc/options/common_options.hpp @@ -24,7 +24,6 @@ struct common_options { bool check_performance; std::string detector_file; std::string material_file; - bool run_detray_geometry; common_options(po::options_description& desc); void read(const po::variables_map& vm); diff --git a/examples/options/src/options/common_options.cpp b/examples/options/src/options/common_options.cpp index 996231df77..d4474a65c8 100644 --- a/examples/options/src/options/common_options.cpp +++ b/examples/options/src/options/common_options.cpp @@ -30,9 +30,6 @@ traccc::common_options::common_options(po::options_description& desc) { "specify detector file"); desc.add_options()("material_file", po::value(), "specify material file"); - desc.add_options()("run_detray_geometry", - po::value()->default_value(false), - "generate performance result"); } void traccc::common_options::read(const po::variables_map& vm) { @@ -52,5 +49,4 @@ void traccc::common_options::read(const po::variables_map& vm) { if (vm.count("material_file")) { material_file = vm["material_file"].as(); } - run_detray_geometry = vm["run_detray_geometry"].as(); } \ No newline at end of file diff --git a/examples/run/cpu/seeding_example.cpp b/examples/run/cpu/seeding_example.cpp index d50297bb8e..0bd0cc00ac 100644 --- a/examples/run/cpu/seeding_example.cpp +++ b/examples/run/cpu/seeding_example.cpp @@ -92,30 +92,19 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/, // B field value and its type // @TODO: Set B field as argument const traccc::vector3 B{0, 0, 2 * detray::unit::T}; + auto field = detray::bfield::create_const_field(B); - // Declare detector - host_detector_type host_det{host_mr}; + // Read the detector + detray::io::detector_reader_config reader_cfg{}; + reader_cfg + .add_file(traccc::io::data_directory() + common_opts.detector_file) + .add_file(traccc::io::data_directory() + common_opts.material_file); - // Read the surface transforms - traccc::geometry surface_transforms; + auto [host_det, names] = + detray::io::read_detector(host_mr, reader_cfg); - if (not common_opts.run_detray_geometry) { - surface_transforms = - traccc::io::read_geometry(common_opts.detector_file); - } else { - // Read the detector - detray::io::detector_reader_config reader_cfg{}; - reader_cfg - .add_file(traccc::io::data_directory() + common_opts.detector_file) - .add_file(traccc::io::data_directory() + common_opts.material_file) - .bfield_vec(B[0], B[1], B[2]); - - auto [det, names] = - detray::io::read_detector(host_mr, reader_cfg); - host_det = std::move(det); - - surface_transforms = traccc::io::alt_read_geometry(host_det); - } + traccc::geometry surface_transforms = + traccc::io::alt_read_geometry(host_det); // Seeding algorithm traccc::seedfinder_config finder_config; @@ -171,32 +160,30 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/, traccc::track_candidate_container_types::host track_candidates; traccc::track_state_container_types::host track_states; - if (common_opts.run_detray_geometry) { + // Read measurements + traccc::io::measurement_reader_output meas_read_out(&host_mr); + traccc::io::read_measurements(meas_read_out, event, + common_opts.input_directory, + traccc::data_format::csv); + traccc::measurement_collection_types::host& measurements_per_event = + meas_read_out.measurements; + n_measurements += measurements_per_event.size(); - // Read measurements - traccc::io::measurement_reader_output meas_read_out(&host_mr); - traccc::io::read_measurements(meas_read_out, event, - common_opts.input_directory, - traccc::data_format::csv); - traccc::measurement_collection_types::host& measurements_per_event = - meas_read_out.measurements; - n_measurements += measurements_per_event.size(); + /*------------------------ + Track Finding with CKF + ------------------------*/ - /*------------------------ - Track Finding with CKF - ------------------------*/ + track_candidates = + host_finding(host_det, field, measurements_per_event, params); + n_found_tracks += track_candidates.size(); - track_candidates = - host_finding(host_det, measurements_per_event, params); - n_found_tracks += track_candidates.size(); + /*------------------------ + Track Fitting with KF + ------------------------*/ - /*------------------------ - Track Fitting with KF - ------------------------*/ + track_states = host_fitting(host_det, field, track_candidates); + n_fitted_tracks += track_states.size(); - track_states = host_fitting(host_det, track_candidates); - n_fitted_tracks += track_states.size(); - } /*------------ Statistics ------------*/ @@ -210,33 +197,23 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/, if (common_opts.check_performance) { - if (common_opts.run_detray_geometry) { - - traccc::event_map2 evt_map(event, common_opts.input_directory, - common_opts.input_directory, - common_opts.input_directory); - sd_performance_writer.write( - vecmem::get_data(seeds), - vecmem::get_data(spacepoints_per_event), evt_map); - - find_performance_writer.write( - traccc::get_data(track_candidates), evt_map); - - for (unsigned int i = 0; i < track_states.size(); i++) { - const auto& trk_states_per_track = track_states.at(i).items; - - const auto& fit_info = track_states[i].header; - - fit_performance_writer.write(trk_states_per_track, fit_info, - host_det, evt_map); - } - } else { - traccc::event_map evt_map(event, common_opts.detector_file, - common_opts.input_directory, - common_opts.input_directory, host_mr); - sd_performance_writer.write( - vecmem::get_data(seeds), - vecmem::get_data(spacepoints_per_event), evt_map); + traccc::event_map2 evt_map(event, common_opts.input_directory, + common_opts.input_directory, + common_opts.input_directory); + sd_performance_writer.write(vecmem::get_data(seeds), + vecmem::get_data(spacepoints_per_event), + evt_map); + + find_performance_writer.write(traccc::get_data(track_candidates), + evt_map); + + for (unsigned int i = 0; i < track_states.size(); i++) { + const auto& trk_states_per_track = track_states.at(i).items; + + const auto& fit_info = track_states[i].header; + + fit_performance_writer.write(trk_states_per_track, fit_info, + host_det, evt_map); } } } diff --git a/examples/run/cpu/truth_finding_example.cpp b/examples/run/cpu/truth_finding_example.cpp index 60461707d4..41f1c21a63 100644 --- a/examples/run/cpu/truth_finding_example.cpp +++ b/examples/run/cpu/truth_finding_example.cpp @@ -24,6 +24,7 @@ // Detray include(s). #include "detray/core/detector.hpp" +#include "detray/detectors/bfield.hpp" #include "detray/detectors/toy_metadata.hpp" #include "detray/io/common/detector_reader.hpp" #include "detray/propagator/navigator.hpp" @@ -47,10 +48,9 @@ int seq_run(const traccc::finding_input_config& i_cfg, /// Type declarations using host_detector_type = - detray::detector, covfie::field, - detray::host_container_types>; + detray::detector; - using b_field_t = typename host_detector_type::bfield_type; + using b_field_t = covfie::field; using rk_stepper_type = detray::rk_stepper>; @@ -75,13 +75,13 @@ int seq_run(const traccc::finding_input_config& i_cfg, // B field value and its type // @TODO: Set B field as argument const traccc::vector3 B{0, 0, 2 * detray::unit::T}; + auto field = detray::bfield::create_const_field(B); // Read the detector detray::io::detector_reader_config reader_cfg{}; reader_cfg .add_file(traccc::io::data_directory() + common_opts.detector_file) - .add_file(traccc::io::data_directory() + common_opts.material_file) - .bfield_vec(B[0], B[1], B[2]); + .add_file(traccc::io::data_directory() + common_opts.material_file); const auto [host_det, names] = detray::io::read_detector(host_mr, reader_cfg); @@ -152,13 +152,13 @@ int seq_run(const traccc::finding_input_config& i_cfg, // Run finding auto track_candidates = - host_finding(host_det, measurements_per_event, seeds); + host_finding(host_det, field, measurements_per_event, seeds); std::cout << "Number of found tracks: " << track_candidates.size() << std::endl; // Run fitting - auto track_states = host_fitting(host_det, track_candidates); + auto track_states = host_fitting(host_det, field, track_candidates); std::cout << "Number of fitted tracks: " << track_states.size() << std::endl; diff --git a/examples/run/cuda/seeding_example_cuda.cpp b/examples/run/cuda/seeding_example_cuda.cpp index 4625f9c7a8..500bbfc6cb 100644 --- a/examples/run/cuda/seeding_example_cuda.cpp +++ b/examples/run/cuda/seeding_example_cuda.cpp @@ -36,6 +36,7 @@ // Detray include(s). #include "detray/core/detector.hpp" +#include "detray/detectors/bfield.hpp" #include "detray/detectors/toy_metadata.hpp" #include "detray/io/common/detector_reader.hpp" #include "detray/propagator/navigator.hpp" @@ -63,13 +64,11 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/, const traccc::common_options& common_opts, bool run_cpu) { /// Type declarations - using host_detector_type = detray::detector>; - + using host_detector_type = detray::detector; using device_detector_type = - detray::detector, covfie::field_view, - detray::device_container_types>; + detray::detector; - using b_field_t = typename host_detector_type::bfield_type; + using b_field_t = covfie::field; using rk_stepper_type = detray::rk_stepper::T}; + auto field = detray::bfield::create_const_field(B); - host_detector_type host_det{mng_mr}; - - // Read the surface transforms - traccc::geometry surface_transforms; - - if (not common_opts.run_detray_geometry) { - surface_transforms = - traccc::io::read_geometry(common_opts.detector_file); - } else { - - // Read the detector - detray::io::detector_reader_config reader_cfg{}; - reader_cfg - .add_file(traccc::io::data_directory() + common_opts.detector_file) - .add_file(traccc::io::data_directory() + common_opts.material_file) - .bfield_vec(B[0], B[1], B[2]); + // Read the detector + detray::io::detector_reader_config reader_cfg{}; + reader_cfg + .add_file(traccc::io::data_directory() + common_opts.detector_file) + .add_file(traccc::io::data_directory() + common_opts.material_file); - auto [det, names] = - detray::io::read_detector(host_mr, reader_cfg); - host_det = std::move(det); + auto [host_det, names] = + detray::io::read_detector(host_mr, reader_cfg); - surface_transforms = traccc::io::alt_read_geometry(host_det); - } + traccc::geometry surface_transforms = + traccc::io::alt_read_geometry(host_det); // Detector view object auto det_view = detray::get_data(host_det); @@ -312,52 +300,49 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/, {0.f, 0.f, finder_config.bFieldInZ}); } // stop measuring track params cpu timer - if (common_opts.run_detray_geometry) { - - // Navigation buffer - auto navigation_buffer = detray::create_candidates_buffer( - host_det, - device_finding.get_config().max_num_branches_per_seed * - copy.get_size(seeds_cuda_buffer), - mr.main, mr.host); + // Navigation buffer + auto navigation_buffer = detray::create_candidates_buffer( + host_det, + device_finding.get_config().max_num_branches_per_seed * + copy.get_size(seeds_cuda_buffer), + mr.main, mr.host); - /*------------------------ - Track Finding with CKF - ------------------------*/ + /*------------------------ + Track Finding with CKF + ------------------------*/ - { - traccc::performance::timer t( - "Track finding with CKF (cuda)", elapsedTimes); - track_candidates_cuda_buffer = device_finding( - det_view, navigation_buffer, measurements_cuda_buffer, - params_cuda_buffer); - } + { + traccc::performance::timer t("Track finding with CKF (cuda)", + elapsedTimes); + track_candidates_cuda_buffer = device_finding( + det_view, field, navigation_buffer, + measurements_cuda_buffer, params_cuda_buffer); + } - if (run_cpu) { - traccc::performance::timer t("Track finding with CKF (cpu)", - elapsedTimes); - track_candidates = - host_finding(host_det, measurements_per_event, params); - } + if (run_cpu) { + traccc::performance::timer t("Track finding with CKF (cpu)", + elapsedTimes); + track_candidates = host_finding(host_det, field, + measurements_per_event, params); + } - /*------------------------ - Track Fitting with KF - ------------------------*/ + /*------------------------ + Track Fitting with KF + ------------------------*/ - { - traccc::performance::timer t("Track fitting with KF (cuda)", - elapsedTimes); + { + traccc::performance::timer t("Track fitting with KF (cuda)", + elapsedTimes); - track_states_cuda_buffer = - device_fitting(det_view, navigation_buffer, - track_candidates_cuda_buffer); - } + track_states_cuda_buffer = + device_fitting(det_view, field, navigation_buffer, + track_candidates_cuda_buffer); + } - if (run_cpu) { - traccc::performance::timer t("Track fitting with KF (cpu)", - elapsedTimes); - track_states = host_fitting(host_det, track_candidates); - } + if (run_cpu) { + traccc::performance::timer t("Track fitting with KF (cpu)", + elapsedTimes); + track_states = host_fitting(host_det, field, track_candidates); } } // Stop measuring wall time @@ -398,26 +383,24 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/, compare_track_parameters(vecmem::get_data(params), vecmem::get_data(params_cuda)); - if (common_opts.run_detray_geometry) { - // Compare the track candidates made on the host and on the - // device - unsigned int n_matches = 0; - for (unsigned int i = 0; i < track_candidates.size(); i++) { - auto iso = traccc::details::is_same_object( - track_candidates.at(i).items); - - for (unsigned int j = 0; j < track_candidates_cuda.size(); - j++) { - if (iso(track_candidates_cuda.at(j).items)) { - n_matches++; - break; - } + // Compare the track candidates made on the host and on the + // device + unsigned int n_matches = 0; + for (unsigned int i = 0; i < track_candidates.size(); i++) { + auto iso = traccc::details::is_same_object( + track_candidates.at(i).items); + + for (unsigned int j = 0; j < track_candidates_cuda.size(); + j++) { + if (iso(track_candidates_cuda.at(j).items)) { + n_matches++; + break; } } - std::cout << "Track candidate matching Rate: " - << float(n_matches) / track_candidates.size() - << std::endl; } + std::cout << "Track candidate matching Rate: " + << float(n_matches) / track_candidates.size() + << std::endl; } /*---------------- @@ -438,46 +421,24 @@ int seq_run(const traccc::seeding_input_config& /*i_cfg*/, ------------*/ if (common_opts.check_performance) { - if (common_opts.run_detray_geometry) { - - traccc::event_map2 evt_map(event, common_opts.input_directory, - common_opts.input_directory, - common_opts.input_directory); - sd_performance_writer.write( - vecmem::get_data(seeds_cuda), - vecmem::get_data(sp_reader_output.spacepoints), evt_map); - - find_performance_writer.write( - traccc::get_data(track_candidates_cuda), evt_map); - - for (unsigned int i = 0; i < track_states_cuda.size(); i++) { - const auto& trk_states_per_track = - track_states_cuda.at(i).items; - - const auto& fit_info = track_states_cuda[i].header; - - fit_performance_writer.write(trk_states_per_track, fit_info, - host_det, evt_map); - } - } else { - traccc::event_map evt_map(event, common_opts.detector_file, - common_opts.input_directory, - common_opts.input_directory, host_mr); + traccc::event_map2 evt_map(event, common_opts.input_directory, + common_opts.input_directory, + common_opts.input_directory); + sd_performance_writer.write( + vecmem::get_data(seeds_cuda), + vecmem::get_data(sp_reader_output.spacepoints), evt_map); - std::vector> nseeds; + find_performance_writer.write( + traccc::get_data(track_candidates_cuda), evt_map); - std::transform( - seeds_cuda.cbegin(), seeds_cuda.cend(), - std::back_inserter(nseeds), - [](const traccc::seed& s) { return traccc::nseed<3>(s); }); + for (unsigned int i = 0; i < track_states_cuda.size(); i++) { + const auto& trk_states_per_track = + track_states_cuda.at(i).items; - nsd_performance_writer.register_event( - event, nseeds.begin(), nseeds.end(), - sp_reader_output.spacepoints.begin(), evt_map); + const auto& fit_info = track_states_cuda[i].header; - sd_performance_writer.write( - vecmem::get_data(seeds_cuda), - vecmem::get_data(sp_reader_output.spacepoints), evt_map); + fit_performance_writer.write(trk_states_per_track, fit_info, + host_det, evt_map); } } } diff --git a/examples/run/cuda/truth_finding_example_cuda.cpp b/examples/run/cuda/truth_finding_example_cuda.cpp index f5d69104f1..5ef6161e45 100644 --- a/examples/run/cuda/truth_finding_example_cuda.cpp +++ b/examples/run/cuda/truth_finding_example_cuda.cpp @@ -32,6 +32,7 @@ // detray include(s). #include "detray/core/detector.hpp" +#include "detray/detectors/bfield.hpp" #include "detray/detectors/toy_metadata.hpp" #include "detray/io/common/detector_reader.hpp" #include "detray/propagator/navigator.hpp" @@ -59,13 +60,11 @@ int seq_run(const traccc::finding_input_config& i_cfg, /// Type declarations using host_detector_type = - detray::detector, covfie::field, - detray::host_container_types>; + detray::detector; using device_detector_type = - detray::detector, covfie::field_view, - detray::device_container_types>; + detray::detector; - using b_field_t = typename host_detector_type::bfield_type; + using b_field_t = covfie::field; using rk_stepper_type = detray::rk_stepper>; @@ -102,13 +101,13 @@ int seq_run(const traccc::finding_input_config& i_cfg, // B field value and its type // @TODO: Set B field as argument const traccc::vector3 B{0, 0, 2 * detray::unit::T}; + auto field = detray::bfield::create_const_field(B); // Read the detector detray::io::detector_reader_config reader_cfg{}; reader_cfg .add_file(traccc::io::data_directory() + common_opts.detector_file) - .add_file(traccc::io::data_directory() + common_opts.material_file) - .bfield_vec(B[0], B[1], B[2]); + .add_file(traccc::io::data_directory() + common_opts.material_file); auto [host_det, names] = detray::io::read_detector(mng_mr, reader_cfg); @@ -230,7 +229,7 @@ int seq_run(const traccc::finding_input_config& i_cfg, // Run finding track_candidates_cuda_buffer = - device_finding(det_view, navigation_buffer, + device_finding(det_view, field, navigation_buffer, measurements_cuda_buffer, seeds_buffer); } @@ -245,8 +244,9 @@ int seq_run(const traccc::finding_input_config& i_cfg, traccc::performance::timer t("Track fitting (cuda)", elapsedTimes); // Run fitting - track_states_cuda_buffer = device_fitting( - det_view, navigation_buffer, track_candidates_cuda_buffer); + track_states_cuda_buffer = + device_fitting(det_view, field, navigation_buffer, + track_candidates_cuda_buffer); } traccc::track_state_container_types::host track_states_cuda = track_state_d2h(track_states_cuda_buffer); @@ -263,8 +263,8 @@ int seq_run(const traccc::finding_input_config& i_cfg, elapsedTimes); // Run finding - track_candidates = - host_finding(host_det, measurements_per_event, seeds); + track_candidates = host_finding(host_det, field, + measurements_per_event, seeds); } { @@ -272,7 +272,7 @@ int seq_run(const traccc::finding_input_config& i_cfg, elapsedTimes); // Run fitting - track_states = host_fitting(host_det, track_candidates); + track_states = host_fitting(host_det, field, track_candidates); } } diff --git a/examples/simulation/simulate_telescope.cpp b/examples/simulation/simulate_telescope.cpp index 41c7788ac2..719f98e205 100644 --- a/examples/simulation/simulate_telescope.cpp +++ b/examples/simulation/simulate_telescope.cpp @@ -18,6 +18,7 @@ #include "traccc/simulation/smearing_writer.hpp" // detray include(s). +#include "detray/detectors/bfield.hpp" #include "detray/detectors/create_telescope_detector.hpp" #include "detray/io/common/detector_writer.hpp" #include "detray/masks/unbounded.hpp" @@ -54,7 +55,9 @@ int simulate(std::string output_directory, unsigned int events, 120., 140, 160, 180.}; // B field value and its type + using b_field_t = covfie::field; const vector3 B{2 * detray::unit::T, 0, 0}; + auto field = detray::bfield::create_const_field(B); // Create the detector const auto mat = detray::silicon_tml(); @@ -70,7 +73,6 @@ int simulate(std::string output_directory, unsigned int events, tel_cfg.module_material(mat); tel_cfg.mat_thickness(thickness); tel_cfg.pilot_track(traj); - tel_cfg.bfield_vec(B); const auto [det, name_map] = create_telescope_detector(host_mr, tel_cfg); @@ -79,11 +81,17 @@ int simulate(std::string output_directory, unsigned int events, ***************************/ // Origin of particles - auto generator = + using generator_type = detray::random_track_generator( - pg_opts.gen_nparticles, pg_opts.vertex, pg_opts.vertex_stddev, - pg_opts.mom_range, pg_opts.theta_range, pg_opts.phi_range); + uniform_gen_t>; + generator_type::configuration gen_cfg{}; + gen_cfg.n_tracks(pg_opts.gen_nparticles); + gen_cfg.origin(pg_opts.vertex); + gen_cfg.origin_stddev(pg_opts.vertex_stddev); + gen_cfg.phi_range(pg_opts.phi_range[0], pg_opts.phi_range[1]); + gen_cfg.theta_range(pg_opts.theta_range[0], pg_opts.theta_range[1]); + gen_cfg.mom_range(pg_opts.mom_range[0], pg_opts.mom_range[1]); + generator_type generator(gen_cfg); // Smearing value for measurements traccc::measurement_smearer meas_smearer( @@ -103,8 +111,9 @@ int simulate(std::string output_directory, unsigned int events, boost::filesystem::create_directories(full_path); - auto sim = traccc::simulator( - events, det, std::move(generator), std::move(smearer_writer_cfg), + auto sim = traccc::simulator( + events, det, field, std::move(generator), std::move(smearer_writer_cfg), full_path); sim.run(); diff --git a/examples/simulation/simulate_toy_detector.cpp b/examples/simulation/simulate_toy_detector.cpp index 3c7b8cc2c0..1d6e1f12c5 100644 --- a/examples/simulation/simulate_toy_detector.cpp +++ b/examples/simulation/simulate_toy_detector.cpp @@ -19,6 +19,7 @@ #include "traccc/simulation/smearing_writer.hpp" // detray include(s). +#include "detray/detectors/bfield.hpp" #include "detray/detectors/create_toy_geometry.hpp" #include "detray/io/common/detector_writer.hpp" #include "detray/simulation/event_generator/track_generators.hpp" @@ -49,31 +50,33 @@ int simulate(std::string output_directory, unsigned int events, *****************************/ // Detector type - using detector_type = detray::detector>; + using detector_type = detray::detector; // B field value and its type // @TODO: Set B field as argument + using b_field_t = covfie::field; const vector3 B{0, 0, 2 * detray::unit::T}; - using field_type = typename detector_type::bfield_type; + auto field = detray::bfield::create_const_field(B); // Create the toy geometry - const auto [det, name_map] = - detray::create_toy_geometry( - host_mr, - field_type( - field_type::backend_t::configuration_t{B[0], B[1], B[2]}), - 4u, 7u); + const auto [det, name_map] = detray::create_toy_geometry(host_mr, {4u, 7u}); /*************************** * Generate simulation data ***************************/ // Origin of particles - auto generator = + using generator_type = detray::random_track_generator( - pg_opts.gen_nparticles, pg_opts.vertex, pg_opts.vertex_stddev, - pg_opts.mom_range, pg_opts.theta_range, pg_opts.phi_range); + uniform_gen_t>; + generator_type::configuration gen_cfg{}; + gen_cfg.n_tracks(pg_opts.gen_nparticles); + gen_cfg.origin(pg_opts.vertex); + gen_cfg.origin_stddev(pg_opts.vertex_stddev); + gen_cfg.phi_range(pg_opts.phi_range[0], pg_opts.phi_range[1]); + gen_cfg.theta_range(pg_opts.theta_range[0], pg_opts.theta_range[1]); + gen_cfg.mom_range(pg_opts.mom_range[0], pg_opts.mom_range[1]); + generator_type generator(gen_cfg); // Smearing value for measurements traccc::measurement_smearer meas_smearer( @@ -92,8 +95,9 @@ int simulate(std::string output_directory, unsigned int events, boost::filesystem::create_directories(full_path); - auto sim = traccc::simulator( - events, det, std::move(generator), std::move(smearer_writer_cfg), + auto sim = traccc::simulator( + events, det, field, std::move(generator), std::move(smearer_writer_cfg), full_path); sim.get_config().step_constraint = propagation_opts.step_constraint; sim.get_config().overstep_tolerance = propagation_opts.overstep_tolerance; diff --git a/extern/detray/CMakeLists.txt b/extern/detray/CMakeLists.txt index df6c5ed214..24bf614b1c 100644 --- a/extern/detray/CMakeLists.txt +++ b/extern/detray/CMakeLists.txt @@ -18,7 +18,7 @@ message( STATUS "Building Detray as part of the TRACCC project" ) # Declare where to get Detray from. set( TRACCC_DETRAY_SOURCE - "URL;https://github.com/acts-project/detray/archive/refs/tags/v0.44.0.tar.gz;URL_MD5;d45877ceca4f61d1f9783f09777fcad0" + "URL;https://github.com/acts-project/detray/archive/refs/tags/v0.45.0.tar.gz;URL_MD5;0569160697740ec398420f294c46b38e" CACHE STRING "Source for Detray, when built as part of this project" ) mark_as_advanced( TRACCC_DETRAY_SOURCE ) diff --git a/simulation/include/traccc/simulation/simulator.hpp b/simulation/include/traccc/simulation/simulator.hpp index 09d2013eba..25570fdd02 100644 --- a/simulation/include/traccc/simulation/simulator.hpp +++ b/simulation/include/traccc/simulation/simulator.hpp @@ -26,7 +26,8 @@ namespace traccc { -template +template struct simulator { using scalar_type = typename detector_t::scalar_type; @@ -37,7 +38,7 @@ struct simulator { }; using transform3 = typename detector_t::transform3; - using bfield_type = typename detector_t::bfield_type; + using bfield_type = bfield_t; using actor_chain_type = detray::actor_chain, @@ -45,18 +46,20 @@ struct simulator { detray::parameter_resetter, writer_t>; using navigator_type = detray::navigator; - using stepper_type = detray::rk_stepper>; + using stepper_type = + detray::rk_stepper>; using propagator_type = detray::propagator; simulator(std::size_t events, const detector_t& det, - track_generator_t&& track_gen, + const bfield_type& field, track_generator_t&& track_gen, typename writer_t::config&& writer_cfg, const std::string directory = "") : m_events(events), m_directory(directory), - m_detector(std::make_unique(det)), + m_detector(det), + m_field(field), m_track_generator( std::make_unique(std::move(track_gen))), m_writer_cfg(writer_cfg) {} @@ -81,8 +84,8 @@ struct simulator { writer_state.write_particle(track); - typename propagator_type::state propagation( - track, m_detector->get_bfield(), *m_detector); + typename propagator_type::state propagation(track, m_field, + m_detector); propagator_type p({}, {}); @@ -105,7 +108,8 @@ struct simulator { config m_cfg; std::size_t m_events{0u}; std::string m_directory = ""; - std::unique_ptr m_detector; + const detector_t& m_detector; + const bfield_type& m_field; std::unique_ptr m_track_generator; typename writer_t::config m_writer_cfg; diff --git a/tests/cpu/test_ckf_sparse_tracks.cpp b/tests/cpu/test_ckf_sparse_tracks.cpp index 347ae4caf1..cb3b5fb17f 100644 --- a/tests/cpu/test_ckf_sparse_tracks.cpp +++ b/tests/cpu/test_ckf_sparse_tracks.cpp @@ -65,26 +65,31 @@ TEST_P(CkfSparseTrackTests, Run) { tel_cfg.module_material(mat); tel_cfg.mat_thickness(thickness); tel_cfg.pilot_track(traj); - tel_cfg.bfield_vec(B); auto [host_det, name_map] = create_telescope_detector(host_mr, tel_cfg); + auto field = detray::bfield::create_const_field(B); /*************************** * Generate simulation data ***************************/ // Track generator - auto generator = + using generator_type = detray::random_track_generator(n_truth_tracks, origin, - origin_stddev, mom_range, - theta_range, phi_range); + uniform_gen_t>; + generator_type::configuration gen_cfg{}; + gen_cfg.n_tracks(n_truth_tracks); + gen_cfg.origin(origin); + gen_cfg.origin_stddev(origin_stddev); + gen_cfg.phi_range(phi_range[0], phi_range[1]); + gen_cfg.theta_range(theta_range[0], theta_range[1]); + gen_cfg.mom_range(mom_range[0], mom_range[1]); + generator_type generator(gen_cfg); // Smearing value for measurements traccc::measurement_smearer meas_smearer(smearing[0], smearing[1]); - using generator_type = decltype(generator); using writer_type = traccc::smearing_writer>; @@ -94,10 +99,10 @@ TEST_P(CkfSparseTrackTests, Run) { const std::string path = name + "/"; const std::string full_path = io::data_directory() + path; std::filesystem::create_directories(full_path); - auto sim = - traccc::simulator( - n_events, host_det, std::move(generator), - std::move(smearer_writer_cfg), full_path); + auto sim = traccc::simulator( + n_events, host_det, field, std::move(generator), + std::move(smearer_writer_cfg), full_path); sim.run(); /***************************** @@ -148,12 +153,12 @@ TEST_P(CkfSparseTrackTests, Run) { // Run finding auto track_candidates = - host_finding(host_det, measurements_per_event, seeds); + host_finding(host_det, field, measurements_per_event, seeds); ASSERT_EQ(track_candidates.size(), n_truth_tracks); // Run fitting - auto track_states = host_fitting(host_det, track_candidates); + auto track_states = host_fitting(host_det, field, track_candidates); ASSERT_EQ(track_states.size(), n_truth_tracks); diff --git a/tests/cpu/test_kalman_fitter.cpp b/tests/cpu/test_kalman_fitter.cpp index 8970a96ed8..213d00ba24 100644 --- a/tests/cpu/test_kalman_fitter.cpp +++ b/tests/cpu/test_kalman_fitter.cpp @@ -63,25 +63,31 @@ TEST_P(KalmanFittingTests, Run) { tel_cfg.module_material(mat); tel_cfg.mat_thickness(thickness); tel_cfg.pilot_track(traj); - tel_cfg.bfield_vec(B); auto [det, name_map] = create_telescope_detector(host_mr, tel_cfg); + auto field = detray::bfield::create_const_field(B); /*************************** * Generate simulation data ***************************/ - auto generator = + // Track generator + using generator_type = detray::random_track_generator(n_truth_tracks, origin, - origin_stddev, mom_range, - theta_range, phi_range); + uniform_gen_t>; + generator_type::configuration gen_cfg{}; + gen_cfg.n_tracks(n_truth_tracks); + gen_cfg.origin(origin); + gen_cfg.origin_stddev(origin_stddev); + gen_cfg.phi_range(phi_range[0], phi_range[1]); + gen_cfg.theta_range(theta_range[0], theta_range[1]); + gen_cfg.mom_range(mom_range[0], mom_range[1]); + generator_type generator(gen_cfg); // Smearing value for measurements traccc::measurement_smearer meas_smearer(smearing[0], smearing[1]); - using generator_type = decltype(generator); using writer_type = traccc::smearing_writer>; @@ -91,10 +97,10 @@ TEST_P(KalmanFittingTests, Run) { const std::string path = name + "/"; const std::string full_path = io::data_directory() + path; std::filesystem::create_directories(full_path); - auto sim = - traccc::simulator( - n_events, det, std::move(generator), std::move(smearer_writer_cfg), - full_path); + auto sim = traccc::simulator( + n_events, det, field, std::move(generator), + std::move(smearer_writer_cfg), full_path); sim.run(); /*************** @@ -121,7 +127,7 @@ TEST_P(KalmanFittingTests, Run) { ASSERT_EQ(track_candidates.size(), n_truth_tracks); // Run fitting - auto track_states = fitting(det, track_candidates); + auto track_states = fitting(det, field, track_candidates); // Iterator over tracks const std::size_t n_tracks = track_states.size(); diff --git a/tests/cpu/test_simulation.cpp b/tests/cpu/test_simulation.cpp index 0a3db5b963..a6f14fa0a9 100644 --- a/tests/cpu/test_simulation.cpp +++ b/tests/cpu/test_simulation.cpp @@ -6,6 +6,7 @@ */ // Project include(s). +#include "traccc/edm/track_parameters.hpp" #include "traccc/io/csv/make_hit_reader.hpp" #include "traccc/io/csv/make_measurement_hit_id_reader.hpp" #include "traccc/io/csv/make_measurement_reader.hpp" @@ -13,6 +14,7 @@ #include "traccc/simulation/simulator.hpp" // Detray include(s). +#include "detray/detectors/bfield.hpp" #include "detray/detectors/create_telescope_detector.hpp" #include "detray/detectors/create_toy_geometry.hpp" #include "detray/geometry/surface.hpp" @@ -42,24 +44,24 @@ TEST(simulation, simulation) { const mask> re{ 0u, 10.f * detray::unit::mm, 10.f * detray::unit::mm}; - bound_track_parameters bound_params; + detray::bound_track_parameters bound_params; auto& bound_vec = bound_params.vector(); getter::element(bound_vec, traccc::e_bound_loc0, 0u) = 1.f; getter::element(bound_vec, traccc::e_bound_loc1, 0u) = 2.f; measurement_smearer smearer(0.f, 0.f); - io::csv::measurement iomeas1; + traccc::io::csv::measurement iomeas1; smearer(ln, {-3.f, 2.f}, bound_params, iomeas1); ASSERT_NEAR(iomeas1.local0, 0.f, tol); ASSERT_NEAR(iomeas1.local1, 0.f, tol); - io::csv::measurement iomeas2; + traccc::io::csv::measurement iomeas2; smearer(ln, {2.f, -5.f}, bound_params, iomeas2); ASSERT_NEAR(iomeas2.local0, 3.f, tol); ASSERT_NEAR(iomeas2.local1, 0.f, tol); - io::csv::measurement iomeas3; + traccc::io::csv::measurement iomeas3; smearer(re, {2.f, -5.f}, bound_params, iomeas3); ASSERT_NEAR(iomeas3.local0, 3.f, tol); ASSERT_NEAR(iomeas3.local1, -3.f, tol); @@ -67,31 +69,33 @@ TEST(simulation, simulation) { GTEST_TEST(detray_simulation, toy_geometry_simulation) { - // Use deterministic random number generator for testing - using normal_gen_t = - random_numbers, std::seed_seq>; - // Create geometry vecmem::host_memory_resource host_mr; // Create B field + using b_field_t = covfie::field; const vector3 B{0.f, 0.f, 2.f * detray::unit::T}; + auto field = detray::bfield::create_const_field(B); // Create geometry - using b_field_t = decltype(create_toy_geometry(host_mr).first)::bfield_type; - const auto [detector, names] = create_toy_geometry( - host_mr, - b_field_t(b_field_t::backend_t::configuration_t{B[0], B[1], B[2]})); + const auto [detector, names] = create_toy_geometry(host_mr); using geo_cxt_t = typename decltype(detector)::geometry_context; const geo_cxt_t ctx{}; // Create track generator + using uniform_gen_t = + detray::random_numbers, + std::seed_seq>; + using generator_type = + detray::random_track_generator; + generator_type::configuration gen_cfg{}; constexpr unsigned int n_tracks{2500u}; const vector3 ori{0.f, 0.f, 0.f}; - auto generator = - random_track_generator, normal_gen_t>( - n_tracks, ori); + gen_cfg.n_tracks(n_tracks); + gen_cfg.origin(ori); + generator_type generator(gen_cfg); // Create smearer measurement_smearer smearer(67.f * detray::unit::um, @@ -100,13 +104,12 @@ GTEST_TEST(detray_simulation, toy_geometry_simulation) { std::size_t n_events{10u}; using detector_type = decltype(detector); - using generator_type = decltype(generator); using writer_type = smearing_writer>; typename writer_type::config writer_cfg{smearer}; - auto sim = simulator( - n_events, detector, std::move(generator), std::move(writer_cfg)); + auto sim = simulator( + n_events, detector, field, std::move(generator), std::move(writer_cfg)); // Lift step size constraints sim.get_config().step_constraint = std::numeric_limits::max(); @@ -116,35 +119,36 @@ GTEST_TEST(detray_simulation, toy_geometry_simulation) { for (std::size_t i_event = 0u; i_event < n_events; i_event++) { - std::vector particles; - auto particle_reader = io::csv::make_particle_reader( + std::vector particles; + auto particle_reader = traccc::io::csv::make_particle_reader( detail::get_event_filename(i_event, "-particles.csv")); - io::csv::particle io_particle; + traccc::io::csv::particle io_particle; while (particle_reader.read(io_particle)) { particles.push_back(io_particle); } - std::vector hits; - auto hit_reader = io::csv::make_hit_reader( + std::vector hits; + auto hit_reader = traccc::io::csv::make_hit_reader( detail::get_event_filename(i_event, "-hits.csv")); - io::csv::hit io_hit; + traccc::io::csv::hit io_hit; while (hit_reader.read(io_hit)) { hits.push_back(io_hit); } - std::vector measurements; - auto measurement_reader = io::csv::make_measurement_reader( + std::vector measurements; + auto measurement_reader = traccc::io::csv::make_measurement_reader( detail::get_event_filename(i_event, "-measurements.csv")); - io::csv::measurement io_measurement; + traccc::io::csv::measurement io_measurement; while (measurement_reader.read(io_measurement)) { measurements.push_back(io_measurement); } - std::vector meas_hit_ids; + std::vector meas_hit_ids; auto measurement_hit_id_reader = - io::csv::make_measurement_hit_id_reader(detail::get_event_filename( - i_event, "-measurement-simhit-map.csv")); - io::csv::measurement_hit_id io_meas_hit_id; + traccc::io::csv::make_measurement_hit_id_reader( + detail::get_event_filename(i_event, + "-measurement-simhit-map.csv")); + traccc::io::csv::measurement_hit_id io_meas_hit_id; while (measurement_hit_id_reader.read(io_meas_hit_id)) { meas_hit_ids.push_back(io_meas_hit_id); } @@ -199,10 +203,10 @@ TEST_P(TelescopeDetectorSimulation, telescope_detector_simulation) { // A thickness larger than 0.1 cm will flip the track direction of low // energy (or non-relativistic) particle due to the large scattering - const scalar thickness = 0.005f * unit::cm; + const scalar thickness = 0.005f * detray::unit::cm; - tel_det_config> tel_cfg{1000.f * unit::mm, - 1000.f * unit::mm}; + tel_det_config> tel_cfg{1000.f * detray::unit::mm, + 1000.f * detray::unit::mm}; tel_cfg.positions(positions).mat_thickness(thickness); const auto [detector, names] = create_telescope_detector(host_mr, tel_cfg); @@ -211,6 +215,11 @@ TEST_P(TelescopeDetectorSimulation, telescope_detector_simulation) { const std::string directory = std::get<0>(GetParam()) + "/"; std::filesystem::create_directory(directory); + // Field + using b_field_t = covfie::field; + const vector3 B{0.f, 0.f, 2.f * detray::unit::T}; + auto field = detray::bfield::create_const_field(B); + // Momentum const scalar mom = std::get<1>(GetParam()); @@ -219,12 +228,21 @@ TEST_P(TelescopeDetectorSimulation, telescope_detector_simulation) { constexpr unsigned int phi_steps{1u}; const vector3 ori{0.f, 0.f, 0.f}; const scalar theta = std::get<2>(GetParam()); - auto generator = uniform_track_generator>( - theta_steps, phi_steps, ori, mom, {theta, theta}, {0.f, 0.f}); + + // Track generator + using generator_type = + detray::uniform_track_generator; + generator_type::configuration gen_cfg{}; + gen_cfg.theta_steps(theta_steps); + gen_cfg.phi_steps(phi_steps); + gen_cfg.origin(ori); + gen_cfg.theta_range(theta, theta); + gen_cfg.p_mag(mom); + generator_type generator(gen_cfg); // Create smearer - measurement_smearer smearer(50.f * unit::um, - 50.f * unit::um); + measurement_smearer smearer(50.f * detray::unit::um, + 50.f * detray::unit::um); std::size_t n_events{1000u}; @@ -234,8 +252,8 @@ TEST_P(TelescopeDetectorSimulation, telescope_detector_simulation) { typename writer_type::config writer_cfg{smearer}; - auto sim = simulator( - n_events, detector, std::move(generator), std::move(writer_cfg), + auto sim = simulator( + n_events, detector, field, std::move(generator), std::move(writer_cfg), directory); // Lift step size constraints @@ -246,11 +264,11 @@ TEST_P(TelescopeDetectorSimulation, telescope_detector_simulation) { for (std::size_t i_event{0u}; i_event < n_events; i_event++) { - std::vector measurements; - auto measurement_reader = io::csv::make_measurement_reader( + std::vector measurements; + auto measurement_reader = traccc::io::csv::make_measurement_reader( directory + detail::get_event_filename(i_event, "-measurements.csv")); - io::csv::measurement io_measurement; + traccc::io::csv::measurement io_measurement; while (measurement_reader.read(io_measurement)) { measurements.push_back(io_measurement); } diff --git a/tests/cuda/test_ckf_sparse_tracks.cpp b/tests/cuda/test_ckf_sparse_tracks.cpp index 456ed48027..2e6761ddd7 100644 --- a/tests/cuda/test_ckf_sparse_tracks.cpp +++ b/tests/cuda/test_ckf_sparse_tracks.cpp @@ -75,9 +75,9 @@ TEST_P(CkfSparseTrackTests, Run) { tel_cfg.module_material(mat); tel_cfg.mat_thickness(thickness); tel_cfg.pilot_track(traj); - tel_cfg.bfield_vec(B); auto [host_det, name_map] = create_telescope_detector(mng_mr, tel_cfg); + auto field = detray::bfield::create_const_field(B); // Detector view object auto det_view = detray::get_data(host_det); @@ -86,17 +86,22 @@ TEST_P(CkfSparseTrackTests, Run) { * Generate simulation data ***************************/ - auto generator = + // Track generator + using generator_type = detray::random_track_generator(n_truth_tracks, origin, - origin_stddev, mom_range, - theta_range, phi_range); + uniform_gen_t>; + generator_type::configuration gen_cfg{}; + gen_cfg.n_tracks(n_truth_tracks); + gen_cfg.origin(origin); + gen_cfg.origin_stddev(origin_stddev); + gen_cfg.phi_range(phi_range[0], phi_range[1]); + gen_cfg.theta_range(theta_range[0], theta_range[1]); + gen_cfg.mom_range(mom_range[0], mom_range[1]); + generator_type generator(gen_cfg); // Smearing value for measurements traccc::measurement_smearer meas_smearer(smearing[0], smearing[1]); - - using generator_type = decltype(generator); using writer_type = traccc::smearing_writer>; @@ -106,10 +111,10 @@ TEST_P(CkfSparseTrackTests, Run) { const std::string path = name + "/"; const std::string full_path = io::data_directory() + path; std::filesystem::create_directories(full_path); - auto sim = - traccc::simulator( - n_events, host_det, std::move(generator), - std::move(smearer_writer_cfg), full_path); + auto sim = traccc::simulator( + n_events, host_det, field, std::move(generator), + std::move(smearer_writer_cfg), full_path); sim.run(); /***************************** @@ -198,8 +203,9 @@ TEST_P(CkfSparseTrackTests, Run) { mr.main, mr.host); // Run finding - track_candidates_cuda_buffer = device_finding( - det_view, navigation_buffer, measurements_buffer, seeds_buffer); + track_candidates_cuda_buffer = + device_finding(det_view, field, navigation_buffer, + measurements_buffer, seeds_buffer); traccc::track_candidate_container_types::host track_candidates_cuda = track_candidate_d2h(track_candidates_cuda_buffer); @@ -211,8 +217,8 @@ TEST_P(CkfSparseTrackTests, Run) { {{}, *(mr.host)}, {{}, *(mr.host), mr.host}}; // Run fitting - track_states_cuda_buffer = device_fitting(det_view, navigation_buffer, - track_candidates_cuda_buffer); + track_states_cuda_buffer = device_fitting( + det_view, field, navigation_buffer, track_candidates_cuda_buffer); traccc::track_state_container_types::host track_states_cuda = track_state_d2h(track_states_cuda_buffer); diff --git a/tests/cuda/test_kalman_filter.cpp b/tests/cuda/test_kalman_filter.cpp index ba94053c1c..343ef970e3 100644 --- a/tests/cuda/test_kalman_filter.cpp +++ b/tests/cuda/test_kalman_filter.cpp @@ -76,25 +76,31 @@ TEST_P(KalmanFittingTests, Run) { tel_cfg.module_material(mat); tel_cfg.mat_thickness(thickness); tel_cfg.pilot_track(traj); - tel_cfg.bfield_vec(B); auto [host_det, name_map] = create_telescope_detector(mng_mr, tel_cfg); + auto field = detray::bfield::create_const_field(B); /*************************** * Generate simulation data ***************************/ - auto generator = + // Track generator + using generator_type = detray::random_track_generator(n_truth_tracks, origin, - origin_stddev, mom_range, - theta_range, phi_range); + uniform_gen_t>; + generator_type::configuration gen_cfg{}; + gen_cfg.n_tracks(n_truth_tracks); + gen_cfg.origin(origin); + gen_cfg.origin_stddev(origin_stddev); + gen_cfg.phi_range(phi_range[0], phi_range[1]); + gen_cfg.theta_range(theta_range[0], theta_range[1]); + gen_cfg.mom_range(mom_range[0], mom_range[1]); + generator_type generator(gen_cfg); // Smearing value for measurements traccc::measurement_smearer meas_smearer(smearing[0], smearing[1]); - using generator_type = decltype(generator); using writer_type = traccc::smearing_writer>; @@ -104,10 +110,10 @@ TEST_P(KalmanFittingTests, Run) { const std::string path = name + "/"; const std::string full_path = io::data_directory() + path; std::filesystem::create_directories(full_path); - auto sim = - traccc::simulator( - n_events, host_det, std::move(generator), - std::move(smearer_writer_cfg), full_path); + auto sim = traccc::simulator( + n_events, host_det, field, std::move(generator), + std::move(smearer_writer_cfg), full_path); sim.run(); /*************** @@ -161,8 +167,8 @@ TEST_P(KalmanFittingTests, Run) { track_candidate_h2d(traccc::get_data(track_candidates)); // Run fitting - track_states_cuda_buffer = device_fitting(det_view, navigation_buffer, - track_candidates_cuda_buffer); + track_states_cuda_buffer = device_fitting( + det_view, field, navigation_buffer, track_candidates_cuda_buffer); traccc::track_state_container_types::host track_states_cuda = track_state_d2h(track_states_cuda_buffer); diff --git a/tests/cuda/test_spacepoint_formation.cpp b/tests/cuda/test_spacepoint_formation.cpp index a23913168a..9248ef6913 100644 --- a/tests/cuda/test_spacepoint_formation.cpp +++ b/tests/cuda/test_spacepoint_formation.cpp @@ -57,7 +57,7 @@ TEST(spacepoint_formation, cuda) { auto [det, name_map] = create_telescope_detector(mng_mr, tel_cfg); using device_detector_type = detray::detector>, - covfie::field_view, detray::device_container_types>; + detray::device_container_types>; // Surface lookup auto surfaces = det.surface_lookup();