Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 08:34:28

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2016-2018 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 http://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 #include <Acts/Utilities/Result.hpp>
0015 #include <DD4hep/Detector.h>
0016 #include <gsl/pointers>
0017 #include <memory>
0018 #include <utility>
0019 #include <variant>
0020 
0021 namespace eicrecon::BField {
0022 
0023 ///// The Context to be handed around
0024 //struct ScalableBFieldContext {
0025 //  double scalor = 1.;
0026 //};
0027 
0028 /** Use the dd4hep magnetic field in acts.
0029    *
0030    * \ingroup magnets
0031    * \ingroup magsvc
0032    */
0033 class DD4hepBField final : public Acts::MagneticFieldProvider {
0034 public:
0035   gsl::not_null<const dd4hep::Detector*> m_det;
0036 
0037 public:
0038   struct Cache {
0039     Cache(const Acts::MagneticFieldContext& /*mcfg*/) {}
0040   };
0041 
0042   Acts::MagneticFieldProvider::Cache
0043   makeCache(const Acts::MagneticFieldContext& mctx) const override {
0044 #if Acts_VERSION_MAJOR >= 32
0045     return Acts::MagneticFieldProvider::Cache(std::in_place_type<Cache>, mctx);
0046 #else
0047     return Acts::MagneticFieldProvider::Cache::make<Cache>(mctx);
0048 #endif
0049   }
0050 
0051   /** construct constant magnetic field from field vector.
0052     *
0053     * @param [in] DD4hep detector instance
0054     */
0055   explicit DD4hepBField(gsl::not_null<const dd4hep::Detector*> det) : m_det(det) {}
0056 
0057   /**  retrieve magnetic field value.
0058      *
0059      *  @param [in] position global position
0060      *  @param [in] cache Cache object (is ignored)
0061      *  @return magnetic field vector
0062      *
0063      *  @note The @p position is ignored and only kept as argument to provide
0064      *        a consistent interface with other magnetic field services.
0065      */
0066   Acts::Result<Acts::Vector3> getField(const Acts::Vector3& position,
0067                                        Acts::MagneticFieldProvider::Cache& cache) const override;
0068 
0069 #if Acts_VERSION_MAJOR < 39
0070   /** @brief retrieve magnetic field value & its gradient
0071      *
0072      * @param [in]  position   global position
0073      * @param [out] derivative gradient of magnetic field vector as (3x3)
0074      * matrix
0075      * @param [in] cache Cache object (is ignored)
0076      * @return magnetic field vector
0077      *
0078      * @note The @p position is ignored and only kept as argument to provide
0079      *       a consistent interface with other magnetic field services.
0080      * @note currently the derivative is not calculated
0081      * @todo return derivative
0082      */
0083   Acts::Result<Acts::Vector3>
0084   getFieldGradient(const Acts::Vector3& position, Acts::ActsMatrix<3, 3>& /*derivative*/,
0085                    Acts::MagneticFieldProvider::Cache& cache) const override;
0086 #endif
0087 };
0088 
0089 using BFieldVariant = std::variant<std::shared_ptr<const DD4hepBField>>;
0090 
0091 } // namespace eicrecon::BField