Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:15

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2023-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Project include(s).
0009 #include "traccc/definitions/common.hpp"
0010 #include "traccc/definitions/primitives.hpp"
0011 #include "traccc/examples/make_magnetic_field.hpp"
0012 #include "traccc/examples/print_fitted_tracks_statistics.hpp"
0013 #include "traccc/fitting/kalman_fitting_algorithm.hpp"
0014 #include "traccc/geometry/detector.hpp"
0015 #include "traccc/io/read_detector.hpp"
0016 #include "traccc/io/utils.hpp"
0017 #include "traccc/options/detector.hpp"
0018 #include "traccc/options/input_data.hpp"
0019 #include "traccc/options/magnetic_field.hpp"
0020 #include "traccc/options/performance.hpp"
0021 #include "traccc/options/program_options.hpp"
0022 #include "traccc/options/track_fitting.hpp"
0023 #include "traccc/options/track_propagation.hpp"
0024 #include "traccc/resolution/fitting_performance_writer.hpp"
0025 #include "traccc/utils/propagation.hpp"
0026 #include "traccc/utils/seed_generator.hpp"
0027 
0028 // VecMem include(s).
0029 #include <vecmem/memory/host_memory_resource.hpp>
0030 #include <vecmem/utils/copy.hpp>
0031 
0032 // System include(s).
0033 #include <cstdlib>
0034 #include <exception>
0035 #include <iomanip>
0036 #include <iostream>
0037 
0038 using namespace traccc;
0039 namespace po = boost::program_options;
0040 
0041 // The main routine
0042 //
0043 int main(int argc, char* argv[]) {
0044   std::unique_ptr<const traccc::Logger> ilogger = traccc::getDefaultLogger(
0045       "TracccExampleTruthFitting", traccc::Logging::Level::INFO);
0046 
0047   TRACCC_LOCAL_LOGGER(std::move(ilogger));
0048 
0049   // Program options.
0050   traccc::opts::detector detector_opts;
0051   traccc::opts::magnetic_field bfield_opts;
0052   traccc::opts::input_data input_opts;
0053   traccc::opts::track_propagation propagation_opts;
0054   traccc::opts::track_fitting fitting_opts;
0055   traccc::opts::performance performance_opts;
0056   traccc::opts::program_options program_opts{
0057       "Truth Track Fitting on the Host",
0058       {detector_opts, bfield_opts, input_opts, propagation_opts, fitting_opts,
0059        performance_opts},
0060       argc,
0061       argv,
0062       logger().cloneWithSuffix("Options")};
0063 
0064   // Memory resources used by the application.
0065   vecmem::host_memory_resource host_mr;
0066   // Copy obejct
0067   vecmem::copy copy;
0068 
0069   // Performance writer
0070   traccc::fitting_performance_writer fit_performance_writer(
0071       traccc::fitting_performance_writer::config{},
0072       logger().clone("FittingPerformanceWriter"));
0073 
0074   /*****************************
0075    * Build a geometry
0076    *****************************/
0077 
0078   // B field value
0079   const auto field = traccc::details::make_magnetic_field(bfield_opts);
0080 
0081   // Read the detector
0082   traccc::host_detector polymorphic_detector;
0083   traccc::io::read_detector(
0084       polymorphic_detector, host_mr, detector_opts.detector_file,
0085       detector_opts.material_file, detector_opts.grid_file);
0086 
0087   /*****************************
0088    * Do the reconstruction
0089    *****************************/
0090 
0091   /// Standard deviations for seed track parameters
0092   static constexpr std::array<double, e_bound_size> stddevs = {
0093       0.03 * traccc::unit<double>::mm,
0094       0.03 * traccc::unit<double>::mm,
0095       0.017,
0096       0.017,
0097       0.001 / traccc::unit<double>::GeV,
0098       1. * traccc::unit<double>::ns};
0099 
0100   // Fitting algorithm object
0101   traccc::fitting_config fit_cfg(fitting_opts);
0102   fit_cfg.propagation = propagation_opts;
0103 
0104   traccc::host::kalman_fitting_algorithm host_fitting(
0105       fit_cfg, host_mr, copy, logger().clone("FittingAlg"));
0106 
0107   // Iterate over events
0108   for (auto event = input_opts.skip;
0109        event < input_opts.events + input_opts.skip; ++event) {
0110     // Truth Track Candidates
0111     traccc::event_data evt_data(
0112         input_opts.directory, event, host_mr, input_opts.use_acts_geom_source,
0113         &polymorphic_detector, input_opts.format, false);
0114 
0115     traccc::edm::measurement_collection::host truth_measurements{host_mr};
0116     traccc::edm::track_container<traccc::default_algebra>::host
0117         truth_track_candidates{host_mr};
0118 
0119     host_detector_visitor<detector_type_list>(
0120         polymorphic_detector, [&]<typename detector_traits_t>(
0121                                   const typename detector_traits_t::host& det) {
0122           typename traccc::seed_generator<
0123               typename detector_traits_t::host>::config seed_cfg{};
0124           seed_cfg.initial_sigmas = stddevs;
0125 
0126           // Seed generator
0127           traccc::seed_generator<typename detector_traits_t::host> sg(det,
0128                                                                       seed_cfg);
0129           evt_data.generate_truth_candidates(truth_track_candidates,
0130                                              truth_measurements, sg, host_mr);
0131         });
0132     truth_track_candidates.measurements = vecmem::get_data(truth_measurements);
0133 
0134     // Run fitting
0135     auto track_states = host_fitting(
0136         polymorphic_detector, field,
0137         traccc::edm::track_container<traccc::default_algebra>::const_data(
0138             truth_track_candidates));
0139 
0140     details::print_fitted_tracks_statistics(track_states, logger());
0141 
0142     const std::size_t n_fitted_tracks = track_states.tracks.size();
0143 
0144     if (performance_opts.run) {
0145       for (unsigned int i = 0; i < n_fitted_tracks; i++) {
0146         host_detector_visitor<detector_type_list>(
0147             polymorphic_detector,
0148             [&]<typename detector_traits_t>(
0149                 const typename detector_traits_t::host& det) {
0150               fit_performance_writer.write(track_states.tracks.at(i),
0151                                            track_states.states,
0152                                            truth_measurements, det, evt_data);
0153             });
0154       }
0155     }
0156   }
0157 
0158   if (performance_opts.run) {
0159     fit_performance_writer.finalize();
0160   }
0161 
0162   return EXIT_SUCCESS;
0163 }