ATLAS Offline Software
ATLASMagneticFieldWrapper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ACTSGEOMETRY_ATLASMAGNETICFIELDWRAPPER_H
6 #define ACTSGEOMETRY_ATLASMAGNETICFIELDWRAPPER_H
7 
10 #include "Acts/Definitions/Algebra.hpp"
11 #include "Acts/Definitions/Units.hpp"
12 #include "Acts/MagneticField/MagneticFieldContext.hpp"
13 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
14 
15 class ATLASMagneticFieldWrapper final : public Acts::MagneticFieldProvider {
16 
17 public:
18 
19  struct Cache {
20 
21  Cache(const Acts::MagneticFieldContext mctx) {
22  const auto* atlasField = mctx.get<const AtlasFieldCacheCondObj*>();
23  atlasField->getInitializedCache(fieldCache);
24 
25  }
26 
28  };
29 
31 
32 
33  MagneticFieldProvider::Cache
34  makeCache(const Acts::MagneticFieldContext& mctx) const override {
35  return Acts::MagneticFieldProvider::Cache(std::in_place_type<Cache>, mctx);
36  }
37 
38  Acts::Result<Acts::Vector3>
39  getField(const Acts::Vector3& position, Acts::MagneticFieldProvider::Cache& gcache) const override {
40  Cache& cache = gcache.as<Cache>();
41  double posXYZ[3];
42  posXYZ[0] = position.x();
43  posXYZ[1] = position.y();
44  posXYZ[2] = position.z();
45  double BField[3];
46 
47  cache.fieldCache.getField(posXYZ, BField);
48 
49  // Magnetic field
50  Acts::Vector3 bfield{BField[0],BField[1],BField[2]};
51 
52  bfield *= m_bFieldUnit; // kT -> T;
53 
54  return Acts::Result<Acts::Vector3>::success(bfield);
55  }
56 
57  Acts::Result<Acts::Vector3>
58  getFieldGradient(const Acts::Vector3& position,
59  Acts::ActsMatrix<3, 3>& gradient,
60  Acts::MagneticFieldProvider::Cache& gcache) const override
61  {
62  Cache& cache = gcache.as<Cache>();
63  double posXYZ[3];
64  posXYZ[0] = position.x();
65  posXYZ[1] = position.y();
66  posXYZ[2] = position.z();
67  double BField[3];
68  double grad[9];
69 
70  cache.fieldCache.getField(posXYZ, BField, grad);
71 
72  // Magnetic field
73  Acts::Vector3 bfield{BField[0], BField[1],BField[2]};
74  Acts::ActsMatrix<3, 3> tempGrad;
75  tempGrad << grad[0], grad[1], grad[2], grad[3], grad[4], grad[5], grad[6], grad[7], grad[8];
76  gradient = tempGrad;
77 
78 
79  bfield *= m_bFieldUnit; // kT -> T;
80  gradient *= m_bFieldUnit;
81 
82  return Acts::Result<Acts::Vector3>::success(bfield);
83  }
84 
85 private:
86  const double m_bFieldUnit = 1000.*Acts::UnitConstants::T;
87 };
88 
89 
90 #endif
ATLASMagneticFieldWrapper::getFieldGradient
Acts::Result< Acts::Vector3 > getFieldGradient(const Acts::Vector3 &position, Acts::ActsMatrix< 3, 3 > &gradient, Acts::MagneticFieldProvider::Cache &gcache) const override
Definition: ATLASMagneticFieldWrapper.h:58
ATLASMagneticFieldWrapper
Definition: ATLASMagneticFieldWrapper.h:15
AtlasFieldCacheCondObj
Definition: AtlasFieldCacheCondObj.h:19
ATLASMagneticFieldWrapper::Cache
Definition: ATLASMagneticFieldWrapper.h:19
AtlasFieldCacheCondObj.h
ATLASMagneticFieldWrapper::ATLASMagneticFieldWrapper
ATLASMagneticFieldWrapper()=default
ATLASMagneticFieldWrapper::Cache::fieldCache
MagField::AtlasFieldCache fieldCache
Definition: ATLASMagneticFieldWrapper.h:27
ATLASMagneticFieldWrapper::makeCache
MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
Definition: ATLASMagneticFieldWrapper.h:34
AtlasFieldCacheCondObj::getInitializedCache
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d (solenoid) or 3-d (toroid) position.
Definition: AtlasFieldCacheCondObj.h:52
ATLASMagneticFieldWrapper::m_bFieldUnit
const double m_bFieldUnit
Definition: ATLASMagneticFieldWrapper.h:86
ReadCondHandleKey.h
ATLASMagneticFieldWrapper::getField
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Acts::MagneticFieldProvider::Cache &gcache) const override
Definition: ATLASMagneticFieldWrapper.h:39
MagField::AtlasFieldCache
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h)
Definition: AtlasFieldCache.h:43
ATLASMagneticFieldWrapper::Cache::Cache
Cache(const Acts::MagneticFieldContext mctx)
Definition: ATLASMagneticFieldWrapper.h:21
MagField::AtlasFieldCache::getField
void getField(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field value at given position xyz[3] is in mm, bxyz[3] is in kT if deriv[9] is given,...
Definition: AtlasFieldCache.cxx:42
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35