Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:51:01

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 // For whatever reason, this compilation unit does not compile
0010 // with those assertions and GCC 13. For now just disable the
0011 // flags in this case.
0012 #if defined(_GLIBCXX_ASSERTIONS) && __GNUC__ == 13
0013 #undef _GLIBCXX_ASSERTIONS
0014 #endif
0015 
0016 #include "Acts/Plugins/Json/DetrayJsonHelper.hpp"
0017 
0018 namespace Acts::DetrayJsonHelper {
0019 
0020 std::tuple<unsigned int, std::vector<double>> maskFromBounds(
0021     const Acts::SurfaceBounds& sBounds, bool portal) {
0022   SurfaceBounds::BoundsType bType = sBounds.type();
0023   std::vector<double> bValues = sBounds.values();
0024   // Return value
0025   unsigned int type = 13u;
0026   std::vector<double> boundaries = bValues;
0027   // Special treatment for some portals
0028   if (portal && bType == SurfaceBounds::BoundsType::eCylinder) {
0029     boundaries = {bValues.at(0u), -bValues.at(1u), bValues.at(1u)};
0030     type = 4u;
0031   } else {
0032     switch (bType) {
0033       case SurfaceBounds::BoundsType::eAnnulus: {
0034         type = 0u;
0035       } break;
0036       case SurfaceBounds::BoundsType::eRectangle: {
0037         type = 5u;
0038         // ACTS: eMinX = 0, eMinY = 1, eMaxX = 2, eMaxY = 3,
0039         // detray: e_half_x, e_half_y
0040         boundaries = std::vector{0.5 * (bValues.at(2) - bValues.at(0)),
0041                                  0.5 * (bValues.at(3) - bValues.at(1))};
0042       } break;
0043       case SurfaceBounds::BoundsType::eCylinder: {
0044         boundaries =
0045             std::vector{bValues.at(0u), -bValues.at(1u), bValues.at(1u)};
0046         type = 2u;
0047       } break;
0048       case SurfaceBounds::BoundsType::eTrapezoid: {
0049         type = 7u;
0050         boundaries = std::vector{bValues.at(0u), bValues.at(1u), bValues.at(2u),
0051                                  1 / (2 * bValues.at(2u))};
0052       } break;
0053       case SurfaceBounds::BoundsType::eDisc: {
0054         boundaries = std::vector{bValues[0u], bValues[1u]};
0055         type = 6u;
0056       } break;
0057       default:
0058         break;
0059     }
0060   }
0061   return {type, boundaries};
0062 }
0063 
0064 void addVolumeLink(nlohmann::json& jSurface, int vLink) {
0065   jSurface["volume_link"] = vLink;
0066 }
0067 
0068 std::size_t accelerationLink(std::span<const AxisDirection> casts) {
0069   // Default is `brute_force`
0070   using enum AxisDirection;
0071   std::size_t accLink = 0u;
0072   if (casts.size() == 2u) {
0073     if (casts[0u] == AxisX && casts[1u] == AxisY) {
0074       accLink = 1u;
0075     } else if (casts[0u] == AxisR && casts[1u] == AxisPhi) {
0076       accLink = 3u;
0077     } else if (casts[0u] == AxisZ && casts[1u] == AxisPhi) {
0078       accLink = 4u;
0079     } else if (casts[0u] == AxisZ && casts[1u] == AxisR) {
0080       accLink = 5u;
0081     }
0082   } else if (casts.size() == 3u) {
0083     if (casts[0u] == AxisX && casts[1u] == AxisY && casts[2u] == AxisZ) {
0084       accLink = 2u;
0085     } else if (casts[0u] == AxisZ && casts[1u] == AxisPhi &&
0086                casts[2u] == AxisR) {
0087       accLink = 5u;
0088     }
0089   }
0090   return accLink;
0091 }
0092 }  // namespace Acts::DetrayJsonHelper