ATLAS Offline Software
Loading...
Searching...
No Matches
SurfaceEncoding.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
19namespace ActsTrk {
21 std::vector<float>& translation,
22 std::vector<float>& rotation,
23 std::vector<float>& boundValues,
24 const Acts::Surface* surface,
25 const Acts::GeometryContext& geoContext) {
26 // return if surf is a nullptr
27 if (!surface) {
28 return;
29 }
30 switch (surface->type()){
31 using enum Acts::Surface::SurfaceType;
32 case Cone:
33 surfaceType = xAOD::SurfaceType::Cone;
34 break;
35 case Cylinder:
36 surfaceType = xAOD::SurfaceType::Cylinder;
37 break;
38 case Disc:
39 surfaceType = xAOD::SurfaceType::Disc;
40 break;
41 case Perigee:
42 surfaceType = xAOD::SurfaceType::Perigee;
43 break;
44 case Plane:
45 surfaceType = xAOD::SurfaceType::Plane;
46 break;
47 case Straw:
48 surfaceType = xAOD::SurfaceType::Straw;
49 break;
50 case Curvilinear:
52 break;
53 case Other:
54 surfaceType = xAOD::SurfaceType::Other;
55 break;
56 }
57
58 Acts::RotationMatrix3 lRotation =
59 surface->transform(geoContext).rotation();
60 Acts::Vector3 eulerAngles = lRotation.eulerAngles(2, 1, 0);
61 Acts::Vector3 lTranslation = surface->center(geoContext);
62
63 for (int i = 0; i < 3; ++i) {
64 rotation.push_back(eulerAngles[i]);
65 translation.push_back(lTranslation[i]);
66 }
67 // copy and transform double->float
68 const std::vector<double>& values = surface->bounds().values();
69 boundValues.insert(boundValues.end(), values.begin(), values.end());
70}
71
73 const Acts::Surface* surface,
74 const Acts::GeometryContext& geo) {
75 encodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
76 s->boundValues[i], surface, geo);
77}
78
79void encodeSurface(xAOD::TrackSurface* s, const Acts::Surface* surface,
80 const Acts::GeometryContext& geo) {
81 xAOD::SurfaceType surfaceType;
82 std::vector<float> translation, rotation, bounds;
83 encodeSurface(surfaceType, translation, rotation, bounds, surface, geo);
84
85 s->setSurfaceType(surfaceType);
86 s->setTranslation(translation);
87 s->setRotation(rotation);
88 s->setBoundValues(bounds);
89}
90
91std::shared_ptr<const Acts::Surface> decodeSurface(
92 const xAOD::SurfaceType surfaceType, const std::vector<float>& translation,
93 const std::vector<float>& rotation, const std::vector<float>& boundValues) {
94
95 // Translation and rotation
96
97 // create the transformation matrix
98 Amg::Transform3D transform =
99 Amg::getTranslate3D(translation[0], translation[1], translation[2]) *
100 Amg::getRotateZ3D(rotation[0]) *
101 Amg::getRotateY3D(rotation[1]) *
102 Amg::getRotateX3D(rotation[2]);
103
104 switch (surfaceType) {
105 using enum xAOD::SurfaceType;
106 case Cone:
107 return Acts::Surface::makeShared<Acts::ConeSurface>(std::move(transform),
108 boundValues[0], boundValues[1], boundValues[2], boundValues[3]);
109 case Cylinder: {
110 // phi/2 must be slightly < Pi to avoid crashing
111 const float fixedPhi = boundValues[2] > M_PI - 0.001 ? M_PI - 0.001 : boundValues[2];
112 return Acts::Surface::makeShared<Acts::CylinderSurface>(std::move(transform),
113 boundValues[0], boundValues[1], fixedPhi, boundValues[3], boundValues[4]);
114 } case Disc:
115 return Acts::Surface::makeShared<Acts::DiscSurface>(std::move(transform),
116 boundValues[0], boundValues[1], boundValues[2]);
117 case Perigee:
118 return Acts::Surface::makeShared<Acts::PerigeeSurface>(std::move(transform));
119 case Plane: {
120 Acts::Vector2 min(boundValues[0], boundValues[1]),
121 max(boundValues[2], boundValues[3]);
122 auto rBounds = std::make_shared<const Acts::RectangleBounds>(min, max);
123 return Acts::Surface::makeShared<Acts::PlaneSurface>(std::move(transform), rBounds);
124 } case Straw:
125 return Acts::Surface::makeShared<Acts::StrawSurface>(std::move(transform),
126 boundValues[0], boundValues[1]);
127 case Curvilinear:
128 case Other:
129 THROW_EXCEPTION("EncodeSurface this type " <<static_cast<int>(surfaceType)<<
130 " of xAOD::surface cannot be converted into an Acts one");
131 }
132
133 return nullptr;
134}
135
136std::shared_ptr<const Acts::Surface> decodeSurface(const xAOD::TrackSurface* s) {
137 return decodeSurface(s->surfaceType(), s->translation(), s->rotation(),
138 s->boundValues());
139}
140
141std::shared_ptr<const Acts::Surface> decodeSurface(const xAOD::TrackSurfaceAuxContainer* s,
142 size_t i) {
143 return decodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
144 s->boundValues[i]);
145}
146
147} // namespace ActsTrk
148#endif
#define M_PI
#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)
get a rotation transformation around 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)
get a rotation transformation around Z-axis
Eigen::Affine3d Transform3D
Amg::Transform3D getRotateY3D(double angle)
get a rotation transformation around Y-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