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 Point:
54 case Other:
55 surfaceType = xAOD::SurfaceType::Other;
56 break;
57 }
58
59 Acts::RotationMatrix3 lRotation =
60 surface->localToGlobalTransform(geoContext).rotation();
61 Acts::Vector3 eulerAngles = lRotation.eulerAngles(2, 1, 0);
62 Acts::Vector3 lTranslation = surface->center(geoContext);
63
64 for (int i = 0; i < 3; ++i) {
65 rotation.push_back(eulerAngles[i]);
66 translation.push_back(lTranslation[i]);
67 }
68 // copy and transform double->float
69 const std::vector<double>& values = surface->bounds().values();
70 boundValues.insert(boundValues.end(), values.begin(), values.end());
71}
72
74 const Acts::Surface* surface,
75 const Acts::GeometryContext& geo) {
76 encodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
77 s->boundValues[i], surface, geo);
78}
79
80void encodeSurface(xAOD::TrackSurface* s, const Acts::Surface* surface,
81 const Acts::GeometryContext& geo) {
82 xAOD::SurfaceType surfaceType;
83 std::vector<float> translation, rotation, bounds;
84 encodeSurface(surfaceType, translation, rotation, bounds, surface, geo);
85
86 s->setSurfaceType(surfaceType);
87 s->setTranslation(translation);
88 s->setRotation(rotation);
89 s->setBoundValues(bounds);
90}
91
92std::shared_ptr<const Acts::Surface> decodeSurface(
93 const xAOD::SurfaceType surfaceType, const std::vector<float>& translation,
94 const std::vector<float>& rotation, const std::vector<float>& boundValues) {
95
96 // Translation and rotation
97
98 // create the transformation matrix
99 Amg::Transform3D transform =
100 Amg::getTranslate3D(translation[0], translation[1], translation[2]) *
101 Amg::getRotateZ3D(rotation[0]) *
102 Amg::getRotateY3D(rotation[1]) *
103 Amg::getRotateX3D(rotation[2]);
104
105 switch (surfaceType) {
106 using enum xAOD::SurfaceType;
107 case Cone:
108 return Acts::Surface::makeShared<Acts::ConeSurface>(std::move(transform),
109 boundValues[0], boundValues[1], boundValues[2], boundValues[3]);
110 case Cylinder: {
111 // phi/2 must be slightly < Pi to avoid crashing
112 const float fixedPhi = boundValues[2] > M_PI - 0.001 ? M_PI - 0.001 : boundValues[2];
113 return Acts::Surface::makeShared<Acts::CylinderSurface>(std::move(transform),
114 boundValues[0], boundValues[1], fixedPhi, boundValues[3], boundValues[4]);
115 } case Disc:
116 return Acts::Surface::makeShared<Acts::DiscSurface>(std::move(transform),
117 boundValues[0], boundValues[1], boundValues[2]);
118 case Perigee:
119 return Acts::Surface::makeShared<Acts::PerigeeSurface>(std::move(transform));
120 case Plane: {
121 Acts::Vector2 min(boundValues[0], boundValues[1]),
122 max(boundValues[2], boundValues[3]);
123 auto rBounds = std::make_shared<const Acts::RectangleBounds>(min, max);
124 return Acts::Surface::makeShared<Acts::PlaneSurface>(std::move(transform), rBounds);
125 } case Straw:
126 return Acts::Surface::makeShared<Acts::StrawSurface>(std::move(transform),
127 boundValues[0], boundValues[1]);
128 case Curvilinear:
129 case Other:
130 THROW_EXCEPTION("EncodeSurface this type " <<static_cast<int>(surfaceType)<<
131 " of xAOD::surface cannot be converted into an Acts one");
132 }
133
134 return nullptr;
135}
136
137std::shared_ptr<const Acts::Surface> decodeSurface(const xAOD::TrackSurface* s) {
138 return decodeSurface(s->surfaceType(), s->translation(), s->rotation(),
139 s->boundValues());
140}
141
142std::shared_ptr<const Acts::Surface> decodeSurface(const xAOD::TrackSurfaceAuxContainer* s,
143 size_t i) {
144 return decodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
145 s->boundValues[i]);
146}
147
148} // namespace ActsTrk
149#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