Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 08:19:58

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Geant4/MagneticFieldWrapper.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0013 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0014 #include "ActsExamples/Geant4/UnitConversion.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   assert(bField != nullptr);
0030 
0031   auto bCache = m_cfg.magneticField->makeCache(Acts::MagneticFieldContext());
0032 
0033   auto fieldRes = m_cfg.magneticField->getField(
0034       {convertLengthToActs * point[0], convertLengthToActs * point[1],
0035        convertLengthToActs * point[2]},
0036       bCache);
0037   if (!fieldRes.ok()) {
0038     ACTS_ERROR("Field lookup error: " << fieldRes.error());
0039     return;
0040   }
0041   // Get the field now
0042   const Acts::Vector3& field = *fieldRes;
0043 
0044   bField[0] = convertFieldToGeant4 * field[0];
0045   bField[1] = convertFieldToGeant4 * field[1];
0046   bField[2] = convertFieldToGeant4 * field[2];
0047 }
0048 
0049 }  // namespace ActsExamples::Geant4