Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2024-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Project include(s).
0011 #include "traccc/edm/measurement_collection.hpp"
0012 #include "traccc/edm/particle.hpp"
0013 #include "traccc/edm/silicon_cell_collection.hpp"
0014 #include "traccc/edm/silicon_cluster_collection.hpp"
0015 #include "traccc/edm/track_container.hpp"
0016 #include "traccc/geometry/detector.hpp"
0017 #include "traccc/geometry/detector_conditions_description.hpp"
0018 #include "traccc/geometry/host_detector.hpp"
0019 #include "traccc/io/csv/cell.hpp"
0020 #include "traccc/io/csv/hit.hpp"
0021 #include "traccc/io/csv/measurement.hpp"
0022 #include "traccc/io/csv/measurement_hit_id.hpp"
0023 #include "traccc/io/csv/particle.hpp"
0024 #include "traccc/io/data_format.hpp"
0025 #include "traccc/utils/seed_generator.hpp"
0026 
0027 // Vecmem include(s).
0028 #include <vecmem/memory/memory_resource.hpp>
0029 
0030 // System include(s).
0031 #include <map>
0032 #include <string>
0033 
0034 namespace traccc {
0035 
0036 struct event_data {
0037  public:
0038   event_data() = delete;
0039 
0040   /// Event data constructor
0041   ///
0042   /// @param[in] event_dir Event data directory
0043   /// data
0044   /// @param[in] event_id  Event id
0045   /// @param[in] use_acts_geom_source  Use acts geometry source
0046   /// @param[in] det       detray detector
0047   /// @param[in] format    file format
0048   /// @param[in] include_silicon_cells Use silicon cell data in object
0049   /// construction
0050   ///
0051   event_data(const std::string& event_dir, const std::size_t event_id,
0052              vecmem::memory_resource& resource,
0053              bool use_acts_geom_source = false,
0054              const host_detector* det = nullptr,
0055              data_format format = data_format::csv,
0056              bool include_silicon_cells = false);
0057 
0058   /// Fill the member variables related to CCA
0059   ///
0060   /// @param[in] cells cell EDM
0061   /// @param[in] cca_clusters cluster EDM from CCL algorithm
0062   /// @param[in] cca_measurements measurement EDM from measurement creation
0063   /// @param[in] det_desc    Detector design description
0064   ///
0065   void fill_cca_result(
0066       const edm::silicon_cell_collection::host& cells,
0067       const edm::silicon_cluster_collection::host& cca_clusters,
0068       const edm::measurement_collection::host& cca_measurements,
0069       const detector_conditions_description::host& det_cond);
0070 
0071   /// Generate truth candidate used for truth fitting
0072   ///
0073   /// @param[out] truth_candidates Truth candidates
0074   /// @param[in] sg Seed generator for fitting
0075   /// @param[in] resource vecmem memory resource
0076   ///
0077   template <typename detector_type>
0078   void generate_truth_candidates(
0079       edm::track_container<default_algebra>::host& truth_candidates,
0080       edm::measurement_collection::host& truth_measurements,
0081       seed_generator<detector_type>& sg, vecmem::memory_resource& resource,
0082       float pt_cut = 0.f) {
0083     for (auto const& [ptc, measurements] : m_ptc_to_meas_map) {
0084       const auto& param = m_meas_to_param_map.at(measurements[0]);
0085       const free_track_parameters<> free_param(param.first, 0.f, param.second,
0086                                                ptc.charge);
0087 
0088       auto ptc_particle =
0089           detail::particle_from_pdg_number<scalar>(ptc.particle_type);
0090 
0091       if (ptc_particle.pdg_num() == 0) {
0092         // TODO: Add some debug logging here.
0093         continue;
0094       } else if (free_param.pT(ptc_particle.charge()) <= pt_cut) {
0095         continue;
0096       }
0097 
0098       auto seed_params =
0099           sg(measurements[0].surface_link(), free_param, ptc_particle);
0100 
0101       // Record the measurements, and remember their indices.
0102       vecmem::vector<edm::track_constituent_link> meas_links{&resource};
0103       truth_measurements.reserve(truth_measurements.size() +
0104                                  measurements.size());
0105       meas_links.reserve(measurements.size());
0106       for (const auto& meas : measurements) {
0107         meas_links.push_back(
0108             {edm::track_constituent_link::measurement,
0109              static_cast<unsigned int>(truth_measurements.size())});
0110         truth_measurements.push_back(meas);
0111       }
0112 
0113       // Record the truth track candidate.
0114       edm::track_collection<traccc::default_algebra>::host::object_type track;
0115       track.params() = seed_params;
0116       track.constituent_links() = meas_links;
0117       truth_candidates.tracks.push_back(track);
0118     }
0119   }
0120 
0121   /// All internally defined measurements
0122   edm::measurement_collection::host m_measurements;
0123   /// Proxy type for the following maps
0124   using measurement_proxy = edm::measurement_collection::host::object_type;
0125 
0126   // Measurement map
0127   std::map<measurement_id_type, measurement_proxy> m_measurement_map;
0128   // Particle map
0129   std::map<particle_id, particle> m_particle_map;
0130   // Measurement to the contributing particle map
0131   std::map<measurement_proxy, std::map<particle, std::size_t>>
0132       m_meas_to_ptc_map;
0133   // CCA measurement to the contributing particle map
0134   std::map<measurement_proxy, std::map<particle, std::size_t>>
0135       m_found_meas_to_ptc_map;
0136   // Particle to its Measurements map
0137   std::map<particle, std::vector<measurement_proxy>> m_ptc_to_meas_map;
0138   // Measurement to its track parameter map
0139   std::map<measurement_proxy, std::pair<point3, point3>> m_meas_to_param_map;
0140   // CCA measurement to its track parameter map
0141   std::map<measurement_proxy, std::pair<point3, point3>>
0142       m_found_meas_to_param_map;
0143   // Cell to particle map
0144   std::map<io::csv::cell, particle> m_cell_to_particle_map;
0145 
0146   // Input arguments
0147   const std::string m_event_dir;
0148   const std::size_t m_event_id;
0149   std::reference_wrapper<vecmem::memory_resource> m_mr;
0150 
0151  private:
0152   void setup_csv(bool use_acts_geom_source, const host_detector* det,
0153                  bool include_silicon_cells);
0154 };
0155 
0156 }  // namespace traccc