Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MagneticFieldWrapper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MagneticFieldWrapper.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
16 
17 #include <ostream>
18 #include <system_error>
19 #include <utility>
20 
21 #include <G4SystemOfUnits.hh>
22 #include <G4UnitsTable.hh>
23 
25  const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
26  : G4MagneticField(), m_cfg(cfg), m_logger(std::move(logger)) {}
27 
29  G4double* Bfield) const {
30  constexpr double convertLength = CLHEP::mm / Acts::UnitConstants::mm;
31  constexpr double convertField = CLHEP::tesla / Acts::UnitConstants::T;
32 
33  auto bCache = m_cfg.magneticField->makeCache(Acts::MagneticFieldContext());
34 
35  auto fieldRes = m_cfg.magneticField->getField(
36  {convertLength * Point[0], convertLength * Point[1],
37  convertLength * Point[2]},
38  bCache);
39  if (!fieldRes.ok()) {
40  ACTS_ERROR("Field lookup error: " << fieldRes.error());
41  return;
42  }
43  // Get the field now
44  const Acts::Vector3& field = *fieldRes;
45 
46  Bfield[0] = convertField * field[0];
47  Bfield[1] = convertField * field[1];
48  Bfield[2] = convertField * field[2];
49 }