Project
Loading...
Searching...
No Matches
MagneticFieldAdapter.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
18
19#include <stdexcept>
20
21#include <TGeoGlobalMagField.h>
22
23#include "Acts/Definitions/Units.hpp"
24#include "Field/MagneticField.h"
25#include "Framework/Logger.h"
26
27namespace o2::acts
28{
29
30namespace
31{
33constexpr double kGaussToActs = 0.1 * Acts::UnitConstants::T;
34} // namespace
35
37 : MagneticFieldAdapter(static_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField()))
38{
39}
40
42{
43 if (mField == nullptr) {
44 throw std::runtime_error(
45 "o2::acts::MagneticFieldAdapter: no O2 magnetic field available. Request GRPMagField in the "
46 "GRPGeomRequest of the workflow, or initialise the field explicitly with "
47 "o2::base::Propagator::initFieldFromGRP().");
48 }
49 LOG(info) << "ACTS magnetic field adapter bound to O2 field '" << mField->GetName() << "'";
50}
51
52Acts::MagneticFieldProvider::Cache MagneticFieldAdapter::makeCache(const Acts::MagneticFieldContext& /*mctx*/) const
53{
54 // The O2 field parametrisation keeps its own internal caches and offers no
55 // per-client cache handle, so there is nothing to carry here.
56 return Acts::MagneticFieldProvider::Cache(std::in_place_type<CacheImpl>);
57}
58
59Acts::Result<Acts::Vector3> MagneticFieldAdapter::getField(const Acts::Vector3& position,
60 Cache& /*cache*/) const
61{
62 const double xyz[3] = {position[0] / Acts::UnitConstants::cm,
63 position[1] / Acts::UnitConstants::cm,
64 position[2] / Acts::UnitConstants::cm};
65 double bxyz[3] = {0., 0., 0.};
66 mField->Field(xyz, bxyz);
67
68 return Acts::Result<Acts::Vector3>::success(
69 Acts::Vector3{bxyz[0] * kGaussToActs, bxyz[1] * kGaussToActs, bxyz[2] * kGaussToActs});
70}
71
72} // namespace o2::acts
Acts::MagneticFieldProvider backed by the O2 field.
Definition of the MagF class.
Acts::Vector3 position
Cache makeCache(const Acts::MagneticFieldContext &mctx) const final
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Cache &cache) const final
void Field(const Double_t *__restrict__ point, Double_t *__restrict__ bField) override
std::vector< Entry > Cache
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"