File indexing completed on 2025-01-18 09:11:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Geant4/MagneticFieldWrapper.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0014 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0015
0016 #include <utility>
0017
0018 #include <G4SystemOfUnits.hh>
0019 #include <G4UnitsTable.hh>
0020
0021 namespace ActsExamples::Geant4 {
0022
0023 MagneticFieldWrapper::MagneticFieldWrapper(
0024 const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
0025 : G4MagneticField(), m_cfg(cfg), m_logger(std::move(logger)) {}
0026
0027 void MagneticFieldWrapper::GetFieldValue(const G4double Point[4],
0028 G4double* Bfield) const {
0029 constexpr double convertLength = CLHEP::mm / Acts::UnitConstants::mm;
0030 constexpr double convertField = CLHEP::tesla / Acts::UnitConstants::T;
0031
0032 auto bCache = m_cfg.magneticField->makeCache(Acts::MagneticFieldContext());
0033
0034 auto fieldRes = m_cfg.magneticField->getField(
0035 {convertLength * Point[0], convertLength * Point[1],
0036 convertLength * Point[2]},
0037 bCache);
0038 if (!fieldRes.ok()) {
0039 ACTS_ERROR("Field lookup error: " << fieldRes.error());
0040 return;
0041 }
0042
0043 const Acts::Vector3& field = *fieldRes;
0044
0045 Bfield[0] = convertField * field[0];
0046 Bfield[1] = convertField * field[1];
0047 Bfield[2] = convertField * field[2];
0048 }
0049
0050 }