EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Surface.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Surface.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2020 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 
10 
12 
13 #include <iomanip>
14 #include <iostream>
15 #include <utility>
16 
18  : GeometryObject(), m_transform(transform) {}
19 
21  : GeometryObject(), m_associatedDetElement(&detelement) {}
22 
24  : GeometryObject(other),
26  m_transform(other.m_transform),
27  m_surfaceMaterial(other.m_surfaceMaterial) {}
28 
30  const Transform3D& shift)
31  : GeometryObject(),
32  m_transform(shift * other.transform(gctx)),
33  m_associatedLayer(nullptr),
34  m_surfaceMaterial(other.m_surfaceMaterial) {}
35 
36 Acts::Surface::~Surface() = default;
37 
39  const Vector3D& position,
40  const Vector3D& momentum,
41  const BoundaryCheck& bcheck) const {
42  // global to local transformation
43  auto lpResult = globalToLocal(gctx, position, momentum);
44  if (lpResult.ok()) {
45  return bcheck ? bounds().inside(lpResult.value(), bcheck) : true;
46  }
47  return false;
48 }
49 
51  const GeometryContext& gctx, const FreeVector& derivatives,
52  const Vector3D& position, const Vector3D& direction) const {
53  // The vector between position and center
54  const ActsRowVector<double, 3> pcRowVec =
55  (position - center(gctx)).transpose();
56  // The local frame rotation
57  const auto& rotation = transform(gctx).rotation();
58  // The axes of local frame
59  const Vector3D localXAxis = rotation.col(0);
60  const Vector3D localYAxis = rotation.col(1);
61  const Vector3D localZAxis = rotation.col(2);
62 
63  // 1) Calcuate the derivative of local frame axes w.r.t its rotation
64  const auto& [rotToLocalXAxis, rotToLocalYAxis, rotToLocalZAxis] =
66  // 2) Calculate the derivative of local 3D Cartesian coordinates w.r.t.
67  // alignment parameters (without path correction)
68  AlignmentToLocalCartesianMatrix alignToLoc3D =
69  AlignmentToLocalCartesianMatrix::Zero();
70  alignToLoc3D.block<1, 3>(eX, eAlignmentCenter0) = -localXAxis.transpose();
71  alignToLoc3D.block<1, 3>(eY, eAlignmentCenter0) = -localYAxis.transpose();
72  alignToLoc3D.block<1, 3>(eZ, eAlignmentCenter0) = -localZAxis.transpose();
73  alignToLoc3D.block<1, 3>(eX, eAlignmentRotation0) =
74  pcRowVec * rotToLocalXAxis;
75  alignToLoc3D.block<1, 3>(eY, eAlignmentRotation0) =
76  pcRowVec * rotToLocalYAxis;
77  alignToLoc3D.block<1, 3>(eZ, eAlignmentRotation0) =
78  pcRowVec * rotToLocalZAxis;
79  // 3) Calculate the derivative of track position represented in
80  // (local) bound track parameters (could be in non-Cartesian coordinates)
81  // w.r.t. track position represented in local 3D Cartesian coordinates.
82  const auto& loc3DToLocBound =
83  localCartesianToBoundLocalDerivative(gctx, position);
84  // 4) Calculate the derivative of path length w.r.t. alignment parameters
85  const auto& alignToPath =
86  alignmentToPathDerivative(gctx, rotToLocalZAxis, position, direction);
87  // 5) Calculate the jacobian from free parameters to bound parameters
88  FreeToBoundMatrix jacToLocal = FreeToBoundMatrix::Zero();
89  initJacobianToLocal(gctx, jacToLocal, position, direction);
90  // 6) Initialize the derivative of bound parameters w.r.t. alignment
91  // parameters
92  AlignmentToBoundMatrix alignToBound = AlignmentToBoundMatrix::Zero();
93  // -> For bound track parameters eBoundLoc0, eBoundLoc1, it's
94  // loc3DToLocBound*alignToLoc3D +
95  // jacToLocal*derivatives*alignToPath
96  alignToBound.block<2, eAlignmentSize>(eBoundLoc0, eAlignmentCenter0) =
97  loc3DToLocBound * alignToLoc3D +
98  jacToLocal.block<2, eFreeSize>(eBoundLoc0, eFreePos0) * derivatives *
99  alignToPath;
100  // -> For bound track parameters eBoundPhi, eBoundTheta, eBoundQOverP,
101  // eBoundTime, it's jacToLocal*derivatives*alignToPath
102  alignToBound.block<4, eAlignmentSize>(eBoundPhi, eAlignmentCenter0) =
103  jacToLocal.block<4, eFreeSize>(eBoundPhi, eFreePos0) * derivatives *
104  alignToPath;
105 
106  return alignToBound;
107 }
108 
110  const GeometryContext& gctx, const RotationMatrix3D& rotToLocalZAxis,
111  const Vector3D& position, const Vector3D& direction) const {
112  // The vector between position and center
113  const ActsRowVector<double, 3> pcRowVec =
114  (position - center(gctx)).transpose();
115  // The local frame rotation
116  const auto& rotation = transform(gctx).rotation();
117  // The local frame z axis
118  const Vector3D localZAxis = rotation.col(2);
119 
120  // Cosine of angle between momentum direction and local frame z axis
121  const double dirZ = localZAxis.dot(direction);
122  // Initialize the derivative of propagation path w.r.t. local frame
123  // translation (origin) and rotation
124  AlignmentRowVector alignToPath = AlignmentRowVector::Zero();
125  alignToPath.segment<3>(eAlignmentCenter0) = localZAxis.transpose() / dirZ;
126  alignToPath.segment<3>(eAlignmentRotation0) =
127  -pcRowVec * rotToLocalZAxis / dirZ;
128 
129  return alignToPath;
130 }
131 
132 std::shared_ptr<Acts::Surface> Acts::Surface::getSharedPtr() {
133  return shared_from_this();
134 }
135 
136 std::shared_ptr<const Acts::Surface> Acts::Surface::getSharedPtr() const {
137  return shared_from_this();
138 }
139 
141  if (&other != this) {
143  // detector element, identifier & layer association are unique
144  m_transform = other.m_transform;
145  m_associatedLayer = other.m_associatedLayer;
146  m_surfaceMaterial = other.m_surfaceMaterial;
147  m_associatedDetElement = other.m_associatedDetElement;
148  }
149  return *this;
150 }
151 
152 bool Acts::Surface::operator==(const Surface& other) const {
153  // (a) fast exit for pointer comparison
154  if (&other == this) {
155  return true;
156  }
157  // (b) fast exit for type
158  if (other.type() != type()) {
159  return false;
160  }
161  // (c) fast exit for bounds
162  if (other.bounds() != bounds()) {
163  return false;
164  }
165  // (d) compare detector elements
166  if (m_associatedDetElement != other.m_associatedDetElement) {
167  return false;
168  }
169  // (e) compare transform values
170  if (!m_transform.isApprox(other.m_transform, 1e-9)) {
171  return false;
172  }
173  // (f) compare material
174  if (m_surfaceMaterial != other.m_surfaceMaterial) {
175  return false;
176  }
177 
178  // we should be good
179  return true;
180 }
181 
182 // overload dump for stream operator
184  std::ostream& sl) const {
185  sl << std::setiosflags(std::ios::fixed);
186  sl << std::setprecision(4);
187  sl << name() << std::endl;
188  const Vector3D& sfcenter = center(gctx);
189  sl << " Center position (x, y, z) = (" << sfcenter.x() << ", "
190  << sfcenter.y() << ", " << sfcenter.z() << ")" << std::endl;
191  Acts::RotationMatrix3D rot(transform(gctx).matrix().block<3, 3>(0, 0));
192  Acts::Vector3D rotX(rot.col(0));
193  Acts::Vector3D rotY(rot.col(1));
194  Acts::Vector3D rotZ(rot.col(2));
195  sl << std::setprecision(6);
196  sl << " Rotation: colX = (" << rotX(0) << ", " << rotX(1)
197  << ", " << rotX(2) << ")" << std::endl;
198  sl << " colY = (" << rotY(0) << ", " << rotY(1)
199  << ", " << rotY(2) << ")" << std::endl;
200  sl << " colZ = (" << rotZ(0) << ", " << rotZ(1)
201  << ", " << rotZ(2) << ")" << std::endl;
202  sl << " Bounds : " << bounds();
203  sl << std::setprecision(-1);
204  return sl;
205 }
206 
208  return !(operator==(sf));
209 }