Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:13:30

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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/MagneticFieldProvider.hpp"
0015 
0016 #include <DD4hep/Fields.h>
0017 #include <DD4hep/Handle.h>
0018 #include <DD4hep/Objects.h>
0019 
0020 namespace Acts {
0021 
0022 DD4hepFieldAdapter::DD4hepFieldAdapter(dd4hep::OverlayedField field)
0023     : m_field{std::make_unique<dd4hep::OverlayedField>(field)} {
0024   m_fieldConversionFactor = dd4hep::_toDouble("1/tesla") * UnitConstants::T;
0025   m_lengthConversionFactor = dd4hep::_toDouble("1*mm") / UnitConstants::mm;
0026 }
0027 
0028 MagneticFieldProvider::Cache DD4hepFieldAdapter::makeCache(
0029     const MagneticFieldContext& /*mctx*/) const {
0030   return MagneticFieldProvider::Cache{};
0031 }
0032 
0033 Result<Vector3> DD4hepFieldAdapter::getField(
0034     const Vector3& position, MagneticFieldProvider::Cache& /*cache*/) const {
0035   dd4hep::Position dd4hepPosition{position.x(), position.y(), position.z()};
0036 
0037   // ACTS mm -> dd4hep mm
0038   dd4hepPosition *= m_lengthConversionFactor;
0039 
0040   const auto direction = m_field->combinedMagnetic(dd4hepPosition);
0041 
0042   Vector3 result{direction.x(), direction.y(), direction.z()};
0043 
0044   // dd4hep tesla -> ACTS tesla
0045   result *= m_fieldConversionFactor;
0046 
0047   return Result<Vector3>::success(result);
0048 }
0049 
0050 }  // namespace Acts