ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PropagationTestsAtlasField.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PropagationTestsAtlasField.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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 
9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
11 
15 #include "Acts/MagneticField/SharedBFieldMap.hpp"
16 #include "Acts/MagneticField/concept/AnyFieldLookup.hpp"
25 #include "Acts/Utilities/Units.hpp"
29 
30 namespace bdata = boost::unit_test::data;
31 namespace tt = boost::test_tools;
32 
33 namespace Acts {
34 
38 
39 namespace IntegrationTest {
40 
41 // Create a mapper from the a text file
42 InterpolatedBFieldMap::FieldMapper<3, 3> readFieldXYZ(
43  std::function<size_t(std::array<size_t, 3> binsXYZ,
44  std::array<size_t, 3> nBinsXYZ)>
45  localToGlobalBin,
46  std::string fieldMapFile = "Field.txt", double lengthUnit = 1.,
47  double BFieldUnit = 1., size_t nPoints = 100000, bool firstOctant = false) {
49  // Grid position points in x, y and z
50  std::vector<double> xPos;
51  std::vector<double> yPos;
52  std::vector<double> zPos;
53  // components of magnetic field on grid points
54  std::vector<Acts::Vector3D> bField;
55  // reserve estimated size
56  xPos.reserve(nPoints);
57  yPos.reserve(nPoints);
58  zPos.reserve(nPoints);
59  bField.reserve(nPoints);
60  // [1] Read in file and fill values
61  std::ifstream map_file(fieldMapFile.c_str(), std::ios::in);
62  std::string line;
63  double x = 0., y = 0., z = 0.;
64  double bx = 0., by = 0., bz = 0.;
65  while (std::getline(map_file, line)) {
66  if (line.empty() || line[0] == '%' || line[0] == '#' ||
67  line.find_first_not_of(' ') == std::string::npos)
68  continue;
69 
70  std::istringstream tmp(line);
71  tmp >> x >> y >> z >> bx >> by >> bz;
72  xPos.push_back(x);
73  yPos.push_back(y);
74  zPos.push_back(z);
75  bField.push_back(Acts::Vector3D(bx, by, bz));
76  }
77  map_file.close();
78 
79  return fieldMapperXYZ(localToGlobalBin, xPos, yPos, zPos, bField, lengthUnit,
80  BFieldUnit, firstOctant);
81 }
82 
83 // create a bfiel map from a mapper
84 std::shared_ptr<const InterpolatedBFieldMap> atlasBField(
85  std::string fieldMapFile = "Field.txt") {
86  // Declare the mapper
87  concept ::AnyFieldLookup<> mapper;
88  double lengthUnit = UnitConstants::mm;
89  double BFieldUnit = UnitConstants::T;
90  // read the field x,y,z from a text file
91  mapper = readFieldXYZ(
92  [](std::array<size_t, 3> binsXYZ, std::array<size_t, 3> nBinsXYZ) {
93  return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2)) +
94  binsXYZ.at(1) * nBinsXYZ.at(2) + binsXYZ.at(2));
95  },
96  fieldMapFile, lengthUnit, BFieldUnit);
97  // create the config
99  config.scale = 1.;
100  config.mapper = std::move(mapper);
101  // make the interpolated field
102  return std::make_shared<const InterpolatedBFieldMap>(std::move(config));
103 }
104 
105 double Bz = 2_T;
106 
113 
114 auto bField = atlasBField("Field.txt");
117 
122 
123 // The actual test - needs to be included to avoid
124 // template inside template definition through boost
125 #include "PropagationTestBase.hpp"
126 
127 } // namespace IntegrationTest
128 
129 } // namespace Acts