File indexing completed on 2025-01-18 09:12:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/DD4hep/DD4hepFieldAdapter.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0014 #include "Acts/MagneticField/MagneticFieldError.hpp"
0015 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0016
0017 #include <DD4hep/Fields.h>
0018 #include <DD4hep/Handle.h>
0019 #include <DD4hep/Objects.h>
0020
0021 namespace Acts {
0022
0023 DD4hepFieldAdapter::DD4hepFieldAdapter(dd4hep::OverlayedField field)
0024 : m_field{std::make_unique<dd4hep::OverlayedField>(field)} {
0025 m_fieldConversionFactor =
0026 dd4hep::_toDouble("1/tesla") * Acts::UnitConstants::T;
0027 m_lengthConversionFactor =
0028 dd4hep::_toDouble("1*mm") / Acts::UnitConstants::mm;
0029 }
0030
0031 MagneticFieldProvider::Cache DD4hepFieldAdapter::makeCache(
0032 const Acts::MagneticFieldContext& ) const {
0033 return MagneticFieldProvider::Cache{};
0034 }
0035
0036 Result<Vector3> DD4hepFieldAdapter::getField(
0037 const Vector3& position, MagneticFieldProvider::Cache& ) const {
0038 dd4hep::Position dd4hepPosition{position.x(), position.y(), position.z()};
0039
0040
0041 dd4hepPosition *= m_lengthConversionFactor;
0042
0043 const auto direction = m_field->combinedMagnetic(dd4hepPosition);
0044
0045 Vector3 result{direction.x(), direction.y(), direction.z()};
0046
0047
0048 result *= m_fieldConversionFactor;
0049
0050 return Result<Vector3>::success(result);
0051 }
0052
0053 }