Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:53

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 MagneticField
0018 ///
0019 /// This class implements a simple constant magnetic field. The
0020 /// magnetic field value has to be set at creation time, but can
0021 /// be updated later on.
0022 class ConstantBField final : public MagneticFieldProvider {
0023  public:
0024   struct Cache {
0025     /// @brief constructor with context
0026     Cache(const MagneticFieldContext& /*mcfg*/) {}
0027   };
0028 
0029   /// Construct constant magnetic field from field vector.
0030   ///
0031   /// @param [in] B magnetic field vector in global coordinate system
0032   explicit ConstantBField(Vector3 B) : m_BField(std::move(B)) {}
0033 
0034   /// @brief Get the B field at a position
0035   Vector3 getField() const { return m_BField; }
0036 
0037   /// @copydoc MagneticFieldProvider::getField(const Vector3&,MagneticFieldProvider::Cache&) const
0038   ///
0039   /// @note The @p position is ignored and only kept as argument to provide
0040   ///       a consistent interface with other magnetic field services.
0041   Result<Vector3> getField(const Vector3& position,
0042                            MagneticFieldProvider::Cache& cache) const override {
0043     (void)position;
0044     (void)cache;
0045     return Result<Vector3>::success(m_BField);
0046   }
0047 
0048   /// @copydoc MagneticFieldProvider::makeCache(const MagneticFieldContext&) const
0049   Acts::MagneticFieldProvider::Cache makeCache(
0050       const Acts::MagneticFieldContext& mctx) const override {
0051     return Acts::MagneticFieldProvider::Cache(std::in_place_type<Cache>, mctx);
0052   }
0053 
0054   /// @brief check whether given 3D position is inside look-up domain
0055   ///
0056   /// @return Always true for constant magnetic field
0057   bool isInside(const Vector3& /*position*/) const { return true; }
0058 
0059   /// @brief update magnetic field vector
0060   ///
0061   /// @param [in] B magnetic field vector in global coordinate system
0062   void setField(const Vector3& B) { m_BField = B; }
0063 
0064  private:
0065   /// magnetic field vector
0066   Vector3 m_BField;
0067 };
0068 }  // namespace Acts