File indexing completed on 2025-01-18 09:11:25
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/MagneticField/MultiRangeBField.hpp"
0010
0011 #include "Acts/MagneticField/MagneticFieldError.hpp"
0012
0013 namespace Acts {
0014
0015 MultiRangeBField::Cache::Cache(const MagneticFieldContext& ) {}
0016
0017 MultiRangeBField::MultiRangeBField(const std::vector<BFieldRange>& ranges)
0018 : fieldRanges(ranges) {}
0019
0020 MultiRangeBField::MultiRangeBField(
0021 std::vector<MultiRangeBField::BFieldRange>&& ranges)
0022 : fieldRanges(std::move(ranges)) {}
0023
0024 MagneticFieldProvider::Cache MultiRangeBField::makeCache(
0025 const MagneticFieldContext& mctx) const {
0026 return MagneticFieldProvider::Cache(std::in_place_type<Cache>, mctx);
0027 }
0028
0029 Result<Vector3> MultiRangeBField::getField(
0030 const Vector3& position, MagneticFieldProvider::Cache& cache) const {
0031
0032
0033
0034
0035 std::optional<std::size_t> foundRange = {};
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 if (Cache& lCache = cache.as<Cache>();
0046 lCache.index.has_value() &&
0047 std::get<0>(fieldRanges[*lCache.index])
0048 .contains({position[0], position[1], position[2]})) {
0049 foundRange = *lCache.index;
0050 }
0051
0052
0053
0054
0055 for (std::size_t i = (foundRange.has_value() ? (*foundRange) + 1 : 0);
0056 i < fieldRanges.size(); ++i) {
0057 if (std::get<0>(fieldRanges[i])
0058 .contains({position[0], position[1], position[2]})) {
0059 foundRange = i;
0060 }
0061 }
0062
0063
0064 cache.as<Cache>().index = foundRange;
0065
0066
0067
0068 if (foundRange.has_value()) {
0069 return Result<Vector3>::success(std::get<1>(fieldRanges[*foundRange]));
0070 } else {
0071 return Result<Vector3>::failure(MagneticFieldError::OutOfBounds);
0072 }
0073 }
0074
0075 }