Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #include "traccc/gbts_seeding/gbts_seeding_config.hpp"
0009 
0010 #include <algorithm>
0011 #include <climits>
0012 #include <ranges>
0013 
0014 namespace traccc {
0015 
0016 // binTables contains pairs of linked layer-eta bins
0017 // the layerInfo should really be calculated from the geoIDBinning
0018 // GeoIDBinning pair is detray geo ID and bin index (corrisponding to the
0019 // layers in layerInfo) minPt in MeV
0020 bool gbts_seedfinder_config::setLinkingScheme(
0021     const std::vector<std::pair<unsigned int, std::vector<unsigned int>>>&
0022         input_binTables,
0023     const device::gbts_layerInfo input_layerInfo,
0024     std::vector<std::pair<uint64_t, short>>& detrayGeoIDBinning,
0025     const float minPt = 900.0f,
0026     std::unique_ptr<const traccc::Logger> callers_logger =
0027         getDummyLogger().clone()) {
0028   TRACCC_LOCAL_LOGGER(std::move(callers_logger));
0029   // copy layer-eta binning infomation
0030   layerInfo = input_layerInfo;
0031   // unroll binTables
0032   for (std::pair<unsigned int, std::vector<unsigned int>> binPairs :
0033        input_binTables) {
0034     for (unsigned int bin2 : binPairs.second) {
0035       binTables.push_back(std::make_pair(binPairs.first, bin2));
0036     }
0037   }
0038 
0039   for (std::pair<unsigned int, unsigned int> lI : layerInfo.info)
0040     n_eta_bins = std::max(n_eta_bins, lI.first + lI.second);
0041 
0042   // bin by volume
0043   std::ranges::sort(detrayGeoIDBinning, [](const std::pair<uint64_t, short> a,
0044                                            const std::pair<uint64_t, short> b) {
0045     return a.first > b.first;
0046   });
0047 
0048   unsigned int largest_volume_index =
0049       detray::geometry::identifier(detrayGeoIDBinning[0].first).volume();
0050   auto current_volume = static_cast<short>(largest_volume_index);
0051   if (largest_volume_index >= SHRT_MAX) {
0052     TRACCC_ERROR(
0053         "volume index to large to fit in type-short GBTS volume to layer "
0054         "map");
0055     return false;
0056   }
0057 
0058   bool layerChange = false;
0059   short current_layer = detrayGeoIDBinning[0].second;
0060 
0061   unsigned int split_volumes = 0;
0062   std::vector<std::pair<short, unsigned int>> volumeToLayerMap_unordered;
0063   detrayGeoIDBinning.push_back(
0064       std::make_pair(UINT_MAX, -1));  // end-of-vector element
0065   std::vector<std::pair<unsigned int, unsigned int>> surfacesInVolume;
0066   for (std::pair<uint64_t, short> geoIDLayerPair : detrayGeoIDBinning) {
0067     detray::geometry::identifier geo_id(geoIDLayerPair.first);
0068     if (current_volume != static_cast<short>(geo_id.volume())) {
0069       // reached the end of this volume so add it to the maps
0070       short bin = current_layer;
0071       if (layerChange) {
0072         split_volumes++;
0073         bin = -1 * static_cast<short>(
0074                        surfaceToLayerMap.size() +
0075                        1);  // start of this volume's surfaces in the map + 1
0076         for (std::pair<unsigned int, unsigned int> pair : surfacesInVolume)
0077           surfaceToLayerMap.push_back(pair);
0078       }
0079       volumeToLayerMap_unordered.push_back(std::make_pair(
0080           bin, current_volume));  // layerIdx if not split, begin-index in
0081                                   // the surface map otherwise
0082 
0083       current_volume = static_cast<short>(geo_id.volume());
0084       current_layer = geoIDLayerPair.second;
0085       layerChange = false;
0086       surfacesInVolume.clear();
0087     }
0088     // is volume encompassed by a layer
0089     layerChange |= (current_layer != geoIDLayerPair.second);
0090 
0091     // save surfaces incase volume is not encommpassed by a layer
0092     surfacesInVolume.push_back(
0093         std::make_pair(static_cast<unsigned int>(geo_id.index()),
0094                        static_cast<unsigned int>(geoIDLayerPair.second)));
0095   }
0096   // make volume by layer map
0097   volumeToLayerMap.resize(largest_volume_index + 1);
0098   for (unsigned int i = 0; i < largest_volume_index + 1; ++i)
0099     volumeToLayerMap.push_back(SHRT_MAX);
0100   for (std::pair<short, unsigned int> vLpair : volumeToLayerMap_unordered)
0101     volumeToLayerMap[vLpair.second] = vLpair.first;
0102   // scale cuts
0103   float ptScale = 900.0f / minPt;
0104   gbts_dphi_window_params.min_delta_phi *= ptScale;
0105   gbts_dphi_window_params.dphi_coeff *= ptScale;
0106   gbts_dphi_window_params.min_delta_phi_low_dr *= ptScale;
0107   gbts_dphi_window_params.dphi_coeff_low_dr *= ptScale;
0108   gbts_make_graph_edges_params.max_Kappa *= ptScale;
0109 
0110   // contianers sizes
0111   nLayers = static_cast<unsigned int>(layerInfo.type.size());
0112 
0113   TRACCC_INFO("volume layer map has " << volumeToLayerMap_unordered.size()
0114                                       << " volumes");
0115   TRACCC_INFO("The maxium volume index in the layer map is "
0116               << volumeToLayerMap.size());
0117   TRACCC_INFO("surface to layer map has " << surfaceToLayerMap.size()
0118                                           << " geo IDs from " << split_volumes
0119                                           << " multi-layer volumes");
0120   TRACCC_INFO("layer info found for " << nLayers << " layers");
0121   TRACCC_INFO(binTables.size() << " linked layer-eta bins for GBTS");
0122 
0123   if (nLayers == 0) {
0124     TRACCC_ERROR("no layers input");
0125     return false;
0126   } else if (volumeToLayerMap.size() == 0) {
0127     TRACCC_ERROR("empty volume to layer map");
0128     return false;
0129   } else if (surfaceToLayerMap.size() > SHRT_MAX) {
0130     TRACCC_ERROR("surface to layer map is to large");
0131     return false;
0132   }
0133   return true;
0134 }
0135 
0136 }  // namespace traccc