Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:18

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/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& /*mctx*/) const {
0033   return MagneticFieldProvider::Cache{};
0034 }
0035 
0036 Result<Vector3> DD4hepFieldAdapter::getField(
0037     const Vector3& position, MagneticFieldProvider::Cache& /*cache*/) const {
0038   dd4hep::Position dd4hepPosition{position.x(), position.y(), position.z()};
0039 
0040   // ACTS mm -> dd4hep mm
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   // dd4hep tesla -> ACTS tesla
0048   result *= m_fieldConversionFactor;
0049 
0050   return Result<Vector3>::success(result);
0051 }
0052 
0053 }  // namespace Acts