Analysis Software
Documentation for sPHENIX simulation 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 
17 #include "Acts/MagneticField/SharedBFieldMap.hpp"
18 #include "Acts/MagneticField/concept/AnyFieldLookup.hpp"
28 
29 #include "PropagationTestHelper.hpp"
30 
31 namespace bdata = boost::unit_test::data;
32 namespace tt = boost::test_tools;
33 
34 namespace Acts {
35 
39 
40 namespace IntegrationTest {
41 
42 // Create a mapper from a text file
43 InterpolatedBFieldMap::FieldMapper<3, 3> readFieldXYZ(
44  std::function<size_t(std::array<size_t, 3> binsXYZ,
45  std::array<size_t, 3> nBinsXYZ)>
46  localToGlobalBin,
47  std::string fieldMapFile = "Field.txt", double lengthUnit = 1.,
48  double BFieldUnit = 1., size_t nPoints = 100000, bool firstOctant = false) {
50  // Grid position points in x, y and z
51  std::vector<double> xPos;
52  std::vector<double> yPos;
53  std::vector<double> zPos;
54  // components of magnetic field on grid points
55  std::vector<Acts::Vector3> bField;
56  // reserve estimated size
57  xPos.reserve(nPoints);
58  yPos.reserve(nPoints);
59  zPos.reserve(nPoints);
60  bField.reserve(nPoints);
61  // [1] Read in file and fill values
62  std::ifstream map_file(fieldMapFile.c_str(), std::ios::in);
64  double x = 0., y = 0., z = 0.;
65  double bx = 0., by = 0., bz = 0.;
66  while (std::getline(map_file, line)) {
67  if (line.empty() || line[0] == '%' || line[0] == '#' ||
68  line.find_first_not_of(' ') == std::string::npos)
69  continue;
70 
71  std::istringstream tmp(line);
72  tmp >> x >> y >> z >> bx >> by >> bz;
73  xPos.push_back(x);
74  yPos.push_back(y);
75  zPos.push_back(z);
76  bField.push_back(Acts::Vector3(bx, by, bz));
77  }
78  map_file.close();
79 
80  return fieldMapperXYZ(localToGlobalBin, xPos, yPos, zPos, bField, lengthUnit,
81  BFieldUnit, firstOctant);
82 }
83 
84 // create a bfiel map from a mapper
85 std::shared_ptr<const InterpolatedBFieldMap> atlasBField(
86  std::string fieldMapFile = "Field.txt") {
87  // Declare the mapper
88  Concepts ::AnyFieldLookup<> mapper;
90  double BFieldUnit = UnitConstants::T;
91  // read the field x,y,z from a text file
92  mapper = readFieldXYZ(
93  [](std::array<size_t, 3> binsXYZ, std::array<size_t, 3> nBinsXYZ) {
94  return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2)) +
95  binsXYZ.at(1) * nBinsXYZ.at(2) + binsXYZ.at(2));
96  },
97  fieldMapFile, lengthUnit, BFieldUnit);
98  // create the config
100  config.scale = 1.;
101  config.mapper = std::move(mapper);
102  // make the interpolated field
103  return std::make_shared<const InterpolatedBFieldMap>(std::move(config));
104 }
105 
106 double Bz = 2_T;
107 
113 
114 auto bField = atlasBField("Field.txt");
115 
120 
121 // The actual test - needs to be included to avoid
122 // template inside template definition through boost
123 #include "PropagationTestBase.hpp"
124 
125 } // namespace IntegrationTest
126 
127 } // namespace Acts