Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-06 07:48:56

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 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/MagneticField/InterpolatedBFieldMap.hpp"
0014 #include "Acts/Utilities/AxisDefinitions.hpp"
0015 #include "Acts/Utilities/Grid.hpp"
0016 
0017 #include <array>
0018 #include <cstddef>
0019 #include <functional>
0020 #include <tuple>
0021 #include <utility>
0022 #include <vector>
0023 
0024 // Convenience functions to ease creation of and Acts::InterpolatedBFieldMap
0025 // and to avoid code duplication. Currently implemented for the two most common
0026 // formats: rz and xyz.
0027 
0028 namespace Acts {
0029 
0030 /// @addtogroup magnetic_field
0031 /// @{
0032 
0033 class SolenoidBField;
0034 class ToroidField;
0035 
0036 /// Method to set up the FieldMap
0037 /// @param localToGlobalBin Function mapping the local bins of r,z to the global
0038 /// bin of the map magnetic field value
0039 ///
0040 /// e.g.: we have small grid with the
0041 /// values: r={2,3}, z ={4,5}, the corresponding indices are i (belonging to r)
0042 /// and j (belonging to z), the
0043 /// globalIndex is M (belonging to the value of the magnetic field B(r,z)) and
0044 /// the field map is:
0045 ///|   r |    i |    z |    j |   B(r,z) |   M |
0046 ///|----:|:----:|:----:|:----:|:--------:|:----|
0047 ///|   2 |    0 |    4 |    0 |  2.323   |   0 |
0048 ///|   2 |    0 |    5 |    1 |  2.334   |   1 |
0049 ///|   3 |    1 |    4 |    0 |  2.325   |   2 |
0050 ///|   3 |    1 |    5 |    1 |  2.331   |   3 |
0051 ///
0052 /// In this case the function would look like:
0053 /// @code
0054 /// [](std::array<std::size_t, 2> binsRZ, std::array<std::size_t, 2> nBinsRZ) {
0055 ///    return (binsRZ.at(0) * nBinsRZ.at(1) + binsRZ.at(1));
0056 /// }
0057 /// @endcode
0058 /// @param[in] rPos Values of the grid points in r
0059 /// @note The values do not need to be sorted or unique (this will be done
0060 /// inside the function)
0061 /// @param[in] zPos Values of the grid points in z
0062 /// @note The values do not need to be sorted or unique (this will be done
0063 /// inside the function)
0064 /// @param[in] bField The magnetic field values inr r and z for all given grid
0065 /// points stored in a vector
0066 /// @note The function localToGlobalBin determines how the magnetic field was
0067 /// stored in the vector in respect to the grid values
0068 /// @param[in] lengthUnit The unit of the grid points
0069 /// @param[in] BFieldUnit The unit of the magnetic field
0070 /// @param[in] firstQuadrant Flag if set to true indicating that only the first
0071 /// quadrant of the grid points and the BField values has been given.
0072 /// @note If @p firstQuadrant is true will create a field that is symmetric for all quadrants.
0073 ///       e.g. we have the grid values r={0,1} with BFieldValues={2,3} on the r
0074 ///       axis. If the flag is set to true the r-axis grid values will be set to
0075 ///       {-1,0,1} and the BFieldValues will be set to {3,2,3}.
0076 /// @return A field map instance for use in interpolation.
0077 Acts::InterpolatedBFieldMap<
0078     Acts::Grid<Acts::Vector2, Acts::Axis<Acts::AxisType::Equidistant>,
0079                Acts::Axis<Acts::AxisType::Equidistant>>>
0080 fieldMapRZ(const std::function<std::size_t(std::array<std::size_t, 2> binsRZ,
0081                                            std::array<std::size_t, 2> nBinsRZ)>&
0082                localToGlobalBin,
0083            std::vector<double> rPos, std::vector<double> zPos,
0084            const std::vector<Acts::Vector2>& bField,
0085            double lengthUnit = UnitConstants::mm,
0086            double BFieldUnit = UnitConstants::T, bool firstQuadrant = false);
0087 
0088 /// Method to set up the FieldMap
0089 /// @param localToGlobalBin Function mapping the local bins of x,y,z to the
0090 ///                         global bin of the map magnetic field value
0091 ///
0092 /// e.g.: we have small grid with the
0093 /// values: x={2,3}, y={3,4}, z ={4,5}, the corresponding indices are i
0094 /// (belonging to x), j (belonging to y)
0095 /// and k (belonging to z), the globalIndex is M (belonging to the value of the
0096 /// magnetic field B(x,y,z)) and the field map is:
0097 ///
0098 ///| x   |    i |    y |    j |    z |    k | B(x,y,z) |   M |
0099 ///|----:|:----:|:----:|:----:|:----:|:----:|:--------:|:----|
0100 ///|   2 |    0 |    3 |    0 |    4 |    0 |  2.323   |   0 |
0101 ///|   2 |    0 |    3 |    0 |    5 |    1 |  2.334   |   1 |
0102 ///|   2 |    0 |    4 |    1 |    4 |    0 |  2.325   |   2 |
0103 ///|   2 |    0 |    4 |    1 |    5 |    1 |  2.331   |   3 |
0104 ///|   3 |    1 |    3 |    0 |    4 |    0 |  2.323   |   4 |
0105 ///|   3 |    1 |    3 |    0 |    5 |    1 |  2.334   |   5 |
0106 ///|   3 |    1 |    4 |    1 |    4 |    0 |  2.325   |   6 |
0107 ///|   3 |    1 |    4 |    1 |    5 |    1 |  2.331   |   7 |
0108 ///
0109 /// In this case the function would look like:
0110 /// @code
0111 /// [](std::array<std::size_t, 3> binsXYZ, std::array<std::size_t, 3> nBinsXYZ)
0112 /// {
0113 ///   return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2))
0114 ///        + binsXYZ.at(1) * nBinsXYZ.at(2)
0115 ///        + binsXYZ.at(2));
0116 /// }
0117 /// @endcode
0118 /// @note The grid point values @p xPos, @p yPos and @p zPos do not need to be
0119 ///       sorted or unique (this will be done inside the function)
0120 /// @param[in] xPos Values of the grid points in x
0121 /// @param[in] yPos Values of the grid points in y
0122 /// @param[in] zPos Values of the grid points in z
0123 /// @param[in] bField The magnetic field values inr r and z for all given grid
0124 ///                   points stored in a vector
0125 /// @note The function @p localToGlobalBin determines how the magnetic field was
0126 ///       stored in the vector in respect to the grid values
0127 /// @param[in] lengthUnit The unit of the grid points
0128 /// @param[in] BFieldUnit The unit of the magnetic field
0129 /// @param[in] firstOctant Flag if set to true indicating that only the first
0130 /// octant of the grid points and the BField values has been given.
0131 /// @note If @p firstOctant is true, the function will assume a symmetrical
0132 ///       field for all quadrants.  e.g. we have the grid values z={0,1} with
0133 ///       BFieldValues={2,3} on the r axis.  If the flag is set to true the
0134 ///       z-axis grid values will be set to {-1,0,1} and the BFieldValues will
0135 ///       be set to {3,2,3}.
0136 /// @return A field map instance for use in interpolation.
0137 Acts::InterpolatedBFieldMap<
0138     Acts::Grid<Acts::Vector3, Acts::Axis<Acts::AxisType::Equidistant>,
0139                Acts::Axis<Acts::AxisType::Equidistant>,
0140                Acts::Axis<Acts::AxisType::Equidistant>>>
0141 fieldMapXYZ(
0142     const std::function<std::size_t(std::array<std::size_t, 3> binsXYZ,
0143                                     std::array<std::size_t, 3> nBinsXYZ)>&
0144         localToGlobalBin,
0145     std::vector<double> xPos, std::vector<double> yPos,
0146     std::vector<double> zPos, const std::vector<Acts::Vector3>& bField,
0147     double lengthUnit = UnitConstants::mm, double BFieldUnit = UnitConstants::T,
0148     bool firstOctant = false);
0149 
0150 /// Function which takes an existing SolenoidBField instance and
0151 /// creates a field mapper by sampling grid points from the analytical
0152 /// solenoid field.
0153 ///
0154 /// @param rLim pair of r bounds
0155 /// @param zLim pair of z bounds
0156 /// @param nBins pair of bin counts
0157 /// @param field the solenoid field instance
0158 ///
0159 /// @return A field map instance for use in interpolation.
0160 Acts::InterpolatedBFieldMap<
0161     Acts::Grid<Acts::Vector2, Acts::Axis<Acts::AxisType::Equidistant>,
0162                Acts::Axis<Acts::AxisType::Equidistant>>>
0163 solenoidFieldMap(const std::pair<double, double>& rLim,
0164                  const std::pair<double, double>& zLim,
0165                  const std::pair<std::size_t, std::size_t>& nBins,
0166                  const SolenoidBField& field);
0167 
0168 /// Function which takes an existing ToroidField instance and creates a
0169 /// cylindrical field mapper by sampling grid points from the analytical
0170 /// toroidal field.
0171 ///
0172 /// @param rLim pair of r bounds
0173 /// @param phiLim pair of phi bounds
0174 /// @param zLim pair of z bounds
0175 /// @param nBins tuple of bin counts
0176 /// @param field the toroid field instance
0177 ///
0178 /// @return A field map instance for use in interpolation.
0179 Acts::InterpolatedBFieldMap<
0180     Acts::Grid<Acts::Vector3, Acts::Axis<Acts::AxisType::Equidistant>,
0181                Acts::Axis<Acts::AxisType::Equidistant>,
0182                Acts::Axis<Acts::AxisType::Equidistant>>>
0183 toroidFieldMapCyl(
0184     const std::pair<double, double>& rLim,
0185     const std::pair<double, double>& phiLim,
0186     const std::pair<double, double>& zLim,
0187     const std::tuple<std::size_t, std::size_t, std::size_t>& nBins,
0188     const ToroidField& field);
0189 
0190 /// Function which takes an existing ToroidField instance and creates a
0191 /// Cartesian field mapper by sampling grid points from the analytical toroidal
0192 /// field.
0193 ///
0194 /// @param xLim pair of x bounds
0195 /// @param yLim pair of y bounds
0196 /// @param zLim pair of z bounds
0197 /// @param nBins tuple of bin counts
0198 /// @param field the toroid field instance
0199 ///
0200 /// @return A field map instance for use in interpolation.
0201 Acts::InterpolatedBFieldMap<
0202     Acts::Grid<Acts::Vector3, Acts::Axis<Acts::AxisType::Equidistant>,
0203                Acts::Axis<Acts::AxisType::Equidistant>,
0204                Acts::Axis<Acts::AxisType::Equidistant>>>
0205 toroidFieldMapXYZ(
0206     const std::pair<double, double>& xLim,
0207     const std::pair<double, double>& yLim,
0208     const std::pair<double, double>& zLim,
0209     const std::tuple<std::size_t, std::size_t, std::size_t>& nBins,
0210     const ToroidField& field);
0211 
0212 /// @}
0213 
0214 }  // namespace Acts