Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-05 08:17:33

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Utilities/Logger.hpp"
0012 
0013 #include <cstdint>
0014 #include <memory>
0015 #include <optional>
0016 #include <span>
0017 #include <unordered_map>
0018 #include <unordered_set>
0019 #include <vector>
0020 
0021 namespace Acts::Experimental {
0022 
0023 /// Builds the GBTS layer connection table from observed track hits.
0024 class GbtsLayerConnectionTool {
0025  public:
0026   /// Struct to hold r and z bounds for a given detector layer
0027   struct LayerDescription {
0028     /// Constructor for filling detector layer information
0029     /// @param minR_ minimum radius of layer
0030     /// @param maxR_ maximum radius of layer
0031     /// @param minZ_ minimum z coordinate of layer
0032     /// @param maxZ_ maximum z coordinate of layer
0033     /// @param gbtsId_ GBTS id of layer
0034     LayerDescription(float minR_, float maxR_, float minZ_, float maxZ_,
0035                      std::int32_t gbtsId_);
0036 
0037     /// Minimum radius
0038     float minR{};
0039     /// Maximum radius
0040     float maxR{};
0041     /// Minimum z coordinate
0042     float minZ{};
0043     /// Maximum z coordinate
0044     float maxZ{};
0045     /// layer ID
0046     std::int32_t gbtsId{};
0047   };
0048 
0049   /// Configuration for the layer connection tool
0050   struct Config {
0051     /// List of detector layers
0052     std::vector<LayerDescription> detectorGeometry{};
0053 
0054     // tolerances used for assigning layer ID's
0055 
0056     /// Tolerance on minimum z value
0057     float zMinTol = 0.2340f;
0058     /// Tolerance on maximum z value
0059     float zMaxTol = 0.2340f;
0060     /// Tolerance on minimum radius value
0061     float rMinTol = 2.5337f;
0062     /// Tolerance on maximum radius value
0063     float rMaxTol = 2.5337f;
0064 
0065     /// Symmeterize layer connection table
0066     bool doSymmetrization = false;
0067     /// Minimum probability cut applied to layer transitions
0068     float probThreshold = -1;
0069   };
0070 
0071   /// Container for track layer hit information
0072   struct HitCoordinates {
0073     /// Radius value of hit
0074     float r{};
0075     /// z value of hit
0076     float z{};
0077   };
0078 
0079   /// pair of layer transitions
0080   using LayerIdPair = std::pair<std::int32_t, std::int32_t>;
0081 
0082   /// Hash id used for unordered sets and maps
0083   struct LayerIdPairHash {
0084     /// operator to allow the lookup of std::pair objects
0085     /// in unordered maps or sets
0086     /// @param pair Layer transition pair
0087     /// @return hash id
0088     std::size_t operator()(const LayerIdPair& pair) const noexcept {
0089       const auto h1 = std::hash<std::int32_t>{}(pair.first);
0090       const auto h2 = std::hash<std::int32_t>{}(pair.second);
0091 
0092       return h1 ^ (h2 << 1);
0093     }
0094   };
0095 
0096   /// Container of pairs of layer transitions
0097   using LayerIdPairs = std::unordered_set<LayerIdPair, LayerIdPairHash>;
0098   /// Map of layer pair transitions, quantifying the amount of times they occur
0099   using LayerIdPairMap =
0100       std::unordered_map<LayerIdPair, std::uint32_t, LayerIdPairHash>;
0101 
0102   /// @param config Tool configuration
0103   /// @param logger The Acts logger
0104   explicit GbtsLayerConnectionTool(
0105       const Config& config,
0106       std::unique_ptr<const Logger> logger =
0107           getDefaultLogger("GbtsLayerConnectionTool", Logging::Level::INFO));
0108 
0109   /// converts layer hits to layer transitions
0110   /// @param track the layer hits of a particle
0111   void addTrack(std::span<const HitCoordinates> track);
0112 
0113   /// Creates the connection table
0114   /// @return layer pairs
0115   GbtsLayerConnectionTool::LayerIdPairs createConnectionTable() const;
0116 
0117  private:
0118   /// returns the Acts logger
0119   const Logger& logger() const { return *m_logger; }
0120 
0121   /// Finds the Gbts Coordinate of a given hits coordinate
0122   /// @param hit the coordinates of the particle hit on a layer
0123   /// @return gbts coordinate
0124   std::optional<std::int32_t> findGbtsIdByCoord(
0125       const HitCoordinates& hit) const;
0126 
0127   /// gets the index to the vector of detector layers via an GBTS id
0128   /// @param gbtsId Gbts Id of layer
0129   /// @return detector layer index
0130   std::uint32_t getIndexByGbtsId(std::int32_t gbtsId) const;
0131 
0132   /// finds the opposide layer of a symmetrical detector with a given reference
0133   /// layer
0134   /// @param layer the detector layer
0135   /// @return oppsite side layers gbts id
0136   std::optional<std::int32_t> oppositeSideLayer(std::int32_t layer) const;
0137 
0138   /// Config for layer connection tool
0139   Config m_cfg;
0140   /// Acts logger
0141   std::unique_ptr<const Acts::Logger> m_logger;
0142   /// map of layer transition pairs
0143   LayerIdPairMap m_layerPairs{};
0144   /// total number of tracks used to train the table on
0145   std::uint32_t m_totalTracks = 0;
0146 };
0147 
0148 }  // namespace Acts::Experimental