Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:45

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2021 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 http://mozilla.org/MPL/2.0/.
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 "Acts/Utilities/Result.hpp"
0016 
0017 #include <ostream>
0018 #include <system_error>
0019 #include <utility>
0020 
0021 #include <G4SystemOfUnits.hh>
0022 #include <G4UnitsTable.hh>
0023 
0024 ActsExamples::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 ActsExamples::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   // Get the field now
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 }