LDMX Software
TrackingGeometryUser.cxx
1#include "Tracking/Reco/TrackingGeometryUser.h"
2
3#include "Acts/MagneticField/ConstantBField.hpp"
4
5namespace tracking::reco {
6
7TrackingGeometryUser::TrackingGeometryUser(const std::string& name,
9 : framework::Producer(name, p) {}
10
11const Acts::GeometryContext& TrackingGeometryUser::geometryContext() {
12 return getNamedCondition<geo::GeometryContext>().get();
13}
14const Acts::MagneticFieldContext& TrackingGeometryUser::magneticFieldContext() {
15 return getNamedCondition<geo::MagneticFieldContext>().get();
16}
17const Acts::CalibrationContext& TrackingGeometryUser::calibrationContext() {
18 return getNamedCondition<geo::CalibrationContext>().get();
19}
20const geo::TrackersTrackingGeometry& TrackingGeometryUser::geometry() {
21 return getNamedCondition<geo::TrackersTrackingGeometry>();
22}
23
24void TrackingGeometryUser::loadBField(const BFieldDistortion& distortion) {
25 loadBField(geometry().fieldMapFile(), distortion);
26}
27
28void TrackingGeometryUser::loadBField(const std::string& path,
29 const BFieldDistortion& distortion) {
30 if (path.empty()) {
31 ldmx_log(warn) << "No B-field map path provided — using zero B-field";
32 b_field_ =
33 std::make_shared<Acts::ConstantBField>(Acts::Vector3(0., 0., 0.));
34 return;
35 }
36
37 if (distortion.isNominal()) {
38 b_field_ = std::make_shared<InterpolatedMagneticField3>(
39 loadDefaultBField(path, defaultTransformPos, defaultTransformBField));
40 return;
41 }
42
43 const Acts::RotationMatrix3 rot{distortion.rotationMatrix()};
44 const Acts::RotationMatrix3 rot_inv{rot.transpose()};
45 const Acts::Vector3 translation{distortion.translation_};
46 const Acts::Vector3 pivot{distortion.pivot_};
47 const double scale{distortion.scale_};
48
49 // undo the distortion, then the nominal ACTS -> map transform
50 auto transform_pos = [rot_inv, translation, pivot](const Acts::Vector3& pos) {
51 return defaultTransformPos(rot_inv * (pos - translation - pivot) + pivot);
52 };
53 // nominal map -> ACTS transform, then redo the distortion
54 auto transform_b = [rot, scale](const Acts::Vector3& field,
55 const Acts::Vector3& pos) {
56 return Acts::Vector3(scale * (rot * defaultTransformBField(field, pos)));
57 };
58
59 ldmx_log(info) << "B-field distortion active (LDMX frame): translation ("
60 << translation(1) << ", " << translation(2) << ", "
61 << translation(0) << ") mm, rotation ("
62 << distortion.rotation_(1) << ", " << distortion.rotation_(2)
63 << ", " << distortion.rotation_(0) << ") rad about ("
64 << pivot(1) << ", " << pivot(2) << ", " << pivot(0)
65 << ") mm, scale " << scale;
66
67 b_field_ = std::make_shared<InterpolatedMagneticField3>(
68 loadDefaultBField(path, transform_pos, transform_b));
69}
70
71BFieldDistortion TrackingGeometryUser::bFieldDistortion(
72 const framework::config::Parameters& parameters) {
73 const auto translation{
74 parameters.get<std::vector<double>>("bfield_translation", {0., 0., 0.})};
75 const auto rotation{
76 parameters.get<std::vector<double>>("bfield_rotation", {0., 0., 0.})};
77 const auto pivot{parameters.get<std::vector<double>>(
78 "bfield_pivot", {0., 0., -DIPOLE_OFFSET})};
79
80 auto require_three = [](const std::string& name,
81 const std::vector<double>& v) {
82 if (v.size() != 3)
83 EXCEPTION_RAISE("BadConf", name + " must have three entries");
84 };
85 require_three("bfield_translation", translation);
86 require_three("bfield_rotation", rotation);
87 require_three("bfield_pivot", pivot);
88
89 // LDMX (x, y, z) -> ACTS (z, x, y); a cyclic permutation, so the rotation
90 // angles reorder the same way as the positions
91 BFieldDistortion distortion;
92 distortion.translation_ =
93 Acts::Vector3(translation[2], translation[0], translation[1]);
94 distortion.rotation_ = Acts::Vector3(rotation[2], rotation[0], rotation[1]);
95 distortion.pivot_ = Acts::Vector3(pivot[2], pivot[0], pivot[1]);
96 distortion.scale_ = parameters.get<double>("bfield_scale", 1.);
97 return distortion;
98}
99
100} // namespace tracking::reco
Class which represents the process under execution.
Definition Process.h:37
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
All classes in the ldmx-sw project use this namespace.
A deliberate mis-placement of the reconstruction magnetic field, used to quantify how well we need to...
double scale_
overall scaling of the field strength
Acts::Vector3 pivot_
centre of rotation [mm], default the field-map origin
Acts::Vector3 rotation_
rotation about x, y, z through pivot [rad]
Acts::RotationMatrix3 rotationMatrix() const
Rz(gamma) * Ry(beta) * Rx(alpha)
Acts::Vector3 translation_
displacement of the magnet [mm]
bool isNominal() const
Exact comparison on purpose: the nominal case reuses the default transforms unchanged,...