Juggler
Juggling algorithms and event processing using gaudi framework
DD4hepBField.h
Go to the documentation of this file.
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <variant>
12 
13 #include "Acts/Definitions/Algebra.hpp"
14 #include "Acts/MagneticField/MagneticFieldContext.hpp"
15 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
16 #include "Acts/Utilities/Result.hpp"
17 
18 #include "DD4hep/Detector.h"
19 #include "DD4hep/DD4hepUnits.h"
20 
21 
22 namespace Jug::BField {
23 
24  ///// The Context to be handed around
25  //struct ScalableBFieldContext {
26  // double scalor = 1.;
27  //};
28 
29  /** Use the dd4hep magnetic field in acts.
30  *
31  * \ingroup magnets
32  * \ingroup magsvc
33  */
34  class DD4hepBField final : public Acts::MagneticFieldProvider {
35  public:
36  std::shared_ptr<dd4hep::Detector> m_det;
37 
38  public:
39  struct Cache {
40  Cache(const Acts::MagneticFieldContext& /*mcfg*/) { }
41  };
42 
43  Acts::MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext& mctx) const override
44  {
45  return Acts::MagneticFieldProvider::Cache::make<Cache>(mctx);
46  }
47 
48  /** construct constant magnetic field from field vector.
49  *
50  * @param [in] DD4hep detector instance
51  */
52  explicit DD4hepBField(dd4hep::Detector* det) : m_det(std::shared_ptr<dd4hep::Detector>(det)) {}
53 
54  /** retrieve magnetic field value.
55  *
56  * @param [in] position global position
57  * @param [in] cache Cache object (is ignored)
58  * @return magnetic field vector
59  *
60  * @note The @p position is ignored and only kept as argument to provide
61  * a consistent interface with other magnetic field services.
62  */
63  Acts::Result<Acts::Vector3> getField(const Acts::Vector3& position, Acts::MagneticFieldProvider::Cache& cache) const override;
64 
65  /** @brief retrieve magnetic field value & its gradient
66  *
67  * @param [in] position global position
68  * @param [out] derivative gradient of magnetic field vector as (3x3)
69  * matrix
70  * @param [in] cache Cache object (is ignored)
71  * @return magnetic field vector
72  *
73  * @note The @p position is ignored and only kept as argument to provide
74  * a consistent interface with other magnetic field services.
75  * @note currently the derivative is not calculated
76  * @todo return derivative
77  */
78  Acts::Result<Acts::Vector3> getFieldGradient(const Acts::Vector3& position, Acts::ActsMatrix<3, 3>& /*derivative*/,
79  Acts::MagneticFieldProvider::Cache& cache) const override;
80  };
81 
82  using BFieldVariant = std::variant<std::shared_ptr<const DD4hepBField>>;
83 
84 
85 
86 } // namespace Jug::BField
Jug::BField::DD4hepBField::Cache::Cache
Cache(const Acts::MagneticFieldContext &)
Definition: DD4hepBField.h:40
Jug::BField::DD4hepBField::getField
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Acts::MagneticFieldProvider::Cache &cache) const override
Definition: DD4hepBField.cpp:19
Jug::BField::DD4hepBField::makeCache
Acts::MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
Definition: DD4hepBField.h:43
Jug::BField::BFieldVariant
std::variant< std::shared_ptr< const DD4hepBField > > BFieldVariant
Definition: DD4hepBField.h:82
Jug::BField::DD4hepBField::Cache
Definition: DD4hepBField.h:39
Jug::BField::DD4hepBField::DD4hepBField
DD4hepBField(dd4hep::Detector *det)
Definition: DD4hepBField.h:52
dd4hep
Definition: IGeoSvc.h:10
Jug::BField::DD4hepBField
Definition: DD4hepBField.h:34
Jug::BField::DD4hepBField::getFieldGradient
Acts::Result< Acts::Vector3 > getFieldGradient(const Acts::Vector3 &position, Acts::ActsMatrix< 3, 3 > &, Acts::MagneticFieldProvider::Cache &cache) const override
retrieve magnetic field value & its gradient
Definition: DD4hepBField.cpp:27
Jug::BField
Definition: DD4hepBField.h:22
Jug::BField::DD4hepBField::m_det
std::shared_ptr< dd4hep::Detector > m_det
Definition: DD4hepBField.h:36