Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Local include(s).
0009 #include "read_spacepoints.hpp"
0010 
0011 #include "read_measurements.hpp"
0012 #include "traccc/io/csv/make_hit_reader.hpp"
0013 #include "traccc/io/csv/make_measurement_hit_id_reader.hpp"
0014 
0015 // Project include(s).
0016 #include "traccc/definitions/primitives.hpp"
0017 
0018 // System include(s).
0019 #include <ranges>
0020 #include <stdexcept>
0021 #include <unordered_map>
0022 
0023 namespace traccc::io::csv {
0024 
0025 void read_spacepoints(
0026     edm::spacepoint_collection::host& spacepoints,
0027     edm::measurement_collection::host& measurements,
0028     std::string_view hit_filename, std::string_view meas_filename,
0029     std::string_view meas_hit_map_filename,
0030     const traccc::host_detector* detector,
0031     const traccc::detector_design_description::host* det_desc,
0032     const traccc::detector_conditions_description::host* det_cond,
0033     const bool sort_measurements) {
0034   // Read all measurements.
0035   const std::vector<measurement_id_type> new_idx_map =
0036       read_measurements(measurements, meas_filename, detector, det_desc,
0037                         det_cond, sort_measurements);
0038 
0039   // Measurement hit id reader
0040   auto mhid_reader =
0041       io::csv::make_measurement_hit_id_reader(meas_hit_map_filename);
0042   std::unordered_map<std::size_t, traccc::io::csv::measurement_hit_id>
0043       measurement_hit_ids;
0044   traccc::io::csv::measurement_hit_id io_mh_id;
0045   while (mhid_reader.read(io_mh_id)) {
0046     if (sort_measurements) {
0047       io_mh_id.measurement_id = new_idx_map[io_mh_id.measurement_id];
0048     }
0049     measurement_hit_ids.insert({io_mh_id.hit_id, io_mh_id});
0050   }
0051 
0052   // Construct the hit reader object.
0053   auto hit_reader = make_hit_reader(hit_filename);
0054 
0055   // Read the hits from the input file.
0056   hit iohit;
0057   while (hit_reader.read(iohit)) {
0058     // Find the index of the measurement that this hit/spacepoint belongs
0059     // to. Which may not be valid, as some simulated hits are not associated
0060     // with a measurement.
0061     const auto measurement_id_it = measurement_hit_ids.find(spacepoints.size());
0062     const unsigned int measurement_index =
0063         (measurement_id_it != measurement_hit_ids.end())
0064             ? static_cast<unsigned int>(
0065                   measurement_id_it->second.measurement_id)
0066             : static_cast<unsigned int>(-1);
0067 
0068     // Create a new spacepoint for the SoA container.
0069     spacepoints.push_back(
0070         {measurement_index,
0071          edm::spacepoint_collection::host::INVALID_MEASUREMENT_INDEX,
0072          {iohit.tx, iohit.ty, iohit.tz},
0073          0.f,
0074          0.f});
0075   }
0076 }
0077 
0078 }  // namespace traccc::io::csv