ATLAS Offline Software
SurfaceEncoding.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 namespace ActsTrk {
7 void encodeSurface(xAOD::SurfaceType& surfaceType,
8  std::vector<float>& translation,
9  std::vector<float>& rotation,
10  std::vector<float>& boundValues,
11  const Acts::Surface* surface,
12  const Acts::GeometryContext& geoContext) {
13  // return if surf is a nullptr
14  if (surface == nullptr) {
15  return;
16  }
17 
18  // surface type specifics
19  if (surface->type() == Acts::Surface::Cone) {
20  surfaceType = xAOD::SurfaceType::Cone;
21  } else if (surface->type() == Acts::Surface::Cylinder) {
22  surfaceType = xAOD::SurfaceType::Cylinder;
23  } else if (surface->type() == Acts::Surface::Disc) {
24  surfaceType = xAOD::SurfaceType::Disc;
25  } else if (surface->type() == Acts::Surface::Perigee) {
26  surfaceType = xAOD::SurfaceType::Perigee;
27  } else if (surface->type() == Acts::Surface::Plane) {
28  surfaceType = xAOD::SurfaceType::Plane;
29  } else if (surface->type() == Acts::Surface::Straw) {
30  surfaceType = xAOD::SurfaceType::Straw;
31  } else {
32  throw std::out_of_range(
33  "encodeSurface this type " +
34  std::to_string(static_cast<int>(surface->type())) +
35  " of Acts Surface can not be saved in xAOD::TrackSurface");
36  return;
37  }
38 
39  Acts::RotationMatrix3 lRotation =
40  surface->transform(geoContext).rotation();
41  Acts::Vector3 eulerAngles = lRotation.eulerAngles(2, 1, 0);
42  Acts::Vector3 lTranslation = surface->center(geoContext);
43 
44  for (int i = 0; i < 3; i++) {
45  rotation.push_back(eulerAngles[i]);
46  translation.push_back(lTranslation[i]);
47  }
48 
49  // copy and transform double->float
50  const std::vector<double>& values = surface->bounds().values();
51  for (double v: values)
52  boundValues.push_back(v);
53 }
54 
56  const Acts::Surface* surface,
57  const Acts::GeometryContext& geo) {
58  encodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
59  s->boundValues[i], surface, geo);
60 }
61 
62 void encodeSurface(xAOD::TrackSurface* s, const Acts::Surface* surface,
63  const Acts::GeometryContext& geo) {
64  xAOD::SurfaceType surfaceType;
65  std::vector<float> translation, rotation, bounds;
66  encodeSurface(surfaceType, translation, rotation, bounds, surface, geo);
67 
68  s->setSurfaceType(surfaceType);
69  s->setTranslation(translation);
70  s->setRotation(rotation);
71  s->setBoundValues(bounds);
72 }
73 
74 std::shared_ptr<const Acts::Surface> decodeSurface(
75  const xAOD::SurfaceType surfaceType, const std::vector<float>& translation,
76  const std::vector<float>& rotation, const std::vector<float>& boundValues,
77  const Acts::GeometryContext&) {
78 
79  // Translation and rotation
80 
81  // create the transformation matrix
82  auto transform = Acts::Transform3(
83  Acts::Translation3(translation[0], translation[1], translation[2]));
84  transform *=
85  Acts::AngleAxis3(rotation[0], Acts::Vector3(0., 0., 1.)); // rotZ
86  transform *=
87  Acts::AngleAxis3(rotation[1], Acts::Vector3(0., 1., 0.)); // rotY
88  transform *=
89  Acts::AngleAxis3(rotation[2], Acts::Vector3(1., 0., 0.)); // rotX
90 
91  // cone
92  if (surfaceType == xAOD::Cone) {
93  auto surface = Acts::Surface::makeShared<Acts::ConeSurface>(
94  transform, boundValues[0], boundValues[1], boundValues[2],
95  boundValues[3]);
96  return surface;
97  }
98  // Cylinder
99  else if (surfaceType == xAOD::Cylinder) {
100  // phi/2 must be slightly < Pi to avoid crashing
101  float fixedPhi =
102  boundValues[2] > M_PI - 0.001 ? M_PI - 0.001 : boundValues[2];
103  auto surface = Acts::Surface::makeShared<Acts::CylinderSurface>(
104  transform, boundValues[0], boundValues[1], fixedPhi, boundValues[3],
105  boundValues[4]);
106  return surface;
107  }
108  // Disc
109  else if (surfaceType == xAOD::Disc) {
110  auto surface = Acts::Surface::makeShared<Acts::DiscSurface>(
111  transform, boundValues[0], boundValues[1], boundValues[2]);
112  return surface;
113  }
114  // Perigee
115  else if (surfaceType == xAOD::Perigee) {
116  auto surface = Acts::Surface::makeShared<Acts::PerigeeSurface>(transform);
117  return surface;
118  }
119  // Plane
120  else if (surfaceType == xAOD::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  auto surface =
125  Acts::Surface::makeShared<Acts::PlaneSurface>(transform, rBounds);
126  return surface;
127  }
128  // Straw
129  else if (surfaceType == xAOD::Straw) {
130  auto surface = Acts::Surface::makeShared<Acts::StrawSurface>(
131  transform, boundValues[0], boundValues[1]);
132  return surface;
133  } else {
134  throw std::out_of_range(
135  "encodeSurface this type " +
136  std::to_string(static_cast<int>(surfaceType)) +
137  " of Acts Surface can not be saved in xAOD::TrackSurface");
138  return nullptr;
139  }
140  return nullptr;
141 }
142 
143 std::shared_ptr<const Acts::Surface> decodeSurface(
144  const xAOD::TrackSurface* s, const Acts::GeometryContext& geo) {
145  return decodeSurface(s->surfaceType(), s->translation(), s->rotation(),
146  s->boundValues(), geo);
147 }
148 
149 std::shared_ptr<const Acts::Surface> decodeSurface(
150  const xAOD::TrackSurfaceAuxContainer* s, size_t i,
151  const Acts::GeometryContext& geo) {
152  return decodeSurface(s->surfaceType[i], s->translation[i], s->rotation[i],
153  s->boundValues[i], geo);
154 }
155 
156 } // namespace ActsTrk
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::SurfaceType
SurfaceType
Definition: TrackingPrimitives.h:551
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:805
xAOD::Cone
@ Cone
Definition: TrackingPrimitives.h:552
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:55
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::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:554
xAOD::Perigee
@ Perigee
Definition: TrackingPrimitives.h:555
xAOD::Straw
@ Straw
Definition: TrackingPrimitives.h:557
xAOD::Cylinder
@ Cylinder
Definition: TrackingPrimitives.h:553
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
ActsTrk::decodeSurface
std::shared_ptr< const Acts::Surface > decodeSurface(const xAOD::TrackSurface *backend, const Acts::GeometryContext &geoContext)
Creates transient Acts Surface objects given a surface backend implementation should be exact mirror ...
Definition: SurfaceEncoding.cxx:143
python.PyAthena.v
v
Definition: PyAthena.py:154
LArCellConditions.geo
bool geo
Definition: LArCellConditions.py:46
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
xAOD::Plane
@ Plane
Definition: TrackingPrimitives.h:556