ATLAS Offline Software
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 
19 namespace ActsTrk {
20 void encodeSurface(xAOD::SurfaceType& surfaceType,
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:
51  surfaceType = xAOD::SurfaceType::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 
79 void 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 
91 std::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
99  Amg::getTranslate3D(translation[0], translation[1], translation[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 
136 std::shared_ptr<const Acts::Surface> decodeSurface(const xAOD::TrackSurface* s) {
137  return decodeSurface(s->surfaceType(), s->translation(), s->rotation(),
138  s->boundValues());
139 }
140 
141 std::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
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::SurfaceType
SurfaceType
Definition: TrackingPrimitives.h:552
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
M_PI
#define M_PI
Definition: ActiveFraction.h:11
xAOD::TrackSurfaceAuxContainer_v1
Definition: TrackSurfaceAuxContainer_v1.h:12
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
Amg::getRotateZ3D
Amg::Transform3D getRotateZ3D(double angle)
get a rotation transformation around Z-axis
Definition: GeoPrimitivesHelpers.h:270
xAOD::Cone
@ Cone
Definition: TrackingPrimitives.h:553
ActsTrk::encodeSurface
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.
Definition: SurfaceEncoding.cxx:72
Amg::getRotateX3D
Amg::Transform3D getRotateX3D(double angle)
get a rotation transformation around X-axis
Definition: GeoPrimitivesHelpers.h:252
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::TrackSurface_v1
TrackSurface for Acts MultiTrajectory and TrackSummary.
Definition: TrackSurface_v1.h:22
SurfaceEncoding.h
xAOD::rotation
rotation
Definition: TrackSurface_v1.cxx:15
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
xAOD::Disc
@ Disc
Definition: TrackingPrimitives.h:555
xAOD::Straw
@ Straw
Definition: TrackingPrimitives.h:558
xAOD::Cylinder
@ Cylinder
Definition: TrackingPrimitives.h:554
xAOD::Curvilinear
@ Curvilinear
Definition: TrackingPrimitives.h:559
Amg::getRotateY3D
Amg::Transform3D getRotateY3D(double angle)
get a rotation transformation around Y-axis
Definition: GeoPrimitivesHelpers.h:261
THROW_EXCEPTION
#define THROW_EXCEPTION(MESSAGE)
Definition: throwExcept.h:10
LArCellConditions.geo
bool geo
Definition: LArCellConditions.py:46
GeoPrimitivesHelpers.h
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MdtCalibInput.h:31
xAOD::Plane
@ Plane
Definition: TrackingPrimitives.h:557
ActsTrk::decodeSurface
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 ...
Definition: SurfaceEncoding.cxx:136
Amg::getTranslate3D
Amg::Transform3D getTranslate3D(const double X, const double Y, const double Z)
: Returns a shift transformation along an arbitrary axis
Definition: GeoPrimitivesHelpers.h:289