FairShip
Loading...
Searching...
No Matches
ActsShipField.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#include "ActsShipField.hpp"
6
7#include <stdexcept>
8
9#include "Acts/Definitions/Units.hpp"
10#include "ActsFrame.hpp"
11#include "TVirtualMagField.h"
12
13namespace SHiP {
14
15namespace {
16// FairRoot/VMC fields are in kGauss
17constexpr double kKiloGauss = 0.1 * Acts::UnitConstants::T;
18} // namespace
19
20ActsShipField::ActsShipField(TVirtualMagField* field) : m_field(field) {
21 if (m_field == nullptr) {
22 throw std::invalid_argument("ActsShipField: field is null");
23 }
24}
25
26Acts::MagneticFieldProvider::Cache ActsShipField::makeCache(
27 const Acts::MagneticFieldContext& /*mctx*/) const {
28 return Cache{};
29}
30
31Acts::Result<Acts::Vector3> ActsShipField::getField(
32 const Acts::Vector3& position, Cache& /*cache*/) const {
33 const Acts::Vector3 shipPosition = ActsFrame::positionToShip(position);
34 const double x[3] = {shipPosition.x(), shipPosition.y(), shipPosition.z()};
35 double b[3] = {0., 0., 0.};
36 m_field->Field(x, b);
37 const Acts::Vector3 shipField(b[0], b[1], b[2]);
38 return Acts::Result<Acts::Vector3>::success(ActsFrame::toActsRotation() *
39 shipField * kKiloGauss);
40}
41
42} // namespace SHiP
TVirtualMagField * m_field
ActsShipField(TVirtualMagField *field)
The field is not owned and must outlive this object.
Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Cache &cache) const override
Acts::RotationMatrix3 toActsRotation()
Rotation taking SHiP-frame vectors to the ACTS frame.
Definition ActsFrame.hpp:31
Acts::Vector3 positionToShip(const Acts::Vector3 &position)
Definition ActsFrame.hpp:42