File indexing completed on 2025-10-18 08:22:09
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/GeoModel/detail/GeoModelExtentHelper.hpp"
0010
0011 #include "Acts/Utilities/BinningData.hpp"
0012 #include "Acts/Utilities/Enumerate.hpp"
0013 #include "ActsPlugins/GeoModel/detail/GeoModelBinningHelper.hpp"
0014
0015 #include <boost/algorithm/string.hpp>
0016
0017 using namespace Acts;
0018
0019 std::vector<AxisDirection>
0020 ActsPlugins::detail::GeoModelExentHelper::readBoundsConstaints(
0021 const std::string& boundsEntry, const std::string& ctype) {
0022 std::vector<std::string> boundsEntrySplit;
0023 boost::split(boundsEntrySplit, boundsEntry, boost::is_any_of(","));
0024 if (boundsEntrySplit.size() < 2u) {
0025 throw std::invalid_argument(
0026 "GeoModelBlueprintCreater: Bounds entry has to have at least 2 "
0027 "entries (type, values)");
0028 }
0029 std::set<AxisDirection> constraints;
0030
0031 if (boundsEntrySplit[0u] == "cyl") {
0032
0033 std::vector<std::string> valuesEntry = {boundsEntrySplit.begin() + 1,
0034 boundsEntrySplit.end()};
0035 if (valuesEntry.size() < 4u) {
0036 throw std::invalid_argument(
0037 "GeoModelBlueprintCreater: Cylinder bounds entry has to have at "
0038 "least 4 entries (rmin, rmax, zmin, zmax)");
0039 }
0040
0041 constexpr std::array<AxisDirection, 6u> bvCyl = {
0042 AxisDirection::AxisR, AxisDirection::AxisR, AxisDirection::AxisZ,
0043 AxisDirection::AxisZ, AxisDirection::AxisPhi, AxisDirection::AxisPhi};
0044
0045 for (auto [iv, value] : enumerate(valuesEntry)) {
0046 if (value == ctype || value[0u] == ctype[0u]) {
0047 constraints.insert(bvCyl.at(iv));
0048 }
0049 }
0050 }
0051 return {constraints.begin(), constraints.end()};
0052 }
0053
0054 std::vector<AxisDirection>
0055 ActsPlugins::detail::GeoModelExentHelper::readBinningConstraints(
0056 const std::vector<std::string>& binningEntry) {
0057 std::set<AxisDirection> constraints;
0058
0059 for (const auto& sbe : binningEntry) {
0060 if (sbe.empty()) {
0061 continue;
0062 }
0063 std::vector<std::string> sbTokens;
0064 boost::split(sbTokens, sbe, boost::is_any_of(","));
0065 AxisDirection bv =
0066 detail::GeoModelBinningHelper::toAxisDirection(sbTokens[0]);
0067 if (sbTokens.size() > 1u) {
0068 std::vector<std::string> valueTokens = {sbTokens.begin() + 1,
0069 sbTokens.end()};
0070 if (!valueTokens.empty() && valueTokens[0] == "bound") {
0071 constraints.insert(bv);
0072 }
0073 }
0074 }
0075
0076 return {constraints.begin(), constraints.end()};
0077 }
0078
0079 std::tuple<VolumeBounds::BoundsType, Extent>
0080 ActsPlugins::detail::GeoModelExentHelper::extentFromTable(
0081 const std::vector<std::string>& boundsEntrySplit,
0082 const Extent& externalExtent, const Extent& internalExtent,
0083 bool roundInternalExtent) {
0084
0085 if (boundsEntrySplit.size() < 2u) {
0086 throw std::invalid_argument(
0087 "GeoModelBlueprintCreater: Bounds entry has to have at least 2 "
0088 "entries (type, values)");
0089 }
0090
0091
0092
0093 VolumeBounds::BoundsType boundsType = VolumeBounds::BoundsType::eOther;
0094 Extent extent;
0095
0096 if (boundsEntrySplit[0u] == "cyl") {
0097
0098 boundsType = VolumeBounds::BoundsType::eCylinder;
0099
0100 std::vector<std::string> valuesEntry = {boundsEntrySplit.begin() + 1,
0101 boundsEntrySplit.end()};
0102 if (valuesEntry.size() < 4u) {
0103 throw std::invalid_argument(
0104 "GeoModelBlueprintCreater: Cylinder bounds entry has to have at "
0105 "least 4 entries (rmin, rmax, zmin, zmax)");
0106 }
0107
0108 constexpr std::array<AxisDirection, 6u> bvCyl = {
0109 AxisDirection::AxisR, AxisDirection::AxisR, AxisDirection::AxisZ,
0110 AxisDirection::AxisZ, AxisDirection::AxisPhi, AxisDirection::AxisPhi};
0111 for (auto [iv, value] : enumerate(valuesEntry)) {
0112
0113 AxisDirection bValue = bvCyl.at(iv);
0114 double val = std::numeric_limits<double>::max();
0115 bool isMin = (iv % 2 == 0);
0116
0117 if (value == "e") {
0118
0119 if (!externalExtent.constrains(bValue)) {
0120 throw std::invalid_argument(
0121 "GeoModelExtentHelper: External extent does not constrain. ");
0122 }
0123 val = isMin ? externalExtent.min(bValue) : externalExtent.max(bValue);
0124 } else if (value == "i" || value[0u] == 'i') {
0125
0126 double envelope = 0.;
0127 if (value.size() > 2u) {
0128 std::vector<std::string> valEntry;
0129 boost::split(valEntry, value, boost::is_any_of("+"));
0130 envelope = std::stod(valEntry[1]);
0131 }
0132
0133
0134 if (!internalExtent.constrains(bValue)) {
0135 throw std::invalid_argument(
0136 "GeoModelExtentHelper: Internals do not constrain.");
0137 }
0138 val = isMin ? internalExtent.min(bValue) - envelope
0139 : internalExtent.max(bValue) + envelope;
0140
0141 } else {
0142 val = std::stod(value);
0143 }
0144
0145 if (isMin) {
0146 extent.setMin(bValue, val);
0147 } else {
0148 extent.setMax(bValue, val);
0149 }
0150 }
0151 }
0152
0153 if (roundInternalExtent) {
0154 for (const auto& bv : allAxisDirections()) {
0155 if (internalExtent.constrains(bv)) {
0156 extent.setMin(bv, std::floor(extent.min(bv)));
0157 extent.setMax(bv, std::ceil(extent.max(bv)));
0158 }
0159 }
0160 }
0161
0162 return {boundsType, extent};
0163 }