File indexing completed on 2025-01-18 09:27:42
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Plugins/Json/AlgebraJsonConverter.hpp"
0012 #include "Acts/Plugins/Json/GridJsonConverter.hpp"
0013 #include "Acts/Plugins/Json/UtilitiesJsonConverter.hpp"
0014 #include "Acts/Utilities/Grid.hpp"
0015 #include "Acts/Utilities/GridAxisGenerators.hpp"
0016 #include "Acts/Utilities/detail/AxisFwd.hpp"
0017
0018 #include <tuple>
0019
0020 namespace Acts {
0021 using namespace GridAxisGenerators;
0022
0023 namespace IndexedGridJsonHelper {
0024
0025
0026
0027
0028
0029
0030 template <typename index_grid>
0031 nlohmann::json convertImpl(const index_grid& indexGrid, bool detray = false,
0032 bool checkSwap = false) {
0033 nlohmann::json jIndexedGrid;
0034
0035
0036 bool swapAxes = checkSwap;
0037
0038
0039 nlohmann::json jCasts;
0040
0041 if constexpr (index_grid::grid_type::DIM == 1u) {
0042 jCasts.push_back(indexGrid.casts[0u]);
0043 }
0044
0045 if constexpr (index_grid::grid_type::DIM == 2u) {
0046 jCasts.push_back(indexGrid.casts[0u]);
0047 jCasts.push_back(indexGrid.casts[1u]);
0048
0049 swapAxes = checkSwap &&
0050 (indexGrid.casts[0u] == binZ && indexGrid.casts[1u] == binPhi);
0051 }
0052 jIndexedGrid["casts"] = jCasts;
0053 jIndexedGrid["transform"] =
0054 Transform3JsonConverter::toJson(indexGrid.transform);
0055 if (detray) {
0056 jIndexedGrid = GridJsonConverter::toJsonDetray(indexGrid.grid, swapAxes);
0057 } else {
0058 jIndexedGrid["grid"] = GridJsonConverter::toJson(indexGrid.grid);
0059 }
0060 return jIndexedGrid;
0061 }
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 template <typename updator_type, typename generator_type>
0074 updator_type generateFromJson(const nlohmann::json& jUpdater,
0075 const std::string& jIndicator) {
0076 generator_type generator;
0077
0078 using ValueType = typename generator_type::value_type;
0079
0080
0081
0082 auto eqExtractor = [](const nlohmann::json& jAxis)
0083 -> std::tuple<std::array<ActsScalar, 2u>, std::size_t> {
0084 std::array<ActsScalar, 2u> range = jAxis["range"];
0085 std::size_t bins = jAxis["bins"];
0086 return std::make_tuple(range, bins);
0087 };
0088
0089
0090
0091 auto vExtractor = [](const nlohmann::json& jAxis) -> std::vector<ActsScalar> {
0092 std::vector<ActsScalar> vEx(jAxis["boundaries"]);
0093 return vEx;
0094 };
0095
0096
0097 if (jUpdater["type"] == jIndicator) {
0098 if (jUpdater.find("grid") != jUpdater.end()) {
0099 Transform3 transform =
0100 Transform3JsonConverter::fromJson(jUpdater["transform"]);
0101 auto jGrid = jUpdater["grid"];
0102 auto jCasts = jUpdater["casts"].get<std::vector<BinningValue>>();
0103 auto jAxes = jGrid["axes"];
0104
0105
0106 if (jAxes.size() == 1u) {
0107 BinningValue bValue = jCasts[0u];
0108 auto jAxis = jAxes[0u];
0109
0110 detail::AxisType axisType = jAxis["type"];
0111 detail::AxisBoundaryType axisBoundaryType = jAxis["boundary_type"];
0112
0113
0114 if (axisType == detail::AxisType::Equidistant) {
0115 auto [range, bins] = eqExtractor(jAxis);
0116 if (axisBoundaryType == detail::AxisBoundaryType::Closed) {
0117 EqClosed ecAG{range, bins};
0118 auto grid =
0119 GridJsonConverter::fromJson<EqClosed, ValueType>(jGrid, ecAG);
0120 return generator.createUpdater(std::move(grid), {bValue},
0121 transform);
0122 } else {
0123 EqBound ebAG{range, bins};
0124 auto grid =
0125 GridJsonConverter::fromJson<EqBound, ValueType>(jGrid, ebAG);
0126 return generator.createUpdater(std::move(grid), {bValue},
0127 transform);
0128 }
0129 } else {
0130
0131 if (axisBoundaryType == detail::AxisBoundaryType::Closed) {
0132 VarClosed vcAG{vExtractor(jAxis)};
0133 auto grid =
0134 GridJsonConverter::fromJson<VarClosed, ValueType>(jGrid, vcAG);
0135 return generator.createUpdater(std::move(grid), {bValue},
0136 transform);
0137 } else {
0138 VarBound vbAG{vExtractor(jAxis)};
0139 auto grid =
0140 GridJsonConverter::fromJson<VarBound, ValueType>(jGrid, vbAG);
0141 return generator.createUpdater(std::move(grid), {bValue},
0142 transform);
0143 }
0144 }
0145 } else if (jAxes.size() == 2u) {
0146
0147
0148
0149 BinningValue bValueA = jCasts[0u];
0150 BinningValue bValueB = jCasts[1u];
0151 auto jAxisA = jAxes[0u];
0152 auto jAxisB = jAxes[1u];
0153
0154 detail::AxisType axisTypeA = jAxisA["type"];
0155 detail::AxisType axisTypeB = jAxisB["type"];
0156 detail::AxisBoundaryType axisBoundaryTypeB = jAxisB["boundary_type"];
0157
0158 if (axisBoundaryTypeB != detail::AxisBoundaryType::Closed) {
0159
0160 if (axisTypeA == detail::AxisType::Equidistant) {
0161 auto [rangeA, binsA] = eqExtractor(jAxisA);
0162 if (axisTypeB == detail::AxisType::Equidistant) {
0163 auto [rangeB, binsB] = eqExtractor(jAxisB);
0164 EqBoundEqBound ebebAG{rangeA, binsA, rangeB, binsB};
0165 auto grid =
0166 GridJsonConverter::fromJson<EqBoundEqBound, ValueType>(
0167 jGrid, ebebAG);
0168 return generator.createUpdater(std::move(grid),
0169 {bValueA, bValueB}, transform);
0170 } else {
0171 EqBoundVarBound ebvbAG{rangeA, binsA, vExtractor(jAxisB)};
0172 auto grid =
0173 GridJsonConverter::fromJson<EqBoundVarBound, ValueType>(
0174 jGrid, ebvbAG);
0175 return generator.createUpdater(std::move(grid),
0176 {bValueA, bValueB}, transform);
0177 }
0178 } else {
0179 if (axisTypeB == detail::AxisType::Equidistant) {
0180 auto [rangeB, binsB] = eqExtractor(jAxisB);
0181 VarBoundEqBound vbebAG{vExtractor(jAxisA), rangeB, binsB};
0182 auto grid =
0183 GridJsonConverter::fromJson<VarBoundEqBound, ValueType>(
0184 jGrid, vbebAG);
0185 return generator.createUpdater(std::move(grid),
0186 {bValueA, bValueB}, transform);
0187 } else {
0188 VarBoundVarBound vbvbAG{vExtractor(jAxisA), vExtractor(jAxisB)};
0189 auto grid =
0190 GridJsonConverter::fromJson<VarBoundVarBound, ValueType>(
0191 jGrid, vbvbAG);
0192 return generator.createUpdater(std::move(grid),
0193 {bValueA, bValueB}, transform);
0194 }
0195 }
0196 } else {
0197
0198 if (axisTypeA == detail::AxisType::Equidistant) {
0199 auto [rangeA, binsA] = eqExtractor(jAxisA);
0200 if (axisTypeB == detail::AxisType::Equidistant) {
0201 auto [rangeB, binsB] = eqExtractor(jAxisB);
0202 EqBoundEqClosed ebecAG{rangeA, binsA, rangeB, binsB};
0203 auto grid =
0204 GridJsonConverter::fromJson<EqBoundEqClosed, ValueType>(
0205 jGrid, ebecAG);
0206 return generator.createUpdater(std::move(grid),
0207 {bValueA, bValueB}, transform);
0208 } else {
0209 EqBoundVarClosed ebvcAG{rangeA, binsA, vExtractor(jAxisB)};
0210 auto grid =
0211 GridJsonConverter::fromJson<EqBoundVarClosed, ValueType>(
0212 jGrid, ebvcAG);
0213 return generator.createUpdater(std::move(grid),
0214 {bValueA, bValueB}, transform);
0215 }
0216 } else {
0217 if (axisTypeB == detail::AxisType::Equidistant) {
0218 auto [rangeB, binsB] = eqExtractor(jAxisB);
0219 VarBoundEqClosed vbecAG{vExtractor(jAxisA), rangeB, binsB};
0220 auto grid =
0221 GridJsonConverter::fromJson<VarBoundEqClosed, ValueType>(
0222 jGrid, vbecAG);
0223 return generator.createUpdater(std::move(grid),
0224 {bValueA, bValueB}, transform);
0225 } else {
0226 VarBoundVarClosed vbvcAG{vExtractor(jAxisA), vExtractor(jAxisB)};
0227 auto grid =
0228 GridJsonConverter::fromJson<VarBoundVarClosed, ValueType>(
0229 jGrid, vbvcAG);
0230 return generator.createUpdater(std::move(grid),
0231 {bValueA, bValueB}, transform);
0232 }
0233 }
0234 }
0235 }
0236 }
0237 }
0238
0239 updator_type updator;
0240 return updator;
0241 }
0242
0243 }
0244 }