Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetrayJsonHelper.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetrayJsonHelper.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
12 
13 #include <string>
14 #include <tuple>
15 
16 namespace Acts {
17 
18 namespace DetrayJsonHelper {
19 
42 inline static std::tuple<unsigned int, std::vector<ActsScalar>> maskFromBounds(
43  const Acts::SurfaceBounds& sBounds, bool portal = false) {
44  auto bType = sBounds.type();
45  auto bValues = sBounds.values();
46  // Return value
47  unsigned int type = 13u;
48  std::vector<double> boundaries = bValues;
49  // Special treatment for some portals
50  if (portal and bType == SurfaceBounds::BoundsType::eCylinder) {
51  boundaries = {bValues[0u], -bValues[1u], bValues[1u]};
52  type = 4u;
53  } else {
54  switch (bType) {
55  case SurfaceBounds::BoundsType::eAnnulus: {
56  type = 0u;
57  } break;
58  case SurfaceBounds::BoundsType::eRectangle: {
59  type = 5u;
60  // ACTS: eMinX = 0, eMinY = 1, eMaxX = 2, eMaxY = 3,
61  // detray: e_half_x, e_half_y
62  boundaries = {0.5 * (bValues[2] - bValues[0]),
63  0.5 * (bValues[3] - bValues[1])};
64  } break;
65  case SurfaceBounds::BoundsType::eCylinder: {
66  boundaries = {bValues[0u], -bValues[1u], bValues[1u]};
67  type = 2u;
68  } break;
69  case SurfaceBounds::BoundsType::eTrapezoid: {
70  type = 7u;
71  boundaries = {bValues[0u], bValues[1u], bValues[2u],
72  1 / (2 * bValues[2u])};
73  } break;
74  case SurfaceBounds::BoundsType::eDisc: {
75  boundaries = {bValues[0u], bValues[1u]};
76  type = 6u;
77  } break;
78  default:
79  break;
80  }
81  }
82  return std::tie(type, boundaries);
83 }
84 
89 inline static void addVolumeLink(nlohmann::json& jSurface, int vLink) {
90  jSurface["volume_link"] = vLink;
91 }
92 
93 } // namespace DetrayJsonHelper
94 } // namespace Acts