|
| 1 | +/** TRACCC library, part of the ACTS project (R&D line) |
| 2 | + * |
| 3 | + * (c) 2023 CERN for the benefit of the ACTS project |
| 4 | + * |
| 5 | + * Mozilla Public License Version 2.0 |
| 6 | + */ |
| 7 | + |
| 8 | +// Project include(s). |
| 9 | +#include "traccc/definitions/common.hpp" |
| 10 | +#include "traccc/definitions/primitives.hpp" |
| 11 | +#include "traccc/fitting/fitting_algorithm.hpp" |
| 12 | +#include "traccc/fitting/kalman_filter/kalman_fitter.hpp" |
| 13 | +#include "traccc/io/read_geometry.hpp" |
| 14 | +#include "traccc/io/read_measurements.hpp" |
| 15 | +#include "traccc/io/utils.hpp" |
| 16 | +#include "traccc/options/common_options.hpp" |
| 17 | +#include "traccc/options/handle_argument_errors.hpp" |
| 18 | +#include "traccc/options/propagation_options.hpp" |
| 19 | +#include "traccc/resolution/fitting_performance_writer.hpp" |
| 20 | +#include "traccc/utils/seed_generator.hpp" |
| 21 | + |
| 22 | +// Detray include(s). |
| 23 | +#include "detray/core/detector.hpp" |
| 24 | +#include "detray/core/detector_metadata.hpp" |
| 25 | +#include "detray/detectors/bfield.hpp" |
| 26 | +#include "detray/io/common/detector_reader.hpp" |
| 27 | +#include "detray/propagator/navigator.hpp" |
| 28 | +#include "detray/propagator/propagator.hpp" |
| 29 | +#include "detray/propagator/rk_stepper.hpp" |
| 30 | + |
| 31 | +// VecMem include(s). |
| 32 | +#include <vecmem/memory/host_memory_resource.hpp> |
| 33 | + |
| 34 | +// System include(s). |
| 35 | +#include <exception> |
| 36 | +#include <iomanip> |
| 37 | +#include <iostream> |
| 38 | + |
| 39 | +using namespace traccc; |
| 40 | +namespace po = boost::program_options; |
| 41 | + |
| 42 | +// The main routine |
| 43 | +// |
| 44 | +int main(int argc, char* argv[]) { |
| 45 | + // Set up the program options |
| 46 | + po::options_description desc("Allowed options"); |
| 47 | + |
| 48 | + // Add options |
| 49 | + desc.add_options()("help,h", "Give some help with the program's options"); |
| 50 | + traccc::common_options common_opts(desc); |
| 51 | + traccc::propagation_options<scalar> propagation_opts(desc); |
| 52 | + |
| 53 | + po::variables_map vm; |
| 54 | + po::store(po::parse_command_line(argc, argv, desc), vm); |
| 55 | + |
| 56 | + // Check errors |
| 57 | + traccc::handle_argument_errors(vm, desc); |
| 58 | + |
| 59 | + // Read options |
| 60 | + common_opts.read(vm); |
| 61 | + propagation_opts.read(vm); |
| 62 | + |
| 63 | + std::cout << "Running " << argv[0] << " " << common_opts.input_directory |
| 64 | + << " " << common_opts.events << std::endl; |
| 65 | + |
| 66 | + /// Type declarations |
| 67 | + using host_detector_type = detray::detector<detray::default_metadata, |
| 68 | + detray::host_container_types>; |
| 69 | + |
| 70 | + using b_field_t = covfie::field<detray::bfield::const_bknd_t>; |
| 71 | + using rk_stepper_type = |
| 72 | + detray::rk_stepper<b_field_t::view_t, traccc::transform3, |
| 73 | + detray::constrained_step<>>; |
| 74 | + |
| 75 | + using host_navigator_type = detray::navigator<const host_detector_type>; |
| 76 | + using host_fitter_type = |
| 77 | + traccc::kalman_fitter<rk_stepper_type, host_navigator_type>; |
| 78 | + |
| 79 | + // Memory resources used by the application. |
| 80 | + vecmem::host_memory_resource host_mr; |
| 81 | + |
| 82 | + // Performance writer |
| 83 | + traccc::fitting_performance_writer fit_performance_writer( |
| 84 | + traccc::fitting_performance_writer::config{}); |
| 85 | + |
| 86 | + /***************************** |
| 87 | + * Build a geometry |
| 88 | + *****************************/ |
| 89 | + |
| 90 | + // B field value and its type |
| 91 | + // @TODO: Set B field as argument |
| 92 | + const traccc::vector3 B{0, 0, 2 * detray::unit<traccc::scalar>::T}; |
| 93 | + auto field = detray::bfield::create_const_field(B); |
| 94 | + |
| 95 | + // Read the detector |
| 96 | + detray::io::detector_reader_config reader_cfg{}; |
| 97 | + reader_cfg |
| 98 | + .add_file(traccc::io::data_directory() + common_opts.detector_file) |
| 99 | + .add_file(traccc::io::data_directory() + common_opts.material_file) |
| 100 | + .add_file(traccc::io::data_directory() + common_opts.grid_file); |
| 101 | + |
| 102 | + const auto [host_det, names] = |
| 103 | + detray::io::read_detector<host_detector_type>(host_mr, reader_cfg); |
| 104 | + |
| 105 | + /***************************** |
| 106 | + * Do the reconstruction |
| 107 | + *****************************/ |
| 108 | + |
| 109 | + /// Standard deviations for seed track parameters |
| 110 | + static constexpr std::array<scalar, e_bound_size> stddevs = { |
| 111 | + 0.03 * detray::unit<scalar>::mm, |
| 112 | + 0.03 * detray::unit<scalar>::mm, |
| 113 | + 0.017, |
| 114 | + 0.017, |
| 115 | + 0.01 / detray::unit<scalar>::GeV, |
| 116 | + 1 * detray::unit<scalar>::ns}; |
| 117 | + |
| 118 | + // Fitting algorithm object |
| 119 | + typename traccc::fitting_algorithm<host_fitter_type>::config_type fit_cfg; |
| 120 | + fit_cfg.step_constraint = propagation_opts.step_constraint; |
| 121 | + traccc::fitting_algorithm<host_fitter_type> host_fitting(fit_cfg); |
| 122 | + |
| 123 | + // Seed generator |
| 124 | + traccc::seed_generator<host_detector_type> sg(host_det, stddevs); |
| 125 | + |
| 126 | + // Iterate over events |
| 127 | + for (unsigned int event = common_opts.skip; |
| 128 | + event < common_opts.events + common_opts.skip; ++event) { |
| 129 | + |
| 130 | + // Truth Track Candidates |
| 131 | + traccc::event_map2 evt_map2(event, common_opts.input_directory, |
| 132 | + common_opts.input_directory, |
| 133 | + common_opts.input_directory); |
| 134 | + |
| 135 | + traccc::track_candidate_container_types::host truth_track_candidates = |
| 136 | + evt_map2.generate_truth_candidates(sg, host_mr); |
| 137 | + |
| 138 | + // Run fitting |
| 139 | + auto track_states = |
| 140 | + host_fitting(host_det, field, truth_track_candidates); |
| 141 | + |
| 142 | + std::cout << "Number of fitted tracks: " << track_states.size() |
| 143 | + << std::endl; |
| 144 | + |
| 145 | + const unsigned int n_fitted_tracks = track_states.size(); |
| 146 | + |
| 147 | + if (common_opts.check_performance) { |
| 148 | + |
| 149 | + for (unsigned int i = 0; i < n_fitted_tracks; i++) { |
| 150 | + const auto& trk_states_per_track = track_states.at(i).items; |
| 151 | + |
| 152 | + const auto& fit_info = track_states[i].header; |
| 153 | + |
| 154 | + fit_performance_writer.write(trk_states_per_track, fit_info, |
| 155 | + host_det, evt_map2); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + if (common_opts.check_performance) { |
| 161 | + fit_performance_writer.finalize(); |
| 162 | + } |
| 163 | + |
| 164 | + return 1; |
| 165 | +} |
0 commit comments