Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:42

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Surfaces/SurfaceBounds.hpp"
0012 #include "Acts/Utilities/BinningData.hpp"
0013 
0014 #include <string>
0015 #include <tuple>
0016 
0017 #include <nlohmann/json.hpp>
0018 
0019 namespace Acts::DetrayJsonHelper {
0020 
0021 /// @brief Helper function to switch keys from ACTS to detray
0022 ///
0023 /// DETRAY types @todo change to detray imports when available
0024 ///    annulus2 = 0u,
0025 ///    cuboid3 = 1u,
0026 ///    cylinder2 = 2u,
0027 ///    cylinder3 = 3u,
0028 ///    portal_cylinder2 = 4u,
0029 ///    rectangle2 = 5u,
0030 ///    ring2 = 6u,
0031 ///    trapezoid2 = 7u,
0032 ///    cell_wire = 8u,
0033 ///    straw_wire = 9u,
0034 ///    single1 = 10u,
0035 ///    single2 = 11u,
0036 ///    single3 = 12u,
0037 ///    unknown = 13u
0038 ///
0039 /// @param sBounds is the surface bounds type
0040 /// @param portal is the flag for conversion into detray portal format
0041 ///
0042 /// @return type and value array in detray format
0043 inline static std::tuple<unsigned int, std::vector<ActsScalar>> maskFromBounds(
0044     const Acts::SurfaceBounds& sBounds, bool portal = false) {
0045   auto bType = sBounds.type();
0046   auto bValues = sBounds.values();
0047   // Return value
0048   unsigned int type = 13u;
0049   std::vector<double> boundaries = bValues;
0050   // Special treatment for some portals
0051   if (portal && bType == SurfaceBounds::BoundsType::eCylinder) {
0052     boundaries = {bValues[0u], -bValues[1u], bValues[1u]};
0053     type = 4u;
0054   } else {
0055     switch (bType) {
0056       case SurfaceBounds::BoundsType::eAnnulus: {
0057         type = 0u;
0058       } break;
0059       case SurfaceBounds::BoundsType::eRectangle: {
0060         type = 5u;
0061         // ACTS: eMinX = 0, eMinY = 1, eMaxX = 2, eMaxY = 3,
0062         // detray: e_half_x, e_half_y
0063         boundaries = {0.5 * (bValues[2] - bValues[0]),
0064                       0.5 * (bValues[3] - bValues[1])};
0065       } break;
0066       case SurfaceBounds::BoundsType::eCylinder: {
0067         boundaries = {bValues[0u], -bValues[1u], bValues[1u]};
0068         type = 2u;
0069       } break;
0070       case SurfaceBounds::BoundsType::eTrapezoid: {
0071         type = 7u;
0072         boundaries = {bValues[0u], bValues[1u], bValues[2u],
0073                       1 / (2 * bValues[2u])};
0074       } break;
0075       case SurfaceBounds::BoundsType::eDisc: {
0076         boundaries = {bValues[0u], bValues[1u]};
0077         type = 6u;
0078       } break;
0079       default:
0080         break;
0081     }
0082   }
0083   return std::tie(type, boundaries);
0084 }
0085 
0086 /// @brief add volume link
0087 ///
0088 /// @param jSurface [in,out] is the json object to be patched
0089 /// @param vLink is the volume link to be added
0090 inline static void addVolumeLink(nlohmann::json& jSurface, int vLink) {
0091   jSurface["volume_link"] = vLink;
0092 }
0093 
0094 /// Determine the acceleration link from a grid
0095 ///
0096 ///
0097 ///   brute_force = 0u,      // try all
0098 ///   cartesian2_grid = 1u,  // rectangle, trapezoid, (triangle) grids
0099 ///   cuboid3_grid = 2u,     // cuboid grid
0100 ///   polar2_grid = 3u,      // ring/disc, annulus grids
0101 ///   cylinder2_grid = 4u,   // 2D cylinder grid
0102 ///   cylinder3_grid = 5u,   // 3D cylinder grid
0103 ///
0104 /// @param casts are the grid axes cast types
0105 ///
0106 /// @return the acceleration link idnetifier
0107 template <typename binning_values_t>
0108 inline static std::size_t accelerationLink(const binning_values_t& casts) {
0109   // Default is `brute_force`
0110   std::size_t accLink = 0u;
0111   if (casts.size() == 2u) {
0112     if (casts[0u] == binX && casts[1u] == binY) {
0113       accLink = 1u;
0114     } else if (casts[0u] == binR && casts[1u] == binPhi) {
0115       accLink = 3u;
0116     } else if (casts[0u] == binZ && casts[1u] == binPhi) {
0117       accLink = 4u;
0118     } else if (casts[0u] == binZ && casts[1u] == binR) {
0119       accLink = 5u;
0120     }
0121   } else if (casts.size() == 3u) {
0122     if (casts[0u] == binX && casts[1u] == binY && casts[2u] == binZ) {
0123       accLink = 2u;
0124     } else if (casts[0u] == binZ && casts[1u] == binPhi && casts[2u] == binR) {
0125       accLink = 5u;
0126     }
0127   }
0128   return accLink;
0129 }
0130 
0131 }  // namespace Acts::DetrayJsonHelper