ATLAS Offline Software
Loading...
Searching...
No Matches
SurfaceEncoding.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef SIMULATIONBASE
5
7
9
10#include "Acts/Surfaces/ConeSurface.hpp"
11#include "Acts/Surfaces/CylinderSurface.hpp"
12#include "Acts/Surfaces/DiscSurface.hpp"
13#include "Acts/Surfaces/PerigeeSurface.hpp"
14#include "Acts/Surfaces/PlaneSurface.hpp"
15#include "Acts/Surfaces/RectangleBounds.hpp"
16#include "Acts/Surfaces/StrawSurface.hpp"
17#include "Acts/Surfaces/SurfaceBounds.hpp"
18
19#include <algorithm>
20#include <cmath>
21#include <limits>
22
23namespace {
28double decodeHalfPhiSector(float halfPhiSector) {
29 constexpr double fullAzimuthSnap =
30 std::numeric_limits<float>::epsilon() * M_PI;
31 const double value = halfPhiSector;
32 if (std::abs(value - M_PI) < fullAzimuthSnap) {
33 return M_PI;
34 }
35 return std::clamp(value, 0., M_PI);
36}
37} // namespace
38
39namespace ActsTrk {
41 std::vector<float>& translation,
42 std::vector<float>& rotation,
43 std::vector<float>& boundValues,
44 const Acts::Surface* surface,
45 const Acts::GeometryContext& geoContext) {
46 // return if surf is a nullptr
47 if (!surface) {
48 return;
49 }
50 switch (surface->type()){
51 using enum Acts::Surface::SurfaceType;
52 case Cone:
53 surfaceType = xAOD::SurfaceType::Cone;
54 break;
55 case Cylinder:
56 surfaceType = xAOD::SurfaceType::Cylinder;
57 break;
58 case Disc:
59 surfaceType = xAOD::SurfaceType::Disc;
60 break;
61 case Perigee:
62 surfaceType = xAOD::SurfaceType::Perigee;
63 break;
64 case Plane:
65 surfaceType = xAOD::SurfaceType::Plane;
66 break;
67 case Straw:
68 surfaceType = xAOD::SurfaceType::Straw;
69 break;
70 case Curvilinear:
72 break;
73 case Point:
74 case Other:
75 surfaceType = xAOD::SurfaceType::Other;
76 break;
77 }
78
79 Acts::RotationMatrix3 lRotation =
80 surface->localToGlobalTransform(geoContext).rotation();
81 Acts::Vector3 eulerAngles = lRotation.eulerAngles(2, 1, 0);
82 Acts::Vector3 lTranslation = surface->center(geoContext);
83
84 for (int i = 0; i < 3; ++i) {
85 rotation.push_back(eulerAngles[i]);
86 translation.push_back(lTranslation[i]);
87 }
88 // copy and transform double->float
89 const std::vector<double>& values = surface->bounds().values();
90 boundValues.insert(boundValues.end(), values.begin(), values.end());
91}
92
94 const Acts::Surface* surface,
95 const Acts::GeometryContext& geo) {
96 encodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
97 s->boundValues[i], surface, geo);
98}
99
100void encodeSurface(xAOD::TrackSurface* s, const Acts::Surface* surface,
101 const Acts::GeometryContext& geo) {
102 xAOD::SurfaceType surfaceType;
103 std::vector<float> translation, rotation, bounds;
104 encodeSurface(surfaceType, translation, rotation, bounds, surface, geo);
105
106 s->setSurfaceType(surfaceType);
107 s->setTranslation(translation);
108 s->setRotation(rotation);
109 s->setBoundValues(bounds);
110}
111
112std::shared_ptr<const Acts::Surface> decodeSurface(
113 const xAOD::SurfaceType surfaceType, const std::vector<float>& translation,
114 const std::vector<float>& rotation, const std::vector<float>& boundValues) {
115
116 // Translation and rotation
117
118 // create the transformation matrix
119 Amg::Transform3D transform =
120 Amg::getTranslate3D(translation[0], translation[1], translation[2]) *
121 Amg::getRotateZ3D(rotation[0]) *
122 Amg::getRotateY3D(rotation[1]) *
123 Amg::getRotateX3D(rotation[2]);
124
125 switch (surfaceType) {
126 using enum xAOD::SurfaceType;
127 case Cone:
128 return Acts::Surface::makeShared<Acts::ConeSurface>(std::move(transform),
129 boundValues[0], boundValues[1], boundValues[2],
130 decodeHalfPhiSector(boundValues[3]));
131 case Cylinder:
132 return Acts::Surface::makeShared<Acts::CylinderSurface>(std::move(transform),
133 boundValues[0], boundValues[1], decodeHalfPhiSector(boundValues[2]),
134 boundValues[3], boundValues[4]);
135 case Disc:
136 return Acts::Surface::makeShared<Acts::DiscSurface>(std::move(transform),
137 boundValues[0], boundValues[1], decodeHalfPhiSector(boundValues[2]));
138 case Perigee:
139 return Acts::Surface::makeShared<Acts::PerigeeSurface>(std::move(transform));
140 case Plane: {
141 Acts::Vector2 min(boundValues[0], boundValues[1]),
142 max(boundValues[2], boundValues[3]);
143 auto rBounds = std::make_shared<const Acts::RectangleBounds>(min, max);
144 return Acts::Surface::makeShared<Acts::PlaneSurface>(std::move(transform), rBounds);
145 } case Straw:
146 return Acts::Surface::makeShared<Acts::StrawSurface>(std::move(transform),
147 boundValues[0], boundValues[1]);
148 case Curvilinear:
149 case Other:
150 THROW_EXCEPTION("EncodeSurface this type " <<static_cast<int>(surfaceType)<<
151 " of xAOD::surface cannot be converted into an Acts one");
152 }
153
154 return nullptr;
155}
156
157std::shared_ptr<const Acts::Surface> decodeSurface(const xAOD::TrackSurface* s) {
158 return decodeSurface(s->surfaceType(), s->translation(), s->rotation(),
159 s->boundValues());
160}
161
162std::shared_ptr<const Acts::Surface> decodeSurface(const xAOD::TrackSurfaceAuxContainer* s,
163 size_t i) {
164 return decodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
165 s->boundValues[i]);
166}
167
168} // namespace ActsTrk
169#endif
#define M_PI
ChargedTracksWeightFilter::Spline::Point Point
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
void encodeSurface(xAOD::TrackSurfaceAuxContainer *backend, size_t index, const Acts::Surface *surface, const Acts::GeometryContext &geoContext)
Prepares persistifiable representation of surface into xAOD::TrackSurface object.
std::shared_ptr< const Acts::Surface > decodeSurface(const xAOD::TrackSurface *backend)
Creates transient Acts Surface objects given a surface backend implementation should be exact mirror ...
Amg::Transform3D getRotateX3D(double angle)
Rotate the coordinate system by an angle around the x-axis.
Amg::Transform3D getTranslate3D(const double X, const double Y, const double Z)
: Returns a shift transformation along an arbitrary axis
Amg::Transform3D getRotateZ3D(double angle)
Rotate the coordinate system by an angle around the z-axis.
Eigen::Affine3d Transform3D
Amg::Transform3D getRotateY3D(double angle)
Rotate the coordinate system by an angle around the z-axis.
TrackSurfaceAuxContainer_v1 TrackSurfaceAuxContainer
SurfaceType
This enumerator simplifies the persistency & calculations, by saving a dynamic_cast,...
TrackSurface_v1 TrackSurface
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10