File indexing completed on 2025-09-13 08:13:26
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 #include "ActsExamples/Geant4/AlgebraConverters.hpp"
0016
0017 #include <utility>
0018
0019 #include <G4SystemOfUnits.hh>
0020 #include <G4UnitsTable.hh>
0021
0022 namespace ActsExamples::Geant4 {
0023
0024 MagneticFieldWrapper::MagneticFieldWrapper(
0025 const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
0026 : G4MagneticField(), m_cfg(cfg), m_logger(std::move(logger)) {}
0027
0028 void MagneticFieldWrapper::GetFieldValue(const G4double Point[4],
0029 G4double* Bfield) const {
0030 constexpr double convertLength = CLHEP::mm / Acts::UnitConstants::mm;
0031 constexpr double convertField = CLHEP::tesla / Acts::UnitConstants::T;
0032
0033 auto bCache = m_cfg.magneticField->makeCache(Acts::MagneticFieldContext());
0034
0035 auto fieldRes = m_cfg.magneticField->getField(
0036 {convertLength * Point[0], convertLength * Point[1],
0037 convertLength * Point[2]},
0038 bCache);
0039 if (!fieldRes.ok()) {
0040 ACTS_ERROR("Field lookup error: " << fieldRes.error());
0041 return;
0042 }
0043
0044 const Acts::Vector3& field = *fieldRes;
0045
0046 Bfield[0] = convertField * field[0];
0047 Bfield[1] = convertField * field[1];
0048 Bfield[2] = convertField * field[2];
0049 }
0050
0051 }