EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Surface.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Surface.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 inline Vector3D Surface::center(const GeometryContext& gctx) const {
10  // fast access via tranform matrix (and not translation())
11  auto tMatrix = transform(gctx).matrix();
12  return Vector3D(tMatrix(0, 3), tMatrix(1, 3), tMatrix(2, 3));
13 }
14 
15 inline Vector3D Surface::normal(const GeometryContext& gctx,
16  const Vector3D& /*unused*/) const {
17  return normal(gctx, s_origin2D);
18 }
19 
21  const GeometryContext& gctx) const {
22  if (m_associatedDetElement != nullptr) {
23  return m_associatedDetElement->transform(gctx);
24  }
25  return m_transform;
26 }
27 
28 inline bool Surface::insideBounds(const Vector2D& lposition,
29  const BoundaryCheck& bcheck) const {
30  return bounds().inside(lposition, bcheck);
31 }
32 
33 inline RotationMatrix3D Surface::referenceFrame(
34  const GeometryContext& gctx, const Vector3D& /*unused*/,
35  const Vector3D& /*unused*/) const {
36  return transform(gctx).matrix().block<3, 3>(0, 0);
37 }
38 
39 inline void Surface::initJacobianToGlobal(const GeometryContext& gctx,
40  BoundToFreeMatrix& jacobian,
41  const Vector3D& position,
42  const Vector3D& direction,
43  const BoundVector& /*pars*/) const {
44  // The trigonometry required to convert the direction to spherical
45  // coordinates and then compute the sines and cosines again can be
46  // surprisingly expensive from a performance point of view.
47  //
48  // Here, we can avoid it because the direction is by definition a unit
49  // vector, with the following coordinate conversions...
50  const double x = direction(0); // == cos(phi) * sin(theta)
51  const double y = direction(1); // == sin(phi) * sin(theta)
52  const double z = direction(2); // == cos(theta)
53 
54  // ...which we can invert to directly get the sines and cosines:
55  const double cos_theta = z;
56  const double sin_theta = sqrt(x * x + y * y);
57  const double inv_sin_theta = 1. / sin_theta;
58  const double cos_phi = x * inv_sin_theta;
59  const double sin_phi = y * inv_sin_theta;
60  // retrieve the reference frame
61  const auto rframe = referenceFrame(gctx, position, direction);
62  // the local error components - given by reference frame
63  jacobian.topLeftCorner<3, 2>() = rframe.topLeftCorner<3, 2>();
64  // the time component
65  jacobian(3, eBoundTime) = 1;
66  // the momentum components
67  jacobian(4, eBoundPhi) = (-sin_theta) * sin_phi;
68  jacobian(4, eBoundTheta) = cos_theta * cos_phi;
69  jacobian(5, eBoundPhi) = sin_theta * cos_phi;
70  jacobian(5, eBoundTheta) = cos_theta * sin_phi;
71  jacobian(6, eBoundTheta) = (-sin_theta);
72  jacobian(7, eBoundQOverP) = 1;
73 }
74 
75 inline RotationMatrix3D Surface::initJacobianToLocal(
76  const GeometryContext& gctx, FreeToBoundMatrix& jacobian,
77  const Vector3D& position, const Vector3D& direction) const {
78  // Optimized trigonometry on the propagation direction
79  const double x = direction(0); // == cos(phi) * sin(theta)
80  const double y = direction(1); // == sin(phi) * sin(theta)
81  const double z = direction(2); // == cos(theta)
82  // can be turned into cosine/sine
83  const double cosTheta = z;
84  const double sinTheta = sqrt(x * x + y * y);
85  const double invSinTheta = 1. / sinTheta;
86  const double cosPhi = x * invSinTheta;
87  const double sinPhi = y * invSinTheta;
88  // The measurement frame of the surface
89  RotationMatrix3D rframeT =
90  referenceFrame(gctx, position, direction).transpose();
91  // given by the refernece frame
92  jacobian.block<2, 3>(0, 0) = rframeT.block<2, 3>(0, 0);
93  // Time component
94  jacobian(eBoundTime, 3) = 1;
95  // Directional and momentum elements for reference frame surface
96  jacobian(eBoundPhi, 4) = -sinPhi * invSinTheta;
97  jacobian(eBoundPhi, 5) = cosPhi * invSinTheta;
98  jacobian(eBoundTheta, 4) = cosPhi * cosTheta;
99  jacobian(eBoundTheta, 5) = sinPhi * cosTheta;
100  jacobian(eBoundTheta, 6) = -sinTheta;
101  jacobian(eBoundQOverP, 7) = 1;
102  // return the frame where this happened
103  return rframeT;
104 }
105 
106 inline BoundRowVector Surface::derivativeFactors(
107  const GeometryContext& /*unused*/, const Vector3D& /*unused*/,
108  const Vector3D& direction, const RotationMatrix3D& rft,
109  const BoundToFreeMatrix& jacobian) const {
110  // Create the normal and scale it with the projection onto the direction
111  ActsRowVectorD<3> norm_vec = rft.template block<1, 3>(2, 0);
112  norm_vec /= (norm_vec * direction);
113  // calculate the s factors
114  return (norm_vec * jacobian.topLeftCorner<3, eBoundSize>());
115 }
116 
117 inline const DetectorElementBase* Surface::associatedDetectorElement() const {
118  return m_associatedDetElement;
119 }
120 
121 inline const Layer* Surface::associatedLayer() const {
122  return (m_associatedLayer);
123 }
124 
125 inline const ISurfaceMaterial* Surface::surfaceMaterial() const {
126  return m_surfaceMaterial.get();
127 }
128 
129 inline const std::shared_ptr<const ISurfaceMaterial>&
130 Surface::surfaceMaterialSharedPtr() const {
131  return m_surfaceMaterial;
132 }
133 
134 inline void Surface::assignSurfaceMaterial(
135  std::shared_ptr<const ISurfaceMaterial> material) {
136  m_surfaceMaterial = std::move(material);
137 }
138 
139 inline void Surface::associateLayer(const Layer& lay) {
140  m_associatedLayer = (&lay);
141 }