Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 08:19:07

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 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0013 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0014 
0015 namespace Acts {
0016 
0017 /// @ingroup magnetic_field
0018 ///
0019 /// The simplest magnetic field implementation is a constant field, which
0020 /// returns the same field values at every queried location.
0021 class ConstantBField final : public MagneticFieldProvider {
0022  public:
0023   /// Cache object for constant magnetic field
0024   struct Cache {
0025     /// Constructor with context
0026     /// @note For the constant field, the cache is empty.
0027     explicit Cache(const MagneticFieldContext& /*mcfg*/) {}
0028   };
0029 
0030   /// Construct constant magnetic field from field vector.
0031   ///
0032   /// @param [in] B magnetic field vector in global coordinate system
0033   explicit ConstantBField(Vector3 B) : m_BField(std::move(B)) {}
0034 
0035   /// @brief Get the B field at a position
0036   /// @return The constant magnetic field vector
0037   Vector3 getField() const { return m_BField; }
0038 
0039   /// @copydoc MagneticFieldProvider::getField(const Vector3&,MagneticFieldProvider::Cache&) const
0040   ///
0041   /// @note The @p position is ignored and only kept as argument to provide
0042   ///       a consistent interface with other magnetic field services.
0043   Result<Vector3> getField(const Vector3& position,
0044                            MagneticFieldProvider::Cache& cache) const override {
0045     static_cast<void>(position);
0046     static_cast<void>(cache);
0047     return Result<Vector3>::success(m_BField);
0048   }
0049 
0050   /// @copydoc MagneticFieldProvider::makeCache(const MagneticFieldContext&) const
0051   Acts::MagneticFieldProvider::Cache makeCache(
0052       const Acts::MagneticFieldContext& mctx) const override {
0053     return Acts::MagneticFieldProvider::Cache(std::in_place_type<Cache>, mctx);
0054   }
0055 
0056   /// @brief check whether given 3D position is inside look-up domain
0057   ///
0058   /// @return Always true for constant magnetic field
0059   bool isInside(const Vector3& /*position*/) const { return true; }
0060 
0061   /// @brief update magnetic field vector
0062   ///
0063   /// @param [in] B magnetic field vector in global coordinate system
0064   void setField(const Vector3& B) { m_BField = B; }
0065 
0066  private:
0067   /// magnetic field vector
0068   Vector3 m_BField;
0069 };
0070 }  // namespace Acts