forked from sPHENIX-Collaboration/acts
/
PropagationTestsAtlasField.cpp
129 lines (112 loc) · 4.48 KB
/
PropagationTestsAtlasField.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This file is part of the Acts project.
//
// Copyright (C) 2017-2018 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/MagneticField/BFieldMapUtils.hpp"
#include "Acts/MagneticField/InterpolatedBFieldMap.hpp"
#include "Acts/MagneticField/SharedBFieldMap.hpp"
#include "Acts/MagneticField/concept/AnyFieldLookup.hpp"
#include "Acts/Propagator/AtlasStepper.hpp"
#include "Acts/Propagator/EigenStepper.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Surfaces/CylinderSurface.hpp"
#include "Acts/Surfaces/DiscSurface.hpp"
#include "Acts/Surfaces/PlaneSurface.hpp"
#include "Acts/Surfaces/StrawSurface.hpp"
#include "Acts/Utilities/Definitions.hpp"
#include "Acts/Utilities/Units.hpp"
#include "Acts/Utilities/detail/Axis.hpp"
#include "Acts/Utilities/detail/Grid.hpp"
#include "PropagationTestHelper.hpp"
namespace bdata = boost::unit_test::data;
namespace tt = boost::test_tools;
namespace Acts {
/// Get the ATLAS field from :
/// http://acts.web.cern.ch/ACTS/data/AtlasField/AtlasField.tar.gz
/// to run this
namespace IntegrationTest {
// Create a mapper from the a text file
InterpolatedBFieldMap::FieldMapper<3, 3> readFieldXYZ(
std::function<size_t(std::array<size_t, 3> binsXYZ,
std::array<size_t, 3> nBinsXYZ)>
localToGlobalBin,
std::string fieldMapFile = "Field.txt", double lengthUnit = 1.,
double BFieldUnit = 1., size_t nPoints = 100000, bool firstOctant = false) {
/// [1] Read in field map file
// Grid position points in x, y and z
std::vector<double> xPos;
std::vector<double> yPos;
std::vector<double> zPos;
// components of magnetic field on grid points
std::vector<Acts::Vector3D> bField;
// reserve estimated size
xPos.reserve(nPoints);
yPos.reserve(nPoints);
zPos.reserve(nPoints);
bField.reserve(nPoints);
// [1] Read in file and fill values
std::ifstream map_file(fieldMapFile.c_str(), std::ios::in);
std::string line;
double x = 0., y = 0., z = 0.;
double bx = 0., by = 0., bz = 0.;
while (std::getline(map_file, line)) {
if (line.empty() || line[0] == '%' || line[0] == '#' ||
line.find_first_not_of(' ') == std::string::npos)
continue;
std::istringstream tmp(line);
tmp >> x >> y >> z >> bx >> by >> bz;
xPos.push_back(x);
yPos.push_back(y);
zPos.push_back(z);
bField.push_back(Acts::Vector3D(bx, by, bz));
}
map_file.close();
return fieldMapperXYZ(localToGlobalBin, xPos, yPos, zPos, bField, lengthUnit,
BFieldUnit, firstOctant);
}
// create a bfiel map from a mapper
std::shared_ptr<const InterpolatedBFieldMap> atlasBField(
std::string fieldMapFile = "Field.txt") {
// Declare the mapper
concept ::AnyFieldLookup<> mapper;
double lengthUnit = UnitConstants::mm;
double BFieldUnit = UnitConstants::T;
// read the field x,y,z from a text file
mapper = readFieldXYZ(
[](std::array<size_t, 3> binsXYZ, std::array<size_t, 3> nBinsXYZ) {
return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2)) +
binsXYZ.at(1) * nBinsXYZ.at(2) + binsXYZ.at(2));
},
fieldMapFile, lengthUnit, BFieldUnit);
// create the config
InterpolatedBFieldMap::Config config;
config.scale = 1.;
config.mapper = std::move(mapper);
// make the interpolated field
return std::make_shared<const InterpolatedBFieldMap>(std::move(config));
}
double Bz = 2_T;
using BFieldType = InterpolatedBFieldMap;
using SharedFieldType = SharedBField<InterpolatedBFieldMap>;
using EigenStepperType = EigenStepper<SharedFieldType>;
using AtlasStepperType = AtlasStepper<SharedFieldType>;
using EigenPropagatorType = Propagator<EigenStepperType>;
using AtlasPropagatorType = Propagator<AtlasStepperType>;
auto bField = atlasBField("Field.txt");
auto bFieldSharedA = SharedFieldType(bField);
auto bFieldSharedE = SharedFieldType(bField);
EigenStepperType estepper(bFieldSharedE);
EigenPropagatorType epropagator(std::move(estepper));
AtlasStepperType astepper(bFieldSharedA);
AtlasPropagatorType apropagator(std::move(astepper));
// The actual test - needs to be included to avoid
// template inside template definition through boost
#include "PropagationTestBase.hpp"
} // namespace IntegrationTest
} // namespace Acts